X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAlignViewport.java;h=62e05d0c365cda273965a7661b47b47fc6c2d565;hb=ac93424cd4c19aa35f7831e4f3da7bbcaf6baf15;hp=5944b806f65f9ce098d6c52a9feec9c0e6204977;hpb=9b3219d225131af5a165553f206ebf8da304ee23;p=jalview.git diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 5944b80..62e05d0 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -43,6 +43,9 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.analysis.NJTree; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; +import jalview.api.FeatureColourI; +import jalview.api.FeatureSettingsModelI; +import jalview.api.FeaturesDisplayedI; import jalview.api.ViewStyleI; import jalview.bin.Cache; import jalview.commands.CommandI; @@ -72,7 +75,6 @@ import java.awt.Rectangle; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; -import java.util.Set; import java.util.Vector; import javax.swing.JInternalFrame; @@ -461,7 +463,7 @@ public class AlignViewport extends AlignmentViewport implements AlignmentI al = getAlignment(); if (al != null) { - Set mappings = al.getCodonFrames(); + List mappings = al.getCodonFrames(); if (mappings != null) { StructureSelectionManager ssm = StructureSelectionManager @@ -505,17 +507,6 @@ public class AlignViewport extends AlignmentViewport implements /** * DOCUMENT ME! * - * @return DOCUMENT ME! - */ - @Override - public ColumnSelection getColumnSelection() - { - return colSel; - } - - /** - * DOCUMENT ME! - * * @param tree * DOCUMENT ME! */ @@ -661,39 +652,6 @@ public class AlignViewport extends AlignmentViewport implements } /** - * synthesize a column selection if none exists so it covers the given - * selection group. if wholewidth is false, no column selection is made if the - * selection group covers the whole alignment width. - * - * @param sg - * @param wholewidth - */ - public void expandColSelection(SequenceGroup sg, boolean wholewidth) - { - int sgs, sge; - if (sg != null - && (sgs = sg.getStartRes()) >= 0 - && sg.getStartRes() <= (sge = sg.getEndRes()) - && (colSel == null || colSel.getSelected() == null || colSel - .getSelected().size() == 0)) - { - if (!wholewidth && alignment.getWidth() == (1 + sge - sgs)) - { - // do nothing - return; - } - if (colSel == null) - { - colSel = new ColumnSelection(); - } - for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++) - { - colSel.addElement(cspos); - } - } - } - - /** * Returns the (Desktop) instance of the StructureSelectionManager */ @Override @@ -714,27 +672,42 @@ public class AlignViewport extends AlignmentViewport implements List seqvectors = new ArrayList(); for (PDBEntry pdb : pdbEntries) { - List seqs = new ArrayList(); + List choosenSeqs = new ArrayList(); for (SequenceI sq : alignment.getSequences()) { - Vector pdbs = sq.getDatasetSequence().getAllPDBEntries(); - if (pdbs == null) + Vector pdbRefEntries = sq.getDatasetSequence().getAllPDBEntries(); + if (pdbRefEntries == null) { continue; } - for (PDBEntry p1 : pdbs) + for (PDBEntry pdbRefEntry : pdbRefEntries) { - if (p1.getId().equals(pdb.getId())) + if (pdbRefEntry.getId().equals(pdb.getId())) { - if (!seqs.contains(sq)) + if (pdbRefEntry.getChainCode() != null + && pdb.getChainCode() != null) + { + if (pdbRefEntry.getChainCode().equalsIgnoreCase( + pdb.getChainCode()) + && !choosenSeqs.contains(sq)) + { + choosenSeqs.add(sq); + continue; + } + } + else { - seqs.add(sq); - continue; + if (!choosenSeqs.contains(sq)) + { + choosenSeqs.add(sq); + continue; + } } + } } } - seqvectors.add(seqs.toArray(new SequenceI[seqs.size()])); + seqvectors.add(choosenSeqs.toArray(new SequenceI[choosenSeqs.size()])); } return seqvectors.toArray(new SequenceI[seqvectors.size()][]); } @@ -855,7 +828,7 @@ public class AlignViewport extends AlignmentViewport implements * Check if any added sequence could be the object of a mapping or * cross-reference; if so, make the mapping explicit */ - realiseMappings(getAlignment(), toAdd); + getAlignment().realiseMappings(toAdd.getSequences()); /* * If any cDNA/protein mappings exist or can be made between the alignments, @@ -863,17 +836,6 @@ public class AlignViewport extends AlignmentViewport implements */ if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, true)) { - // if (toAdd.getDataset() == null) - // { - // // need to create ds seqs - // for (SequenceI sq : toAdd.getSequences()) - // { - // if (sq.getDatasetSequence() == null) - // { - // sq.createDatasetSequence(); - // } - // } - // } if (AlignmentUtils.isMappable(toAdd, getAlignment())) { if (openLinkedAlignment(toAdd, title)) @@ -889,61 +851,26 @@ public class AlignViewport extends AlignmentViewport implements // TODO: JAL-407 regardless of above - identical sequences (based on ID and // provenance) should share the same dataset sequence + AlignmentI al = getAlignment(); + String gap = String.valueOf(al.getGapCharacter()); for (int i = 0; i < toAdd.getHeight(); i++) { - getAlignment().addSequence(toAdd.getSequenceAt(i)); - } - - setEndSeq(getAlignment().getHeight()); - firePropertyChange("alignment", null, getAlignment().getSequences()); - } - - /** - * Check if any added sequence could be the object of a mapping or - * cross-reference; if so, make the mapping explicit. Returns the count of - * mappings updated. - * - * @param al - * @param toAdd - */ - protected int realiseMappings(AlignmentI al, AlignmentI toAdd) - { - // TODO this is proof of concept - // we might want to give the user some choice here - int count = 0; - for (SequenceI seq : toAdd.getSequences()) - { - count += realiseMappingsTo(al, seq); - } - return count; - } - - /** - * If the alignment holds any mappings to a dummy (placeholder) sequence that - * matches the given sequence, then update the mapping to point to the - * sequence. Returns the number of mappings updated. - * - * @param al - * @param seq - * @return - */ - protected int realiseMappingsTo(AlignmentI al, SequenceI seq) - { - int count = 0; - Set mappings = al.getDataset().getCodonFrames(); - // TODO are mappings on alignment or alignment dataset?!? - for (AlignedCodonFrame mapping : mappings) - { + SequenceI seq = toAdd.getSequenceAt(i); /* - * TODO could just go straight to realiseWith() here unless we want - * to give the user some choice before going ahead + * experimental! + * - 'align' any mapped sequences as per existing + * e.g. cdna to genome, domain hit to protein sequence + * very experimental! (need a separate menu option for this) + * - only add mapped sequences ('select targets from a dataset') */ - if (mapping.isRealisableWith(seq)) + if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/) { - count += mapping.realiseWith(seq); + al.addSequence(seq); } } - return count; + + setEndSeq(getAlignment().getHeight()); + firePropertyChange("alignment", null, getAlignment().getSequences()); } /** @@ -1172,4 +1099,68 @@ public class AlignViewport extends AlignmentViewport implements return true; } + /** + * Applies the supplied feature settings descriptor to currently known + * features. This supports an 'initial configuration' of feature colouring + * based on a preset or user favourite. This may then be modified in the usual + * way using the Feature Settings dialogue. + * + * @param featureSettings + */ + @Override + public void applyFeaturesStyle(FeatureSettingsModelI featureSettings) + { + if (featureSettings == null) + { + return; + } + + FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas + .getFeatureRenderer(); + fr.findAllFeatures(true); + List renderOrder = fr.getRenderOrder(); + FeaturesDisplayedI displayed = fr.getFeaturesDisplayed(); + displayed.clear(); + // TODO this clears displayed.featuresRegistered - do we care? + + /* + * set feature colour if specified by feature settings + * set visibility of all features + */ + for (String type : renderOrder) + { + FeatureColourI preferredColour = featureSettings + .getFeatureColour(type); + if (preferredColour != null) + { + fr.setColour(type, preferredColour); + } + if (featureSettings.isFeatureDisplayed(type)) + { + displayed.setVisible(type); + } + } + + /* + * set visibility of feature groups + */ + for (String group : fr.getFeatureGroups()) + { + fr.setGroupVisibility(group, featureSettings.isGroupDisplayed(group)); + } + + /* + * order the features + */ + if (featureSettings.optimiseOrder()) + { + // TODO not supported (yet?) + } + else + { + fr.orderFeatures(featureSettings); + } + fr.setTransparency(featureSettings.getTransparency()); + } + }