X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fensembl%2FEnsemblGene.java;h=edeeeddb08d5ac7ebc5d6708a30f60df29e94de1;hb=3d0101179759ef157b088ea135423cd909512d9f;hp=3b3279778f8be594fba60cfad13dc2be059375c7;hpb=6c52cc0b81ae3abdc3c5f6f88a23364a0246351a;p=jalview.git diff --git a/src/jalview/ext/ensembl/EnsemblGene.java b/src/jalview/ext/ensembl/EnsemblGene.java index 3b32797..edeeedd 100644 --- a/src/jalview/ext/ensembl/EnsemblGene.java +++ b/src/jalview/ext/ensembl/EnsemblGene.java @@ -1,17 +1,36 @@ +/* + * 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; -import jalview.api.FeatureSettingsI; +import jalview.api.FeatureSettingsModelI; 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.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; @@ -29,9 +48,6 @@ import com.stevesoft.pat.Regex; */ public class EnsemblGene extends EnsemblSeqProxy { - private static final List CROSS_REFERENCES = Arrays - .asList(new String[] { "CCDS" }); - private static final String GENE_PREFIX = "gene:"; /* @@ -93,7 +109,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
  • @@ -104,59 +121,110 @@ public class EnsemblGene extends EnsemblSeqProxy * * * @param query - * one or more identifiers separated by a space - * @return an alignment containing one or more genes, and possibly - * transcripts, or null + * a single gene or transcript identifier or gene name + * @return an alignment containing a gene, and possibly transcripts, or null */ @Override public AlignmentI getSequenceRecords(String query) throws Exception { - // todo: tidy up handling of one or multiple accession ids - String[] queries = query.split(getAccessionSeparator()); - /* - * 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) { - // we are assuming all transcripts have the same gene parent here - query = new EnsemblLookup(getDomain()).getParent(queries[0]); - if (query == null) + /* + * fetch the gene sequence(s) with features and xrefs + */ + AlignmentI geneAlignment = super.getSequenceRecords(geneId); + if (geneAlignment == null) { - return null; + continue; + } + if (geneAlignment.getHeight() == 1) + { + getTranscripts(geneAlignment, geneId); + } + if (al == null) + { + al = geneAlignment; + } + else + { + al.append(geneAlignment); } } + return al; + } - /* - * if given a gene or other external name, lookup and fetch - * the corresponding gene for all model organisms - */ - if (!isGeneIdentifier(query)) + /** + * Converts a query, which may contain one or more gene or transcript + * identifiers, into a non-redundant list of gene identifiers. + * + * @param accessions + * @return + */ + List getGeneIds(String accessions) + { + List geneIds = new ArrayList(); + + for (String acc : accessions.split(getAccessionSeparator())) { - List geneIds = new EnsemblSymbol(getDomain()).getIds(query); - if (geneIds.isEmpty()) + if (isGeneIdentifier(acc)) { - return null; + if (!geneIds.contains(acc)) + { + geneIds.add(acc); + } } - String theIds = StringUtils.listToDelimitedString(geneIds, - getAccessionSeparator()); - return getSequenceRecords(theIds); - } - /* - * fetch the gene sequence(s) with features and xrefs - */ - AlignmentI al = super.getSequenceRecords(query); + /* + * if given a transcript id, look up its gene parent + */ + else if (isTranscriptIdentifier(acc)) + { + String geneId = new EnsemblLookup(getDomain()).getParent(acc); + if (geneId != null && !geneIds.contains(geneId)) + { + geneIds.add(geneId); + } + } + else if (isProteinIdentifier(acc)) + { + String tscriptId = new EnsemblLookup(getDomain()).getParent(acc); + if (tscriptId != null) + { + String geneId = new EnsemblLookup(getDomain()) + .getParent(tscriptId); - /* - * if we retrieved a single gene, get its transcripts as well - */ - if (al.getHeight() == 1) - { - getTranscripts(al, query); + if (geneId != null && !geneIds.contains(geneId)) + { + geneIds.add(geneId); + } + } + // NOTE - acc is lost if it resembles an ENS.+ ID but isn't actually + // resolving to one... e.g. ENSMICP00000009241 + } + /* + * if given a gene or other external name, lookup and fetch + * the corresponding gene for all model organisms + */ + else + { + List ids = new EnsemblSymbol(getDomain(), getDbSource(), + getDbVersion()).getIds(acc); + for (String geneId : ids) + { + if (!geneIds.contains(geneId)) + { + geneIds.add(geneId); + } + } + } } - - return al; + return geneIds; } /** @@ -168,7 +236,8 @@ public class EnsemblGene extends EnsemblSeqProxy */ protected String getGeneIdentifiersForName(String query) { - List ids = new EnsemblSymbol(getDomain()).getIds(query); + List ids = new EnsemblSymbol(getDomain(), getDbSource(), + getDbVersion()).getIds(query); if (ids != null) { for (String id : ids) @@ -228,9 +297,8 @@ public class EnsemblGene extends EnsemblSeqProxy filtered.add(sf); } } - gene.setSequenceFeatures(filtered - .toArray(new SequenceFeature[filtered - .size()])); + gene.setSequenceFeatures( + filtered.toArray(new SequenceFeature[filtered.size()])); } } @@ -247,8 +315,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) @@ -296,7 +364,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 @@ -328,19 +397,19 @@ public class EnsemblGene extends EnsemblSeqProxy List mapTo = new ArrayList(); mapTo.add(new int[] { 1, transcriptLength }); MapList mapping = new MapList(mappedFrom, mapTo, 1, 1); - new EnsemblCdna(getDomain()).transferFeatures( - gene.getSequenceFeatures(), transcript.getDatasetSequence(), - mapping, parentId); + EnsemblCdna cdna = new EnsemblCdna(getDomain()); + cdna.transferFeatures(gene.getSequenceFeatures(), + transcript.getDatasetSequence(), mapping, parentId); /* * fetch and save cross-references */ - new EnsemblCdna(getDomain()).getCrossReferences(transcript); + cdna.getCrossReferences(transcript); /* * and finally fetch the protein product and save as a cross-reference */ - new EnsemblCdna(getDomain()).addProteinProduct(transcript); + cdna.addProteinProduct(transcript); return transcript; } @@ -465,15 +534,6 @@ public class EnsemblGene extends EnsemblSeqProxy return false; } - @Override - protected List getCrossReferenceDatabases() - { - // found these for ENSG00000157764 on 30/01/2016: - // return new String[] {"Vega_gene", "OTTG", "ENS_LRG_gene", "ArrayExpress", - // "EntrezGene", "HGNC", "MIM_GENE", "MIM_MORBID", "WikiGene"}; - return CROSS_REFERENCES; - } - /** * Override to do nothing as Ensembl doesn't return a protein sequence for a * gene identifier @@ -489,17 +549,28 @@ public class EnsemblGene extends EnsemblSeqProxy return ACCESSION_REGEX; } + /** + * Returns a descriptor for suitable feature display settings with + *
      + *
    • only exon or sequence_variant features (or their subtypes in the + * Sequence Ontology) visible
    • + *
    • variant features coloured red
    • + *
    • exon features coloured by label (exon name)
    • + *
    • variants displayed above (on top of) exons
    • + *
    + */ @Override - public FeatureSettingsI getFeatureColourScheme() + public FeatureSettingsModelI getFeatureColourScheme() { 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 @@ -507,7 +578,7 @@ public class EnsemblGene extends EnsemblSeqProxy { if (so.isA(type, SequenceOntologyI.EXON)) { - return new FeatureColourAdapter() + return new FeatureColour() { @Override public boolean isColourByLabel() @@ -518,7 +589,7 @@ public class EnsemblGene extends EnsemblSeqProxy } if (so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT)) { - return new FeatureColourAdapter() + return new FeatureColour() { @Override