1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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/>.
17 *******************************************************************************/
18 package jalview.io.packed;
20 import jalview.datamodel.AlignmentI;
21 import jalview.datamodel.SequenceI;
22 import jalview.io.NewickFile;
24 import java.util.ArrayList;
25 import java.util.Hashtable;
26 import java.util.List;
28 public class JalviewDataset
31 * dataset that new data (sequences, alignments) will be added to
33 AlignmentI parentDataset;
36 * @return the parentDataset
38 public AlignmentI getParentDataset()
44 * @param parentDataset
45 * the parentDataset to set
47 public void setParentDataset(AlignmentI parentDataset)
49 this.parentDataset = parentDataset;
53 * @return the featureColours
55 public Hashtable getFeatureColours()
57 return featureColours;
61 * @param featureColours
62 * the featureColours to set
64 public void setFeatureColours(Hashtable featureColours)
66 this.featureColours = featureColours;
70 * @return the seqDetails
72 public Hashtable getSeqDetails()
79 * the seqDetails to set
81 public void setSeqDetails(Hashtable seqDetails)
83 this.seqDetails = seqDetails;
89 public List<AlignmentSet> getAl()
91 return (al == null) ? new ArrayList<AlignmentSet>() : al;
95 * current alignment being worked on.
97 List<AlignmentSet> al;
99 public class AlignmentSet
101 public AlignmentI al;
103 public List<jalview.io.NewickFile> trees;
105 AlignmentSet(AlignmentI a)
108 trees = new ArrayList<jalview.io.NewickFile>();
112 * deuniquify the current alignment in the context, merging any new
113 * annotation/features with the existing set
117 void deuniquifyAlignment()
119 if (seqDetails == null || seqDetails.size() == 0)
124 // 1. recover correct names and attributes for each sequence in alignment.
126 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
127 * for input sequences, and then dataset sequence creation for new
128 * sequences retrieved from service // finally, attempt to de-uniquify to
129 * recover input sequence identity, and try to map back onto dataset Note:
130 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
131 * will NOT WORK - the returned alignment may contain multiple versions of
132 * the input sequence, each being a subsequence of the original.
133 * deuniquify also removes existing annotation and features added in the
134 * previous step... al.setDataset(dataset); // add in new sequences
135 * retrieved from sequence search which are not already in dataset. //
136 * trigger a 'fetchDBids' to annotate sequences with database ids...
138 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
139 // seqDetails, al,true);
141 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
142 al.getSequencesArray(), true);
143 // 2. Update names of associated nodes in any trees
144 for (NewickFile nf : trees)
146 // the following works because all trees are already had node/SequenceI
147 // associations created.
148 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(
149 al.getSequencesArray(), nf);
150 // this just updates the displayed leaf name on the tree according to
152 njt.renameAssociatedNodes();
158 * set modification flag. If anything modifies the alignment in the current
159 * set, this flag should be true
161 private boolean modified = false;
164 * @return the modified
166 public boolean isModified()
172 * or the modification state with the given state
174 * @param modifiedFromAction
176 public void updateSetModified(boolean modifiedFromAction)
178 modified |= modifiedFromAction;
183 * current set of feature colours
185 Hashtable featureColours;
188 * original identity of each sequence in results
190 Hashtable seqDetails;
192 public boolean relaxedIdMatching = false;
194 public JalviewDataset()
196 seqDetails = new Hashtable();
197 al = new ArrayList<AlignmentSet>();
198 parentDataset = null;
199 featureColours = new Hashtable();
203 * context created from an existing alignment.
205 * @param parentAlignment
207 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
210 this(aldataset, fc, seqDets, null);
216 * - parent dataset for any new alignment/sequence data (must not be
219 * (may be null) feature settings for the alignment where new feature
220 * renderstyles are stored
222 * - (may be null) anonymised sequence information created by
223 * Sequence uniquifier
224 * @param parentAlignment
225 * (may be null) alignment to associate new annotation and trees
228 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
229 Hashtable seqDets, AlignmentI parentAlignment)
232 parentDataset = aldataset;
233 if (parentAlignment != null)
235 parentDataset = parentAlignment.getDataset();
236 if (parentDataset == null)
238 parentDataset = parentAlignment;
242 addAlignment(parentAlignment);
247 seqDetails = seqDets;
256 public boolean hasAlignments()
258 return al != null && al.size() > 0;
261 public AlignmentI getLastAlignment()
263 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
266 public AlignmentSet getLastAlignmentSet()
268 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
272 * post process (deuniquify) the current alignment and its dependent data, and
273 * then add newal to the dataset.
277 public void addAlignment(AlignmentI newal)
279 if (!hasAlignments())
281 al = new ArrayList<AlignmentSet>();
283 AlignmentSet last = getLastAlignmentSet();
286 System.err.println("Deuniquifying last alignment set.");
287 last.deuniquifyAlignment();
289 al.add(new AlignmentSet(newal));
292 public void addTreeFromFile(NewickFile nf)
294 AlignmentSet lal = getLastAlignmentSet();
298 public boolean hasSequenceAssoc()
300 // TODO: discover where sequence associated data should be put.
304 public SequenceI getLastAssociatedSequence()
306 // TODO: delineate semantics for associating uniquified data with
307 // potentially de-uniquified sequence.
312 * update the modified state flag for the current set with the given
316 * - this will be ored with current modification state
318 public void updateSetModified(boolean modified)
320 getLastAlignmentSet().updateSetModified(modified);