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.Hashtable;
29 import java.util.List;
31 public class JalviewDataset
34 * dataset that new data (sequences, alignments) will be added to
36 AlignmentI parentDataset;
39 * @return the parentDataset
41 public AlignmentI getParentDataset()
47 * @param parentDataset
48 * the parentDataset to set
50 public void setParentDataset(AlignmentI parentDataset)
52 this.parentDataset = parentDataset;
56 * @return the featureColours
58 public Hashtable getFeatureColours()
60 return featureColours;
64 * @param featureColours
65 * the featureColours to set
67 public void setFeatureColours(Hashtable featureColours)
69 this.featureColours = featureColours;
73 * @return the seqDetails
75 public Hashtable getSeqDetails()
82 * the seqDetails to set
84 public void setSeqDetails(Hashtable seqDetails)
86 this.seqDetails = seqDetails;
92 public List<AlignmentSet> getAl()
94 return (al == null) ? new ArrayList<AlignmentSet>() : al;
98 * current alignment being worked on.
100 List<AlignmentSet> al;
102 public class AlignmentSet
104 public AlignmentI al;
106 public List<jalview.io.NewickFile> trees;
108 AlignmentSet(AlignmentI a)
111 trees = new ArrayList<jalview.io.NewickFile>();
115 * deuniquify the current alignment in the context, merging any new
116 * annotation/features with the existing set
120 void deuniquifyAlignment()
122 if (seqDetails == null || seqDetails.size() == 0)
127 // 1. recover correct names and attributes for each sequence in alignment.
129 * TODO: housekeeping w.r.t. recovery of dataset and annotation references
130 * for input sequences, and then dataset sequence creation for new
131 * sequences retrieved from service // finally, attempt to de-uniquify to
132 * recover input sequence identity, and try to map back onto dataset Note:
133 * this jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true);
134 * will NOT WORK - the returned alignment may contain multiple versions of
135 * the input sequence, each being a subsequence of the original.
136 * deuniquify also removes existing annotation and features added in the
137 * previous step... al.setDataset(dataset); // add in new sequences
138 * retrieved from sequence search which are not already in dataset. //
139 * trigger a 'fetchDBids' to annotate sequences with database ids...
141 // jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset,
142 // seqDetails, al,true);
144 jalview.analysis.SeqsetUtils.deuniquify(seqDetails,
145 al.getSequencesArray(), true);
146 // 2. Update names of associated nodes in any trees
147 for (NewickFile nf : trees)
149 // the following works because all trees are already had node/SequenceI
150 // associations created.
151 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(
152 al.getSequencesArray(), nf);
153 // this just updates the displayed leaf name on the tree according to
155 njt.renameAssociatedNodes();
161 * set modification flag. If anything modifies the alignment in the current
162 * set, this flag should be true
164 private boolean modified = false;
167 * @return the modified
169 public boolean isModified()
175 * or the modification state with the given state
177 * @param modifiedFromAction
179 public void updateSetModified(boolean modifiedFromAction)
181 modified |= modifiedFromAction;
186 * current set of feature colours
188 Hashtable featureColours;
191 * original identity of each sequence in results
193 Hashtable seqDetails;
195 public boolean relaxedIdMatching = false;
197 public JalviewDataset()
199 seqDetails = new Hashtable();
200 al = new ArrayList<AlignmentSet>();
201 parentDataset = null;
202 featureColours = new Hashtable();
206 * context created from an existing alignment.
208 * @param parentAlignment
210 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
213 this(aldataset, fc, seqDets, null);
219 * - parent dataset for any new alignment/sequence data (must not be
222 * (may be null) feature settings for the alignment where new feature
223 * renderstyles are stored
225 * - (may be null) anonymised sequence information created by
226 * Sequence uniquifier
227 * @param parentAlignment
228 * (may be null) alignment to associate new annotation and trees
231 public JalviewDataset(AlignmentI aldataset, Hashtable fc,
232 Hashtable seqDets, AlignmentI parentAlignment)
235 parentDataset = aldataset;
236 if (parentAlignment != null)
238 parentDataset = parentAlignment.getDataset();
239 if (parentDataset == null)
241 parentDataset = parentAlignment;
245 addAlignment(parentAlignment);
250 seqDetails = seqDets;
259 public boolean hasAlignments()
261 return al != null && al.size() > 0;
264 public AlignmentI getLastAlignment()
266 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1).al;
269 public AlignmentSet getLastAlignmentSet()
271 return (al == null || al.size() < 1) ? null : al.get(al.size() - 1);
275 * post process (deuniquify) the current alignment and its dependent data, and
276 * then add newal to the dataset.
280 public void addAlignment(AlignmentI newal)
282 if (!hasAlignments())
284 al = new ArrayList<AlignmentSet>();
286 AlignmentSet last = getLastAlignmentSet();
289 System.err.println("Deuniquifying last alignment set.");
290 last.deuniquifyAlignment();
292 al.add(new AlignmentSet(newal));
295 public void addTreeFromFile(NewickFile nf)
297 AlignmentSet lal = getLastAlignmentSet();
301 public boolean hasSequenceAssoc()
303 // TODO: discover where sequence associated data should be put.
307 public SequenceI getLastAssociatedSequence()
309 // TODO: delineate semantics for associating uniquified data with
310 // potentially de-uniquified sequence.
315 * update the modified state flag for the current set with the given
319 * - this will be ored with current modification state
321 public void updateSetModified(boolean modified)
323 getLastAlignmentSet().updateSetModified(modified);