| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.ext.htsjdk; |
| 22 |
|
|
| 23 |
|
import static org.testng.Assert.assertEquals; |
| 24 |
|
import static org.testng.Assert.assertFalse; |
| 25 |
|
import static org.testng.Assert.assertTrue; |
| 26 |
|
import htsjdk.samtools.util.CloseableIterator; |
| 27 |
|
import htsjdk.variant.variantcontext.Allele; |
| 28 |
|
import htsjdk.variant.variantcontext.VariantContext; |
| 29 |
|
|
| 30 |
|
import java.io.File; |
| 31 |
|
import java.io.IOException; |
| 32 |
|
import java.io.PrintWriter; |
| 33 |
|
import java.util.List; |
| 34 |
|
|
| 35 |
|
import org.testng.annotations.Test; |
| 36 |
|
|
| |
|
| 80.5% |
Uncovered Elements: 16 (82) |
Complexity: 5 |
Complexity Density: 0.06 |
|
| 37 |
|
public class VCFReaderTest |
| 38 |
|
{ |
| 39 |
|
private static final String[] VCF = new String[] { "##fileformat=VCFv4.2", |
| 40 |
|
"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO", |
| 41 |
|
"20\t3\t.\tC\tG\t.\tPASS\tDP=100", |
| 42 |
|
"20\t7\t.\tG\tGA\t.\tPASS\tDP=100", |
| 43 |
|
"18\t2\t.\tACG\tA\t.\tPASS\tDP=100" }; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
private static final String VCF_PATH = "/Volumes/gjb/smacgowan/NOBACK/resources/gnomad/gnomad.exomes.r2.0.1.sites.vcf.gz"; |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
@throws |
| 55 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 56 |
1 |
@Test(groups = "Functional")... |
| 57 |
|
public void testReadVcf_plain() throws IOException |
| 58 |
|
{ |
| 59 |
1 |
File f = writeVcfFile(); |
| 60 |
1 |
VCFReader reader = new VCFReader(f.getAbsolutePath()); |
| 61 |
1 |
CloseableIterator<VariantContext> variants = reader.iterator(); |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
1 |
VariantContext vc = variants.next(); |
| 67 |
1 |
assertTrue(vc.isSNP()); |
| 68 |
1 |
Allele ref = vc.getReference(); |
| 69 |
1 |
assertEquals(ref.getBaseString(), "C"); |
| 70 |
1 |
List<Allele> alleles = vc.getAlleles(); |
| 71 |
1 |
assertEquals(alleles.size(), 2); |
| 72 |
1 |
assertTrue(alleles.get(0).isReference()); |
| 73 |
1 |
assertEquals(alleles.get(0).getBaseString(), "C"); |
| 74 |
1 |
assertFalse(alleles.get(1).isReference()); |
| 75 |
1 |
assertEquals(alleles.get(1).getBaseString(), "G"); |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
1 |
vc = variants.next(); |
| 81 |
1 |
assertFalse(vc.isSNP()); |
| 82 |
1 |
assertTrue(vc.isSimpleInsertion()); |
| 83 |
1 |
ref = vc.getReference(); |
| 84 |
1 |
assertEquals(ref.getBaseString(), "G"); |
| 85 |
1 |
alleles = vc.getAlleles(); |
| 86 |
1 |
assertEquals(alleles.size(), 2); |
| 87 |
1 |
assertTrue(alleles.get(0).isReference()); |
| 88 |
1 |
assertEquals(alleles.get(0).getBaseString(), "G"); |
| 89 |
1 |
assertFalse(alleles.get(1).isReference()); |
| 90 |
1 |
assertEquals(alleles.get(1).getBaseString(), "GA"); |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
1 |
vc = variants.next(); |
| 96 |
1 |
assertFalse(vc.isSNP()); |
| 97 |
1 |
assertTrue(vc.isSimpleDeletion()); |
| 98 |
1 |
ref = vc.getReference(); |
| 99 |
1 |
assertEquals(ref.getBaseString(), "ACG"); |
| 100 |
1 |
alleles = vc.getAlleles(); |
| 101 |
1 |
assertEquals(alleles.size(), 2); |
| 102 |
1 |
assertTrue(alleles.get(0).isReference()); |
| 103 |
1 |
assertEquals(alleles.get(0).getBaseString(), "ACG"); |
| 104 |
1 |
assertFalse(alleles.get(1).isReference()); |
| 105 |
1 |
assertEquals(alleles.get(1).getBaseString(), "A"); |
| 106 |
|
|
| 107 |
1 |
assertFalse(variants.hasNext()); |
| 108 |
|
|
| 109 |
1 |
variants.close(); |
| 110 |
1 |
reader.close(); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@return |
| 117 |
|
@throws |
| 118 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 119 |
2 |
protected File writeVcfFile() throws IOException... |
| 120 |
|
{ |
| 121 |
2 |
File f = File.createTempFile("Test", "vcf"); |
| 122 |
2 |
f.deleteOnExit(); |
| 123 |
2 |
PrintWriter pw = new PrintWriter(f); |
| 124 |
2 |
for (String vcfLine : VCF) |
| 125 |
|
{ |
| 126 |
10 |
pw.println(vcfLine); |
| 127 |
|
} |
| 128 |
2 |
pw.close(); |
| 129 |
2 |
return f; |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
@throws |
| 137 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 138 |
0 |
@Test... |
| 139 |
|
public void testQuery_indexed() throws IOException |
| 140 |
|
{ |
| 141 |
|
|
| 142 |
|
|
| 143 |
|
|
| 144 |
0 |
VCFReader reader = new VCFReader(VCF_PATH); |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
|
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
0 |
CloseableIterator<VariantContext> features = reader.query("17", |
| 153 |
|
43128978 + 9724, 43128978 + 9734); |
| 154 |
|
|
| 155 |
0 |
assertEquals(printNext(features), 43138702); |
| 156 |
0 |
assertEquals(printNext(features), 43138704); |
| 157 |
0 |
assertEquals(printNext(features), 43138707); |
| 158 |
0 |
assertEquals(printNext(features), 43138708); |
| 159 |
0 |
assertEquals(printNext(features), 43138710); |
| 160 |
0 |
assertEquals(printNext(features), 43138711); |
| 161 |
0 |
assertFalse(features.hasNext()); |
| 162 |
|
|
| 163 |
0 |
features.close(); |
| 164 |
0 |
reader.close(); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
|
@param |
| 172 |
|
@return |
| 173 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 174 |
0 |
protected int printNext(CloseableIterator<VariantContext> features)... |
| 175 |
|
{ |
| 176 |
0 |
VariantContext next = features.next(); |
| 177 |
0 |
System.out.println(next.toString()); |
| 178 |
0 |
return next.getStart(); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
@throws |
| 187 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
| 188 |
1 |
@Test(groups = "Functional")... |
| 189 |
|
public void testQuery_plain() throws IOException |
| 190 |
|
{ |
| 191 |
1 |
File f = writeVcfFile(); |
| 192 |
1 |
VCFReader reader = new VCFReader(f.getAbsolutePath()); |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
|
| 197 |
1 |
CloseableIterator<VariantContext> variants = reader.query("20", 5, 8); |
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
1 |
VariantContext vc = variants.next(); |
| 203 |
1 |
assertTrue(vc.isIndel()); |
| 204 |
1 |
assertEquals(vc.getStart(), 7); |
| 205 |
1 |
assertEquals(vc.getEnd(), 7); |
| 206 |
1 |
Allele ref = vc.getReference(); |
| 207 |
1 |
assertEquals(ref.getBaseString(), "G"); |
| 208 |
1 |
List<Allele> alleles = vc.getAlleles(); |
| 209 |
1 |
assertEquals(alleles.size(), 2); |
| 210 |
1 |
assertTrue(alleles.get(0).isReference()); |
| 211 |
1 |
assertEquals(alleles.get(0).getBaseString(), "G"); |
| 212 |
1 |
assertFalse(alleles.get(1).isReference()); |
| 213 |
1 |
assertEquals(alleles.get(1).getBaseString(), "GA"); |
| 214 |
|
|
| 215 |
1 |
assertFalse(variants.hasNext()); |
| 216 |
|
|
| 217 |
1 |
variants.close(); |
| 218 |
1 |
reader.close(); |
| 219 |
|
} |
| 220 |
|
} |