*/
protected MapList mapCdsToProtein(SequenceI dnaSeq, SequenceI proteinSeq)
{
- SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
- if (sfs == null)
+ List<int[]> ranges = new ArrayList<int[]>(50);
+
+ int mappedDnaLength = getCdsRanges(dnaSeq, ranges);
+
+ int proteinLength = proteinSeq.getLength();
+ List<int[]> proteinRange = new ArrayList<int[]>();
+ int proteinStart = 1;
+
+ /*
+ * incomplete start codon may mean X at start of peptide
+ * we ignore both for mapping purposes
+ */
+ if (proteinSeq.getCharAt(0) == 'X')
{
- return null;
+ proteinStart = 2;
+ proteinLength--;
}
+ proteinRange.add(new int[] { proteinStart, proteinLength });
- List<int[]> ranges = new ArrayList<int[]>(50);
- SequenceOntology so = SequenceOntology.getInstance();
-
- int mappedDnaLength = 0;
-
/*
- * Map CDS columns of dna to peptide. No need to worry about reverse strand
- * dna here since the retrieved sequence is as transcribed (reverse
- * complement for reverse strand), i.e in the same sense as the peptide.
+ * dna length should map to protein (or protein plus stop codon)
*/
- boolean fivePrimeIncomplete = false;
+ int codesForResidues = mappedDnaLength / 3;
+ if (codesForResidues == proteinLength
+ || codesForResidues == (proteinLength + 1))
+ {
+ return new MapList(ranges, proteinRange, 3, 1);
+ }
+ return null;
+ }
+
+ /**
+ * Adds CDS ranges to the ranges list, and returns the total length mapped.
+ *
+ * No need to worry about reverse strand dna here since the retrieved sequence
+ * is as transcribed (reverse complement for reverse strand), i.e in the same
+ * sense as the peptide.
+ *
+ * @param dnaSeq
+ * @param ranges
+ * @return
+ */
+ protected int getCdsRanges(SequenceI dnaSeq, List<int[]> ranges)
+ {
+ SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
+ if (sfs == null)
+ {
+ return 0;
+ }
+ int mappedDnaLength = 0;
for (SequenceFeature sf : sfs)
{
/*
* process a CDS feature (or a sub-type of CDS)
*/
- if (so.isA(sf.getType(), SequenceOntology.CDS))
+ if (SequenceOntology.getInstance().isA(sf.getType(), SequenceOntology.CDS))
{
int phase = 0;
try {
int end = sf.getEnd();
if (ranges.isEmpty() && phase > 0)
{
- fivePrimeIncomplete = true;
begin += phase;
if (begin > end)
{
mappedDnaLength += Math.abs(end - begin) + 1;
}
}
- int proteinLength = proteinSeq.getLength();
- List<int[]> proteinRange = new ArrayList<int[]>();
- int proteinStart = 1;
- if (fivePrimeIncomplete && proteinSeq.getCharAt(0) == 'X')
- {
- proteinStart = 2;
- proteinLength--;
- }
- proteinRange.add(new int[] { proteinStart, proteinLength });
-
- /*
- * dna length should map to protein (or protein plus stop codon)
- */
- int codesForResidues = mappedDnaLength / 3;
- if (codesForResidues == proteinLength
- || codesForResidues == (proteinLength + 1))
- {
- return new MapList(ranges, proteinRange, 3, 1);
- }
- return null;
+ return mappedDnaLength;
}
/**
peptide = peptide.getDatasetSequence();
}
- mapExonsToProtein(dnaSeq, peptide, dnaToProtein);
+ mapExonFeaturesToProtein(dnaSeq, peptide, dnaToProtein);
LinkedHashMap<Integer, String[][]> variants = buildDnaVariantsMap(
dnaSeq, dnaToProtein);
residue);
if (!peptideVariants.isEmpty())
{
- Collections.sort(peptideVariants);
String desc = StringUtils.listToDelimitedString(peptideVariants,
", ");
SequenceFeature sf = new SequenceFeature(
* @param peptide
* @param dnaToProtein
*/
- static int mapExonsToProtein(SequenceI dnaSeq, SequenceI peptide,
+ static int mapExonFeaturesToProtein(SequenceI dnaSeq, SequenceI peptide,
MapList dnaToProtein)
{
SequenceFeature[] sfs = dnaSeq.getSequenceFeatures();
return variants;
}
+ int dnaStart = dnaSeq.getStart();
int[] lastCodon = null;
int lastPeptidePostion = 0;
for (int codonPos = 0; codonPos < 3; codonPos++)
{
String nucleotide = String.valueOf(dnaSeq
- .getCharAt(codon[codonPos] - 1));
+ .getCharAt(codon[codonPos] - dnaStart));
if (codon[codonPos] == dnaCol)
{
/*
}
/**
- * Returns a non-redundant list of all peptide translations generated by the
- * given dna variants, excluding the current residue value
+ * Returns a sorted, non-redundant list of all peptide translations generated
+ * by the given dna variants, excluding the current residue value
*
* @param codonVariants
- * an array of base values for codon positions 1, 2, 3
+ * an array of base values (acgtACGT) for codon positions 1, 2, 3
* @param residue
* the current residue translation
* @return
String peptide = codon.contains("-") ? "-" : ResidueProperties
.codonTranslate(codon);
if (peptide != null && !result.contains(peptide)
- && !peptide.equals(residue))
+ && !peptide.equalsIgnoreCase(residue))
{
result.add(peptide);
}
}
}
}
+
+ /*
+ * sort alphabetically with STOP at the end
+ */
+ Collections.sort(result, new Comparator<String>()
+ {
+
+ @Override
+ public int compare(String o1, String o2)
+ {
+ if ("STOP".equals(o1))
+ {
+ return 1;
+ }
+ else if ("STOP".equals(o2))
+ {
+ return -1;
+ }
+ else
+ {
+ return o1.compareTo(o2);
+ }
+ }
+ });
return result;
}