2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 package jalview.io.packed;
21 import jalview.datamodel.AlignmentI;
22 import jalview.datamodel.SequenceI;
23 import jalview.io.NewickFile;
25 import java.util.ArrayList;
26 import java.util.Hashtable;
27 import java.util.List;
29 public class JalviewDataset
32 * dataset that new data (sequences, alignments) will be added to
34 AlignmentI parentDataset;
37 * @return the parentDataset
39 public AlignmentI getParentDataset()
45 * @param parentDataset
46 * the parentDataset to set
48 public void setParentDataset(AlignmentI parentDataset)
50 this.parentDataset = parentDataset;
54 * @return the featureColours
56 public Hashtable getFeatureColours()
58 return featureColours;
62 * @param featureColours
63 * the featureColours to set
65 public void setFeatureColours(Hashtable featureColours)
67 this.featureColours = featureColours;
71 * @return the seqDetails
73 public Hashtable getSeqDetails()
80 * the seqDetails to set
82 public void setSeqDetails(Hashtable seqDetails)
84 this.seqDetails = seqDetails;
90 public List<AlignmentSet> getAl()
92 return (al == null) ? new ArrayList<AlignmentSet>() : al;
96 * current alignment being worked on.
98 List<AlignmentSet> al;
100 public class AlignmentSet
102 public AlignmentI al;
104 public List<jalview.io.NewickFile> trees;
106 AlignmentSet(AlignmentI a)
109 trees = new ArrayList<jalview.io.NewickFile>();
113 * deuniquify the current alignment in the context, merging any new
114 * annotation/features with the existing set
118 void deuniquifyAlignment()
120 if (seqDetails == null || seqDetails.size() == 0)
125 // 1. recover correct names and attributes for each sequence in alignment.
127 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
128 * for input sequences, and then dataset sequence creation for new
129 * sequences retrieved from service // finally, attempt to de-uniquify to
130 * recover input sequence identity, and try to map back onto dataset Note:
131 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
132 * will NOT WORK - the returned alignment may contain multiple versions of
133 * the input sequence, each being a subsequence of the original.
134 * deuniquify also removes existing annotation and features added in the
135 * previous step... al.setDataset(dataset); // add in new sequences
136 * retrieved from sequence search which are not already in dataset. //
137 * trigger a 'fetchDBids' to annotate sequences with database ids...
139 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
140 // seqDetails, al,true);
142 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
143 al.getSequencesArray(), true);
144 // 2. Update names of associated nodes in any trees
145 for (NewickFile nf : trees)
147 // the following works because all trees are already had node/SequenceI
148 // associations created.
149 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(
150 al.getSequencesArray(), nf);
151 // this just updates the displayed leaf name on the tree according to
153 njt.renameAssociatedNodes();
159 * set modification flag. If anything modifies the alignment in the current
160 * set, this flag should be true
162 private boolean modified = false;
165 * @return the modified
167 public boolean isModified()
173 * or the modification state with the given state
175 * @param modifiedFromAction
177 public void updateSetModified(boolean modifiedFromAction)
179 modified |= modifiedFromAction;
184 * current set of feature colours
186 Hashtable featureColours;
189 * original identity of each sequence in results
191 Hashtable seqDetails;
193 public boolean relaxedIdMatching = false;
195 public JalviewDataset()
197 seqDetails = new Hashtable();
198 al = new ArrayList<AlignmentSet>();
199 parentDataset = null;
200 featureColours = new Hashtable();
204 * context created from an existing alignment.
206 * @param parentAlignment
208 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
211 this(aldataset, fc, seqDets, null);
217 * - parent dataset for any new alignment/sequence data (must not be
220 * (may be null) feature settings for the alignment where new feature
221 * renderstyles are stored
223 * - (may be null) anonymised sequence information created by
224 * Sequence uniquifier
225 * @param parentAlignment
226 * (may be null) alignment to associate new annotation and trees
229 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
230 Hashtable seqDets, AlignmentI parentAlignment)
233 parentDataset = aldataset;
234 if (parentAlignment != null)
236 parentDataset = parentAlignment.getDataset();
237 if (parentDataset == null)
239 parentDataset = parentAlignment;
243 addAlignment(parentAlignment);
248 seqDetails = seqDets;
257 public boolean hasAlignments()
259 return al != null && al.size() > 0;
262 public AlignmentI getLastAlignment()
264 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
267 public AlignmentSet getLastAlignmentSet()
269 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
273 * post process (deuniquify) the current alignment and its dependent data, and
274 * then add newal to the dataset.
278 public void addAlignment(AlignmentI newal)
280 if (!hasAlignments())
282 al = new ArrayList<AlignmentSet>();
284 AlignmentSet last = getLastAlignmentSet();
287 System.err.println("Deuniquifying last alignment set.");
288 last.deuniquifyAlignment();
290 al.add(new AlignmentSet(newal));
293 public void addTreeFromFile(NewickFile nf)
295 AlignmentSet lal = getLastAlignmentSet();
299 public boolean hasSequenceAssoc()
301 // TODO: discover where sequence associated data should be put.
305 public SequenceI getLastAssociatedSequence()
307 // TODO: delineate semantics for associating uniquified data with
308 // potentially de-uniquified sequence.
313 * update the modified state flag for the current set with the given
317 * - this will be ored with current modification state
319 public void updateSetModified(boolean modified)
321 getLastAlignmentSet().updateSetModified(modified);