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.datamodel.AlignmentI;
24 import jalview.datamodel.SequenceI;
25 import jalview.io.NewickFile;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.Hashtable;
30 import java.util.List;
33 public class JalviewDataset
36 * dataset that new data (sequences, alignments) will be added to
38 AlignmentI parentDataset;
41 * @return the parentDataset
43 public AlignmentI getParentDataset()
49 * @param parentDataset
50 * the parentDataset to set
52 public void setParentDataset(AlignmentI parentDataset)
54 this.parentDataset = parentDataset;
58 * @return the featureColours
60 public Map<String, Object> getFeatureColours()
62 return featureColours;
66 * @param featureColours
67 * the featureColours to set
69 public void setFeatureColours(Map<String, Object> featureColours)
71 this.featureColours = featureColours;
75 * @return the seqDetails
77 public Hashtable getSeqDetails()
84 * the seqDetails to set
86 public void setSeqDetails(Hashtable seqDetails)
88 this.seqDetails = seqDetails;
94 public List<AlignmentSet> getAl()
96 return (al == null) ? new ArrayList<AlignmentSet>() : al;
100 * current alignment being worked on.
102 List<AlignmentSet> al;
104 public class AlignmentSet
106 public AlignmentI al;
108 public List<jalview.io.NewickFile> trees;
110 AlignmentSet(AlignmentI a)
113 trees = new ArrayList<jalview.io.NewickFile>();
117 * deuniquify the current alignment in the context, merging any new
118 * annotation/features with the existing set
122 void deuniquifyAlignment()
124 if (seqDetails == null || seqDetails.size() == 0)
129 // 1. recover correct names and attributes for each sequence in alignment.
131 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
132 * for input sequences, and then dataset sequence creation for new
133 * sequences retrieved from service // finally, attempt to de-uniquify to
134 * recover input sequence identity, and try to map back onto dataset Note:
135 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
136 * will NOT WORK - the returned alignment may contain multiple versions of
137 * the input sequence, each being a subsequence of the original.
138 * deuniquify also removes existing annotation and features added in the
139 * previous step... al.setDataset(dataset); // add in new sequences
140 * retrieved from sequence search which are not already in dataset. //
141 * trigger a 'fetchDBids' to annotate sequences with database ids...
143 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
144 // seqDetails, al,true);
146 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
147 al.getSequencesArray(), true);
148 // 2. Update names of associated nodes in any trees
149 for (NewickFile nf : trees)
151 // the following works because all trees are already had node/SequenceI
152 // associations created.
153 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(
154 al.getSequencesArray(), nf);
155 // this just updates the displayed leaf name on the tree according to
157 njt.renameAssociatedNodes();
163 * set modification flag. If anything modifies the alignment in the current
164 * set, this flag should be true
166 private boolean modified = false;
169 * @return the modified
171 public boolean isModified()
177 * or the modification state with the given state
179 * @param modifiedFromAction
181 public void updateSetModified(boolean modifiedFromAction)
183 modified |= modifiedFromAction;
188 * current set of feature colours
190 Map<String, Object> featureColours;
193 * original identity of each sequence in results
195 Hashtable seqDetails;
197 public boolean relaxedIdMatching = false;
199 public JalviewDataset()
201 seqDetails = new Hashtable();
202 al = new ArrayList<AlignmentSet>();
203 parentDataset = null;
204 featureColours = new HashMap<String, Object>();
208 * context created from an existing alignment.
210 * @param parentAlignment
212 public JalviewDataset(AlignmentI aldataset, Map<String, Object> fc,
215 // TODO not used - remove?
216 this(aldataset, fc, seqDets, null);
222 * - parent dataset for any new alignment/sequence data (must not be
225 * (may be null) feature settings for the alignment where new feature
226 * renderstyles are stored
228 * - (may be null) anonymised sequence information created by
229 * Sequence uniquifier
230 * @param parentAlignment
231 * (may be null) alignment to associate new annotation and trees
234 public JalviewDataset(AlignmentI aldataset, Map<String, Object> fc,
235 Hashtable seqDets, AlignmentI parentAlignment)
238 parentDataset = aldataset;
239 if (parentAlignment != null)
241 parentDataset = parentAlignment.getDataset();
242 if (parentDataset == null)
244 parentDataset = parentAlignment;
248 addAlignment(parentAlignment);
253 seqDetails = seqDets;
262 public boolean hasAlignments()
264 return al != null && al.size() > 0;
267 public AlignmentI getLastAlignment()
269 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
272 public AlignmentSet getLastAlignmentSet()
274 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
278 * post process (deuniquify) the current alignment and its dependent data, and
279 * then add newal to the dataset.
283 public void addAlignment(AlignmentI newal)
285 if (!hasAlignments())
287 al = new ArrayList<AlignmentSet>();
289 AlignmentSet last = getLastAlignmentSet();
292 System.err.println("Deuniquifying last alignment set.");
293 last.deuniquifyAlignment();
295 al.add(new AlignmentSet(newal));
298 public void addTreeFromFile(NewickFile nf)
300 AlignmentSet lal = getLastAlignmentSet();
304 public boolean hasSequenceAssoc()
306 // TODO: discover where sequence associated data should be put.
310 public SequenceI getLastAssociatedSequence()
312 // TODO: delineate semantics for associating uniquified data with
313 // potentially de-uniquified sequence.
318 * update the modified state flag for the current set with the given
322 * - this will be ored with current modification state
324 public void updateSetModified(boolean modified)
326 getLastAlignmentSet().updateSetModified(modified);