import jalview.api.FeatureColourI;
import jalview.api.FeatureSettingsModelI;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.GeneLociI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.schemes.FeatureColour;
import jalview.schemes.FeatureSettingsAdapter;
import jalview.util.MapList;
+import jalview.util.Platform;
import java.awt.Color;
import java.io.UnsupportedEncodingException;
*/
public class EnsemblGene extends EnsemblSeqProxy
{
- private static final String GENE_PREFIX = "gene:";
-
/*
* accepts anything as we will attempt lookup of gene or
* transcript id or gene name
EnsemblFeatureType.exon, EnsemblFeatureType.cds,
EnsemblFeatureType.variation };
+ private static final String CHROMOSOME = "chromosome";
+
/**
* Default constructor (to use rest.ensembl.org)
*/
* convert to a non-duplicated list of gene identifiers
*/
List<String> geneIds = getGeneIds(query);
-
AlignmentI al = null;
for (String geneId : geneIds)
{
{
continue;
}
+
if (geneAlignment.getHeight() == 1)
{
+ // ensure id has 'correct' case for the Ensembl identifier
+ geneId = geneAlignment.getSequenceAt(0).getName();
+ findGeneLoci(geneAlignment.getSequenceAt(0), geneId);
getTranscripts(geneAlignment, geneId);
}
if (al == null)
}
/**
+ * Calls the /lookup/id REST service, parses the response for gene
+ * coordinates, and if successful, adds these to the sequence. If this fails,
+ * fall back on trying to parse the sequence description in case it is in
+ * Ensembl-gene format e.g. chromosome:GRCh38:17:45051610:45109016:1.
+ *
+ * @param seq
+ * @param geneId
+ */
+ void findGeneLoci(SequenceI seq, String geneId)
+ {
+ GeneLociI geneLoci = new EnsemblLookup(getDomain()).getGeneLoci(geneId);
+ if (geneLoci != null)
+ {
+ seq.setGeneLoci(geneLoci.getSpeciesId(), geneLoci.getAssemblyId(),
+ geneLoci.getChromosomeId(), geneLoci.getMapping());
+ }
+ else
+ {
+ parseChromosomeLocations(seq);
+ }
+ }
+
+ /**
+ * Parses and saves fields of an Ensembl-style description e.g.
+ * chromosome:GRCh38:17:45051610:45109016:1
+ *
+ * @param seq
+ */
+ boolean parseChromosomeLocations(SequenceI seq)
+ {
+ String description = seq.getDescription();
+ if (description == null)
+ {
+ return false;
+ }
+ String[] tokens = description.split(":");
+ if (tokens.length == 6 && tokens[0].startsWith(CHROMOSOME))
+ {
+ String ref = tokens[1];
+ String chrom = tokens[2];
+ try
+ {
+ int chStart = Integer.parseInt(tokens[3]);
+ int chEnd = Integer.parseInt(tokens[4]);
+ boolean forwardStrand = "1".equals(tokens[5]);
+ String species = ""; // not known here
+ int[] from = new int[] { seq.getStart(), seq.getEnd() };
+ int[] to = new int[] { forwardStrand ? chStart : chEnd,
+ forwardStrand ? chEnd : chStart };
+ MapList map = new MapList(from, to, 1, 1);
+ seq.setGeneLoci(species, ref, chrom, map);
+ return true;
+ } catch (NumberFormatException e)
+ {
+ System.err.println("Bad integers in description " + description);
+ }
+ }
+ return false;
+ }
+
+ /**
* Converts a query, which may contain one or more gene, transcript, or
* external (to Ensembl) identifiers, into a non-redundant list of gene
* identifiers.
SequenceOntologyI.NMD_TRANSCRIPT_VARIANT,
SequenceOntologyI.TRANSCRIPT, SequenceOntologyI.EXON,
SequenceOntologyI.CDS };
- List<SequenceFeature> sfs = gene.getFeatures().getFeaturesByOntology(
- soTerms);
+ List<SequenceFeature> sfs = gene.getFeatures()
+ .getFeaturesByOntology(soTerms);
for (SequenceFeature sf : sfs)
{
gene.deleteFeature(sf);
* look for exon features of the transcript, failing that for CDS
* (for example ENSG00000124610 has 1 CDS but no exon features)
*/
- String parentId = "transcript:" + accId;
+ String parentId = accId;
List<SequenceFeature> splices = findFeatures(gene,
SequenceOntologyI.EXON, parentId);
if (splices.isEmpty())
* Ensembl has gene name as transcript Name
* EnsemblGenomes doesn't, but has a url-encoded description field
*/
- String description = (String) transcriptFeature.getValue(NAME);
+ String description = transcriptFeature.getDescription();
if (description == null)
{
description = (String) transcriptFeature.getValue(DESCRIPTION);
cdna.transferFeatures(gene.getFeatures().getPositionalFeatures(),
transcript.getDatasetSequence(), mapping, parentId);
+ mapTranscriptToChromosome(transcript, gene, mapping);
+
/*
* fetch and save cross-references
*/
}
/**
+ * If the gene has a mapping to chromosome coordinates, derive the transcript
+ * chromosome regions and save on the transcript sequence
+ *
+ * @param transcript
+ * @param gene
+ * @param mapping
+ * the mapping from gene to transcript positions
+ */
+ protected void mapTranscriptToChromosome(SequenceI transcript,
+ SequenceI gene, MapList mapping)
+ {
+ GeneLociI loci = gene.getGeneLoci();
+ if (loci == null)
+ {
+ return;
+ }
+
+ MapList geneMapping = loci.getMapping();
+
+ List<int[]> exons = mapping.getFromRanges();
+ List<int[]> transcriptLoci = new ArrayList<>();
+
+ for (int[] exon : exons)
+ {
+ transcriptLoci.add(geneMapping.locateInTo(exon[0], exon[1]));
+ }
+
+ List<int[]> transcriptRange = Arrays
+ .asList(new int[]
+ { transcript.getStart(), transcript.getEnd() });
+ MapList mapList = new MapList(transcriptRange, transcriptLoci, 1, 1);
+
+ transcript.setGeneLoci(loci.getSpeciesId(), loci.getAssemblyId(),
+ loci.getChromosomeId(), mapList);
+ }
+
+ /**
* Returns the 'transcript_id' property of the sequence feature (or null)
*
* @param feature
*/
protected String getTranscriptId(SequenceFeature feature)
{
- return (String) feature.getValue("transcript_id");
+ return (String) feature.getValue(JSON_ID);
}
/**
{
List<SequenceFeature> transcriptFeatures = new ArrayList<>();
- String parentIdentifier = GENE_PREFIX + accId;
+ String parentIdentifier = accId;
List<SequenceFeature> sfs = geneSequence.getFeatures()
.getFeaturesByOntology(SequenceOntologyI.TRANSCRIPT);
@Override
public String getTestQuery()
{
- return "ENSG00000157764"; // BRAF, 5 transcripts, reverse strand
+ return Platform.isJS() ? "ENSG00000123569" : "ENSG00000157764";
+ // ENSG00000123569 // H2BFWT histone, 2 transcripts, reverse strand
+ // ENSG00000157764 // BRAF, 5 transcripts, reverse strand
// ENSG00000090266 // NDUFB2, 15 transcripts, forward strand
// ENSG00000101812 // H2BFM histone, 3 transcripts, forward strand
- // ENSG00000123569 // H2BFWT histone, 2 transcripts, reverse strand
}
/**
- * Answers true for a feature of type 'gene' (or a sub-type of gene in the
- * Sequence Ontology), whose ID is the accession we are retrieving
+ * Answers a list of sequence features (if any) whose type is 'gene' (or a
+ * subtype of gene in the Sequence Ontology), and whose ID is the accession we
+ * are retrieving
*/
@Override
- protected boolean identifiesSequence(SequenceFeature sf, String accId)
+ protected List<SequenceFeature> getIdentifyingFeatures(SequenceI seq,
+ String accId)
{
- if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
- SequenceOntologyI.GENE))
+ List<SequenceFeature> result = new ArrayList<>();
+ List<SequenceFeature> sfs = seq.getFeatures()
+ .getFeaturesByOntology(SequenceOntologyI.GENE);
+ for (SequenceFeature sf : sfs)
{
- // NB features as gff use 'ID'; rest services return as 'id'
- String id = (String) sf.getValue("ID");
- if ((GENE_PREFIX + accId).equalsIgnoreCase(id))
+ String id = (String) sf.getValue(JSON_ID);
+ if (accId.equalsIgnoreCase(id))
{
- return true;
+ result.add(sf);
}
}
- return false;
+ return result;
}
/**
if (isTranscript(type))
{
String parent = (String) sf.getValue(PARENT);
- if (!(GENE_PREFIX + accessionId).equalsIgnoreCase(parent))
+ if (!accessionId.equalsIgnoreCase(parent))
{
return false;
}
}
/**
- * Answers false. This allows an optimisation - a single 'gene' feature is all
- * that is needed to identify the positions of the gene on the genomic
- * sequence.
- */
- @Override
- protected boolean isSpliceable()
- {
- return false;
- }
-
- /**
* Override to do nothing as Ensembl doesn't return a protein sequence for a
* gene identifier
*/
SequenceOntologyI so = SequenceOntologyFactory.getInstance();
@Override
- public boolean isFeatureDisplayed(String type)
+ public boolean isFeatureHidden(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