X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignment.java;h=01d3d8d626f1eb53767631146123f43687d57bdd;hb=b948e764c92b0954100f216927114b2c9720b76c;hp=9cd44c320625d30e786c23d9ed7380ca478e2fa7;hpb=0163e98c7c067236a8ef7080860db5376f4ce0ef;p=jalview.git diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 9cd44c3..01d3d8d 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1,24 +1,33 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1) + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along with Jalview. If not, see . + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.datamodel; -import java.util.*; +import jalview.util.MessageManager; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Vector; /** * Data structure to hold and manipulate a multiple sequence alignment @@ -110,7 +119,7 @@ public class Alignment implements AlignmentI */ public static AlignmentI createAlignment(CigarArray compactAlignment) { - throw new Error("Alignment(CigarArray) not yet implemented"); + throw new Error(MessageManager.getString("error.alignment_cigararray_not_implemented")); // this(compactAlignment.refCigars); } @@ -138,7 +147,9 @@ public class Alignment implements AlignmentI public SequenceI[] getSequencesArray() { if (sequences == null) + { return null; + } synchronized (sequences) { return sequences.toArray(new SequenceI[sequences.size()]); @@ -202,7 +213,9 @@ public class Alignment implements AlignmentI } } if (hiddenSequences != null) + { hiddenSequences.adjustHeightSequenceAdded(); + } } /** @@ -236,7 +249,9 @@ public class Alignment implements AlignmentI public void finalize() { if (getDataset() != null) + { getDataset().removeAlignmentRef(); + } dataset = null; sequences = null; @@ -446,7 +461,8 @@ public class Alignment implements AlignmentI { removeAnnotationForGroup(null); } - for (SequenceGroup sg:groups) { + for (SequenceGroup sg : groups) + { sg.setContext(null); } groups.clear(); @@ -744,7 +760,9 @@ public class Alignment implements AlignmentI continue; } if (tIndex < temp.length) + { temp[tIndex++] = annotations[i]; + } } if (swap) @@ -940,6 +958,27 @@ public class Alignment implements AlignmentI else if (dataset == null && data != null) { dataset = data; + for (int i = 0; i < getHeight(); i++) + { + SequenceI currentSeq = getSequenceAt(i); + SequenceI dsq = currentSeq.getDatasetSequence(); + if (dsq == null) + { + dsq = currentSeq.createDatasetSequence(); + dataset.addSequence(dsq); + } + else + { + while (dsq.getDatasetSequence() != null) + { + dsq = dsq.getDatasetSequence(); + } + if (dataset.findIndex(dsq) == -1) + { + dataset.addSequence(dsq); + } + } + } } dataset.addAlignmentRef(); } @@ -1140,7 +1179,9 @@ public class Alignment implements AlignmentI public void setProperty(Object key, Object value) { if (alignmentProperties == null) + { alignmentProperties = new Hashtable(); + } alignmentProperties.put(key, value); } @@ -1149,9 +1190,13 @@ public class Alignment implements AlignmentI public Object getProperty(Object key) { if (alignmentProperties != null) + { return alignmentProperties.get(key); + } else + { return null; + } } @Override @@ -1173,7 +1218,9 @@ public class Alignment implements AlignmentI public void addCodonFrame(AlignedCodonFrame codons) { if (codons == null) + { return; + } if (codonFrameList == null) { codonFrameList = new AlignedCodonFrame[] @@ -1207,15 +1254,21 @@ public class Alignment implements AlignmentI public AlignedCodonFrame[] getCodonFrame(SequenceI seq) { if (seq == null || codonFrameList == null) + { return null; + } Vector cframes = new Vector(); for (int f = 0; f < codonFrameList.length; f++) { if (codonFrameList[f].involvesSequence(seq)) + { cframes.addElement(codonFrameList[f]); + } } if (cframes.size() == 0) + { return null; + } AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()]; cframes.copyInto(cfr); return cfr; @@ -1242,7 +1295,9 @@ public class Alignment implements AlignmentI public boolean removeCodonFrame(AlignedCodonFrame codons) { if (codons == null || codonFrameList == null) + { return false; + } boolean removed = false; int i = 0, iSize = codonFrameList.length; while (i < iSize) @@ -1434,6 +1489,27 @@ public class Alignment implements AlignmentI return aa; } + /** + * Returns an iterable collection of any annotations that match on given + * sequence ref, calcId and label (ignoring null values). + */ + @Override + public Iterable findAnnotations(SequenceI seq, + String calcId, String label) + { + ArrayList aa = new ArrayList(); + for (AlignmentAnnotation ann : getAlignmentAnnotation()) + { + if (ann.getCalcId() != null && ann.getCalcId().equals(calcId) + && ann.sequenceRef != null && ann.sequenceRef == seq + && ann.label != null && ann.label.equals(label)) + { + aa.add(ann); + } + } + return aa; + } + @Override public void moveSelectedSequencesByOne(SequenceGroup sg, Map map, boolean up) @@ -1484,15 +1560,17 @@ public class Alignment implements AlignmentI } } - @Override - public void validateAnnotation(AlignmentAnnotation alignmentAnnotation) - { - alignmentAnnotation.validateRangeAndDisplay(); - if (isNucleotide() && alignmentAnnotation.isValidStruc()) - { - hasRNAStructure = true; - } - } + + @Override + public void validateAnnotation(AlignmentAnnotation alignmentAnnotation) + { + alignmentAnnotation.validateRangeAndDisplay(); + if (isNucleotide() && alignmentAnnotation.isValidStruc()) + { + hasRNAStructure = true; + } + } + private SequenceI seqrep=null; @@ -1526,24 +1604,27 @@ public class Alignment implements AlignmentI return seqrep != null; } - @Override -public int getEndRes() -{ - return getWidth()-1; -}@Override -public int getStartRes() -{ - return 0; -} + @Override + public int getEndRes() + { + return getWidth() - 1; + } -/* In the case of AlignmentI - returns the dataset for the alignment, if set - * (non-Javadoc) - * @see jalview.datamodel.AnnotatedCollectionI#getContext() - */ -@Override -public AnnotatedCollectionI getContext() -{ - return dataset; -} + @Override + public int getStartRes() + { + return 0; + } + /* + * In the case of AlignmentI - returns the dataset for the alignment, if set + * (non-Javadoc) + * + * @see jalview.datamodel.AnnotatedCollectionI#getContext() + */ + @Override + public AnnotatedCollectionI getContext() + { + return dataset; + } }