From: gmungoc Date: Fri, 6 Jan 2017 09:03:27 +0000 (+0000) Subject: Merge branch 'develop' into features/JAL-2360colourSchemeApplicability X-Git-Tag: Release_2_10_3b1~357^2~16^2~2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a6875ff6ca7894443c98b1d068f78ea25c5bfc87;hp=-c;p=jalview.git Merge branch 'develop' into features/JAL-2360colourSchemeApplicability --- a6875ff6ca7894443c98b1d068f78ea25c5bfc87 diff --combined src/jalview/datamodel/Alignment.java index 49f6268,90bdcae..a6f2bf4 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@@ -54,7 -54,11 +54,7 @@@ public class Alignment implements Align protected char gapCharacter = '-'; - protected int type = NUCLEOTIDE; - - public static final int PROTEIN = 0; - - public static final int NUCLEOTIDE = 1; + private boolean nucleotide = true; public boolean hasRNAStructure = false; @@@ -72,7 -76,14 +72,7 @@@ hiddenSequences = new HiddenSequences(this); codonFrameList = new ArrayList(); - if (Comparison.isNucleotide(seqs)) - { - type = NUCLEOTIDE; - } - else - { - type = PROTEIN; - } + nucleotide = Comparison.isNucleotide(seqs); sequences = Collections.synchronizedList(new ArrayList()); @@@ -207,9 -218,7 +207,9 @@@ } /** - * Adds a sequence to the alignment. Recalculates maxLength and size. + * Adds a sequence to the alignment. Recalculates maxLength and size. Note + * this currently does not recalculate whether or not the alignment is + * nucleotide, so mixed alignments may have undefined behaviour. * * @param snew */ @@@ -357,17 -366,18 +357,18 @@@ * @see jalview.datamodel.AlignmentI#findGroup(jalview.datamodel.SequenceI) */ @Override - public SequenceGroup findGroup(SequenceI s) + public SequenceGroup findGroup(SequenceI seq, int position) { synchronized (groups) { - for (int i = 0; i < this.groups.size(); i++) + for (SequenceGroup sg : groups) { - SequenceGroup sg = groups.get(i); - - if (sg.getSequences(null).contains(s)) + if (sg.getSequences(null).contains(seq)) { - return sg; + if (position >= sg.getStartRes() && position <= sg.getEndRes()) + { + return sg; + } } } } @@@ -968,9 -978,29 +969,9 @@@ } @Override - public void setNucleotide(boolean b) - { - if (b) - { - type = NUCLEOTIDE; - } - else - { - type = PROTEIN; - } - } - - @Override public boolean isNucleotide() { - if (type == NUCLEOTIDE) - { - return true; - } - else - { - return false; - } + return nucleotide; } @Override @@@ -1561,6 -1591,7 +1562,6 @@@ String calcId, boolean autoCalc, SequenceI seqRef, SequenceGroup groupRef) { - assert (name != null); if (annotations != null) { for (AlignmentAnnotation annot : getAlignmentAnnotation()) @@@ -1592,18 -1623,14 +1593,18 @@@ @Override public Iterable findAnnotation(String calcId) { - ArrayList aa = new ArrayList(); - for (AlignmentAnnotation a : getAlignmentAnnotation()) + List aa = new ArrayList(); + AlignmentAnnotation[] alignmentAnnotation = getAlignmentAnnotation(); + if (alignmentAnnotation != null) { - if (a.getCalcId() == calcId - || (a.getCalcId() != null && calcId != null && a.getCalcId() - .equals(calcId))) + for (AlignmentAnnotation a : alignmentAnnotation) { - aa.add(a); + if (a.getCalcId() == calcId + || (a.getCalcId() != null && calcId != null && a + .getCalcId().equals(calcId))) + { + aa.add(a); + } } } return aa; diff --combined src/jalview/datamodel/AlignmentI.java index 1b5cc0b,2df099a..a0b3ff1 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@@ -156,15 -156,16 +156,16 @@@ public interface AlignmentI extends Ann int findIndex(SequenceI s); /** - * Finds group that given sequence is part of. + * Returns the first group (in the order in which groups were added) that + * includes the given sequence and aligned position (base 0), or null if none + * found * - * @param s - * Sequence in alignment. + * @param seq + * @param position * - * @return First group found for sequence. WARNING : Sequences may be members - * of several groups. This method is incomplete. + * @return */ - SequenceGroup findGroup(SequenceI s); + SequenceGroup findGroup(SequenceI seq, int position); /** * Finds all groups that a given sequence is part of. @@@ -298,6 -299,12 +299,6 @@@ boolean hasRNAStructure(); /** - * Set alignment to be a nucleotide sequence - * - */ - void setNucleotide(boolean b); - - /** * Get the associated dataset for the alignment. * * @return Alignment containing dataset sequences or null of this is a diff --combined test/jalview/datamodel/AlignmentTest.java index 0d6c8ae,618bac5..7af77f5 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@@ -611,12 -611,6 +611,12 @@@ public class AlignmentTes AlignmentAnnotation ann = iter.next(); assertEquals("D.melanogaster.2", ann.sequenceRef.getName()); assertFalse(iter.hasNext()); + + // invalid id + anns = al.findAnnotation("CalcIdForD.melanogaster.?"); + assertFalse(iter.hasNext()); + anns = al.findAnnotation(null); + assertFalse(iter.hasNext()); } @Test(groups = { "Functional" }) @@@ -1137,4 -1131,63 +1137,63 @@@ assertSame(pep.getDatasetSequence(), cds.getDBRefs()[0].map.to); } + @Test(groups = { "Functional" }) + public void testFindGroup() + { + SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI"); + SequenceI seq2 = new Sequence("seq2", "---JKLMNO---"); + AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 }); + + assertNull(a.findGroup(null, 0)); + assertNull(a.findGroup(seq1, 1)); + assertNull(a.findGroup(seq1, -1)); + + /* + * add a group consisting of just "DEF" + */ + SequenceGroup sg1 = new SequenceGroup(); + sg1.addSequence(seq1, false); + sg1.setStartRes(3); + sg1.setEndRes(5); + a.addGroup(sg1); + + assertNull(a.findGroup(seq1, 2)); // position not in group + assertNull(a.findGroup(seq1, 6)); // position not in group + assertNull(a.findGroup(seq2, 5)); // sequence not in group + assertSame(a.findGroup(seq1, 3), sg1); // yes + assertSame(a.findGroup(seq1, 4), sg1); + assertSame(a.findGroup(seq1, 5), sg1); + + /* + * add a group consisting of + * EF-- + * KLMN + */ + SequenceGroup sg2 = new SequenceGroup(); + sg2.addSequence(seq1, false); + sg2.addSequence(seq2, false); + sg2.setStartRes(4); + sg2.setEndRes(7); + a.addGroup(sg2); + + assertNull(a.findGroup(seq1, 2)); // unchanged + assertSame(a.findGroup(seq1, 3), sg1); // unchanged + /* + * if a residue is in more than one group, method returns + * the first found (in order groups were added) + */ + assertSame(a.findGroup(seq1, 4), sg1); + assertSame(a.findGroup(seq1, 5), sg1); + + /* + * seq2 only belongs to the second group + */ + assertSame(a.findGroup(seq2, 4), sg2); + assertSame(a.findGroup(seq2, 5), sg2); + assertSame(a.findGroup(seq2, 6), sg2); + assertSame(a.findGroup(seq2, 7), sg2); + assertNull(a.findGroup(seq2, 3)); + assertNull(a.findGroup(seq2, 8)); + } + }