2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.io.packed;
23 import jalview.analysis.TreeModel;
24 import jalview.api.FeatureColourI;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceI;
27 import jalview.io.NewickFile;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.Hashtable;
32 import java.util.List;
35 public class JalviewDataset
38 * dataset that new data (sequences, alignments) will be added to
40 AlignmentI parentDataset;
43 * @return the parentDataset
45 public AlignmentI getParentDataset()
51 * @param parentDataset
52 * the parentDataset to set
54 public void setParentDataset(AlignmentI parentDataset)
56 this.parentDataset = parentDataset;
60 * @return the featureColours
62 public Map<String, FeatureColourI> getFeatureColours()
64 return featureColours;
68 * @param featureColours
69 * the featureColours to set
71 public void setFeatureColours(Map<String, FeatureColourI> featureColours)
73 this.featureColours = featureColours;
77 * @return the seqDetails
79 public Hashtable getSeqDetails()
86 * the seqDetails to set
88 public void setSeqDetails(Hashtable seqDetails)
90 this.seqDetails = seqDetails;
96 public List<AlignmentSet> getAl()
98 return (al == null) ? new ArrayList<AlignmentSet>() : al;
102 * current alignment being worked on.
104 List<AlignmentSet> al;
106 public class AlignmentSet
108 public AlignmentI al;
110 public List<jalview.io.NewickFile> trees;
112 AlignmentSet(AlignmentI a)
115 trees = new ArrayList<jalview.io.NewickFile>();
119 * deuniquify the current alignment in the context, merging any new
120 * annotation/features with the existing set
124 void deuniquifyAlignment()
126 if (seqDetails == null || seqDetails.size() == 0)
131 // 1. recover correct names and attributes for each sequence in alignment.
133 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
134 * for input sequences, and then dataset sequence creation for new
135 * sequences retrieved from service // finally, attempt to de-uniquify to
136 * recover input sequence identity, and try to map back onto dataset Note:
137 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
138 * will NOT WORK - the returned alignment may contain multiple versions of
139 * the input sequence, each being a subsequence of the original.
140 * deuniquify also removes existing annotation and features added in the
141 * previous step... al.setDataset(dataset); // add in new sequences
142 * retrieved from sequence search which are not already in dataset. //
143 * trigger a 'fetchDBids' to annotate sequences with database ids...
145 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
146 // seqDetails, al,true);
148 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
149 al.getSequencesArray(), true);
150 // 2. Update names of associated nodes in any trees
151 for (NewickFile nf : trees)
153 // the following works because all trees are already had node/SequenceI
154 // associations created.
155 TreeModel njt = new TreeModel(al.getSequencesArray(), null, nf);
156 // this just updates the displayed leaf name on the tree according to
158 njt.renameAssociatedNodes();
164 * set modification flag. If anything modifies the alignment in the current
165 * set, this flag should be true
167 private boolean modified = false;
170 * @return the modified
172 public boolean isModified()
178 * or the modification state with the given state
180 * @param modifiedFromAction
182 public void updateSetModified(boolean modifiedFromAction)
184 modified |= modifiedFromAction;
189 * current set of feature colours
191 Map<String, FeatureColourI> featureColours;
194 * original identity of each sequence in results
196 Hashtable seqDetails;
198 public boolean relaxedIdMatching = false;
200 public JalviewDataset()
202 seqDetails = new Hashtable();
203 al = new ArrayList<AlignmentSet>();
204 parentDataset = null;
205 featureColours = new HashMap<String, FeatureColourI>();
209 * context created from an existing alignment.
211 * @param parentAlignment
213 public JalviewDataset(AlignmentI aldataset,
214 Map<String, FeatureColourI> fc, Hashtable seqDets)
216 // TODO not used - remove?
217 this(aldataset, fc, seqDets, null);
223 * - parent dataset for any new alignment/sequence data (must not be
226 * (may be null) feature settings for the alignment where new feature
227 * renderstyles are stored
229 * - (may be null) anonymised sequence information created by
230 * Sequence uniquifier
231 * @param parentAlignment
232 * (may be null) alignment to associate new annotation and trees
235 public JalviewDataset(AlignmentI aldataset,
236 Map<String, FeatureColourI> fc, Hashtable seqDets,
237 AlignmentI parentAlignment)
240 parentDataset = aldataset;
241 if (parentAlignment != null)
243 parentDataset = parentAlignment.getDataset();
244 if (parentDataset == null)
246 parentDataset = parentAlignment;
250 addAlignment(parentAlignment);
255 seqDetails = seqDets;
264 public boolean hasAlignments()
266 return al != null && al.size() > 0;
269 public AlignmentI getLastAlignment()
271 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
274 public AlignmentSet getLastAlignmentSet()
276 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
280 * post process (deuniquify) the current alignment and its dependent data, and
281 * then add newal to the dataset.
285 public void addAlignment(AlignmentI newal)
287 if (!hasAlignments())
289 al = new ArrayList<AlignmentSet>();
291 AlignmentSet last = getLastAlignmentSet();
294 System.err.println("Deuniquifying last alignment set.");
295 last.deuniquifyAlignment();
297 al.add(new AlignmentSet(newal));
300 public void addTreeFromFile(NewickFile nf)
302 AlignmentSet lal = getLastAlignmentSet();
306 public boolean hasSequenceAssoc()
308 // TODO: discover where sequence associated data should be put.
312 public SequenceI getLastAssociatedSequence()
314 // TODO: delineate semantics for associating uniquified data with
315 // potentially de-uniquified sequence.
320 * update the modified state flag for the current set with the given
324 * - this will be ored with current modification state
326 public void updateSetModified(boolean modified)
328 getLastAlignmentSet().updateSetModified(modified);