From: gmungoc Date: Thu, 21 Sep 2017 15:27:01 +0000 (+0100) Subject: JAL-2738 add chromosome coordinate mappings to transcripts X-Git-Tag: Release_2_11_0~239 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=58c1349375691d2285976352f6947a835e745c7c;p=jalview.git JAL-2738 add chromosome coordinate mappings to transcripts --- diff --git a/src/jalview/ext/ensembl/EnsemblGene.java b/src/jalview/ext/ensembl/EnsemblGene.java index 365c1c2..32b7c7c 100644 --- a/src/jalview/ext/ensembl/EnsemblGene.java +++ b/src/jalview/ext/ensembl/EnsemblGene.java @@ -23,6 +23,7 @@ package jalview.ext.ensembl; import jalview.api.FeatureColourI; import jalview.api.FeatureSettingsModelI; import jalview.datamodel.AlignmentI; +import jalview.datamodel.GeneLoci; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; @@ -401,6 +402,8 @@ public class EnsemblGene extends EnsemblSeqProxy cdna.transferFeatures(gene.getFeatures().getPositionalFeatures(), transcript.getDatasetSequence(), mapping, parentId); + mapTranscriptToChromosome(transcript, gene, mapping); + /* * fetch and save cross-references */ @@ -415,6 +418,51 @@ public class EnsemblGene extends EnsemblSeqProxy } /** + * 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(Sequence transcript, + SequenceI gene, MapList mapping) + { + GeneLoci loci = ((Sequence) gene).getGeneLoci(); + if (loci == null) + { + return; + } + + /* + * patch to ensure gene to chromosome mapping is complete + * (in case created before gene length was known) + */ + MapList geneMapping = loci.getMapping(); + if (geneMapping.getFromRanges().get(0)[1] == 0) + { + geneMapping.getFromRanges().get(0)[0] = gene.getStart(); + geneMapping.getFromRanges().get(0)[1] = gene.getEnd(); + } + + List exons = mapping.getFromRanges(); + List transcriptLoci = new ArrayList<>(); + + for (int[] exon : exons) { + transcriptLoci.add(geneMapping.locateInTo(exon[0], exon[1])); + } + + List transcriptRange = Arrays.asList(new int[] { + transcript.getStart(), transcript.getEnd() }); + MapList mapList = new MapList(transcriptRange, transcriptLoci, 1, 1); + GeneLoci gl = new GeneLoci(loci.getSpecies(), loci.getReference(), + loci.getChromosome(), mapList, loci.isForwardStrand()); + + transcript.setGeneLoci(gl); + } + + /** * Returns the 'transcript_id' property of the sequence feature (or null) * * @param feature