1 package jalview.io.packed;
3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.SequenceI;
5 import jalview.io.NewickFile;
7 import java.util.ArrayList;
8 import java.util.Hashtable;
11 public class JalviewDataset
14 * dataset that new data (sequences, alignments) will be added to
16 AlignmentI parentDataset;
19 * @return the parentDataset
21 public AlignmentI getParentDataset()
26 * @param parentDataset the parentDataset to set
28 public void setParentDataset(AlignmentI parentDataset)
30 this.parentDataset = parentDataset;
33 * @return the featureColours
35 public Hashtable getFeatureColours()
37 return featureColours;
40 * @param featureColours the featureColours to set
42 public void setFeatureColours(Hashtable featureColours)
44 this.featureColours = featureColours;
47 * @return the seqDetails
49 public Hashtable getSeqDetails()
54 * @param seqDetails the seqDetails to set
56 public void setSeqDetails(Hashtable seqDetails)
58 this.seqDetails = seqDetails;
63 public List<AlignmentSet> getAl()
65 return (al==null) ? new ArrayList<AlignmentSet>() : al;
68 * current alignment being worked on.
70 List<AlignmentSet> al;
71 public class AlignmentSet {
73 public List<jalview.io.NewickFile> trees;
74 AlignmentSet(AlignmentI a) {
76 trees = new ArrayList<jalview.io.NewickFile>();
79 * deuniquify the current alignment in the context, merging any new
80 * annotation/features with the existing set
84 void deuniquifyAlignment()
86 if (seqDetails==null || seqDetails.size()==0)
91 // 1. recover correct names and attributes for each sequence in alignment.
93 * TODO: housekeeping w.r.t. recovery of dataset and annotation
94 * references for input sequences, and then dataset sequence creation
95 * for new sequences retrieved from service // finally, attempt to
96 * de-uniquify to recover input sequence identity, and try to map back
97 * onto dataset Note: this
98 * jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true); will
99 * NOT WORK - the returned alignment may contain multiple versions of
100 * the input sequence, each being a subsequence of the original.
101 * deuniquify also removes existing annotation and features added in the
102 * previous step... al.setDataset(dataset); // add in new sequences
103 * retrieved from sequence search which are not already in dataset. //
104 * trigger a 'fetchDBids' to annotate sequences with database ids...
106 //jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset, seqDetails, al,true);
108 jalview.analysis.SeqsetUtils.deuniquify(seqDetails, al.getSequencesArray(),true);
109 // 2. Update names of associated nodes in any trees
110 for (NewickFile nf:trees)
112 // the following works because all trees are already had node/SequenceI associations created.
113 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(al.getSequencesArray(), nf);
114 // this just updates the displayed leaf name on the tree according to the SequenceIs.
115 njt.renameAssociatedNodes();
120 * set modification flag. If anything modifies the alignment in the current set, this flag should be true
122 private boolean modified=false;
125 * @return the modified
127 public boolean isModified()
132 * or the modification state with the given state
133 * @param modifiedFromAction
135 public void updateSetModified(boolean modifiedFromAction)
137 modified |= modifiedFromAction;
142 * current set of feature colours
144 Hashtable featureColours;
147 * original identity of each sequence in results
149 Hashtable seqDetails;
151 public boolean relaxedIdMatching=false;
153 public JalviewDataset()
155 seqDetails = new Hashtable();
156 al = new ArrayList<AlignmentSet>();
157 parentDataset = null;
158 featureColours = new Hashtable();
161 * context created from an existing alignment.
162 * @param parentAlignment
164 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets)
166 this(aldataset, fc, seqDets, null);
170 * @param aldataset - parent dataset for any new alignment/sequence data (must not be null)
171 * @param fc (may be null) feature settings for the alignment where new feature renderstyles are stored
172 * @param seqDets - (may be null) anonymised sequence information created by Sequence uniquifier
173 * @param parentAlignment (may be null) alignment to associate new annotation and trees with.
175 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets, AlignmentI parentAlignment)
178 parentDataset = aldataset;
179 if (parentAlignment!=null)
181 parentDataset = parentAlignment.getDataset();
182 if (parentDataset==null)
184 parentDataset = parentAlignment;
186 addAlignment(parentAlignment);
191 seqDetails = seqDets;
201 public boolean hasAlignments()
203 return al!=null && al.size()>0;
206 public AlignmentI getLastAlignment()
208 return (al==null || al.size()<1) ? null: al.get(al.size()-1).al;
210 public AlignmentSet getLastAlignmentSet()
212 return (al==null || al.size()<1) ? null: al.get(al.size()-1);
216 * post process (deuniquify) the current alignment and its dependent data, and then add newal to the dataset.
219 public void addAlignment(AlignmentI newal) {
220 if (!hasAlignments())
222 al = new ArrayList<AlignmentSet>();
224 AlignmentSet last = getLastAlignmentSet();
226 System.err.println("Deuniquifying last alignment set.");
227 last.deuniquifyAlignment();
229 al.add(new AlignmentSet(newal));
232 public void addTreeFromFile(NewickFile nf)
234 AlignmentSet lal = getLastAlignmentSet();
238 public boolean hasSequenceAssoc()
240 // TODO: discover where sequence associated data should be put.
243 public SequenceI getLastAssociatedSequence() {
244 // TODO: delineate semantics for associating uniquified data with potentially de-uniquified sequence.
248 * update the modified state flag for the current set with the given modification state
249 * @param modified - this will be ored with current modification state
251 public void updateSetModified(boolean modified)
253 getLastAlignmentSet().updateSetModified(modified);