JAL-2845 locate reverse strand insertion as complement insertion at a preceding position
[jalview.git] / src / jalview / io / vcf / VCFLoader.java
index 421cf38..9d98b7e 100644 (file)
@@ -556,7 +556,15 @@ public class VCFLoader
       return 0;
     }
 
-    return addVcfVariants(seq, reader, vcfMap, vcfAssembly);
+    /*
+     * work with the dataset sequence here
+     */
+    SequenceI dss = seq.getDatasetSequence();
+    if (dss == null)
+    {
+      dss = seq;
+    }
+    return addVcfVariants(dss, reader, vcfMap, vcfAssembly);
   }
 
   /**
@@ -892,10 +900,24 @@ public class VCFLoader
     String allele = alt.getBaseString();
 
     /*
+     * insertion after a genomic base, if on reverse strand, has to be 
+     * converted to insertion of complement after the preceding position 
+     */
+    int referenceLength = reference.length();
+    if (!forwardStrand && allele.length() > referenceLength
+            && allele.startsWith(reference))
+    {
+      featureStart -= referenceLength;
+      featureEnd = featureStart;
+      char insertAfter = seq.getCharAt(featureStart - seq.getStart());
+      reference = Dna.reverseComplement(String.valueOf(insertAfter));
+      allele = allele.substring(referenceLength) + reference;
+    }
+
+    /*
      * build the ref,alt allele description e.g. "G,A", using the base
      * complement if the sequence is on the reverse strand
      */
-    // FIXME correctly handle insertions on reverse strand JAL-2845
     StringBuilder sb = new StringBuilder();
     sb.append(forwardStrand ? reference : Dna.reverseComplement(reference));
     sb.append(COMMA);