1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, 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()
43 * @param parentDataset the parentDataset to set
45 public void setParentDataset(AlignmentI parentDataset)
47 this.parentDataset = parentDataset;
50 * @return the featureColours
52 public Hashtable getFeatureColours()
54 return featureColours;
57 * @param featureColours the featureColours to set
59 public void setFeatureColours(Hashtable featureColours)
61 this.featureColours = featureColours;
64 * @return the seqDetails
66 public Hashtable getSeqDetails()
71 * @param seqDetails the seqDetails to set
73 public void setSeqDetails(Hashtable seqDetails)
75 this.seqDetails = seqDetails;
80 public List<AlignmentSet> getAl()
82 return (al==null) ? new ArrayList<AlignmentSet>() : al;
85 * current alignment being worked on.
87 List<AlignmentSet> al;
88 public class AlignmentSet {
90 public List<jalview.io.NewickFile> trees;
91 AlignmentSet(AlignmentI a) {
93 trees = new ArrayList<jalview.io.NewickFile>();
96 * deuniquify the current alignment in the context, merging any new
97 * annotation/features with the existing set
101 void deuniquifyAlignment()
103 if (seqDetails==null || seqDetails.size()==0)
108 // 1. recover correct names and attributes for each sequence in alignment.
110 * TODO: housekeeping w.r.t. recovery of dataset and annotation
111 * references for input sequences, and then dataset sequence creation
112 * for new sequences retrieved from service // finally, attempt to
113 * de-uniquify to recover input sequence identity, and try to map back
114 * onto dataset Note: this
115 * jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true); will
116 * NOT WORK - the returned alignment may contain multiple versions of
117 * the input sequence, each being a subsequence of the original.
118 * deuniquify also removes existing annotation and features added in the
119 * previous step... al.setDataset(dataset); // add in new sequences
120 * retrieved from sequence search which are not already in dataset. //
121 * trigger a 'fetchDBids' to annotate sequences with database ids...
123 //jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset, seqDetails, al,true);
125 jalview.analysis.SeqsetUtils.deuniquify(seqDetails, al.getSequencesArray(),true);
126 // 2. Update names of associated nodes in any trees
127 for (NewickFile nf:trees)
129 // the following works because all trees are already had node/SequenceI associations created.
130 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(al.getSequencesArray(), nf);
131 // this just updates the displayed leaf name on the tree according to the SequenceIs.
132 njt.renameAssociatedNodes();
137 * set modification flag. If anything modifies the alignment in the current set, this flag should be true
139 private boolean modified=false;
142 * @return the modified
144 public boolean isModified()
149 * or the modification state with the given state
150 * @param modifiedFromAction
152 public void updateSetModified(boolean modifiedFromAction)
154 modified |= modifiedFromAction;
159 * current set of feature colours
161 Hashtable featureColours;
164 * original identity of each sequence in results
166 Hashtable seqDetails;
168 public boolean relaxedIdMatching=false;
170 public JalviewDataset()
172 seqDetails = new Hashtable();
173 al = new ArrayList<AlignmentSet>();
174 parentDataset = null;
175 featureColours = new Hashtable();
178 * context created from an existing alignment.
179 * @param parentAlignment
181 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets)
183 this(aldataset, fc, seqDets, null);
187 * @param aldataset - parent dataset for any new alignment/sequence data (must not be null)
188 * @param fc (may be null) feature settings for the alignment where new feature renderstyles are stored
189 * @param seqDets - (may be null) anonymised sequence information created by Sequence uniquifier
190 * @param parentAlignment (may be null) alignment to associate new annotation and trees with.
192 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets, AlignmentI parentAlignment)
195 parentDataset = aldataset;
196 if (parentAlignment!=null)
198 parentDataset = parentAlignment.getDataset();
199 if (parentDataset==null)
201 parentDataset = parentAlignment;
203 addAlignment(parentAlignment);
208 seqDetails = seqDets;
218 public boolean hasAlignments()
220 return al!=null && al.size()>0;
223 public AlignmentI getLastAlignment()
225 return (al==null || al.size()<1) ? null: al.get(al.size()-1).al;
227 public AlignmentSet getLastAlignmentSet()
229 return (al==null || al.size()<1) ? null: al.get(al.size()-1);
233 * post process (deuniquify) the current alignment and its dependent data, and then add newal to the dataset.
236 public void addAlignment(AlignmentI newal) {
237 if (!hasAlignments())
239 al = new ArrayList<AlignmentSet>();
241 AlignmentSet last = getLastAlignmentSet();
243 System.err.println("Deuniquifying last alignment set.");
244 last.deuniquifyAlignment();
246 al.add(new AlignmentSet(newal));
249 public void addTreeFromFile(NewickFile nf)
251 AlignmentSet lal = getLastAlignmentSet();
255 public boolean hasSequenceAssoc()
257 // TODO: discover where sequence associated data should be put.
260 public SequenceI getLastAssociatedSequence() {
261 // TODO: delineate semantics for associating uniquified data with potentially de-uniquified sequence.
265 * update the modified state flag for the current set with the given modification state
266 * @param modified - this will be ored with current modification state
268 public void updateSetModified(boolean modified)
270 getLastAlignmentSet().updateSetModified(modified);