- /*
- * Locate any xrefs to CDS database on the protein product and attach to
- * the CDS sequence. Also add as a sub-token of the sequence name.
- */
- // default to "CDS" if we can't locate an actual gene id
- String cdsAccId = FeatureProperties
- .getCodingFeature(DBRefSource.EMBL);
- DBRefEntry[] cdsRefs = DBRefUtils.selectRefs(seqMapping.getTo()
- .getDBRef(), DBRefSource.CODINGDBS);
- if (cdsRefs != null)
+ /*
+ * CDS to peptide is just a contiguous 3:1 mapping, with
+ * the peptide ranges taken unchanged from the dna mapping
+ */
+ List<int[]> cdsRanges = new ArrayList<int[]>();
+ cdsRanges.add(new int[] { 1, cdsSeq.getLength() });
+ MapList cdsToPeptide = new MapList(cdsRanges, dnaMapping.getMap()
+ .getToRanges(), 3, 1);
+ newMappings.addMap(cdsSeq.getDatasetSequence(), dnaMapping.getTo(),
+ cdsToPeptide);
+
+ /*
+ * dna 'from' ranges map 1:1 to the contiguous extracted CDS
+ */
+ MapList dnaToCds = new MapList(
+ dnaMapping.getMap().getFromRanges(), cdsRanges, 1, 1);
+ newMappings.addMap(dnaSeq, cdsSeq.getDatasetSequence(), dnaToCds);
+ return dnaToCds;
+ }
+
+ /**
+ * Makes and returns a CDS-only sequence, where the CDS regions are identified
+ * as the 'from' ranges of the mapping on the dna. Any sequence features on
+ * the dna which overlap the CDS regions are copied to the new sequence.
+ *
+ * @param dnaSeq
+ * nucleotide sequence
+ * @param seqMapping
+ * mappings from CDS regions of nucleotide
+ * @param exonMappings
+ * CDS-to-peptide mapping (to add to)
+ * @return
+ */
+ protected static SequenceI makeCdsSequence(SequenceI dnaSeq,
+ Mapping seqMapping, AlignedCodonFrame exonMappings)
+ {
+ StringBuilder newSequence = new StringBuilder(dnaSeq.getLength());
+ final char[] dna = dnaSeq.getSequence();
+ int offset = dnaSeq.getStart() - 1;
+
+ /*
+ * Get the codon regions as { [2, 5], [7, 12], [14, 14] etc }
+ */
+ final List<int[]> dnaCdsRanges = seqMapping.getMap().getFromRanges();
+ for (int[] range : dnaCdsRanges)
+ {
+ // TODO handle reverse mapping as well (range[1] < range[0])
+ for (int pos = range[0]; pos <= range[1]; pos++)