+ // 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[] cdsRanges = adjustForProteinLength(translationLength,
+ exons);
+ dnaToProteinMapping = new Mapping(product, cdsRanges,
+ 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);
+ }
+ }
+ }
+
+ /*
+ * add cds features to dna sequence
+ */
+ String cds = feature.getName(); // "CDS"
+ for (int xint = 0; exons != null
+ && xint < exons.length - 1; xint += 2)
+ {
+ int exonStart = exons[xint];
+ int exonEnd = exons[xint + 1];
+ int begin = Math.min(exonStart, exonEnd);
+ int end = Math.max(exonStart, exonEnd);
+ int exonNumber = xint / 2 + 1;
+ String desc = String.format("Exon %d for protein '%s' EMBLCDS:%s",
+ exonNumber, proteinName, proteinId);
+
+ SequenceFeature sf = makeCdsFeature(cds, desc, begin, end, sourceDb,
+ vals);
+
+ sf.setEnaLocation(feature.getLocation());
+ boolean forwardStrand = exonStart <= exonEnd;
+ sf.setStrand(forwardStrand ? "+" : "-");
+ sf.setPhase(String.valueOf(codonStart - 1));
+ sf.setValue(FeatureProperties.EXONPOS, exonNumber);
+ sf.setValue(FeatureProperties.EXONPRODUCT, proteinName);
+
+ dna.addSequenceFeature(sf);
+ }
+ }
+
+ /*
+ * add feature dbRefs to sequence, and mappings for Uniprot xrefs
+ */
+ boolean hasUniprotDbref = false;
+ List<XrefType> xrefs = feature.getXref();
+ if (xrefs != null)
+ {
+ boolean mappingUsed = false;
+ for (XrefType xref : xrefs)
+ {
+ /*
+ * ensure UniProtKB/Swiss-Prot converted to UNIPROT
+ */
+ String source = DBRefUtils.getCanonicalName(xref.getDb());
+ String version = xref.getSecondaryId();
+ if (version == null || "".equals(version))
+ {
+ version = "0";
+ }
+ DBRefEntry dbref = new DBRefEntry(source, version, xref.getId());
+ DBRefEntry proteinDbRef = new DBRefEntry(source, version,
+ dbref.getAccessionId());
+ if (source.equals(DBRefSource.UNIPROT))
+ {
+ String proteinSeqName = DBRefSource.UNIPROT + "|"
+ + dbref.getAccessionId();
+ if (dnaToProteinMapping != null
+ && dnaToProteinMapping.getTo() != null)
+ {
+ if (mappingUsed)