- * Inspects the VCF variant record, and adds variant features to the sequence.
- * Only SNP variants are added, not INDELs. Returns the number of features
- * added.
- * <p>
- * If the sequence maps to the reverse strand of the chromosome, reference and
- * variant bases are recorded as their complements (C/G, A/T).
- *
- * @param seq
- * @param variant
- * @param featureStart
- * @param featureEnd
- * @param forwardStrand
- */
- protected int addVariantFeature(SequenceI seq, VariantContext variant,
- int featureStart, int featureEnd, boolean forwardStrand)
- {
- byte[] reference = variant.getReference().getBases();
- if (reference.length != 1)
- {
- /*
- * sorry, we don't handle INDEL variants
- */
- return 0;
- }
-
- if (FEATURE_PER_ALLELE)
- {
- return addAlleleFeatures(seq, variant, featureStart, featureEnd,
- forwardStrand);
- }
-
- /*
- * for now we extract allele frequency as feature score; note
- * this attribute is String for a simple SNP, but List<String> if
- * multiple alleles at the locus; we extract for the simple case only
- */
- float score = getAlleleFrequency(variant, 0);
-
- StringBuilder sb = new StringBuilder();
- sb.append(forwardStrand ? (char) reference[0] : complement(reference));
-
- /*
- * inspect alleles and record SNP variants (as the variant
- * record could be MIXED and include INDEL and SNP alleles)
- * warning: getAlleles gives no guarantee as to the order
- * in which they are returned
- */
- for (Allele allele : variant.getAlleles())
- {
- if (!allele.isReference())
- {
- byte[] alleleBase = allele.getBases();
- if (alleleBase.length == 1)
- {
- sb.append(COMMA).append(
- forwardStrand ? (char) alleleBase[0]
- : complement(alleleBase));
- }
- }
- }
- String alleles = sb.toString(); // e.g. G,A,C
-
- String type = SequenceOntologyI.SEQUENCE_VARIANT;
-
- SequenceFeature sf = new SequenceFeature(type, alleles, featureStart,
- featureEnd, score, FEATURE_GROUP_VCF);
-
- sf.setValue(Gff3Helper.ALLELES, alleles);
-
- Map<String, Object> atts = variant.getAttributes();
- for (Entry<String, Object> att : atts.entrySet())
- {
- sf.setValue(att.getKey(), att.getValue());
- }
- seq.addSequenceFeature(sf);
-
- return 1;
- }
-
- /**