- // if (SequenceOntologyFactory.getInstance().isA(sf.getType(),
- // SequenceOntologyI.SEQUENCE_VARIANT))
- // {
- // String consequence = (String) sf.getValue(CONSEQUENCE_TYPE);
- // if (consequence != null)
- // {
- // SequenceFeature sf2 = new SequenceFeature("consequence",
- // consequence, copy.getBegin(), copy.getEnd(), 0f,
- // null);
- // targetSequence.addSequenceFeature(sf2);
- // }
- // }
+ if (!forwardStrand
+ && SequenceOntologyFactory.getInstance().isA(sf.getType(),
+ SequenceOntologyI.SEQUENCE_VARIANT))
+ {
+ reverseComplementAlleles(copy);
+ }
+ }
+ }
+
+ /**
+ * Change the 'alleles' value of a feature by converting to complementary
+ * bases, and also update the feature description to match
+ *
+ * @param sf
+ */
+ static void reverseComplementAlleles(SequenceFeature sf)
+ {
+ final String alleles = (String) sf.getValue(ALLELES);
+ if (alleles == null)
+ {
+ return;
+ }
+ StringBuilder complement = new StringBuilder(alleles.length());
+ for (String allele : alleles.split(","))
+ {
+ reverseComplementAllele(complement, allele);
+ }
+ String comp = complement.toString();
+ sf.setValue(ALLELES, comp);
+ sf.setDescription(comp);
+
+ /*
+ * replace value of "alleles=" in sf.ATTRIBUTES as well
+ * so 'output as GFF' shows reverse complement alleles
+ */
+ String atts = sf.getAttributes();
+ if (atts != null)
+ {
+ atts = atts.replace(ALLELES + "=" + alleles, ALLELES + "=" + comp);
+ sf.setAttributes(atts);
+ }
+ }
+
+ /**
+ * Makes the 'reverse complement' of the given allele and appends it to the
+ * buffer, after a comma separator if not the first
+ *
+ * @param complement
+ * @param allele
+ */
+ static void reverseComplementAllele(StringBuilder complement,
+ String allele)
+ {
+ if (complement.length() > 0)
+ {
+ complement.append(",");
+ }
+
+ /*
+ * some 'alleles' are actually descriptive terms
+ * e.g. HGMD_MUTATION, PhenCode_variation
+ * - we don't want to 'reverse complement' these
+ */
+ if (!Comparison.isNucleotideSequence(allele, true))
+ {
+ complement.append(allele);
+ }
+ else
+ {
+ for (int i = allele.length() - 1; i >= 0; i--)
+ {
+ complement.append(Dna.getComplement(allele.charAt(i)));
+ }