+ SequenceI product = null;
+ Mapping dnaToProteinMapping = null;
+ if (translation != null && proteinName != null && proteinId != null)
+ {
+ int translationLength = translation.length();
+
+ /*
+ * look for product in peptides list, if not found, add it
+ */
+ product = matcher.findIdMatch(proteinId);
+ if (product == null)
+ {
+ product = new Sequence(proteinId, translation, 1,
+ translationLength);
+ product.setDescription(((proteinName.length() == 0)
+ ? "Protein Product from " + sourceDb
+ : proteinName));
+ peptides.add(product);
+ matcher.add(product);
+ }
+
+ // we have everything - create the mapping and perhaps the protein
+ // sequence
+ if (exons == null || exons.length == 0)
+ {
+ /*
+ * workaround until we handle dna location for CDS sequence
+ * e.g. location="X53828.1:60..1058" correctly
+ */
+ System.err.println(
+ "Implementation Notice: EMBLCDS records not properly supported yet - Making up the CDNA region of this sequence... may be incorrect ("
+ + sourceDb + ":" + entry.getAccession() + ")");
+ int dnaLength = dna.getLength();
+ if (translationLength * 3 == (1 - codonStart + dnaLength))
+ {
+ 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
+ exons = new int[] { dna.getStart() + (codonStart - 1),
+ dna.getEnd() };
+ dnaToProteinMapping = new Mapping(product, exons,
+ new int[]
+ { 1, translationLength }, 3, 1);
+ }
+ if ((translationLength + 1) * 3 == (1 - codonStart + dnaLength))
+ {
+ System.err.println(
+ "Allowing for additional stop codon at end of cDNA fragment... will probably cause an error in VAMSAs!");
+ exons = new int[] { dna.getStart() + (codonStart - 1),
+ dna.getEnd() - 3 };
+ dnaToProteinMapping = new Mapping(product, exons,
+ new int[]
+ { 1, translationLength }, 3, 1);
+ }
+ }
+ else
+ {
+ // Trim the exon mapping if necessary - the given product may only be a
+ // fragment of a larger protein. (EMBL:AY043181 is an example)
+
+ if (isEmblCdna)
+ {
+ // TODO: Add a DbRef back to the parent EMBL sequence with the exon
+ // map
+ // if given a dataset reference, search dataset for parent EMBL
+ // sequence if it exists and set its map
+ // make a new feature annotating the coding contig
+ }
+ else
+ {
+ // final product length truncation check
+ int[] exons2 = adjustForProteinLength(translationLength, exons);
+ dnaToProteinMapping = new Mapping(product, exons2,
+ new int[]
+ { 1, translationLength }, 3, 1);
+ if (product != null)
+ {
+ /*
+ * make xref with mapping from protein to EMBL dna
+ */
+ DBRefEntry proteinToEmblRef = new DBRefEntry(DBRefSource.EMBL,
+ sequenceVersion, proteinId,
+ new Mapping(dnaToProteinMapping.getMap().getInverse()));
+ product.addDBRef(proteinToEmblRef);
+
+ /*
+ * make xref from protein to EMBLCDS; we assume here that the
+ * CDS sequence version is same as dna sequence (?!)
+ */
+ MapList proteinToCdsMapList = new MapList(
+ new int[]
+ { 1, translationLength },
+ new int[]
+ { 1 + (codonStart - 1),
+ (codonStart - 1) + 3 * translationLength },
+ 1, 3);
+ DBRefEntry proteinToEmblCdsRef = new DBRefEntry(
+ DBRefSource.EMBLCDS, sequenceVersion, proteinId,
+ new Mapping(proteinToCdsMapList));
+ product.addDBRef(proteinToEmblCdsRef);
+
+ /*
+ * make 'direct' xref from protein to EMBLCDSPROTEIN
+ */
+ proteinToEmblProteinRef = new DBRefEntry(proteinToEmblCdsRef);
+ proteinToEmblProteinRef.setSource(DBRefSource.EMBLCDSProduct);
+ proteinToEmblProteinRef.setMap(null);
+ product.addDBRef(proteinToEmblProteinRef);
+ }