use of com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress in project jvarkit by lindenb.
the class VcfIndexTabix method doVcfToVcf.
private int doVcfToVcf(String inputName, final VcfIterator vcfIn, final File outFile) throws IOException {
SortingVCFWriter sortingVCW = null;
VariantContextWriterBuilder vcwb = new VariantContextWriterBuilder();
VariantContextWriter w = null;
try {
SAMSequenceDictionary dict = vcfIn.getHeader().getSequenceDictionary();
if (dict != null)
vcwb.setReferenceDictionary(dict);
vcwb.setOutputFile(outFile);
vcwb.setOutputFileType(OutputType.BLOCK_COMPRESSED_VCF);
w = vcwb.build();
if (this.sort) {
LOG.info("Creating a sorting writer");
sortingVCW = new SortingVCFWriter(w);
w = sortingVCW;
}
w.writeHeader(vcfIn.getHeader());
SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(vcfIn.getHeader());
while (vcfIn.hasNext()) {
w.add(progress.watch(vcfIn.next()));
}
progress.finish();
w.close();
w = null;
return RETURN_OK;
} catch (Exception e) {
if (outFile.exists() && outFile.isFile()) {
LOG.warn("Deleting " + outFile);
outFile.delete();
File tbi = new File(outFile.getPath() + TabixUtils.STANDARD_INDEX_EXTENSION);
if (tbi.exists() && tbi.isFile())
tbi.delete();
}
LOG.error(e);
return -1;
} finally {
CloserUtil.close(w);
}
}
use of com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress in project jvarkit by lindenb.
the class VcfMultiToOneAllele method doVcfToVcf.
@Override
public int doVcfToVcf(final String inputName, final VcfIterator r, final VariantContextWriter delegate) {
final VariantContextWriter w = this.component.open(delegate);
w.writeHeader(r.getHeader());
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(r.getHeader()).logger(LOG);
while (r.hasNext()) {
w.add(progress.watch(r.next()));
}
progress.finish();
w.close();
return 0;
}
use of com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress in project jvarkit by lindenb.
the class VcfMultiToOneInfo method doVcfToVcf.
@Override
protected int doVcfToVcf(final String inputName, final VcfIterator in, final VariantContextWriter out) {
final VCFHeader srcHeader = in.getHeader();
final VCFInfoHeaderLine srcInfo = srcHeader.getInfoHeaderLine(this.infoTag);
if (srcInfo == null) {
LOG.error("Cannot find INFO FIELD '" + this.infoTag + "'");
return -1;
}
switch(srcInfo.getCountType()) {
case INTEGER:
break;
case UNBOUNDED:
break;
default:
{
LOG.error("CountType is not supported '" + srcInfo.getCountType() + "'");
return -1;
}
}
switch(srcInfo.getType()) {
case Flag:
{
LOG.error("Type is not supported '" + srcInfo.getType() + "'");
return -1;
}
default:
break;
}
final VCFHeader destHeader = new VCFHeader(srcHeader);
super.addMetaData(destHeader);
final SAMSequenceDictionaryProgress progess = new SAMSequenceDictionaryProgress(srcHeader);
out.writeHeader(destHeader);
while (in.hasNext()) {
final VariantContext ctx = progess.watch(in.next());
final List<Object> L = ctx.getAttributeAsList(srcInfo.getID());
if (L.isEmpty() || L.size() == 1) {
out.add(ctx);
continue;
}
for (final Object o : L) {
final VariantContextBuilder vcb = new VariantContextBuilder(ctx);
vcb.attribute(srcInfo.getID(), o);
out.add(vcb.make());
}
}
progess.finish();
LOG.info("done");
return RETURN_OK;
}
use of com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress in project jvarkit by lindenb.
the class VcfNoCallToHomRef method doVcfToVcf.
@Override
protected int doVcfToVcf(final String inputName, final VcfIterator in, final VariantContextWriter delegate) {
final CtxWriterFactory.CtxWriter out = this.component.open(delegate);
out.writeHeader(in.getHeader());
final SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(in.getHeader()).logger(LOG);
while (in.hasNext()) {
out.add(progress.watch(in.next()));
}
progress.finish();
out.close();
return 0;
}
use of com.github.lindenb.jvarkit.util.picard.SAMSequenceDictionaryProgress in project jvarkit by lindenb.
the class VcfRegulomeDB method doVcfToVcf.
@Override
protected int doVcfToVcf(String inputName, VcfIterator in, VariantContextWriter out) {
VCFHeader header = in.getHeader();
SAMSequenceDictionaryProgress progress = new SAMSequenceDictionaryProgress(header.getSequenceDictionary());
header.addMetaDataLine(new VCFHeaderLine(getClass().getSimpleName() + "CmdLine", String.valueOf(getProgramCommandLine())));
header.addMetaDataLine(new VCFHeaderLine(getClass().getSimpleName() + "Version", String.valueOf(getVersion())));
header.addMetaDataLine(new VCFInfoHeaderLine(this.infoTag, VCFHeaderLineCount.UNBOUNDED, VCFHeaderLineType.String, "Format: Position|Distance|Rank"));
out.writeHeader(header);
while (in.hasNext()) {
List<String> regDataList = new ArrayList<String>();
VariantContext ctx = in.next();
progress.watch(ctx.getContig(), ctx.getStart());
int start = Math.max(0, ctx.getStart() - this.extend);
int end = ctx.getEnd() + this.extend;
for (Iterator<RegData> iter = this.regDataTabixFileReader.iterator(ctx.getContig(), start, end); iter.hasNext(); ) {
RegData curr = iter.next();
if (this.acceptRegex != null && !this.acceptRegex.matcher(curr.rank).matches()) {
continue;
}
String str = String.valueOf(curr.chromSart) + "|" + String.valueOf(Math.abs(curr.chromSart - (ctx.getStart() - 1))) + "|" + curr.rank;
regDataList.add(str);
}
if (regDataList.isEmpty()) {
out.add(ctx);
continue;
}
VariantContextBuilder vcb = new VariantContextBuilder(ctx);
vcb.attribute(this.infoTag, regDataList.toArray());
out.add(vcb.make());
}
progress.finish();
return 0;
}
Aggregations