Merge branch 'feature/JAL-3469clinvarVCF' into spike/clinvar
[jalview.git] / test / jalview / io / vcf / VCFLoaderTest.java
index 808fe86..1d4ba62 100644 (file)
@@ -3,7 +3,7 @@ package jalview.io.vcf;
 import static jalview.io.gff.SequenceOntologyI.SEQUENCE_VARIANT;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
 
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
@@ -13,13 +13,11 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.features.FeatureAttributes;
-import jalview.datamodel.features.FeatureAttributes.Datatype;
 import jalview.datamodel.features.SequenceFeatures;
 import jalview.gui.AlignFrame;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.io.gff.Gff3Helper;
-import jalview.io.gff.SequenceOntologyI;
 import jalview.util.MapList;
 
 import java.io.File;
@@ -62,19 +60,20 @@ public class VCFLoaderTest
           + ">transcript4/1-18\n-----TGG-GGACGAGAGTGTGA-A\n";
 
   private static final String[] VCF = { "##fileformat=VCFv4.2",
-      // fields other than AF are ignored when parsing as they have no INFO definition
+      // note fields with no INFO definition are ignored when parsing
       "##INFO=<ID=AF,Number=A,Type=Float,Description=\"Allele Frequency, for each ALT allele, in the same order as listed\">",
       "##INFO=<ID=AC_Female,Number=A,Type=Integer,Description=\"Allele count in Female genotypes\"",
       "##INFO=<ID=AF_AFR,Number=A,Type=Float,Description=\"Allele Frequency among African/African American genotypes\"",
+      "##INFO=<ID=CLNSIG,Number=.,Type=String,Description=\"Clinical significance for this single variant\"",
       "##reference=Homo_sapiens/GRCh38",
       "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO",
       // A/T,C variants in position 2 of gene sequence (precedes transcript)
       // should create 2 variant features with respective AF values
       // malformed values for AC_Female and AF_AFR should be ignored
-      "17\t45051611\t.\tA\tT,C\t1666.64\tRF\tAC=15;AF=5.0e-03,4.0e-03;AC_Female=12,3d;AF_AFR=low,2.3e-4",
+      "17\t45051611\trs384765\tA\tT,C\t1666.64\tRF;XYZ\tAC=15;AF=5.0e-03,4.0e-03;AC_Female=12,3d;AF_AFR=low,2.3e-4;CLNSIG=benign,probably_benign",
       // SNP G/C in position 4 of gene sequence, position 2 of transcript
       // insertion G/GA is transferred to nucleotide but not to peptide
-      "17\t45051613\t.\tG\tGA,C\t1666.65\tRF\tAC=15;AF=3.0e-03,2.0e-03",
+      "17\t45051613\t.\tG\tGA,C\t1666.65\t.\tAC=15;AF=3.0e-03,2.0e-03",
       // '.' in INFO field should be ignored
       "17\t45051615\t.\tG\tC\t1666.66\tRF\tAC=16;AF=." };
 
@@ -130,6 +129,14 @@ public class VCFLoaderTest
     assertEquals(sf.getValue("AF_AFR"), "2.3e-4");
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,C");
     assertEquals(sf.getType(), SEQUENCE_VARIANT);
+    assertEquals(sf.getValue("POS"), "45051611");
+    assertEquals(sf.getValue("ID"), "rs384765");
+    assertEquals(sf.getValue("QUAL"), "1666.64");
+    assertEquals(sf.getValue("FILTER"), "RF;XYZ");
+    /*
+     * if INFO declares Number=1, all values are attached to each allele
+     */
+    assertEquals(sf.getValue("CLNSIG"), "benign,probably_benign");
     // malformed integer for AC_Female is ignored (JAL-3375)
     assertNull(sf.getValue("AC_Female"));
 
@@ -145,6 +152,7 @@ public class VCFLoaderTest
     // malformed float for AF_AFR is ignored (JAL-3375)
     assertNull(sf.getValue("AC_AFR"));
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "A,T");
+    assertEquals(sf.getValue("CLNSIG"), "benign,probably_benign");
 
     sf = geneFeatures.get(2);
     assertEquals(sf.getFeatureGroup(), "VCF");
@@ -165,6 +173,8 @@ public class VCFLoaderTest
     assertEquals(Float.parseFloat((String) sf.getValue("AF")), 3.0e-03,
             DELTA);
     assertEquals(sf.getValue(Gff3Helper.ALLELES), "G,GA");
+    assertNull(sf.getValue("ID")); // '.' is ignored
+    assertNull(sf.getValue("FILTER")); // '.' is ignored
 
     sf = geneFeatures.get(4);
     assertEquals(sf.getFeatureGroup(), "VCF");
@@ -215,24 +225,11 @@ public class VCFLoaderTest
       }
     }
     List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
-    assertEquals(proteinFeatures.size(), 3);
-    sf = proteinFeatures.get(0);
-    assertEquals(sf.getFeatureGroup(), "VCF");
-    assertEquals(sf.getBegin(), 1);
-    assertEquals(sf.getEnd(), 1);
-    assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
-    assertEquals(sf.getDescription(), "p.Ser1Thr");
 
     /*
-     * check that sequence_variant attribute AF has been clocked as
-     * numeric with correct min and max values
-     * (i.e. invalid values have been ignored - JAL-3375)
+     * JAL-3187 don't precompute protein features, do dynamically instead
      */
-    FeatureAttributes fa = FeatureAttributes.getInstance();
-    assertSame(fa.getDatatype(SEQUENCE_VARIANT, "AF"), Datatype.Number);
-    float[] minmax = fa.getMinMax(SEQUENCE_VARIANT, "AF");
-    assertEquals(minmax[0], 0.002f);
-    assertEquals(minmax[1], 0.005f);
+    assertTrue(proteinFeatures.isEmpty());
   }
 
   private File makeVcfFile() throws IOException
@@ -494,13 +491,11 @@ public class VCFLoaderTest
       }
     }
     List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
-    assertEquals(proteinFeatures.size(), 3);
-    sf = proteinFeatures.get(0);
-    assertEquals(sf.getFeatureGroup(), "VCF");
-    assertEquals(sf.getBegin(), 6);
-    assertEquals(sf.getEnd(), 6);
-    assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
-    assertEquals(sf.getDescription(), "p.Ala6Gly");
+
+    /*
+     * JAL-3187 don't precompute protein features, do dynamically instead
+     */
+    assertTrue(proteinFeatures.isEmpty());
   }
 
   /**
@@ -543,6 +538,7 @@ public class VCFLoaderTest
     // gene features include Consequence for all transcripts
     Map map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
+    assertEquals(map.get("PolyPhen"), "Bad");
 
     sf = geneFeatures.get(1);
     assertEquals(sf.getBegin(), 5);
@@ -552,6 +548,7 @@ public class VCFLoaderTest
     assertEquals(sf.getValue("alleles"), "C,T");
     map = (Map) sf.getValue("CSQ");
     assertEquals(map.size(), 9);
+    assertEquals(map.get("PolyPhen"), "Bad;;"); // %3B%3B decoded
 
     sf = geneFeatures.get(2);
     assertEquals(sf.getBegin(), 9);
@@ -654,20 +651,24 @@ public class VCFLoaderTest
       }
     }
     List<SequenceFeature> proteinFeatures = peptide.getSequenceFeatures();
-    SequenceFeatures.sortFeatures(proteinFeatures, true);
-    assertEquals(proteinFeatures.size(), 2);
-    sf = proteinFeatures.get(0);
-    assertEquals(sf.getFeatureGroup(), "VCF");
-    assertEquals(sf.getBegin(), 1);
-    assertEquals(sf.getEnd(), 1);
-    assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
-    assertEquals(sf.getDescription(), "agC/agT");
-    sf = proteinFeatures.get(1);
-    assertEquals(sf.getFeatureGroup(), "VCF");
-    assertEquals(sf.getBegin(), 4);
-    assertEquals(sf.getEnd(), 4);
-    assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
-    assertEquals(sf.getDescription(), "p.Glu4Gly");
+    /*
+     * JAL-3187 don't precompute protein features, do dynamically instead
+     */
+    assertTrue(proteinFeatures.isEmpty());
+    // SequenceFeatures.sortFeatures(proteinFeatures, true);
+    // assertEquals(proteinFeatures.size(), 2);
+    // sf = proteinFeatures.get(0);
+    // assertEquals(sf.getFeatureGroup(), "VCF");
+    // assertEquals(sf.getBegin(), 1);
+    // assertEquals(sf.getEnd(), 1);
+    // assertEquals(sf.getType(), SequenceOntologyI.SYNONYMOUS_VARIANT);
+    // assertEquals(sf.getDescription(), "agC/agT");
+    // sf = proteinFeatures.get(1);
+    // assertEquals(sf.getFeatureGroup(), "VCF");
+    // assertEquals(sf.getBegin(), 4);
+    // assertEquals(sf.getEnd(), 4);
+    // assertEquals(sf.getType(), SequenceOntologyI.NONSYNONYMOUS_VARIANT);
+    // assertEquals(sf.getDescription(), "p.Glu4Gly");
 
     /*
      * verify variant feature(s) added to transcript4