package jalview.api;
+import java.util.Comparator;
+
/**
* An interface that describes the settings configurable in the Feature Settings
* dialog.
* @author gmcarstairs
*
*/
-public interface FeatureSettingsI
+public interface FeatureSettingsI extends Comparator<String>
{
// note Java 8 will allow default implementations of these methods in the
// interface, simplifying instantiating classes
* @param feature2
* @return
*/
- int compareTo(String feature1, String feature2);
+ @Override
+ int compare(String feature1, String feature2);
/**
* Answers true if features should be initially sorted so that features with a
int getVisibleFeatureCount();
- int getRegisterdFeaturesCount();
+ int getRegisteredFeaturesCount();
}
package jalview.ext.ensembl;
+import jalview.api.FeatureSettingsI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.io.gff.SequenceOntologyFactory;
import jalview.io.gff.SequenceOntologyI;
+import jalview.schemes.FeatureColourScheme;
import jalview.util.MapList;
import jalview.util.StringUtils;
return ACCESSION_REGEX;
}
+ @Override
+ public FeatureSettingsI getFeatureColourScheme()
+ {
+ return FeatureColourScheme.EnsemblVariants;
+ }
+
}
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureSettingsControllerI;
+import jalview.api.FeatureSettingsI;
import jalview.api.SplitContainerI;
import jalview.api.ViewStyleI;
import jalview.api.analysis.ScoreModelI;
import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.SequenceFetcher;
import jalview.ws.jws1.Discoverer;
import jalview.ws.jws2.Jws2Discoverer;
import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.seqfetcher.ASequenceFetcher;
import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.BorderLayout;
@Override
public void fetchSequence_actionPerformed(ActionEvent e)
{
- new SequenceFetcher(this);
+ new jalview.gui.SequenceFetcher(this);
}
@Override
* alternative protein products for my protein's gene
*/
List<SequenceI> addedPeers = new ArrayList<SequenceI>();
- AlignmentI alignment = AlignFrame.this.getViewport().getAlignment();
+ AlignmentI alignment = AlignFrame.this.getViewport()
+ .getAlignment();
Alignment xrefs = CrossRef.findXrefSequences(sel, dna, source,
alignment, addedPeers);
if (xrefs != null)
{
+ /*
+ * figure out colour scheme if any to apply to features
+ */
+ ASequenceFetcher sftch = new SequenceFetcher();
+ List<DbSourceProxy> proxies = sftch.getSourceProxy(source);
+ FeatureSettingsI featureColourScheme = null;
+ for (DbSourceProxy proxy : proxies)
+ {
+ FeatureSettingsI preferredColours = proxy
+ .getFeatureColourScheme();
+ if (preferredColours != null)
+ {
+ featureColourScheme = preferredColours;
+ break;
+ }
+ }
Alignment al = makeCrossReferencesAlignment(
alignment.getDataset(), xrefs);
copyThis.setShowSeqFeatures(showSequenceFeatures);
FeatureRenderer myFeatureStyling = alignPanel.getSeqPanel().seqCanvas
.getFeatureRenderer();
+
/*
* copy feature rendering settings to split frame
*/
copyThis.alignPanel.getSeqPanel().seqCanvas
.getFeatureRenderer().transferSettings(
myFeatureStyling);
+
+ /*
+ * apply 'database source' feature configuration
+ * if any was found
+ */
+ newFrame.getViewport()
+ .applyFeaturesStyle(featureColourScheme);
+ copyThis.getViewport()
+ .applyFeaturesStyle(featureColourScheme);
+
SplitFrame sf = new SplitFrame(dna ? copyThis : newFrame,
dna ? newFrame : copyThis);
newFrame.setVisible(true);
* @param prods
* @return
*/
- protected Alignment makeCrossReferencesAlignment(
-Alignment dataset,
+ protected Alignment makeCrossReferencesAlignment(Alignment dataset,
Alignment prods)
{
SequenceI[] sprods = new SequenceI[prods.getHeight()];
alignPanel.paintAlignment(true);
}
}
- else
- {
- new FileLoader().LoadFile(viewport, file, protocol, format);
- }
+ else
+ {
+ new FileLoader().LoadFile(viewport, file, protocol, format);
+ }
}
}
if (isAnnotation)
@Override
public void run()
{
- boolean isNuclueotide = alignPanel.alignFrame
- .getViewport().getAlignment()
- .isNucleotide();
+ boolean isNuclueotide = alignPanel.alignFrame.getViewport()
+ .getAlignment().isNucleotide();
new jalview.ws.DBRefFetcher(alignPanel.av
- .getSequenceSelection(),
- alignPanel.alignFrame, null,
- alignPanel.alignFrame.featureSettings,
- isNuclueotide)
+ .getSequenceSelection(), alignPanel.alignFrame, null,
+ alignPanel.alignFrame.featureSettings, isNuclueotide)
.fetchDBRefs(false);
}
}).start();
@Override
public void run()
{
- final jalview.ws.SequenceFetcher sf = SequenceFetcher
+ final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher
.getSequenceFetcherSingleton(me);
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
.getSequenceSelection(),
alignPanel.alignFrame, dassource,
alignPanel.alignFrame.featureSettings,
- isNuclueotide)
- .fetchDBRefs(false);
+ isNuclueotide).fetchDBRefs(false);
}
}).start();
}
.getSequenceSelection(),
alignPanel.alignFrame, dassource,
alignPanel.alignFrame.featureSettings,
- isNuclueotide)
- .fetchDBRefs(false);
+ isNuclueotide).fetchDBRefs(false);
}
}).start();
}
.getSequenceSelection(),
alignPanel.alignFrame, dassrc,
alignPanel.alignFrame.featureSettings,
- isNuclueotide)
- .fetchDBRefs(false);
+ isNuclueotide).fetchDBRefs(false);
}
}).start();
}
import jalview.analysis.NJTree;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.api.FeatureColourI;
+import jalview.api.FeatureSettingsI;
+import jalview.api.FeaturesDisplayedI;
import jalview.api.ViewStyleI;
import jalview.bin.Cache;
import jalview.commands.CommandI;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import java.util.Vector;
import javax.swing.JInternalFrame;
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
+ */
+ public void applyFeaturesStyle(FeatureSettingsI featureSettings)
+ {
+ if (featureSettings == null)
+ {
+ return;
+ }
+
+ FeatureRenderer fr = getAlignPanel().getSeqPanel().seqCanvas
+ .getFeatureRenderer();
+ Map<String, Object> featureColours = fr.getFeatureColours();
+ fr.findAllFeatures(true);
+ List<String> 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());
+ }
+
}
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.util.Arrays;
+import java.util.Comparator;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
{
FeatureColourChooser fcc = null;
+ @Override
public void mousePressed(MouseEvent evt)
{
if (fcol instanceof Color)
fcc.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
fcol = fcc.getLastColour();
overlaps.addItemListener(new ItemListener()
{
+ @Override
public void itemStateChanged(ItemEvent e)
{
int index = overlaps.getSelectedIndex();
// colour.setForeground(colour.getBackground());
}
}
+
+ /**
+ * Orders features in render precedence (last in order is last to render, so
+ * displayed on top of other features)
+ *
+ * @param order
+ */
+ public void orderFeatures(Comparator<String> order)
+ {
+ Arrays.sort(renderOrder, order);
+ }
}
*/
package jalview.gui;
+import jalview.api.FeatureSettingsI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
-import jalview.io.FormatAdapter;
-import jalview.io.IdentifyFile;
import jalview.util.DBRefUtils;
import jalview.util.MessageManager;
import jalview.ws.dbsources.das.api.DasSourceRegistryI;
.split(";"));
Iterator<String> en = Arrays.asList(new String[0]).iterator();
int nqueries = qries.length;
+
+ FeatureSettingsI preferredFeatureColours = null;
while (proxies.hasNext() && (en.hasNext() || nextfetch.size() > 0))
{
if (!en.hasNext() && nextfetch.size() > 0)
// Stack results ready for opening in alignment windows
if (aresult != null && aresult.size() > 0)
{
+ FeatureSettingsI proxyColourScheme = proxy.getFeatureColourScheme();
+ if (proxyColourScheme != null)
+ {
+ preferredFeatureColours = proxyColourScheme;
+ }
+
AlignmentI ar = null;
if (isAliSource)
{
// process results
while (presult.size() > 0)
{
- parseResult(presult.remove(0), presultTitle.remove(0), null);
+ parseResult(presult.remove(0), presultTitle.remove(0), null,
+ preferredFeatureColours);
}
// only remove visual delay after we finished parsing.
guiWindow.setProgressBar(null, Thread.currentThread().hashCode());
resetDialog();
}
- AlignmentI parseResult(String result, String title)
- {
- String format = new IdentifyFile().identify(result, "Paste");
- AlignmentI sequences = null;
- if (FormatAdapter.isValidFormat(format))
- {
- sequences = null;
- try
- {
- sequences = new FormatAdapter().readFile(result.toString(),
- "Paste", format);
- } catch (Exception ex)
- {
- }
-
- if (sequences != null)
- {
- return parseResult(sequences, title, format);
- }
- }
- else
- {
- showErrorMessage("Error retrieving " + textArea.getText() + " from "
- + database.getSelectedItem());
- }
-
- return null;
- }
-
/**
*
* @return a standard title for any results retrieved using the currently
}
AlignmentI parseResult(AlignmentI al, String title,
- String currentFileFormat)
+ String currentFileFormat, FeatureSettingsI preferredFeatureColours)
{
if (al != null && al.getHeight() > 0)
}
}
+
+ if (preferredFeatureColours != null)
+ {
+ af.viewport.applyFeaturesStyle(preferredFeatureColours);
+ }
Desktop.addInternalFrame(af, title, AlignFrame.DEFAULT_WIDTH,
AlignFrame.DEFAULT_HEIGHT);
}
/**
- * Order sequence_variant above exon above the rest
+ * order to render sequence_variant after exon after the rest
*/
@Override
- public int compareTo(String feature1, String feature2)
+ public int compare(String feature1, String feature2)
{
if (SEQUENCE_VARIANT.equals(feature1))
{
- return -1;
+ return +1;
}
if (SEQUENCE_VARIANT.equals(feature2))
{
- return +1;
+ return -1;
}
if (EXON.equals(feature1))
{
- return -1;
+ return +1;
}
if (EXON.equals(feature2))
{
- return +1;
+ return -1;
}
return 0;
}
*/
package jalview.schemes;
+import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceFeature;
import java.awt.Color;
updateBounds(min, max);
}
+ public GraduatedColor(FeatureColourI col)
+ {
+ setColourByLabel(col.isColourByLabel());
+ }
+
public Color getMinColor()
{
return new Color(lr, lg, lb);
public boolean areFeaturesDisplayed()
{
return featuresDisplayed != null
- && featuresDisplayed.getRegisterdFeaturesCount() > 0;
+ && featuresDisplayed.getRegisteredFeaturesCount() > 0;
}
/**
package jalview.viewmodel.seqfeatures;
import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
import jalview.api.FeaturesDisplayedI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceFeature;
protected Object currentColour;
/*
- * ordering of rendering, where last means on top
+ * feature types in ordering of rendering, where last means on top
*/
protected String[] renderOrder;
// Object c = featureColours.get(featureType);
// if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
// !((GraduatedColor)c).getMaxColor().equals(_col)))
+ if (col instanceof FeatureColourI)
{
- featureColours.put(featureType, col);
+ if (((FeatureColourI) col).isGraduatedColour())
+ {
+ col = new GraduatedColor((FeatureColourI) col);
+ }
+ else
+ {
+ col = ((FeatureColourI) col).getColour();
+ }
}
+ featureColours.put(featureType, col);
}
public void setTransparency(float value)
}
@Override
- public boolean areVisible(Collection featureTypes)
+ public boolean areVisible(Collection<String> featureTypes)
{
return featuresDisplayed.containsAll(featureTypes);
}
}
@Override
- public void setAllVisible(Collection makeVisible)
+ public void setAllVisible(Collection<String> makeVisible)
{
featuresDisplayed.addAll(makeVisible);
featuresRegistered.addAll(makeVisible);
}
@Override
- public int getRegisterdFeaturesCount()
+ public int getRegisteredFeaturesCount()
{
return featuresRegistered.size();
}
package jalview.ws;
import jalview.ext.ensembl.EnsemblGene;
-import jalview.ext.ensembl.EnsemblProtein;
import jalview.ws.dbsources.EmblCdsSource;
import jalview.ws.dbsources.EmblSource;
import jalview.ws.dbsources.Pdb;
public SequenceFetcher(boolean addDas)
{
- addDBRefSourceImpl(EnsemblProtein.class);
+ // addDBRefSourceImpl(EnsemblProtein.class);
// addDBRefSourceImpl(EnsemblCds.class);
// addDBRefSourceImpl(EnsemblGenome.class);
addDBRefSourceImpl(EnsemblGene.class);
*/
package jalview.ws.seqfetcher;
+import jalview.api.FeatureSettingsI;
import jalview.datamodel.AlignmentI;
import com.stevesoft.pat.Regex;
/**
* generic Reference Retrieval interface for a particular database
- * source/version as cited in DBRefEntry. TODO: add/define property to describe
- * max number of queries that this source can cope with at once. TODO:
- * add/define mechanism for retrieval of Trees and distance matrices from a
- * database (unify with io)
+ * source/version as cited in DBRefEntry.
*
- * @author JimP TODO: promote to API
+ * TODO: add/define mechanism for retrieval of Trees and distance matrices from
+ * a database (unify with io)
+ *
+ * @author JimP
*/
public interface DbSourceProxy
{
*
* @return source string constant used for this DB source
*/
- public String getDbSource();
+ String getDbSource();
/**
* Short meaningful name for this data source for display in menus or
*
* @return String
*/
- public String getDbName();
+ String getDbName();
/**
*
* @return version string for this database.
*/
- public String getDbVersion();
+ String getDbVersion();
/**
* Separator between individual accession queries for a database that allows
* @return string for separating concatenated queries (as individually
* validated by the accession validator)
*/
- public String getAccessionSeparator();
+ String getAccessionSeparator();
/**
* Regular expression for checking form of query string understood by this
*
* @return null or a validation regex
*/
- public Regex getAccessionValidator();
+ Regex getAccessionValidator();
/**
*
* @return a test/example query that can be used to validate retrieval and
* parsing mechanisms
*/
- public String getTestQuery();
+ String getTestQuery();
/**
* Required for sources supporting multiple query retrieval for use with the
* @param accession
* @return
*/
- public boolean isValidReference(String accession);
+ boolean isValidReference(String accession);
/**
* make one or more queries to the database and attempt to parse the response
* exceptions are not raised if query not found in database)
*
*/
- public AlignmentI getSequenceRecords(String queries) throws Exception;
+ AlignmentI getSequenceRecords(String queries) throws Exception;
/**
*
* @return true if a query is currently being made
*/
- public boolean queryInProgress();
+ boolean queryInProgress();
/**
* get the raw reponse from the last set of queries
*
* @return one or more string buffers for each individual query
*/
- public StringBuffer getRawRecords();
+ StringBuffer getRawRecords();
/**
* Tier for this data source
*
* @return 0 - primary datasource, 1 - das primary source, 2 - secondary
*/
- public int getTier();
+ int getTier();
/**
* Extracts valid accession strings from a query string. If there is an
*
* @return
*/
- public int getMaximumQueryCount();
+ int getMaximumQueryCount();
/**
* Returns true if the source may provide coding DNA i.e. sequences with
*
* @return
*/
- public boolean isDnaCoding();
+ boolean isDnaCoding();
/**
* Answers true if the database is a source of alignments (for example, domain
*
* @return
*/
- public boolean isAlignmentSource();
+ boolean isAlignmentSource();
/**
* Returns an (optional) description of the source, suitable for display as a
*
* @return
*/
- public String getDescription();
+ String getDescription();
+
+ /**
+ * Returns the preferred feature colour configuration if there is one, else
+ * null
+ *
+ * @return
+ */
+ FeatureSettingsI getFeatureColourScheme();
}
\ No newline at end of file
*/
package jalview.ws.seqfetcher;
+import jalview.api.FeatureSettingsI;
import jalview.datamodel.AlignmentI;
import jalview.io.FormatAdapter;
import jalview.io.IdentifyFile;
{
return null;
}
+
+ @Override
+ public FeatureSettingsI getFeatureColourScheme()
+ {
+ return null;
+ }
}