1 package jalview.datamodel;
3 import jalview.io.gff.Gff3Helper;
4 import jalview.schemes.ResidueProperties;
5 import jalview.util.MappingUtils;
6 import jalview.util.StringUtils;
8 import java.util.ArrayList;
12 * A data bean to hold a list of mapped sequence features (e.g. CDS features
13 * mapped from protein), and the mapping between the sequences
17 public class MappedFeatures
20 * the mapping from CDS to peptide
22 public final Mapping mapping;
25 * the CDS sequence mapped to
27 public final SequenceI fromSeq;
30 * the residue position in the peptide sequence
32 public final int fromPosition;
35 * the peptide residue at the position
37 public final char fromResidue;
40 * features on CDS that overlap the codon positions
42 public final List<SequenceFeature> features;
52 public MappedFeatures(Mapping theMapping, SequenceI from, int pos,
54 List<SequenceFeature> theFeatures)
60 features = theFeatures;
64 * Computes and returns a (possibly empty) list of HGVS notation peptide
65 * variants derived from codon allele variants
69 public List<String> findProteinVariants()
71 List<String> vars = new ArrayList<>();
74 * determine canonical codon
76 int[] codonPos = MappingUtils.flattenRanges(
77 mapping.getMap().locateInFrom(fromPosition, fromPosition));
78 if (codonPos.length != 3)
83 final char[] baseCodon = new char[3];
84 int cdsStart = fromSeq.getStart();
85 baseCodon[0] = fromSeq.getCharAt(codonPos[0] - cdsStart);
86 baseCodon[1] = fromSeq.getCharAt(codonPos[1] - cdsStart);
87 baseCodon[2] = fromSeq.getCharAt(codonPos[2] - cdsStart);
89 // todo avoid duplication of code in AlignmentUtils.buildDnaVariantsMap
91 for (SequenceFeature sf : features)
93 int cdsPos = sf.getBegin();
94 if (cdsPos != sf.getEnd())
96 // not handling multi-locus variant features
99 if (cdsPos != codonPos[0] && cdsPos != codonPos[1]
100 && cdsPos != codonPos[2])
102 // e.g. feature on intron within spliced codon!
106 String alls = (String) sf.getValue(Gff3Helper.ALLELES);
111 String from3 = StringUtils.toSentenceCase(
112 ResidueProperties.aa2Triplet
113 .get(String.valueOf(fromResidue)));
116 * make a peptide variant for each SNP allele
117 * e.g. C,G,T gives variants G and T for base C
119 String[] alleles = alls.toUpperCase().split(",");
120 for (String allele : alleles)
122 allele = allele.trim().toUpperCase();
123 if (allele.length() > 1)
125 continue; // multi-locus variant
127 char[] variantCodon = new char[3];
128 variantCodon[0] = baseCodon[0];
129 variantCodon[1] = baseCodon[1];
130 variantCodon[2] = baseCodon[2];
133 * poke variant base into canonical codon
135 int i = cdsPos == codonPos[0] ? 0 : (cdsPos == codonPos[1] ? 1 : 2);
136 variantCodon[i] = allele.toUpperCase().charAt(0);
137 String codon = new String(variantCodon);
138 String peptide = ResidueProperties.codonTranslate(codon);
139 if (fromResidue != peptide.charAt(0))
141 String to3 = StringUtils.toSentenceCase(
142 ResidueProperties.aa2Triplet.get(peptide));
143 String var = "p." + from3 + fromPosition + to3;
144 if (!vars.contains(var))