use of htsjdk.variant.vcf.VCFIterator in project jvarkit by lindenb.
the class VcfToBam method doWork.
@Override
public int doWork(final List<String> args) {
if (this.faidx == null) {
LOG.error("No REF defined");
return -1;
}
if (readSize <= 0) {
LOG.error("bad read size");
return -1;
}
if (fragmentSize <= readSize * 2) {
LOG.error("bad fragment size");
return -1;
}
VCFIterator iter = null;
try {
this.indexedFastaSequenceFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(this.faidx);
iter = super.openVCFIterator(super.oneFileOrNull(args));
run(iter);
return 0;
} catch (final Throwable err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(iter);
}
}
use of htsjdk.variant.vcf.VCFIterator in project jvarkit by lindenb.
the class VcfToRdf method scanVCF.
private void scanVCF(final File filein) throws IOException {
VCFIterator in = null;
URI source = null;
try {
if (filein != null)
source = filein.toURI();
in = (filein == null ? VCFUtils.createVCFIteratorStdin() : VCFUtils.createVCFIteratorFromFile(filein));
final VCFHeader header = in.getHeader();
final VepPredictionParser vepPredictionParser = new VepPredictionParserFactory(header).get();
writeHeader(header, source);
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header);
while (in.hasNext()) {
if (this.w.checkError()) {
LOG.warn("I/O interruption");
break;
}
final VariantContext ctx = progress.watch(in.next());
/* Variant */
final URI variant = URI.create("urn:variant/" + ctx.getContig() + ":" + ctx.getStart() + ":" + ctx.getReference().getBaseString());
emit(variant, "rdf:type", "vcf:Variant", "vcf:chrom", URI.create("urn:chrom/" + ctx.getContig()), "vcf:position", ctx.getStart(), "vcf:ref", ctx.getReference().getBaseString(), "vcf:id", (ctx.hasID() ? ctx.getID() : null), "vcf:qual", (ctx.hasLog10PError() ? ctx.getPhredScaledQual() : null));
if (this.printAlleles) {
for (final Allele alt : ctx.getAlternateAlleles()) {
emit(variant, "vcf:alt", alt.getBaseString());
}
}
if (this.printFilters) {
for (final String f : ctx.getFilters()) {
emit(variant, "vcf:filter", URI.create("urn:filter/" + f));
}
}
if (this.printVep) {
for (final VepPrediction prediction : vepPredictionParser.getPredictions(ctx)) {
/*
final List<Object> L=new ArrayList<>();
L.add("rdf:type");L.add("vep:Prediction");
L.add("vcf:variant"); L.add(variant);
L.add("vcf:allele");L.add(prediction.getAllele().getBaseString());
for(final SequenceOntologyTree.Term term:prediction.getSOTerms())
{
L.add("vcf:so");
L.add(URI.create(term.getUri()));
}
if(prediction.getEnsemblTranscript()!=null)
{
final URI transcriptid=URI.create("http://www.ensembl.org/id/"+prediction.getEnsemblTranscript());
L.add("vep:transcript");
L.add(transcriptid);
if(prediction.getEnsemblGene()!=null)
{
emit(transcriptid,
"uniprot:transcribedFrom",//used in uniprot dump
URI.create("http://www.ensembl.org/id/"+prediction.getEnsemblGene())
);
}
if(prediction.getEnsemblProtein()!=null)
{
emit(
transcriptid,
"uniprot:translatedTo",//used in uniprot dump
URI.create("http://www.ensembl.org/id/"+prediction.getEnsemblProtein())
);
}
}
emit(
URI.create("urn:vep/"+(++id_generator)),
L.toArray()
);
*/
}
}
if (this.printGenotypes) {
for (final String sample : ctx.getSampleNames()) {
final Genotype g = ctx.getGenotype(sample);
final List<Object> L = new ArrayList<>();
L.add("vcf:sample");
L.add(URI.create("urn:sample/" + sample));
L.add("vcf:variant");
L.add(variant);
L.add("rdf:type");
L.add("vcf:Genotype");
if (g.hasDP()) {
L.add("vcf:dp");
L.add(g.getDP());
}
if (g.hasGQ()) {
L.add("vcf:gq");
L.add(g.getGQ());
}
if (g.isCalled()) {
if (g.isHet()) {
if (g.isHetNonRef()) {
L.add("rdf:type");
L.add("vcf:HetNonRefGenotype");
} else {
L.add("rdf:type");
L.add("vcf:HetGenotype");
}
} else if (g.isHom()) {
if (g.isHomRef()) {
L.add("rdf:type");
L.add("vcf:HomRefGenotype");
} else {
L.add("rdf:type");
L.add("vcf:HomVarGenotype");
}
}
for (final Allele a : g.getAlleles()) {
L.add("vcf:allele");
L.add(a.getBaseString());
}
}
emit(URI.create("urn:gt/" + ctx.getContig() + ":" + ctx.getStart() + ":" + ctx.getReference().getBaseString() + ":" + sample), L.toArray());
}
}
}
in.close();
in = null;
progress.finish();
} catch (final Exception e) {
throw new IOException(e);
} finally {
CloserUtil.close(in);
}
}
use of htsjdk.variant.vcf.VCFIterator in project jvarkit by lindenb.
the class VcfToTable method doWork.
@Override
public int doWork(final List<String> args) {
VCFIterator in = null;
try {
in = super.openVCFIterator(oneFileOrNull(args));
viewer.writeHeader(in.getHeader());
while (!this.viewer.checkError() && in.hasNext()) {
viewer.add(in.next());
}
viewer.close();
viewer = null;
in.close();
in = null;
return 0;
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(in);
CloserUtil.close(viewer);
}
}
Aggregations