use of com.github.lindenb.jvarkit.util.vcf.TabixVcfFileReader in project jvarkit by lindenb.
the class FindAVariation method scan.
private void scan(final BufferedReader in) throws IOException {
String line;
while ((line = in.readLine()) != null) {
if (line.isEmpty() || line.startsWith("#"))
continue;
final File f = new File(line);
if (!f.isFile())
continue;
if (!f.canRead())
continue;
if (!VCFUtils.isVcfFile(f))
continue;
VcfIterator iter = null;
if (VCFUtils.isTribbleVcfFile(f)) {
VCFFileReader r = null;
try {
r = new VCFFileReader(f, true);
final VCFHeader header = r.getFileHeader();
for (final Mutation m : convertFromVcfHeader(f, header)) {
final CloseableIterator<VariantContext> iter2 = r.query(m.chrom, m.pos, m.pos);
while (iter2.hasNext()) {
final VariantContext ctx = iter2.next();
if (this.onlySnp) {
if (ctx.getStart() != m.pos || ctx.getEnd() != m.pos)
continue;
}
report(f, header, ctx, m);
}
CloserUtil.close(iter2);
}
} catch (final htsjdk.tribble.TribbleException.InvalidHeader err) {
LOG.warn(f + "\t" + err.getMessage());
} catch (final Exception err) {
LOG.severe("cannot read " + f, err);
} finally {
CloserUtil.close(r);
}
} else if (VCFUtils.isTabixVcfFile(f)) {
TabixVcfFileReader r = null;
try {
r = new TabixVcfFileReader(f.getPath());
final VCFHeader header = r.getHeader();
for (final Mutation m : convertFromVcfHeader(f, header)) {
final Iterator<VariantContext> iter2 = r.iterator(m.chrom, m.pos, m.pos);
while (iter2.hasNext()) {
final VariantContext ctx = iter2.next();
if (this.onlySnp) {
if (ctx.getStart() != m.pos || ctx.getEnd() != m.pos)
continue;
}
report(f, header, ctx, m);
}
CloserUtil.close(iter2);
}
} catch (final htsjdk.tribble.TribbleException.InvalidHeader err) {
LOG.warn(f + "\t" + err.getMessage());
} catch (final Exception err) {
LOG.severe("cannot read " + f, err);
} finally {
CloserUtil.close(r);
}
} else if (!this.indexedOnly) {
try {
iter = VCFUtils.createVcfIteratorFromFile(f);
final VCFHeader header = iter.getHeader();
final Set<Mutation> mutlist = convertFromVcfHeader(f, iter.getHeader());
while (iter.hasNext()) {
final VariantContext ctx = iter.next();
final Mutation m = new Mutation(ctx.getContig(), ctx.getStart());
for (final Mutation m2 : mutlist) {
if (m.equals(m2)) {
if (this.onlySnp) {
if (ctx.getStart() != m2.pos || ctx.getEnd() != m2.pos)
continue;
}
report(f, header, ctx, m2);
break;
}
}
}
} catch (final htsjdk.tribble.TribbleException.InvalidHeader err) {
LOG.warn(f + "\t" + err.getMessage());
} catch (final Exception err) {
LOG.severe("Error in " + f, err);
} finally {
CloserUtil.close(iter);
}
}
}
}
use of com.github.lindenb.jvarkit.util.vcf.TabixVcfFileReader in project jvarkit by lindenb.
the class VcfRemoveGenotypeIfInVcf method doWork.
@Override
public int doWork(List<String> args) {
if (tabixFilePath == null) {
LOG.error("Undefined VCF tabix file");
return -1;
}
try {
LOG.info("Opening " + tabixFilePath);
this.tabix = new TabixVcfFileReader(tabixFilePath);
return doVcfToVcf(args, outputFile);
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(this.tabix);
}
}
use of com.github.lindenb.jvarkit.util.vcf.TabixVcfFileReader in project jvarkit by lindenb.
the class BamToSVG method readVariantFile.
private void readVariantFile(String vcf) throws IOException {
LOG.info("Reading " + vcf);
TabixVcfFileReader tfr = new TabixVcfFileReader(vcf);
Iterator<VariantContext> iter = tfr.iterator(this.interval.chrom, this.interval.start, this.interval.end);
while (iter.hasNext()) {
VariantContext ctx = iter.next();
this.pos2variant.add(ctx);
}
tfr.close();
}
Aggregations