/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b1)
* Copyright (C) 2015 The Jalview Authors
*
* This file is part of Jalview.
* @param cdnaAlignment
* @return
*/
- public static boolean mapProteinToCdna(final AlignmentI proteinAlignment,
- final AlignmentI cdnaAlignment)
+ public static boolean mapProteinAlignmentToCdna(
+ final AlignmentI proteinAlignment, final AlignmentI cdnaAlignment)
{
if (proteinAlignment == null || cdnaAlignment == null)
{
final AlignmentI cdnaAlignment, Set<SequenceI> mappedDna,
Set<SequenceI> mappedProtein, boolean xrefsOnly)
{
- boolean mappingPerformed = false;
+ boolean mappingExistsOrAdded = false;
List<SequenceI> thisSeqs = proteinAlignment.getSequences();
for (SequenceI aaSeq : thisSeqs)
{
{
continue;
}
- if (!mappingExists(proteinAlignment.getCodonFrames(),
+ if (mappingExists(proteinAlignment.getCodonFrames(),
aaSeq.getDatasetSequence(), cdnaSeq.getDatasetSequence()))
{
- MapList map = mapProteinToCdna(aaSeq, cdnaSeq);
+ mappingExistsOrAdded = true;
+ }
+ else
+ {
+ MapList map = mapProteinSequenceToCdna(aaSeq, cdnaSeq);
if (map != null)
{
acf.addMap(cdnaSeq, aaSeq, map);
- mappingPerformed = true;
+ mappingExistsOrAdded = true;
proteinMapped = true;
mappedDna.add(cdnaSeq);
mappedProtein.add(aaSeq);
proteinAlignment.addCodonFrame(acf);
}
}
- return mappingPerformed;
+ return mappingExistsOrAdded;
}
/**
* @param cdnaSeq
* @return
*/
- public static MapList mapProteinToCdna(SequenceI proteinSeq,
+ public static MapList mapProteinSequenceToCdna(SequenceI proteinSeq,
SequenceI cdnaSeq)
{
/*
*/
final int mappedLength = 3 * aaSeqChars.length;
int cdnaLength = cdnaSeqChars.length;
- int cdnaStart = 1;
- int cdnaEnd = cdnaLength;
- final int proteinStart = 1;
- final int proteinEnd = aaSeqChars.length;
+ int cdnaStart = cdnaSeq.getStart();
+ int cdnaEnd = cdnaSeq.getEnd();
+ final int proteinStart = proteinSeq.getStart();
+ final int proteinEnd = proteinSeq.getEnd();
/*
* If lengths don't match, try ignoring stop codon.
/*
* If lengths still don't match, try ignoring start codon.
*/
+ int startOffset = 0;
if (cdnaLength != mappedLength
&& cdnaLength > 2
&& String.valueOf(cdnaSeqChars, 0, 3).toUpperCase()
.equals(ResidueProperties.START))
{
+ startOffset += 3;
cdnaStart += 3;
cdnaLength -= 3;
}
{
return null;
}
- if (!translatesAs(cdnaSeqChars, cdnaStart - 1, aaSeqChars))
+ if (!translatesAs(cdnaSeqChars, startOffset, aaSeqChars))
{
return null;
}
/*
* Traverse the aligned protein sequence.
*/
+ int fromOffset = alignFrom.getStart() - 1;
+ int toOffset = alignTo.getStart() - 1;
int sourceGapMappedLength = 0;
boolean inExon = false;
for (char sourceChar : thatAligned)
sourceDsPos++;
// Note mapping positions are base 1, our sequence positions base 0
int[] mappedPos = mapping.getMappedRegion(alignTo, alignFrom,
- sourceDsPos);
+ sourceDsPos + fromOffset);
if (mappedPos == null)
{
/*
* But then 'align dna as protein' doesn't make much sense otherwise.
*/
int intronLength = 0;
- while (basesWritten < mappedCodonEnd && thisSeqPos < thisSeq.length)
+ while (basesWritten + toOffset < mappedCodonEnd
+ && thisSeqPos < thisSeq.length)
{
final char c = thisSeq[thisSeqPos++];
if (c != myGapChar)
{
basesWritten++;
-
- if (basesWritten < mappedCodonStart)
+ int sourcePosition = basesWritten + toOffset;
+ if (sourcePosition < mappedCodonStart)
{
/*
* Found an unmapped (intron) base. First add in any preceding gaps
}
else
{
- final boolean startOfCodon = basesWritten == mappedCodonStart;
+ final boolean startOfCodon = sourcePosition == mappedCodonStart;
int gapsToAdd = calculateGapsToInsert(preserveMappedGaps,
preserveUnmappedGaps, sourceGapMappedLength, inExon,
trailingCopiedGap.length(), intronLength, startOfCodon);
* Just try to make a mapping (it is not yet stored), test whether
* successful.
*/
- return mapProteinToCdna(proteinDs, dnaDs) != null;
+ return mapProteinSequenceToCdna(proteinDs, dnaDs) != null;
}
/**