import jalview.datamodel.AlignedCodon;
import jalview.datamodel.AlignedCodonFrame;
-import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.SequenceMapping;
import jalview.datamodel.features.SequenceFeatures;
import jalview.io.gff.Gff3Helper;
import jalview.io.gff.SequenceOntologyI;
*/
public class AlignmentUtils
{
-
private static final int CODON_LENGTH = 3;
private static final String SEQUENCE_VARIANT = "sequence_variant:";
- private static final String ID = "ID";
+ /*
+ * the 'id' attribute is provided for variant features fetched from
+ * Ensembl using its REST service with JSON format
+ */
+ public static final String VARIANT_ID = "id";
/**
* A data model to hold the 'normal' base value at a position, and an optional
SequenceI prot = mapping.findAlignedSequence(dnaSeq, protein);
if (prot != null)
{
- Mapping seqMap = mapping.getMappingForSequence(dnaSeq);
+ Mapping seqMap = mapping.getMappingForSequence(dnaSeq, false);
addCodonPositions(dnaSeq, prot, protein.getGapCharacter(), seqMap,
alignedCodons);
unmappedProtein.remove(prot);
return;
}
- MapList newMap = targetToFrom.traverse(fromLoci.getMap());
+ MapList newMap = targetToFrom.traverse(fromLoci.getMapping());
if (newMap != null)
{
* @param seqMappings
* the set of mappings involving dnaSeq
* @param aMapping
- * an initial candidate from seqMappings
+ * a transcript-to-peptide mapping
* @return
*/
static SequenceI findCdsForProtein(List<AlignedCodonFrame> mappings,
if (mappedFromLength == dnaLength
|| mappedFromLength == dnaLength - CODON_LENGTH)
{
- return seqDss;
+ /*
+ * if sequence has CDS features, this is a transcript with no UTR
+ * - do not take this as the CDS sequence! (JAL-2789)
+ */
+ if (seqDss.getFeatures().getFeaturesByOntology(SequenceOntologyI.CDS)
+ .isEmpty())
+ {
+ return seqDss;
+ }
}
/*
.findMappingsForSequence(proteinProduct, mappings);
for (AlignedCodonFrame acf : mappingsToPeptide)
{
- for (SequenceToSequenceMapping map : acf.getMappings())
+ for (SequenceMapping map : acf.getMappings())
{
Mapping mapping = map.getMapping();
if (mapping != aMapping
{
/*
* found a 3:1 mapping to the protein product which covers
- * the whole dna sequence i.e. is from CDS; finally check it
- * is from the dna start sequence
+ * the whole dna sequence i.e. is from CDS; finally check the CDS
+ * is mapped from the given dna start sequence
*/
SequenceI cdsSeq = map.getFromSeq();
+ // todo this test is weak if seqMappings contains multiple mappings;
+ // we get away with it if transcript:cds relationship is 1:1
List<AlignedCodonFrame> dnaToCdsMaps = MappingUtils
.findMappingsForSequence(cdsSeq, seqMappings);
if (!dnaToCdsMaps.isEmpty())
protected static List<DBRefEntry> propagateDBRefsToCDS(SequenceI cdsSeq,
SequenceI contig, SequenceI proteinProduct, Mapping mapping)
{
+
// gather direct refs from contig congruent with mapping
List<DBRefEntry> direct = new ArrayList<>();
HashSet<String> directSources = new HashSet<>();
+
if (contig.getDBRefs() != null)
{
for (DBRefEntry dbr : contig.getDBRefs())
int mappedDnaLength = MappingUtils.getLength(ranges);
/*
- * if not a whole number of codons, something is wrong,
- * abort mapping
+ * if not a whole number of codons, truncate mapping
*/
- if (mappedDnaLength % CODON_LENGTH > 0)
+ int codonRemainder = mappedDnaLength % CODON_LENGTH;
+ if (codonRemainder > 0)
{
- return null;
+ mappedDnaLength -= codonRemainder;
+ MappingUtils.removeEndPositions(codonRemainder, ranges);
}
int proteinLength = proteinSeq.getLength();
static int computePeptideVariants(SequenceI peptide, int peptidePos,
List<DnaVariant>[] codonVariants)
{
- String residue = String.valueOf(peptide.getCharAt(peptidePos - 1));
+ String residue = String
+ .valueOf(peptide.getCharAt(peptidePos - peptide.getStart()));
int count = 0;
String base1 = codonVariants[0].get(0).base;
String base2 = codonVariants[1].get(0).base;
{
for (String base : alleles.split(","))
{
- if (!base1.equals(base))
+ if (!base1.equalsIgnoreCase(base))
{
- String codon = base + base2 + base3;
+ String codon = base.toUpperCase() + base2.toLowerCase()
+ + base3.toLowerCase();
+ String canonical = base1.toUpperCase() + base2.toLowerCase()
+ + base3.toLowerCase();
if (addPeptideVariant(peptide, peptidePos, residue, var,
- codon))
+ codon, canonical))
{
count++;
}
{
for (String base : alleles.split(","))
{
- if (!base2.equals(base))
+ if (!base2.equalsIgnoreCase(base))
{
- String codon = base1 + base + base3;
+ String codon = base1.toLowerCase() + base.toUpperCase()
+ + base3.toLowerCase();
+ String canonical = base1.toLowerCase() + base2.toUpperCase()
+ + base3.toLowerCase();
if (addPeptideVariant(peptide, peptidePos, residue, var,
- codon))
+ codon, canonical))
{
count++;
}
{
for (String base : alleles.split(","))
{
- if (!base3.equals(base))
+ if (!base3.equalsIgnoreCase(base))
{
- String codon = base1 + base2 + base;
+ String codon = base1.toLowerCase() + base2.toLowerCase()
+ + base.toUpperCase();
+ String canonical = base1.toLowerCase() + base2.toLowerCase()
+ + base3.toUpperCase();
if (addPeptideVariant(peptide, peptidePos, residue, var,
- codon))
+ codon, canonical))
{
count++;
}
}
/**
- * Helper method that adds a peptide variant feature, provided the given codon
- * translates to a value different to the current residue (is a non-synonymous
- * variant). ID and clinical_significance attributes of the dna variant (if
- * present) are copied to the new feature.
+ * Helper method that adds a peptide variant feature. ID and
+ * clinical_significance attributes of the dna variant (if present) are copied
+ * to the new feature.
*
* @param peptide
* @param peptidePos
* @param residue
* @param var
* @param codon
+ * the variant codon e.g. aCg
+ * @param canonical
+ * the 'normal' codon e.g. aTg
* @return true if a feature was added, else false
*/
static boolean addPeptideVariant(SequenceI peptide, int peptidePos,
- String residue, DnaVariant var, String codon)
+ String residue, DnaVariant var, String codon, String canonical)
{
/*
* get peptide translation of codon e.g. GAT -> D
{
return false;
}
- String desc = codon;
+ String desc = canonical + "/" + codon;
String featureType = "";
if (trans.equals(residue))
{
peptidePos, var.getSource());
StringBuilder attributes = new StringBuilder(32);
- String id = (String) var.variant.getValue(ID);
+ String id = (String) var.variant.getValue(VARIANT_ID);
if (id != null)
{
if (id.startsWith(SEQUENCE_VARIANT))
{
id = id.substring(SEQUENCE_VARIANT.length());
}
- sf.setValue(ID, id);
- attributes.append(ID).append("=").append(id);
+ sf.setValue(VARIANT_ID, id);
+ attributes.append(VARIANT_ID).append("=").append(id);
// TODO handle other species variants JAL-2064
StringBuilder link = new StringBuilder(32);
try