+ vals.put(qname, sb.toString());
+ }
+ }
+ }
+ Sequence product = null;
+ DBRefEntry protEMBLCDS = null;
+ exon = adjustForPrStart(prstart, exon);
+ boolean noProteinDbref = true;
+
+ if (prseq != null && prname != null && prid != null)
+ {
+ // extract proteins.
+ product = new Sequence(prid, prseq, 1, prseq.length());
+ product.setDescription(((prname.length() == 0) ? "Protein Product from "
+ + sourceDb
+ : prname));
+ if (!noPeptide)
+ {
+ // Protein is also added to vector of sequences returned
+ seqs.add(product);
+ }
+ // we have everything - create the mapping and perhaps the protein
+ // sequence
+ if (exon == null || exon.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 - prstart + 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() + (prstart - 1), dna.getEnd() };
+ map = new jalview.datamodel.Mapping(product, exon, new int[] { 1,
+ prseq.length() }, 3, 1);
+ }
+ if ((prseq.length() + 1) * 3 == (1 - prstart + 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() + (prstart - 1),
+ dna.getEnd() - 3 };
+ map = new jalview.datamodel.Mapping(product, exon, new int[] { 1,
+ prseq.length() }, 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 trunctation check
+
+ map = new jalview.datamodel.Mapping(product,
+ adjustForProteinLength(prseq.length(), exon), 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(getVersion()); // same as parent EMBL version.
+ jalview.util.MapList mp = new jalview.util.MapList(new int[] { 1,
+ prseq.length() }, new int[] { 1 + (prstart - 1),
+ (prstart - 1) + 3 * prseq.length() }, 1, 3);
+ // { 1 + (prstart - 1) * 3,
+ // 1 + (prstart - 1) * 3 + prseq.length() * 3 - 1 }, new int[]
+ // { 1prstart, prstart + prseq.length() - 1 }, 3, 1);
+ pcdnaref.setMap(new Mapping(mp));
+ if (product != null)
+ {
+ product.addDBRef(pcdnaref);
+ protEMBLCDS = new DBRefEntry(pcdnaref);
+ protEMBLCDS.setSource(DBRefSource.EMBLCDSProduct);
+ product.addDBRef(protEMBLCDS);
+
+ }
+
+ }
+ }
+ // add cds feature to dna seq - this may include the stop codon
+ for (int xint = 0; exon != null && xint < exon.length; xint += 2)
+ {
+ SequenceFeature sf = new SequenceFeature();
+ sf.setBegin(exon[xint]);
+ sf.setEnd(exon[xint + 1]);
+ sf.setType(feature.getName());
+ sf.setFeatureGroup(sourceDb);
+ sf.setDescription("Exon " + (1 + xint / 2) + " for protein '"
+ + prname + "' EMBLCDS:" + prid);
+ sf.setValue(FeatureProperties.EXONPOS, new Integer(1 + xint));
+ sf.setValue(FeatureProperties.EXONPRODUCT, prname);
+ if (vals != null)
+ {
+ for (Entry<String, String> val : vals.entrySet())
+ {
+ sf.setValue(val.getKey(), val.getValue());
+ }
+ }
+ dna.addSequenceFeature(sf);
+ }
+ }
+ // add dbRefs to sequence
+ if (feature.dbRefs != null)
+ {
+ for (DBRefEntry ref : feature.dbRefs)
+ {
+ ref.setSource(jalview.util.DBRefUtils.getCanonicalName(ref
+ .getSource()));
+ // Hard code the kind of protein product accessions that EMBL cite
+ if (ref.getSource().equals(jalview.datamodel.DBRefSource.UNIPROT))
+ {
+ ref.setMap(map);
+ if (map != null && map.getTo() != null)