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 * current alignment being worked on.
21 List<AlignmentSet> al;
22 public class AlignmentSet {
24 List<jalview.io.NewickFile> trees;
25 AlignmentSet(AlignmentI a) {
27 trees = new ArrayList<jalview.io.NewickFile>();
30 * deuniquify the current alignment in the context, merging any new
31 * annotation/features with the existing set
35 void deuniquifyAlignment()
37 if (seqDetails==null || seqDetails.size()==0)
42 // 1. recover correct names and attributes for each sequence in alignment.
44 * TODO: housekeeping w.r.t. recovery of dataset and annotation
45 * references for input sequences, and then dataset sequence creation
46 * for new sequences retrieved from service // finally, attempt to
47 * de-uniquify to recover input sequence identity, and try to map back
48 * onto dataset Note: this
49 * jalview.analysis.SeqsetUtils.deuniquify(SeqNames, alseqs, true); will
50 * NOT WORK - the returned alignment may contain multiple versions of
51 * the input sequence, each being a subsequence of the original.
52 * deuniquify also removes existing annotation and features added in the
53 * previous step... al.setDataset(dataset); // add in new sequences
54 * retrieved from sequence search which are not already in dataset. //
55 * trigger a 'fetchDBids' to annotate sequences with database ids...
57 //jalview.analysis.SeqsetUtils.deuniquifyAndMerge(parentDataset, seqDetails, al,true);
59 jalview.analysis.SeqsetUtils.deuniquify(seqDetails, al.getSequencesArray(),true);
60 // 2. Update names of associated nodes in any trees
61 for (NewickFile nf:trees)
63 // the following works because all trees are already had node/SequenceI associations created.
64 jalview.analysis.NJTree njt = new jalview.analysis.NJTree(al.getSequencesArray(), nf);
65 // this just updates the displayed leaf name on the try according to the SequenceIs.
66 njt.renameAssociatedNodes();
73 * current set of feature colours
75 Hashtable featureColours;
78 * original identity of each sequence in results
82 public JalviewDataset()
84 seqDetails = new Hashtable();
85 al = new ArrayList<AlignmentSet>();
87 featureColours = new Hashtable();
90 * context created from an existing alignment.
91 * @param parentAlignment
93 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets)
95 this(aldataset, fc, seqDets, null);
99 * @param aldataset - parent dataset for any new alignment/sequence data (must not be null)
100 * @param fc (may be null) feature settings for the alignment where new feature renderstyles are stored
101 * @param seqDets - (may be null) anonymised sequence information created by Sequence uniquifier
102 * @param parentAlignment (may be null) alignment to associate new annotation and trees with.
104 public JalviewDataset(AlignmentI aldataset, Hashtable fc, Hashtable seqDets, AlignmentI parentAlignment)
107 parentDataset = aldataset;
108 if (parentAlignment!=null)
110 parentDataset = parentAlignment.getDataset();
111 if (parentDataset==null)
113 parentDataset = parentAlignment;
115 addAlignment(parentAlignment);
120 seqDetails = seqDets;
130 public boolean hasAlignments()
132 return al!=null && al.size()>0;
135 public AlignmentI getLastAlignment()
137 return (al==null || al.size()<1) ? null: al.get(al.size()-1).al;
139 public AlignmentSet getLastAlignmentSet()
141 return (al==null || al.size()<1) ? null: al.get(al.size()-1);
145 * post process (deuniquify) the current alignment and its dependent data, and then add newal to the dataset.
148 public void addAlignment(AlignmentI newal) {
149 if (!hasAlignments())
151 al = new ArrayList<AlignmentSet>();
153 AlignmentSet last = getLastAlignmentSet();
155 System.err.println("Deuniquifying last alignment set.");
156 last.deuniquifyAlignment();
158 al.add(new AlignmentSet(newal));
161 public void addTreeFromFile(NewickFile nf)
163 AlignmentSet lal = getLastAlignmentSet();
167 public boolean hasSequenceAssoc()
169 // TODO: discover where sequence associated data should be put.
172 public SequenceI getLastAssociatedSequence() {
173 // TODO: delineate semantics for associating uniquified data with potentially de-uniquified sequence.