1 package jalview.viewmodel.seqfeatures;
4 import java.util.ArrayList;
5 import java.util.LinkedHashMap;
7 import java.util.Vector;
9 import jalview.api.DBRefEntryI;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.SequenceFeature;
12 import jalview.datamodel.SequenceI;
13 import jalview.datamodel.features.SequenceFeaturesI;
15 public class IdColumns
18 AlignmentI alignment = null;
20 public IdColumns(AlignmentI al)
23 columns.put(STRUCTURES_NUM.getLabel(), STRUCTURES_NUM);
27 public final static IdColumn STRUCTURES_NUM;
30 STRUCTURES_NUM = new IdColumn("3D Structures",
31 "Number of associated structure files", false);
34 LinkedHashMap<String, IdColumn> columns = new LinkedHashMap<String, IdColumn>();
37 * register a feature on the columnset
40 * @return true if feature was not seen before
42 boolean updateListForFeature(SequenceFeature sf)
44 String colname = sf.getType();
45 if (columns.get(colname) != null)
50 IdColumn col = new IdColumn(colname,
51 "Nonpositional feature: " + colname, false);
52 col.featureTypeName = sf.getType();
53 // col.featureGroupName = sf.getFeatureGroup();
54 columns.put(colname, col);
58 boolean updateListForDbxref(DBRefEntryI dbref)
60 String colname = dbref.getSource();
61 if (columns.get(colname) != null)
66 IdColumn col = new IdColumn(colname,
67 "Database CrossReference: " + colname, false);
68 col.DbRefName = colname;
69 // col.featureGroupName = sf.getFeatureGroup();
70 columns.put(colname, col);
74 public void updateTypeList()
76 for (SequenceI sq : alignment.getSequences())
79 while (seq.getDatasetSequence() != null)
81 seq = seq.getDatasetSequence();
84 SequenceFeaturesI sqf = seq.getFeatures();
85 List<SequenceFeature> nonpos = sqf.getNonPositionalFeatures();
88 for (SequenceFeature sf : nonpos)
90 updateListForFeature(sf);
93 for (DBRefEntryI dbr : seq.getDBRefs())
95 updateListForDbxref(dbr);
100 public void toggleVisible(String column)
102 IdColumn col = columns.get(column);
105 col.visible = !col.visible;
109 public List<IdColumn> getVisible()
111 // probably want to cache this
112 ArrayList<IdColumn> vis = new ArrayList();
113 for (IdColumn col : columns.values())
123 public final class ColumnCell
125 public final String label;
127 public final Color bg;
129 public final Color fg;
131 public ColumnCell(final String label, final Color bg, final Color fg)
140 * render the column value for this sequence
146 public ColumnCell getCellFor(SequenceI seq, IdColumn col)
148 ColumnCell cell = null;
151 SequenceI dseq = seq;
152 while (dseq.getDatasetSequence() != null)
154 dseq = dseq.getDatasetSequence();
156 if (col == STRUCTURES_NUM)
158 Vector pdbE = dseq.getAllPDBEntries();
163 return new ColumnCell("" + pdbE.size(), Color.red, Color.white);
165 if (col.featureTypeName != null)
167 List<SequenceFeature> np = dseq.getFeatures()
168 .getNonPositionalFeatures(col.featureTypeName);
171 for (SequenceFeature npfeat : np)
173 // nb deal with multiplicities!
174 if (col.featureGroupName == null || (npfeat.featureGroup != null
175 && npfeat.featureGroup.equals(col.featureGroupName)))
177 Color fg = Color.black;
178 Color bg = Color.white;
180 return new ColumnCell(npfeat.description, fg, bg);
185 if (col.DbRefName != null)
187 for (DBRefEntryI dbr : dseq.getDBRefs())
189 if (dbr.getSource().equals(col.DbRefName))
191 return new ColumnCell(dbr.getAccessionId(), Color.black,
197 // no value for this sequence in given column
201 public IdColumn[] getIdColumns()
203 return columns.values().toArray(new IdColumn[0]);