X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=1134857428850bf8e49716f31013e37c56b2c37b;hb=ddcce112558a130196ca384c4683b4f9b7d7d133;hp=3f9f03ff230b2d5d44282896a18bde9f4bd697b1;hpb=2acdd7fdaa575dd5238585ad86597f808b30d281;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 3f9f03f..1134857 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -22,13 +22,14 @@ package jalview.datamodel; import jalview.analysis.AlignmentUtils; import jalview.io.FastaFile; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,8 +48,7 @@ public class Alignment implements AlignmentI protected List sequences; - protected List groups = java.util.Collections - .synchronizedList(new ArrayList()); + protected List groups; protected char gapCharacter = '-'; @@ -60,20 +60,21 @@ public class Alignment implements AlignmentI public boolean hasRNAStructure = false; - /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; - HiddenSequences hiddenSequences = new HiddenSequences(this); + HiddenSequences hiddenSequences; public Hashtable alignmentProperties; - private Set codonFrameList = new LinkedHashSet(); + private List codonFrameList; private void initAlignment(SequenceI[] seqs) { - int i = 0; + groups = Collections.synchronizedList(new ArrayList()); + hiddenSequences = new HiddenSequences(this); + codonFrameList = new ArrayList(); - if (jalview.util.Comparison.isNucleotide(seqs)) + if (Comparison.isNucleotide(seqs)) { type = NUCLEOTIDE; } @@ -82,10 +83,9 @@ public class Alignment implements AlignmentI type = PROTEIN; } - sequences = java.util.Collections - .synchronizedList(new ArrayList()); + sequences = Collections.synchronizedList(new ArrayList()); - for (i = 0; i < seqs.length; i++) + for (int i = 0; i < seqs.length; i++) { sequences.add(seqs[i]); } @@ -104,13 +104,12 @@ public class Alignment implements AlignmentI seqs[i] = new Sequence(seqs[i]); } + initAlignment(seqs); + /* - * Share the same dataset sequence mappings (if any). TODO: find a better - * place for these to live (alignment dataset?). + * Share the same dataset sequence mappings (if any). */ this.setCodonFrames(al.getCodonFrames()); - - initAlignment(seqs); } /** @@ -1281,8 +1280,8 @@ public class Alignment implements AlignmentI @Override public void addCodonFrame(AlignedCodonFrame codons) { - Set acfs = getCodonFrames(); - if (codons != null && acfs != null) + List acfs = getCodonFrames(); + if (codons != null && acfs != null && !acfs.contains(codons)) { acfs.add(codons); } @@ -1319,7 +1318,7 @@ public class Alignment implements AlignmentI * @see jalview.datamodel.AlignmentI#setCodonFrames() */ @Override - public void setCodonFrames(Set acfs) + public void setCodonFrames(List acfs) { if (dataset != null) { @@ -1339,7 +1338,7 @@ public class Alignment implements AlignmentI * @see jalview.datamodel.AlignmentI#getCodonFrames() */ @Override - public Set getCodonFrames() + public List getCodonFrames() { return dataset != null ? dataset.getCodonFrames() : codonFrameList; } @@ -1351,7 +1350,7 @@ public class Alignment implements AlignmentI @Override public boolean removeCodonFrame(AlignedCodonFrame codons) { - Set acfs = getCodonFrames(); + List acfs = getCodonFrames(); if (codons == null || acfs == null) { return false; @@ -1770,4 +1769,46 @@ public class Alignment implements AlignmentI } return hasValidSeq; } + + /** + * Update any mappings to 'virtual' sequences to compatible real ones, if + * present in the added sequences. Returns a count of mappings updated. + * + * @param seqs + * @return + */ + @Override + public int realiseMappings(List seqs) + { + int count = 0; + for (SequenceI seq : seqs) + { + for (AlignedCodonFrame mapping : getCodonFrames()) + { + count += mapping.realiseWith(seq); + } + } + return count; + } + + /** + * Returns the first AlignedCodonFrame that has a mapping between the given + * dataset sequences + * + * @param mapFrom + * @param mapTo + * @return + */ + @Override + public AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo) + { + for (AlignedCodonFrame acf : getCodonFrames()) + { + if (acf.getAaForDnaSeq(mapFrom) == mapTo) + { + return acf; + } + } + return null; + } }