use of com.github.lindenb.jvarkit.variant.vcf.BufferedVCFReader in project jvarkit by lindenb.
the class BamPhased01 method beforeSam.
@Override
protected int beforeSam() {
if (!(this.XTAG.length() == 0 || this.XTAG.length() == 2)) {
LOG.error("tag should be empty of length==2 but got " + this.XTAG);
return -1;
}
if (this.XTAG.length() == 2 && !this.XTAG.startsWith("X")) {
LOG.error("tag should start with 'X' but got " + this.XTAG);
return -1;
}
if (this.num_supporting_variants < 2) {
LOG.error("Bad number of supporting variant (should be >=2) " + this.num_supporting_variants);
return -1;
}
this.vcfReader = VCFReaderFactory.makeDefault().open(this.vcfFile, true);
this.bufferedVCFReader = new BufferedVCFReader(this.vcfReader, this.buffSizeInBp);
this.bufferedVCFReader.setSimplifier(V -> simplify(V));
return 0;
}
use of com.github.lindenb.jvarkit.variant.vcf.BufferedVCFReader in project jvarkit by lindenb.
the class VcfPeekAf method beforeVcf.
@Override
protected int beforeVcf() {
final List<AFPeeker> all_peekers = new ArrayList<>();
all_peekers.add(new InfoAcAnPeeker());
all_peekers.add(new InfoAfPeeker());
all_peekers.add(new GtPeeker());
all_peekers.add(new CustomInfoPeeker());
this.indexedVcfFileReader = null;
if (this.buffer_size < 1) {
LOG.error("bad buffer-size");
return -1;
}
try {
if (this.list_peekers) {
try (PrintWriter out = super.openPathOrStdoutAsPrintWriter(this.outputFile)) {
for (final AFPeeker p : all_peekers) out.println(p.getName() + "\n\t" + p.getDescription());
out.flush();
}
System.exit(0);
}
if (StringUtils.isBlank(this.peekerName)) {
LOG.error("peeker name is empty");
return -1;
}
this.peeker = all_peekers.stream().filter(P -> P.getName().equals(this.peekerName)).findFirst().orElse(null);
if (this.peeker == null) {
LOG.error("peeker " + this.peekerName + " not found in " + all_peekers.stream().map(P -> P.getName()).collect(Collectors.joining(";")));
return -1;
}
final VCFReader reader0 = VCFReaderFactory.makeDefault().open(this.resourceVcfFile, true);
this.indexedVcfFileReader = new BufferedVCFReader(reader0, this.buffer_size);
this.peeker.initialize(this.indexedVcfFileReader.getHeader());
this.indexedVcfFileReader.setSimplifier(peeker::sanitize);
return 0;
} catch (final Throwable err) {
LOG.error(err);
return -1;
}
}
use of com.github.lindenb.jvarkit.variant.vcf.BufferedVCFReader in project jvarkit by lindenb.
the class Biostar9501110 method beforeSam.
@Override
protected int beforeSam() {
if (this.min_num_variants < 1) {
LOG.error("--min-variants < 1");
return -1;
}
if (!StringUtils.isBlank(this.attribute)) {
if (this.attribute.length() != 2 || !this.attribute.startsWith("X")) {
LOG.error("attribute should have length==2 and start with X but got " + this.attribute + ".");
return -1;
}
}
this.vcfReader = VCFReaderFactory.makeDefault().open(this.vcfFile, true);
this.bufferedVCFReader = new BufferedVCFReader(this.vcfReader, this.buffSizeInBp);
this.bufferedVCFReader.setSimplifier(V -> simplify(V));
this.findVariantInSamRecord.setUseClip(this.use_clip);
return super.beforeSam();
}
use of com.github.lindenb.jvarkit.variant.vcf.BufferedVCFReader in project jvarkit by lindenb.
the class VcfGnomad method beforeVcf.
@Override
protected int beforeVcf() {
try {
final VCFReader r = VCFReaderFactory.makeDefault().open(this.gnomadPath, true);
this.gnomadReader = new BufferedVCFReader(r, this.gnomadBufferSize);
this.ctgNameConverter = ContigNameConverter.fromOneDictionary(SequenceDictionaryUtils.extractRequired(r.getHeader()));
} catch (final Throwable err) {
LOG.error(err);
return -1;
}
final VCFHeader gnomadHeader = this.gnomadReader.getHeader();
for (final String field : this.infoFieldStr.split("[ ,;\t]+")) {
if (StringUtils.isBlank(field))
continue;
final VCFInfoHeaderLine info = gnomadHeader.getInfoHeaderLines().stream().filter(F -> F.getID().equalsIgnoreCase(field)).findFirst().orElse(null);
if (info == null) {
LOG.error("field INFO/" + field + " is undefined in " + this.gnomadPath);
return -1;
}
if (!field.equals(info.getID())) {
LOG.warn("changed user field INFO/" + field + " to INFO/" + info.getID());
}
if (info.getCountType() != VCFHeaderLineCount.A) {
LOG.warn("field INFO/" + field + " count-type is not 'A' but " + info.getCountType());
}
this.gnomad_info_af_attributes.add(info.getID());
}
if (this.gnomad_info_af_attributes.isEmpty()) {
LOG.error("No INFO attribute defined");
return -1;
}
/* do not keep those INFO in memory */
final List<String> removeAtt = this.gnomadReader.getHeader().getInfoHeaderLines().stream().map(H -> H.getID()).filter(ID -> !this.gnomad_info_af_attributes.contains(ID)).collect(Collectors.toList());
this.gnomadReader.setSimplifier(V -> {
final VariantContextBuilder vcb = new VariantContextBuilder(V);
vcb.rmAttributes(removeAtt).noGenotypes();
return vcb.make();
});
return 0;
}
use of com.github.lindenb.jvarkit.variant.vcf.BufferedVCFReader in project jvarkit by lindenb.
the class VcfGnomadExomeVsGenome method beforeVcf.
@Override
protected int beforeVcf() {
final UnaryOperator<VariantContext> simplifier = V -> new VariantContextBuilder(V).noGenotypes().noID().attributes(Collections.emptyMap()).make();
SAMSequenceDictionary dict1 = null;
try {
final VCFReader r = VCFReaderFactory.makeDefault().open(this.exomePath, true);
this.exomeReader = new BufferedVCFReader(r, this.gnomadBufferSize);
this.exomeReader.setSimplifier(simplifier);
this.ctgNameConverter = ContigNameConverter.fromOneDictionary(SequenceDictionaryUtils.extractRequired(r.getHeader()));
dict1 = SequenceDictionaryUtils.extractRequired(r.getHeader());
} catch (final Throwable err) {
LOG.error(err);
return -1;
}
try {
final VCFReader r = VCFReaderFactory.makeDefault().open(this.genomePath, true);
this.genomeReader = new BufferedVCFReader(r, this.gnomadBufferSize);
this.genomeReader.setSimplifier(simplifier);
final SAMSequenceDictionary dict2 = SequenceDictionaryUtils.extractRequired(r.getHeader());
SequenceUtil.assertSequenceDictionariesEqual(dict1, dict2);
} catch (final Throwable err) {
LOG.error(err);
return -1;
}
return super.beforeVcf();
}
Aggregations