+ if (aMapping.getMap().getFromRatio() == 1)
+ {
+ /*
+ * not a dna-to-protein mapping (likely dna-to-cds)
+ */
+ continue;
+ }
+
+ /*
+ * check for an existing CDS sequence i.e. a 3:1 mapping to
+ * the dna mapping's product
+ */
+ SequenceI cdsSeq = null;
+
+ // TODO better mappings collection data model so we can do
+ // a direct lookup instead of double loops to find mappings
+
+ SequenceI proteinProduct = aMapping.getTo();
+
+ /*
+ * skip if not mapped to one of a specified set of proteins
+ */
+ if (productSeqs != null && !productSeqs.contains(proteinProduct))
+ {
+ continue;
+ }
+
+ for (AlignedCodonFrame acf : MappingUtils
+ .findMappingsForSequence(proteinProduct, mappings))
+ {
+ for (SequenceToSequenceMapping map : acf.getMappings())
+ {
+ if (map.getMapping().getMap().getFromRatio() == 3
+ && proteinProduct == map.getMapping().getTo()
+ && seqDss != map.getFromSeq())
+ {
+ /*
+ * found a 3:1 mapping to the protein product which is not
+ * from the dna sequence...assume it is from the CDS sequence
+ * TODO mappings data model that brings together related
+ * dna-cds-protein mappings in one object
+ */
+ cdsSeq = map.getFromSeq();
+ }
+ }
+ }
+ if (cdsSeq != null)
+ {
+ /*
+ * mappings are always to dataset sequences so create an aligned
+ * sequence to own it; add the dataset sequence to the dataset
+ */
+ SequenceI derivedSequence = cdsSeq.deriveSequence();
+ cdsSeqs.add(derivedSequence);
+ if (!dataset.getSequences().contains(cdsSeq))
+ {
+ dataset.addSequence(cdsSeq);
+ }
+ continue;
+ }
+
+ /*
+ * didn't find mapped CDS sequence - construct it and add
+ * its dataset sequence to the dataset
+ */
+ cdsSeq = makeCdsSequence(seq.getDatasetSequence(), aMapping);
+ SequenceI cdsSeqDss = cdsSeq.createDatasetSequence();