@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
writable.set(ctxh); writable.write(out); writable = new VariantContextWritable(); writable.readFields(new DataInputStream(bis)); VariantContext vc = writable.get(); Assert.assertArrayEquals("comparing Alleles",ctx.getAlleles().toArray(),vc.getAlleles().toArray()); Assert.assertEquals("comparing Log10PError",ctx.getLog10PError(),vc.getLog10PError(),0.01);
vc.set(v, header);
@Before public void setup() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { test_vcf_output = File.createTempFile("test_vcf_output", ""); test_vcf_output.delete(); writable = new VariantContextWritable(); Configuration conf = new Configuration(); conf.set("hadoopbam.vcf.output-format", "VCF"); KeyIgnoringVCFOutputFormat<Long> outputFormat = new KeyIgnoringVCFOutputFormat<Long>(conf); outputFormat.setHeader(readHeader()); taskAttemptContext = new TaskAttemptContextImpl(conf, mock(TaskAttemptID.class)); writer = outputFormat.getRecordWriter(taskAttemptContext, new Path("file://" + test_vcf_output)); }
vc.set(v, header);
@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
@Override public boolean nextKeyValue() throws IOException { if (in.peek() == -1) return false; if (!isBGZF && in.getPosition() >= fileStart + length) return false; final VariantContext v = codec.decode(in); Integer chromIdx = contigDict.get(v.getContig()); if (chromIdx == null) chromIdx = (int)MurmurHash3.murmurhash3(v.getContig(), 0); key.set((long)chromIdx << 32 | (long)(v.getStart() - 1)); vc.set(v); return true; } }
@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
@Override public boolean nextKeyValue() throws IOException { while (true) { String line; while (true) { if (!lineRecordReader.nextKeyValue()) { return false; } line = lineRecordReader.getCurrentValue().toString(); if (!line.startsWith("#")) { break; } } final VariantContext v = codec.decode(line); if (!overlaps(v)) { continue; } Integer chromIdx = contigDict.get(v.getContig()); if (chromIdx == null) chromIdx = (int) MurmurHash3.murmurhash3(v.getContig(), 0); key.set((long) chromIdx << 32 | (long) (v.getStart() - 1)); vc.set(v, header); return true; } }
@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
@Override public boolean nextKeyValue() throws IOException { if (in.peek() == -1) return false; if (!isBGZF && in.getPosition() >= fileStart + length) return false; final VariantContext v = codec.decode(in); Integer chromIdx = contigDict.get(v.getContig()); if (chromIdx == null) chromIdx = (int)MurmurHash3.murmurhash3(v.getContig(), 0); key.set((long)chromIdx << 32 | (long)(v.getStart() - 1)); vc.set(v); return true; } }
@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
@Override public boolean nextKeyValue() throws IOException { if (in.peek() == -1) return false; if (!isBGZF && in.getPosition() >= fileStart + length) return false; final VariantContext v = codec.decode(in); Integer chromIdx = contigDict.get(v.getContig()); if (chromIdx == null) chromIdx = (int)MurmurHash3.murmurhash3(v.getContig(), 0); key.set((long)chromIdx << 32 | (long)(v.getStart() - 1)); vc.set(v); return true; } }
@Override public void write(K ignored, VariantContextWritable vc) { writeRecord(vc.get()); } }
@Test public void testSimple() throws Exception { VariantContextBuilder vctx_builder = new VariantContextBuilder(); ArrayList<Allele> alleles = new ArrayList<Allele>(); alleles.add(Allele.create("A", false)); alleles.add(Allele.create("C", true)); vctx_builder.alleles(alleles); GenotypesContext genotypes = GenotypesContext.NO_GENOTYPES; vctx_builder.genotypes(genotypes); HashSet<String> filters = new HashSet<String>(); vctx_builder.filters(filters); HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("NS", new Integer(4)); vctx_builder.attributes(attributes); vctx_builder.loc("20", 2, 2); vctx_builder.log10PError(-8.0); String[] expected = new String[]{"20", "2", ".", "C", "A", "80", "PASS", "NS=4"}; VariantContext ctx = vctx_builder.make(); writable.set(ctx); writer.write(1L, writable); writer.close(taskAttemptContext); LineNumberReader reader = new LineNumberReader(new FileReader(test_vcf_output)); skipHeader(reader); String[] fields = Arrays.copyOf(reader.readLine().split("\t"), expected.length); Assert.assertArrayEquals("comparing VCF single line", expected, fields); }
public void checkReading(ValidationStringency validationStringency) throws Exception { String filename = "invalid_info_field.vcf"; Configuration conf = new Configuration(); String input_file = ClassLoader.getSystemClassLoader().getResource(filename).getFile(); conf.set("mapred.input.dir", "file://" + input_file); if (validationStringency != null) { VCFRecordReader.setValidationStringency(conf, validationStringency); } TaskAttemptContext taskAttemptContext = new TaskAttemptContextImpl(conf, mock(TaskAttemptID.class)); JobContext ctx = new JobContextImpl(conf, taskAttemptContext.getJobID()); VCFInputFormat inputFormat = new VCFInputFormat(conf); List<InputSplit> splits = inputFormat.getSplits(ctx); assertEquals(1, splits.size()); RecordReader<LongWritable, VariantContextWritable> reader = inputFormat.createRecordReader(splits.get(0), taskAttemptContext); int counter = 0; while (reader.nextKeyValue()) { VariantContextWritable writable = reader.getCurrentValue(); assertNotNull(writable); VariantContext vc = writable.get(); assertNotNull(vc); String value = vc.toString(); assertNotNull(value); counter++; } assertEquals(4, counter); }
@Test public void countEntries() throws Exception { VCFFileReader vcfFileReader = new VCFFileReader(new File("src/test/resources/" + filename), false); Iterator<VariantContext> variantIterator; if (interval == null) { variantIterator = vcfFileReader.iterator(); } else { variantIterator = vcfFileReader.query(interval.getContig(), interval.getStart(), interval.getEnd()); } int expectedCount = Iterators.size(variantIterator); int counter = 0; for (RecordReader<LongWritable, VariantContextWritable> reader : readers) { while (reader.nextKeyValue()) { writable = reader.getCurrentValue(); assertNotNull(writable); VariantContext vc = writable.get(); assertNotNull(vc); String value = vc.toString(); assertNotNull(value); counter++; } } assertEquals(expectedCount, counter); }