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.SeqsetUtils.SequenceInfo;
24 import jalview.analysis.TreeModel;
25 import jalview.api.FeatureColourI;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.SequenceI;
28 import jalview.io.NewickFile;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.Hashtable;
33 import java.util.List;
36 public class JalviewDataset
39 * dataset that new data (sequences, alignments) will be added to
41 AlignmentI parentDataset;
44 * @return the parentDataset
46 public AlignmentI getParentDataset()
52 * @param parentDataset
53 * the parentDataset to set
55 public void setParentDataset(AlignmentI parentDataset)
57 this.parentDataset = parentDataset;
61 * @return the featureColours
63 public Map<String, FeatureColourI> getFeatureColours()
65 return featureColours;
69 * @param featureColours
70 * the featureColours to set
72 public void setFeatureColours(Map<String, FeatureColourI> featureColours)
74 this.featureColours = featureColours;
78 * @return the seqDetails
80 public Map<String, SequenceInfo> getSeqDetails()
87 * the seqDetails to set
89 public void setSeqDetails(Hashtable seqDetails)
91 this.seqDetails = seqDetails;
97 public List<AlignmentSet> getAl()
99 return (al == null) ? new ArrayList<AlignmentSet>() : al;
103 * current alignment being worked on.
105 List<AlignmentSet> al;
107 public class AlignmentSet
109 public AlignmentI al;
111 public List<jalview.io.NewickFile> trees;
113 AlignmentSet(AlignmentI a)
116 trees = new ArrayList<jalview.io.NewickFile>();
120 * deuniquify the current alignment in the context, merging any new
121 * annotation/features with the existing set
125 void deuniquifyAlignment()
127 if (seqDetails == null || seqDetails.size() == 0)
132 // 1. recover correct names and attributes for each sequence in alignment.
134 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
135 * for input sequences, and then dataset sequence creation for new
136 * sequences retrieved from service // finally, attempt to de-uniquify to
137 * recover input sequence identity, and try to map back onto dataset Note:
138 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
139 * will NOT WORK - the returned alignment may contain multiple versions of
140 * the input sequence, each being a subsequence of the original.
141 * deuniquify also removes existing annotation and features added in the
142 * previous step... al.setDataset(dataset); // add in new sequences
143 * retrieved from sequence search which are not already in dataset. //
144 * trigger a 'fetchDBids' to annotate sequences with database ids...
146 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
147 // seqDetails, al,true);
149 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
150 al.getSequencesArray(), true);
151 // 2. Update names of associated nodes in any trees
152 for (NewickFile nf : trees)
154 // the following works because all trees are already had node/SequenceI
155 // associations created.
156 TreeModel njt = new TreeModel(al.getSequencesArray(), null, nf);
157 // this just updates the displayed leaf name on the tree according to
159 njt.renameAssociatedNodes();
165 * set modification flag. If anything modifies the alignment in the current
166 * set, this flag should be true
168 private boolean modified = false;
171 * @return the modified
173 public boolean isModified()
179 * or the modification state with the given state
181 * @param modifiedFromAction
183 public void updateSetModified(boolean modifiedFromAction)
185 modified |= modifiedFromAction;
190 * current set of feature colours
192 Map<String, FeatureColourI> featureColours;
195 * original identity of each sequence in results
197 Map<String, SequenceInfo> seqDetails;
199 public boolean relaxedIdMatching = false;
201 public JalviewDataset()
203 seqDetails = new Hashtable();
204 al = new ArrayList<AlignmentSet>();
205 parentDataset = null;
206 featureColours = new HashMap<String, FeatureColourI>();
210 * context created from an existing alignment.
212 * @param parentAlignment
214 public JalviewDataset(AlignmentI aldataset,
215 Map<String, FeatureColourI> fc, Map<String, SequenceInfo> seqDets)
217 // TODO not used - remove?
218 this(aldataset, fc, seqDets, null);
224 * - parent dataset for any new alignment/sequence data (must not be
227 * (may be null) feature settings for the alignment where new feature
228 * renderstyles are stored
230 * - (may be null) anonymised sequence information created by
231 * Sequence uniquifier
232 * @param parentAlignment
233 * (may be null) alignment to associate new annotation and trees
236 public JalviewDataset(AlignmentI aldataset,
237 Map<String, FeatureColourI> fc, Map<String, SequenceInfo> seqDets,
238 AlignmentI parentAlignment)
241 parentDataset = aldataset;
242 if (parentAlignment != null)
244 parentDataset = parentAlignment.getDataset();
245 if (parentDataset == null)
247 parentDataset = parentAlignment;
251 addAlignment(parentAlignment);
256 seqDetails = seqDets;
265 public boolean hasAlignments()
267 return al != null && al.size() > 0;
270 public AlignmentI getLastAlignment()
272 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
275 public AlignmentSet getLastAlignmentSet()
277 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
281 * post process (deuniquify) the current alignment and its dependent data, and
282 * then add newal to the dataset.
286 public void addAlignment(AlignmentI newal)
288 if (!hasAlignments())
290 al = new ArrayList<AlignmentSet>();
292 AlignmentSet last = getLastAlignmentSet();
295 System.err.println("Deuniquifying last alignment set.");
296 last.deuniquifyAlignment();
298 al.add(new AlignmentSet(newal));
301 public void addTreeFromFile(NewickFile nf)
303 AlignmentSet lal = getLastAlignmentSet();
307 public boolean hasSequenceAssoc()
309 // TODO: discover where sequence associated data should be put.
313 public SequenceI getLastAssociatedSequence()
315 // TODO: delineate semantics for associating uniquified data with
316 // potentially de-uniquified sequence.
321 * update the modified state flag for the current set with the given
325 * - this will be ored with current modification state
327 public void updateSetModified(boolean modified)
329 getLastAlignmentSet().updateSetModified(modified);