X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Fxdb%2Fembl%2FEmblEntry.java;h=a2354edb653b80f81a14b1746d02f872a0e39ad5;hb=f28d892d6d2584e7eb44ff7333d49d60d787f706;hp=320741170977929387195c77ede80c3864e19269;hpb=5071850e8470077a8ac2bdc6a53908c70ad5526d;p=jalview.git diff --git a/src/jalview/datamodel/xdb/embl/EmblEntry.java b/src/jalview/datamodel/xdb/embl/EmblEntry.java index 3207411..a2354ed 100644 --- a/src/jalview/datamodel/xdb/embl/EmblEntry.java +++ b/src/jalview/datamodel/xdb/embl/EmblEntry.java @@ -21,6 +21,7 @@ package jalview.datamodel.xdb.embl; import jalview.analysis.SequenceIdMatcher; +import jalview.bin.Cache; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; import jalview.datamodel.FeatureProperties; @@ -34,6 +35,7 @@ import jalview.util.MapList; import jalview.util.MappingUtils; import jalview.util.StringUtils; +import java.text.ParseException; import java.util.Arrays; import java.util.Hashtable; import java.util.List; @@ -62,21 +64,25 @@ public class EmblEntry String sequenceVersion; + String dataClass; + String moleculeType; String topology; String sequenceLength; - String taxDivision; + String taxonomicDivision; + + String description; - String desc; + String firstPublicDate; - String rCreated; + String firstPublicRelease; - String rLastUpdated; + String lastUpdatedDate; - String lastUpdated; + String lastUpdatedRelease; Vector keywords; @@ -121,23 +127,6 @@ public class EmblEntry } /** - * @return the desc - */ - public String getDesc() - { - return desc; - } - - /** - * @param desc - * the desc to set - */ - public void setDesc(String desc) - { - this.desc = desc; - } - - /** * @return the features */ public Vector getFeatures() @@ -172,57 +161,6 @@ public class EmblEntry } /** - * @return the lastUpdated - */ - public String getLastUpdated() - { - return lastUpdated; - } - - /** - * @param lastUpdated - * the lastUpdated to set - */ - public void setLastUpdated(String lastUpdated) - { - this.lastUpdated = lastUpdated; - } - - /** - * @return the releaseCreated - */ - public String getRCreated() - { - return rCreated; - } - - /** - * @param releaseCreated - * the releaseCreated to set - */ - public void setRCreated(String releaseCreated) - { - this.rCreated = releaseCreated; - } - - /** - * @return the releaseLastUpdated - */ - public String getRLastUpdated() - { - return rLastUpdated; - } - - /** - * @param releaseLastUpdated - * the releaseLastUpdated to set - */ - public void setRLastUpdated(String releaseLastUpdated) - { - this.rLastUpdated = releaseLastUpdated; - } - - /** * @return the sequence */ public EmblSequence getSequence() @@ -240,40 +178,6 @@ public class EmblEntry } /** - * @return the taxDivision - */ - public String getTaxDivision() - { - return taxDivision; - } - - /** - * @param taxDivision - * the taxDivision to set - */ - public void setTaxDivision(String taxDivision) - { - this.taxDivision = taxDivision; - } - - /** - * @return the entry version - */ - public String getEntryVersion() - { - return entryVersion; - } - - /** - * @param version - * the version to set - */ - public void setEntryVersion(String version) - { - this.entryVersion = version; - } - - /** * Recover annotated sequences from EMBL file * * @param sourceDb @@ -285,7 +189,7 @@ public class EmblEntry { SequenceI dna = new Sequence(sourceDb + "|" + accession, sequence.getSequence()); - dna.setDescription(desc); + dna.setDescription(description); DBRefEntry retrievedref = new DBRefEntry(sourceDb, getSequenceVersion(), accession); dna.addDBRef(retrievedref); @@ -293,29 +197,28 @@ public class EmblEntry // dbref retrievedref.setMap(new Mapping(null, new int[] { 1, dna.getLength() }, new int[] { 1, dna.getLength() }, 1, 1)); - // TODO: transform EMBL Database refs to canonical form + + + /* + * transform EMBL Database refs to canonical form + */ if (dbRefs != null) { for (DBRefEntry dbref : dbRefs) { + dbref.setSource(DBRefUtils.getCanonicalName(dbref.getSource())); dna.addDBRef(dbref); } } + SequenceIdMatcher matcher = new SequenceIdMatcher(peptides); try { for (EmblFeature feature : features) { - if (feature.dbRefs != null) - { - for (DBRefEntry dbref : feature.dbRefs) - { - dna.addDBRef(dbref); - } - } if (FeatureProperties.isCodingFeature(sourceDb, feature.getName())) { - parseCodingFeature(feature, sourceDb, dna, peptides); + parseCodingFeature(feature, sourceDb, dna, peptides, matcher); } } } catch (Exception e) @@ -343,19 +246,20 @@ public class EmblEntry * parent dna sequence for this record * @param peptides * list of protein product sequences for Embl entry + * @param matcher + * helper to match xrefs in already retrieved sequences */ void parseCodingFeature(EmblFeature feature, String sourceDb, - SequenceI dna, List peptides) + SequenceI dna, List peptides, SequenceIdMatcher matcher) { boolean isEmblCdna = sourceDb.equals(DBRefSource.EMBLCDS); - int[] exon = getCdsRanges(feature); + int[] exons = getCdsRanges(feature); - String prseq = null; - String prname = ""; - String prid = null; + String translation = null; + String proteinName = ""; + String proteinId = null; Map vals = new Hashtable(); - SequenceIdMatcher matcher = new SequenceIdMatcher(peptides); /* * codon_start 1/2/3 in EMBL corresponds to phase 0/1/2 in CDS @@ -375,17 +279,17 @@ public class EmblEntry if (qname.equals("translation")) { // remove all spaces (precompiled String.replaceAll(" ", "")) - prseq = SPACE_PATTERN.matcher(q.getValues()[0]).replaceAll(""); + translation = SPACE_PATTERN.matcher(q.getValues()[0]).replaceAll(""); } else if (qname.equals("protein_id")) { - prid = q.getValues()[0]; + proteinId = q.getValues()[0].trim(); } else if (qname.equals("codon_start")) { try { - codonStart = Integer.parseInt(q.getValues()[0]); + codonStart = Integer.parseInt(q.getValues()[0].trim()); } catch (NumberFormatException e) { System.err.println("Invalid codon_start in XML for " @@ -395,7 +299,7 @@ public class EmblEntry else if (qname.equals("product")) { // sometimes name is returned e.g. for V00488 - prname = q.getValues()[0]; + proteinName = q.getValues()[0].trim(); } else { @@ -411,53 +315,54 @@ public class EmblEntry } } - DBRefEntry protEMBLCDS = null; - exon = MappingUtils.removeStartPositions(codonStart - 1, exon); - boolean noProteinDbref = true; + DBRefEntry proteinToEmblProteinRef = null; + exons = MappingUtils.removeStartPositions(codonStart - 1, exons); SequenceI product = null; - Mapping map = null; - if (prseq != null && prname != null && prid != null) + Mapping dnaToProteinMapping = null; + if (translation != null && proteinName != null && proteinId != null) { /* * look for product in peptides list, if not found, add it */ - product = matcher.findIdMatch(prid); + product = matcher.findIdMatch(proteinId); if (product == null) { - product = new Sequence(prid, prseq, 1, prseq.length()); - product.setDescription(((prname.length() == 0) ? "Protein Product from " + product = new Sequence(proteinId, translation, 1, translation.length()); + product.setDescription(((proteinName.length() == 0) ? "Protein Product from " + sourceDb - : prname)); + : proteinName)); peptides.add(product); matcher.add(product); } // we have everything - create the mapping and perhaps the protein // sequence - if (exon == null || exon.length == 0) + if (exons == null || exons.length == 0) { System.err .println("Implementation Notice: EMBLCDS records not properly supported yet - Making up the CDNA region of this sequence... may be incorrect (" + sourceDb + ":" + getAccession() + ")"); - if (prseq.length() * 3 == (1 - codonStart + dna.getSequence().length)) + if (translation.length() * 3 == (1 - codonStart + dna.getSequence().length)) { System.err .println("Not allowing for additional stop codon at end of cDNA fragment... !"); // this might occur for CDS sequences where no features are // marked. - exon = new int[] { dna.getStart() + (codonStart - 1), + exons = new int[] { dna.getStart() + (codonStart - 1), dna.getEnd() }; - map = new Mapping(product, exon, new int[] { 1, prseq.length() }, + dnaToProteinMapping = new Mapping(product, exons, new int[] { 1, + translation.length() }, 3, 1); } - if ((prseq.length() + 1) * 3 == (1 - codonStart + dna.getSequence().length)) + if ((translation.length() + 1) * 3 == (1 - codonStart + dna.getSequence().length)) { System.err .println("Allowing for additional stop codon at end of cDNA fragment... will probably cause an error in VAMSAs!"); - exon = new int[] { dna.getStart() + (codonStart - 1), + exons = new int[] { dna.getStart() + (codonStart - 1), dna.getEnd() - 3 }; - map = new Mapping(product, exon, new int[] { 1, prseq.length() }, + dnaToProteinMapping = new Mapping(product, exons, new int[] { 1, + translation.length() }, 3, 1); } } @@ -477,58 +382,71 @@ public class EmblEntry else { // final product length truncation check - // TODO should from range include stop codon even if not in protein - // in order to include stop codon in CDS sequence (as done for - // Ensembl)? - int[] cdsRanges = adjustForProteinLength(prseq.length(), exon); - map = new Mapping(product, cdsRanges, new int[] { 1, - prseq.length() }, 3, 1); - // reconstruct the EMBLCDS entry - // TODO: this is only necessary when there codon annotation is - // complete (I think JBPNote) - DBRefEntry pcdnaref = new DBRefEntry(); - pcdnaref.setAccessionId(prid); - pcdnaref.setSource(DBRefSource.EMBLCDS); - pcdnaref.setVersion(getSequenceVersion()); // same as parent EMBL - // version. - MapList mp = new MapList(new int[] { 1, prseq.length() }, - new int[] { 1 + (codonStart - 1), - (codonStart - 1) + 3 * prseq.length() }, 1, 3); - pcdnaref.setMap(new Mapping(mp)); + int[] cdsRanges = adjustForProteinLength(translation.length(), exons); + dnaToProteinMapping = new Mapping(product, cdsRanges, new int[] { 1, + translation.length() }, 3, 1); if (product != null) { - product.addDBRef(pcdnaref); - protEMBLCDS = new DBRefEntry(pcdnaref); - protEMBLCDS.setSource(DBRefSource.EMBLCDSProduct); - product.addDBRef(protEMBLCDS); + /* + * make xrefs from protein to EMBLCDS and EMBLCDSPROTEIN + */ + DBRefEntry proteinToEmblCdsRef = new DBRefEntry(); + proteinToEmblCdsRef.setAccessionId(proteinId); + proteinToEmblCdsRef.setSource(DBRefSource.EMBLCDS); + proteinToEmblCdsRef.setVersion(getSequenceVersion()); // same as + // parent EMBL + // version. + MapList mp = new MapList(new int[] { 1, translation.length() }, + new int[] { 1 + (codonStart - 1), + (codonStart - 1) + 3 * translation.length() }, 1, 3); + proteinToEmblCdsRef.setMap(new Mapping(mp)); + product.addDBRef(proteinToEmblCdsRef); + proteinToEmblProteinRef = new DBRefEntry(proteinToEmblCdsRef); + MapList mp2 = new MapList( + new int[] { 1, translation.length() }, new int[] { 1, + translation.length() }, 1, 1); + proteinToEmblProteinRef.setMap(new Mapping(mp2)); + proteinToEmblProteinRef.setSource(DBRefSource.EMBLCDSProduct); + product.addDBRef(proteinToEmblProteinRef); } } } - // add cds feature to dna seq - this may include the stop codon - for (int xint = 0; exon != null && xint < exon.length; xint += 2) + + /* + * add cds features to dna sequence + */ + for (int xint = 0; exons != null && xint < exons.length; xint += 2) { - SequenceFeature sf = makeCdsFeature(exon, xint, prname, prid, vals, + SequenceFeature sf = makeCdsFeature(exons, xint, proteinName, proteinId, vals, codonStart); sf.setType(feature.getName()); // "CDS" + sf.setEnaLocation(feature.getLocation()); sf.setFeatureGroup(sourceDb); dna.addSequenceFeature(sf); } } /* - * add dbRefs to sequence, and mappings for Uniprot xrefs + * add feature dbRefs to sequence, and mappings for Uniprot xrefs */ + boolean hasUniprotDbref = false; if (feature.dbRefs != null) { boolean mappingUsed = false; for (DBRefEntry ref : feature.dbRefs) { - ref.setSource(DBRefUtils.getCanonicalName(ref.getSource())); - if (ref.getSource().equals(DBRefSource.UNIPROT)) + /* + * ensure UniProtKB/Swiss-Prot converted to UNIPROT + */ + String source = DBRefUtils.getCanonicalName(ref.getSource()); + ref.setSource(source); + DBRefEntry proteinToDnaRef = new DBRefEntry(ref.getSource(), ref.getVersion(), ref + .getAccessionId()); + if (source.equals(DBRefSource.UNIPROT)) { String proteinSeqName = DBRefSource.UNIPROT + "|" + ref.getAccessionId(); - if (map != null && map.getTo() != null) + if (dnaToProteinMapping != null && dnaToProteinMapping.getTo() != null) { if (mappingUsed) { @@ -536,13 +454,14 @@ public class EmblEntry * two or more Uniprot xrefs for the same CDS - * each needs a distinct Mapping (as to a different sequence) */ - map = new Mapping(map); + dnaToProteinMapping = new Mapping(dnaToProteinMapping); } mappingUsed = true; /* * try to locate the protein mapped to (possibly by a - * previous CDS feature) + * previous CDS feature); if not found, construct it from + * the EMBL translation */ SequenceI proteinSeq = matcher.findIdMatch(proteinSeqName); if (proteinSeq == null) @@ -552,61 +471,62 @@ public class EmblEntry matcher.add(proteinSeq); peptides.add(proteinSeq); } - map.setTo(proteinSeq); - map.getTo().addDBRef( - new DBRefEntry(ref.getSource(), ref.getVersion(), ref - .getAccessionId())); - ref.setMap(map); + dnaToProteinMapping.setTo(proteinSeq); + proteinSeq.addDBRef(proteinToDnaRef); + ref.setMap(dnaToProteinMapping); } - noProteinDbref = false; + hasUniprotDbref = true; } if (product != null) { - DBRefEntry pref = new DBRefEntry(ref.getSource(), - ref.getVersion(), ref.getAccessionId()); + /* + * copy feature dbref to our protein product + */ + DBRefEntry pref = proteinToDnaRef; pref.setMap(null); // reference is direct product.addDBRef(pref); // Add converse mapping reference - if (map != null) + if (dnaToProteinMapping != null) { - Mapping pmap = new Mapping(dna, map.getMap().getInverse()); + Mapping pmap = new Mapping(dna, dnaToProteinMapping.getMap() + .getInverse()); pref = new DBRefEntry(sourceDb, getSequenceVersion(), this.getAccession()); pref.setMap(pmap); - if (map.getTo() != null) + if (dnaToProteinMapping.getTo() != null) { - map.getTo().addDBRef(pref); + dnaToProteinMapping.getTo().addDBRef(pref); } } } dna.addDBRef(ref); } - if (noProteinDbref && product != null) + } + /* + * if we have a product (translation) but no explicit Uniprot dbref + * (example: EMBL AAFI02000057 protein_id EAL65544.1 + * construct mappings to an assumed EMBLCDSPROTEIN accession + */ + if (!hasUniprotDbref && product != null) + { + if (proteinToEmblProteinRef == null) { - // add protein coding reference to dna sequence so xref matches - if (protEMBLCDS == null) - { - protEMBLCDS = new DBRefEntry(); - protEMBLCDS.setAccessionId(prid); - protEMBLCDS.setSource(DBRefSource.EMBLCDSProduct); - protEMBLCDS.setVersion(getSequenceVersion()); - protEMBLCDS - .setMap(new Mapping(product, map.getMap().getInverse())); - } - product.addDBRef(protEMBLCDS); + proteinToEmblProteinRef = new DBRefEntry(); + proteinToEmblProteinRef.setAccessionId(proteinId); + proteinToEmblProteinRef.setSource(DBRefSource.EMBLCDSProduct); + proteinToEmblProteinRef.setVersion(getSequenceVersion()); + proteinToEmblProteinRef.setMap(new Mapping(product, + dnaToProteinMapping.getMap().getInverse())); + } + product.addDBRef(proteinToEmblProteinRef); - // Add converse mapping reference - if (map != null) - { - Mapping pmap = new Mapping(product, protEMBLCDS.getMap().getMap() - .getInverse()); - DBRefEntry ncMap = new DBRefEntry(protEMBLCDS); - ncMap.setMap(pmap); - if (map.getTo() != null) - { - dna.addDBRef(ncMap); - } - } + if (dnaToProteinMapping != null + && dnaToProteinMapping.getTo() != null) + { + DBRefEntry dnaToEmblProteinRef = new DBRefEntry( + proteinToEmblProteinRef); + dnaToEmblProteinRef.setMap(dnaToProteinMapping); + dna.addDBRef(dnaToEmblProteinRef); } } } @@ -661,7 +581,7 @@ public class EmblEntry } /** - * Returns the CDS positions as a list of [start, end, start, end...] + * Returns the CDS positions as a single array of [start, end, start, end...] * positions. If on the reverse strand, these will be in descending order. * * @param feature @@ -673,8 +593,18 @@ public class EmblEntry { return new int[] {}; } - List ranges = DnaUtils.parseLocation(feature.location); - return ranges == null ? new int[] {} : listToArray(ranges); + + try + { + List ranges = DnaUtils.parseLocation(feature.location); + return listToArray(ranges); + } catch (ParseException e) + { + Cache.log.warn(String.format( + "Not parsing inexact CDS location %s in ENA %s", + feature.location, this.accession)); + return new int[] {}; + } } /** @@ -697,26 +627,30 @@ public class EmblEntry } /** - * truncate the last exon interval to the prlength'th codon + * Truncates (if necessary) the exon intervals to match 3 times the length of + * the protein; also accepts 3 bases longer (for stop codon not included in + * protein) * - * @param prlength + * @param proteinLength * @param exon - * @return new exon + * an array of [start, end, start, end...] intervals + * @return the same array (if unchanged) or a truncated copy */ - static int[] adjustForProteinLength(int prlength, int[] exon) + static int[] adjustForProteinLength(int proteinLength, int[] exon) { - if (prlength <= 0 || exon == null) + if (proteinLength <= 0 || exon == null) { return exon; } - int desiredCdsLength = prlength * 3; + int expectedCdsLength = proteinLength * 3; int exonLength = MappingUtils.getLength(Arrays.asList(exon)); /* - * assuming here exon might include stop codon in addition to protein codons + * if exon length matches protein, or is shorter, or longer by the + * length of a stop codon (3 bases), then leave it unchanged */ - if (desiredCdsLength == exonLength - || desiredCdsLength == exonLength - 3) + if (expectedCdsLength >= exonLength + || expectedCdsLength == exonLength - 3) { return exon; } @@ -730,11 +664,11 @@ public class EmblEntry for (int x = 0; x < exon.length; x += 2) { cdspos += Math.abs(exon[x + 1] - exon[x]) + 1; - if (desiredCdsLength <= cdspos) + if (expectedCdsLength <= cdspos) { // advanced beyond last codon. sxpos = x; - if (desiredCdsLength != cdspos) + if (expectedCdsLength != cdspos) { // System.err // .println("Truncating final exon interval on region by " @@ -747,11 +681,11 @@ public class EmblEntry */ if (exon[x + 1] >= exon[x]) { - endxon = exon[x + 1] - cdspos + desiredCdsLength; + endxon = exon[x + 1] - cdspos + expectedCdsLength; } else { - endxon = exon[x + 1] + cdspos - desiredCdsLength; + endxon = exon[x + 1] + cdspos - expectedCdsLength; } break; } @@ -779,6 +713,26 @@ public class EmblEntry this.sequenceVersion = sequenceVersion; } + public String getSequenceLength() + { + return sequenceLength; + } + + public void setSequenceLength(String sequenceLength) + { + this.sequenceLength = sequenceLength; + } + + public String getEntryVersion() + { + return entryVersion; + } + + public void setEntryVersion(String entryVersion) + { + this.entryVersion = entryVersion; + } + public String getMoleculeType() { return moleculeType; @@ -799,33 +753,73 @@ public class EmblEntry this.topology = topology; } - public String getSequenceLength() + public String getTaxonomicDivision() { - return sequenceLength; + return taxonomicDivision; } - public void setSequenceLength(String sequenceLength) + public void setTaxonomicDivision(String taxonomicDivision) { - this.sequenceLength = sequenceLength; + this.taxonomicDivision = taxonomicDivision; + } + + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + + public String getFirstPublicDate() + { + return firstPublicDate; + } + + public void setFirstPublicDate(String firstPublicDate) + { + this.firstPublicDate = firstPublicDate; + } + + public String getFirstPublicRelease() + { + return firstPublicRelease; + } + + public void setFirstPublicRelease(String firstPublicRelease) + { + this.firstPublicRelease = firstPublicRelease; + } + + public String getLastUpdatedDate() + { + return lastUpdatedDate; + } + + public void setLastUpdatedDate(String lastUpdatedDate) + { + this.lastUpdatedDate = lastUpdatedDate; } - public String getrCreated() + public String getLastUpdatedRelease() { - return rCreated; + return lastUpdatedRelease; } - public void setrCreated(String rCreated) + public void setLastUpdatedRelease(String lastUpdatedRelease) { - this.rCreated = rCreated; + this.lastUpdatedRelease = lastUpdatedRelease; } - public String getrLastUpdated() + public String getDataClass() { - return rLastUpdated; + return dataClass; } - public void setrLastUpdated(String rLastUpdated) + public void setDataClass(String dataClass) { - this.rLastUpdated = rLastUpdated; + this.dataClass = dataClass; } }