X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fensembl%2FEnsemblGene.java;h=f46cb1be90e234133ffe68bc3d76aaec3b758fd3;hb=f23f5cefe9c66bfa8b877c707d25862cabba3ddf;hp=84b5dcfd2063f6cba073264b7fbd0112d7659ae4;hpb=70ad0f1ae40759c435ead9d732983aeb091dfd0e;p=jalview.git
diff --git a/src/jalview/ext/ensembl/EnsemblGene.java b/src/jalview/ext/ensembl/EnsemblGene.java
index 84b5dcf..f46cb1b 100644
--- a/src/jalview/ext/ensembl/EnsemblGene.java
+++ b/src/jalview/ext/ensembl/EnsemblGene.java
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.ext.ensembl;
import jalview.api.FeatureColourI;
@@ -6,12 +26,12 @@ import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.SequenceFeatures;
import jalview.io.gff.SequenceOntologyFactory;
import jalview.io.gff.SequenceOntologyI;
-import jalview.schemes.FeatureColourAdapter;
+import jalview.schemes.FeatureColour;
import jalview.schemes.FeatureSettingsAdapter;
import jalview.util.MapList;
-import jalview.util.StringUtils;
import java.awt.Color;
import java.io.UnsupportedEncodingException;
@@ -90,7 +110,8 @@ public class EnsemblGene extends EnsemblSeqProxy
*
resolves an external identifier by looking up xref-ed gene ids
* fetches the gene sequence
* fetches features on the sequence
- * identifies "transcript" features whose Parent is the requested gene
+ * identifies "transcript" features whose Parent is the requested
+ * gene
* fetches the transcript sequence for each transcript
* makes a mapping from the gene to each transcript
* copies features from gene to transcript sequences
@@ -108,70 +129,80 @@ public class EnsemblGene extends EnsemblSeqProxy
public AlignmentI getSequenceRecords(String query) throws Exception
{
/*
- * if given a transcript id, look up its gene parent
+ * convert to a non-duplicated list of gene identifiers
*/
- if (isTranscriptIdentifier(query))
+ List geneIds = getGeneIds(query);
+
+ AlignmentI al = null;
+ for (String geneId : geneIds)
{
- query = new EnsemblLookup(getDomain()).getParent(query);
- if (query == null)
+ /*
+ * fetch the gene sequence(s) with features and xrefs
+ */
+ AlignmentI geneAlignment = super.getSequenceRecords(geneId);
+ if (geneAlignment == null)
{
- return null;
+ continue;
}
- }
-
- /*
- * if given a gene or other external name, lookup and fetch
- * the corresponding gene for all model organisms
- */
- if (!isGeneIdentifier(query))
- {
- List geneIds = new EnsemblSymbol(getDomain()).getIds(query);
- if (geneIds.isEmpty())
+ if (geneAlignment.getHeight() == 1)
{
- return null;
+ getTranscripts(geneAlignment, geneId);
+ }
+ if (al == null)
+ {
+ al = geneAlignment;
+ }
+ else
+ {
+ al.append(geneAlignment);
}
- String theIds = StringUtils.listToDelimitedString(geneIds,
- getAccessionSeparator());
- return getSequenceRecords(theIds);
- }
-
- /*
- * fetch the gene sequence(s) with features and xrefs
- */
- AlignmentI al = super.getSequenceRecords(query);
-
- /*
- * if we retrieved a single gene, get its transcripts as well
- */
- if (al.getHeight() == 1)
- {
- getTranscripts(al, query);
}
-
return al;
}
/**
- * Attempts to get Ensembl stable identifiers for model organisms for a gene
- * name by calling the xrefs symbol REST service to resolve the gene name.
+ * Converts a query, which may contain one or more gene, transcript, or
+ * external (to Ensembl) identifiers, into a non-redundant list of gene
+ * identifiers.
*
- * @param query
+ * @param accessions
* @return
*/
- protected String getGeneIdentifiersForName(String query)
+ List getGeneIds(String accessions)
{
- List ids = new EnsemblSymbol(getDomain()).getIds(query);
- if (ids != null)
+ List geneIds = new ArrayList();
+
+ for (String acc : accessions.split(getAccessionSeparator()))
{
- for (String id : ids)
+ /*
+ * First try lookup as an Ensembl (gene or transcript) identifier
+ */
+ String geneId = new EnsemblLookup(getDomain()).getGeneId(acc);
+ if (geneId != null)
+ {
+ if (!geneIds.contains(geneId))
+ {
+ geneIds.add(geneId);
+ }
+ }
+ else
{
- if (isGeneIdentifier(id))
+ /*
+ * if given a gene or other external name, lookup and fetch
+ * the corresponding gene for all model organisms
+ */
+ List ids = new EnsemblSymbol(getDomain(), getDbSource(),
+ getDbVersion()).getGeneIds(acc);
+ for (String id : ids)
{
- return id;
+ if (!geneIds.contains(id))
+ {
+ geneIds.add(id);
+ }
}
}
}
- return null;
+ return geneIds;
}
/**
@@ -206,23 +237,20 @@ public class EnsemblGene extends EnsemblSeqProxy
*/
protected void clearGeneFeatures(SequenceI gene)
{
- SequenceFeature[] sfs = gene.getSequenceFeatures();
- if (sfs != null)
+ /*
+ * Note we include NMD_transcript_variant here because it behaves like
+ * 'transcript' in Ensembl, although strictly speaking it is not
+ * (it is a sub-type of sequence_variant)
+ */
+ String[] soTerms = new String[] {
+ SequenceOntologyI.NMD_TRANSCRIPT_VARIANT,
+ SequenceOntologyI.TRANSCRIPT, SequenceOntologyI.EXON,
+ SequenceOntologyI.CDS };
+ List sfs = gene.getFeatures().getFeaturesByOntology(
+ soTerms);
+ for (SequenceFeature sf : sfs)
{
- SequenceOntologyI so = SequenceOntologyFactory.getInstance();
- List filtered = new ArrayList();
- for (SequenceFeature sf : sfs)
- {
- String type = sf.getType();
- if (!isTranscript(type) && !so.isA(type, SequenceOntologyI.EXON)
- && !so.isA(type, SequenceOntologyI.CDS))
- {
- filtered.add(sf);
- }
- }
- gene.setSequenceFeatures(filtered
- .toArray(new SequenceFeature[filtered
- .size()]));
+ gene.deleteFeature(sf);
}
}
@@ -239,8 +267,8 @@ public class EnsemblGene extends EnsemblSeqProxy
* the parent gene sequence, with features
* @return
*/
- SequenceI makeTranscript(SequenceFeature transcriptFeature,
- AlignmentI al, SequenceI gene)
+ SequenceI makeTranscript(SequenceFeature transcriptFeature, AlignmentI al,
+ SequenceI gene)
{
String accId = getTranscriptId(transcriptFeature);
if (accId == null)
@@ -272,6 +300,7 @@ public class EnsemblGene extends EnsemblSeqProxy
{
splices = findFeatures(gene, SequenceOntologyI.CDS, parentId);
}
+ SequenceFeatures.sortFeatures(splices, true);
int transcriptLength = 0;
final char[] geneChars = gene.getSequence();
@@ -288,7 +317,8 @@ public class EnsemblGene extends EnsemblSeqProxy
mappedFrom.add(new int[] { sf.getBegin(), sf.getEnd() });
}
- Sequence transcript = new Sequence(accId, seqChars, 1, transcriptLength);
+ Sequence transcript = new Sequence(accId, seqChars, 1,
+ transcriptLength);
/*
* Ensembl has gene name as transcript Name
@@ -321,7 +351,7 @@ public class EnsemblGene extends EnsemblSeqProxy
mapTo.add(new int[] { 1, transcriptLength });
MapList mapping = new MapList(mappedFrom, mapTo, 1, 1);
EnsemblCdna cdna = new EnsemblCdna(getDomain());
- cdna.transferFeatures(gene.getSequenceFeatures(),
+ cdna.transferFeatures(gene.getFeatures().getPositionalFeatures(),
transcript.getDatasetSequence(), mapping, parentId);
/*
@@ -362,19 +392,18 @@ public class EnsemblGene extends EnsemblSeqProxy
List transcriptFeatures = new ArrayList();
String parentIdentifier = GENE_PREFIX + accId;
- SequenceFeature[] sfs = geneSequence.getSequenceFeatures();
+ // todo optimise here by transcript type!
+ List sfs = geneSequence.getFeatures()
+ .getPositionalFeatures();
- if (sfs != null)
+ for (SequenceFeature sf : sfs)
{
- for (SequenceFeature sf : sfs)
+ if (isTranscript(sf.getType()))
{
- if (isTranscript(sf.getType()))
+ String parent = (String) sf.getValue(PARENT);
+ if (parentIdentifier.equals(parent))
{
- String parent = (String) sf.getValue(PARENT);
- if (parentIdentifier.equals(parent))
- {
- transcriptFeatures.add(sf);
- }
+ transcriptFeatures.add(sf);
}
}
}
@@ -488,11 +517,12 @@ public class EnsemblGene extends EnsemblSeqProxy
return new FeatureSettingsAdapter()
{
SequenceOntologyI so = SequenceOntologyFactory.getInstance();
+
@Override
public boolean isFeatureDisplayed(String type)
{
- return (so.isA(type, SequenceOntologyI.EXON) || so.isA(type,
- SequenceOntologyI.SEQUENCE_VARIANT));
+ return (so.isA(type, SequenceOntologyI.EXON)
+ || so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT));
}
@Override
@@ -500,7 +530,7 @@ public class EnsemblGene extends EnsemblSeqProxy
{
if (so.isA(type, SequenceOntologyI.EXON))
{
- return new FeatureColourAdapter()
+ return new FeatureColour()
{
@Override
public boolean isColourByLabel()
@@ -511,7 +541,7 @@ public class EnsemblGene extends EnsemblSeqProxy
}
if (so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT))
{
- return new FeatureColourAdapter()
+ return new FeatureColour()
{
@Override
@@ -551,10 +581,4 @@ public class EnsemblGene extends EnsemblSeqProxy
};
}
- @Override
- public int getMaximumQueryCount()
- {
- return 1;
- }
-
}