From 07bb0da70ad46444f5f9bc0b2fa80e9ee3805394 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 30 Mar 2015 15:18:25 +0100 Subject: [PATCH] JAL-1264 remove broken applet build dependencies --- src/jalview/analysis/AlignmentUtils.java | 48 +++++++++++++++- src/jalview/analysis/CrossRef.java | 43 -------------- src/jalview/analysis/Dna.java | 22 +++----- test/jalview/analysis/AlignmentUtilsTests.java | 59 +++++++++++++++++++ test/jalview/analysis/CrossRefTest.java | 72 ------------------------ 5 files changed, 113 insertions(+), 131 deletions(-) delete mode 100644 test/jalview/analysis/CrossRefTest.java diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 6f0125d..b78afeb 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -37,6 +37,7 @@ import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; import jalview.datamodel.Mapping; import jalview.datamodel.SearchResults; import jalview.datamodel.Sequence; @@ -282,7 +283,7 @@ public class AlignmentUtils * many-to-many, as that would risk mixing species with similar cDNA * sequences. */ - if (xrefsOnly && !CrossRef.haveCrossRef(aaSeq, cdnaSeq)) + if (xrefsOnly && !AlignmentUtils.haveCrossRef(aaSeq, cdnaSeq)) { continue; } @@ -1212,4 +1213,49 @@ public class AlignmentUtils } } } + + /** + * Returns true if either sequence has a cross-reference to the other + * + * @param seq1 + * @param seq2 + * @return + */ + public static boolean haveCrossRef(SequenceI seq1, SequenceI seq2) + { + // Note: moved here from class CrossRef as the latter class has dependencies + // not availability to the applet's classpath + return hasCrossRef(seq1, seq2) || hasCrossRef(seq2, seq1); + } + + /** + * Returns true if seq1 has a cross-reference to seq2. Currently this assumes + * that sequence name is structured as Source|AccessId. + * + * @param seq1 + * @param seq2 + * @return + */ + public static boolean hasCrossRef(SequenceI seq1, SequenceI seq2) + { + if (seq1 == null || seq2 == null) + { + return false; + } + String name = seq2.getName(); + final DBRefEntry[] xrefs = seq1.getDBRef(); + if (xrefs != null) + { + for (DBRefEntry xref : xrefs) + { + String xrefName = xref.getSource() + "|" + xref.getAccessionId(); + // case-insensitive test, consistent with DBRefEntry.equalRef() + if (xrefName.equalsIgnoreCase(name)) + { + return true; + } + } + } + return false; + } } diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index eed2d7e..47bd7bc 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -583,49 +583,6 @@ public class CrossRef } /** - * Returns true if either sequence has a cross-reference to the other - * - * @param seq1 - * @param seq2 - * @return - */ - public static boolean haveCrossRef(SequenceI seq1, SequenceI seq2) - { - return hasCrossRef(seq1, seq2) || hasCrossRef(seq2, seq1); - } - - /** - * Returns true if seq1 has a cross-reference to seq2. Currently this assumes - * that sequence name is structured as Source|AccessId. - * - * @param seq1 - * @param seq2 - * @return - */ - public static boolean hasCrossRef(SequenceI seq1, SequenceI seq2) - { - if (seq1 == null || seq2 == null) - { - return false; - } - String name = seq2.getName(); - final DBRefEntry[] xrefs = seq1.getDBRef(); - if (xrefs != null) - { - for (DBRefEntry xref : xrefs) - { - String xrefName = xref.getSource() + "|" + xref.getAccessionId(); - // case-insensitive test, consistent with DBRefEntry.equalRef() - if (xrefName.equalsIgnoreCase(name)) - { - return true; - } - } - } - return false; - } - - /** * precalculate different products that can be found for seqs in dataset and * return them. * diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index ab606f7..1d5f996 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -20,8 +20,13 @@ */ package jalview.analysis; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + import jalview.api.AlignViewportI; -import jalview.bin.Cache; import jalview.datamodel.AlignedCodon; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; @@ -42,12 +47,6 @@ import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.ShiftList; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Map; - public class Dna { private static final String STOP_X = "X"; @@ -617,14 +616,7 @@ public class Dna if (rf != 0) { final String errMsg = "trimming contigs for incomplete terminal codon."; - if (Cache.log != null) - { - Cache.log.debug(errMsg); - } - else - { - System.err.println(errMsg); - } + System.err.println(errMsg); // map and trim contigs to ORF region vc = scontigs.length - 1; lastnpos = vismapping.shift(lastnpos); // place npos in context of diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index bc6a137..71b1bcb 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -810,4 +810,63 @@ public class AlignmentUtilsTests assertFalse(ann5.visible); assertTrue(ann6.visible); // not sequence-related, not affected } + + /** + * Tests for the method that checks if one sequence cross-references another + */ + @Test + public void testHasCrossRef() + { + assertFalse(AlignmentUtils.hasCrossRef(null, null)); + SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF"); + assertFalse(AlignmentUtils.hasCrossRef(seq1, null)); + assertFalse(AlignmentUtils.hasCrossRef(null, seq1)); + SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF"); + assertFalse(AlignmentUtils.hasCrossRef(seq1, seq2)); + + // different ref + seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20193")); + assertFalse(AlignmentUtils.hasCrossRef(seq1, seq2)); + + // case-insensitive; version number is ignored + seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20192")); + assertTrue(AlignmentUtils.hasCrossRef(seq1, seq2)); + + // right case! + seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); + assertTrue(AlignmentUtils.hasCrossRef(seq1, seq2)); + // test is one-way only + assertFalse(AlignmentUtils.hasCrossRef(seq2, seq1)); + } + + /** + * Tests for the method that checks if either sequence cross-references the + * other + */ + @Test + public void testHaveCrossRef() + { + assertFalse(AlignmentUtils.hasCrossRef(null, null)); + SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF"); + assertFalse(AlignmentUtils.haveCrossRef(seq1, null)); + assertFalse(AlignmentUtils.haveCrossRef(null, seq1)); + SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF"); + assertFalse(AlignmentUtils.haveCrossRef(seq1, seq2)); + + seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); + assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2)); + // next is true for haveCrossRef, false for hasCrossRef + assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1)); + + // now the other way round + seq1.setDBRef(null); + seq2.addDBRef(new DBRefEntry("EMBL", "1", "A12345")); + assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2)); + assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1)); + + // now both ways + seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); + assertTrue(AlignmentUtils.haveCrossRef(seq1, seq2)); + assertTrue(AlignmentUtils.haveCrossRef(seq2, seq1)); + } } diff --git a/test/jalview/analysis/CrossRefTest.java b/test/jalview/analysis/CrossRefTest.java deleted file mode 100644 index 2ae4afc..0000000 --- a/test/jalview/analysis/CrossRefTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package jalview.analysis; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import jalview.datamodel.DBRefEntry; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceI; - -import org.junit.Test; - -public class CrossRefTest -{ - - /** - * Tests for the method that checks if one sequence cross-references another - */ - @Test - public void testHasCrossRef() - { - assertFalse(CrossRef.hasCrossRef(null, null)); - SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF"); - assertFalse(CrossRef.hasCrossRef(seq1, null)); - assertFalse(CrossRef.hasCrossRef(null, seq1)); - SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF"); - assertFalse(CrossRef.hasCrossRef(seq1, seq2)); - - // different ref - seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20193")); - assertFalse(CrossRef.hasCrossRef(seq1, seq2)); - - // case-insensitive; version number is ignored - seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "v20192")); - assertTrue(CrossRef.hasCrossRef(seq1, seq2)); - - // right case! - seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); - assertTrue(CrossRef.hasCrossRef(seq1, seq2)); - // test is one-way only - assertFalse(CrossRef.hasCrossRef(seq2, seq1)); - } - - /** - * Tests for the method that checks if either sequence cross-references the - * other - */ - @Test - public void testHaveCrossRef() - { - assertFalse(CrossRef.hasCrossRef(null, null)); - SequenceI seq1 = new Sequence("EMBL|A12345", "ABCDEF"); - assertFalse(CrossRef.haveCrossRef(seq1, null)); - assertFalse(CrossRef.haveCrossRef(null, seq1)); - SequenceI seq2 = new Sequence("UNIPROT|V20192", "ABCDEF"); - assertFalse(CrossRef.haveCrossRef(seq1, seq2)); - - seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); - assertTrue(CrossRef.haveCrossRef(seq1, seq2)); - // next is true for haveCrossRef, false for hasCrossRef - assertTrue(CrossRef.haveCrossRef(seq2, seq1)); - - // now the other way round - seq1.setDBRef(null); - seq2.addDBRef(new DBRefEntry("EMBL", "1", "A12345")); - assertTrue(CrossRef.haveCrossRef(seq1, seq2)); - assertTrue(CrossRef.haveCrossRef(seq2, seq1)); - - // now both ways - seq1.addDBRef(new DBRefEntry("UNIPROT", "1", "V20192")); - assertTrue(CrossRef.haveCrossRef(seq1, seq2)); - assertTrue(CrossRef.haveCrossRef(seq2, seq1)); - } -} -- 1.7.10.2