From: gmungoc Date: Mon, 5 Sep 2016 15:13:31 +0000 (+0100) Subject: JAL-2106 increased coverage for testGetPrimaryDbRefs X-Git-Tag: Release_2_10_0~47^2~4^2~12 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=e44876a5a8801c0118b67793ebd57d21079be7b0 JAL-2106 increased coverage for testGetPrimaryDbRefs --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 0018ea1..b50e5af 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -28,6 +28,7 @@ import jalview.util.StringUtils; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Vector; @@ -1422,12 +1423,12 @@ public class Sequence extends ASequence implements SequenceI } if (dbrefs==null || dbrefs.length==0) { - return Arrays.asList(new DBRefEntry[0]); + return Collections.emptyList(); } synchronized (dbrefs) { List primaries = new ArrayList(); - DBRefEntry tmp[] = new DBRefEntry[1], res[] = null; + DBRefEntry[] tmp = new DBRefEntry[1]; for (DBRefEntry ref : dbrefs) { if (!ref.isPrimary()) @@ -1462,7 +1463,7 @@ public class Sequence extends ASequence implements SequenceI } // check standard protein or dna sources tmp[0] = ref; - res = DBRefUtils.selectDbRefs(!isProtein(), tmp); + DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp); if (res != null && res[0] == tmp[0]) { primaries.add(ref); diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 0a1ca67..c7e53a9 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -768,32 +768,120 @@ public class SequenceTest } @Test(groups = { "Functional" }) - public void testGetPrimaryDBRefs() + public void testGetPrimaryDBRefs_peptide() { - /* - * test PDB relationships for for getPrimaryDBRefs - */ - SequenceI seq = new Sequence("aseq", "ASDF"); - DBRefEntry upentry = new DBRefEntry("UNIPROT", "0", "1qip"); + SequenceI sq = new Sequence("aseq", "ASDFKYLMQPRST", 10, 22); + + // no dbrefs + List primaryDBRefs = sq.getPrimaryDBRefs(); + assertTrue(primaryDBRefs.isEmpty()); + + // empty dbrefs + sq.setDBRefs(new DBRefEntry[] {}); + primaryDBRefs = sq.getPrimaryDBRefs(); + assertTrue(primaryDBRefs.isEmpty()); + // primary - uniprot - seq.addDBRef(upentry); + DBRefEntry upentry1 = new DBRefEntry("UNIPROT", "0", "Q04760"); + sq.addDBRef(upentry1); + + // primary - uniprot with congruent map + DBRefEntry upentry2 = new DBRefEntry("UNIPROT", "0", "Q04762"); + upentry2.setMap(new Mapping(null, new MapList(new int[] { 10, 22 }, + new int[] { 10, 22 }, 1, 1))); + sq.addDBRef(upentry2); + + // primary - uniprot with map of enclosing sequence + DBRefEntry upentry3 = new DBRefEntry("UNIPROT", "0", "Q04763"); + upentry3.setMap(new Mapping(null, new MapList(new int[] { 8, 24 }, + new int[] { 8, 24 }, 1, 1))); + sq.addDBRef(upentry3); + + // not primary - uniprot with map of sub-sequence (5') + DBRefEntry upentry4 = new DBRefEntry("UNIPROT", "0", "Q04764"); + upentry4.setMap(new Mapping(null, new MapList(new int[] { 10, 18 }, + new int[] { 10, 18 }, 1, 1))); + sq.addDBRef(upentry4); + + // not primary - uniprot with map that overlaps 3' + DBRefEntry upentry5 = new DBRefEntry("UNIPROT", "0", "Q04765"); + upentry5.setMap(new Mapping(null, new MapList(new int[] { 12, 22 }, + new int[] { 12, 22 }, 1, 1))); + sq.addDBRef(upentry5); + + // not primary - uniprot with map to different coordinates frame + DBRefEntry upentry6 = new DBRefEntry("UNIPROT", "0", "Q04766"); + upentry6.setMap(new Mapping(null, new MapList(new int[] { 12, 18 }, + new int[] { 112, 118 }, 1, 1))); + sq.addDBRef(upentry6); + + // not primary - dbref to 'non-core' database + DBRefEntry upentry7 = new DBRefEntry("Pfam", "0", "PF00903"); + sq.addDBRef(upentry7); + // primary - type is PDB DBRefEntry pdbentry = new DBRefEntry("PDB", "0", "1qip"); - seq.addDBRef(pdbentry); + sq.addDBRef(pdbentry); + // not primary - PDBEntry has no file - seq.addDBRef(new DBRefEntry("PDB", "0", "1AAA")); + sq.addDBRef(new DBRefEntry("PDB", "0", "1AAA")); + // not primary - no PDBEntry - seq.addDBRef(new DBRefEntry("PDB", "0", "1DDD")); - // add corroborating PDB entry for primary DBref - needs to have a file as - // well as matching ID - seq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah") + sq.addDBRef(new DBRefEntry("PDB", "0", "1DDD")); + + // add corroborating PDB entry for primary DBref - + // needs to have a file as well as matching ID + // note PDB ID is not treated as case sensitive + sq.addPDBId(new PDBEntry("1QIP", null, Type.PDB, new File("/blah") .toString())); + // not valid DBRef - no file.. - seq.addPDBId(new PDBEntry("1AAA", null, null, null)); - assertTrue("Couldn't find simple primary reference (UNIPROT)", seq - .getPrimaryDBRefs().contains(upentry)); - assertTrue("Couldn't find expected PDB primary reference", seq - .getPrimaryDBRefs().contains(pdbentry)); - assertEquals(2, seq.getPrimaryDBRefs().size()); + sq.addPDBId(new PDBEntry("1AAA", null, null, null)); + + primaryDBRefs = sq.getPrimaryDBRefs(); + assertEquals(4, primaryDBRefs.size()); + assertTrue("Couldn't find simple primary reference (UNIPROT)", + primaryDBRefs.contains(upentry1)); + assertTrue("Couldn't find mapped primary reference (UNIPROT)", + primaryDBRefs.contains(upentry2)); + assertTrue("Couldn't find mapped context reference (UNIPROT)", + primaryDBRefs.contains(upentry3)); + assertTrue("Couldn't find expected PDB primary reference", + primaryDBRefs.contains(pdbentry)); + } + + @Test(groups = { "Functional" }) + public void testGetPrimaryDBRefs_nucleotide() + { + SequenceI sq = new Sequence("aseq", "TGATCACTCGACTAGCATCAGCATA", 10, 34); + + // primary - Ensembl + DBRefEntry dbr1 = new DBRefEntry("ENSEMBL", "0", "ENSG1234"); + sq.addDBRef(dbr1); + + // not primary - Ensembl 'transcript' mapping of sub-sequence + DBRefEntry dbr2 = new DBRefEntry("ENSEMBL", "0", "ENST1234"); + dbr2.setMap(new Mapping(null, new MapList(new int[] { 15, 25 }, + new int[] { 1, 11 }, 1, 1))); + sq.addDBRef(dbr2); + + // primary - EMBL with congruent map + DBRefEntry dbr3 = new DBRefEntry("EMBL", "0", "J1234"); + dbr3.setMap(new Mapping(null, new MapList(new int[] { 10, 34 }, + new int[] { 10, 34 }, 1, 1))); + sq.addDBRef(dbr3); + + // not primary - to non-core database + DBRefEntry dbr4 = new DBRefEntry("CCDS", "0", "J1234"); + sq.addDBRef(dbr4); + + // not primary - to protein + DBRefEntry dbr5 = new DBRefEntry("UNIPROT", "0", "Q87654"); + sq.addDBRef(dbr5); + + List primaryDBRefs = sq.getPrimaryDBRefs(); + assertEquals(2, primaryDBRefs.size()); + assertTrue(primaryDBRefs.contains(dbr1)); + assertTrue(primaryDBRefs.contains(dbr3)); } }