use of com.github.lindenb.jvarkit.util.vcf.predictions.BcfToolsPredictionParserFactory in project jvarkit by lindenb.
the class VcfTools method init.
public void init(final VCFHeader header) {
this.header = header;
this.snpEffPredictionParser = new SnpEffPredictionParserFactory().header(header).get();
this.vepPredictionParser = new VepPredictionParserFactory().header(header).get();
this.annPredictionParser = new AnnPredictionParserFactory(header).get();
this.bcftoolsCsqPredictionParser = new BcfToolsPredictionParserFactory(header).get();
this.lofSnpeffParser = SnpEffLofNmdParser.createLofParser(header);
this.nmdSnpeffParser = SnpEffLofNmdParser.createNmdParser(header);
this.smooveGenesParser = new SmooveGenesParser(header);
}
use of com.github.lindenb.jvarkit.util.vcf.predictions.BcfToolsPredictionParserFactory in project jvarkit by lindenb.
the class VcfBurdenFilterGenes method doVcfToVcf.
@Override
protected int doVcfToVcf(final String inputName, final VCFIterator in, final VariantContextWriter out) {
final VCFHeader header = in.getHeader();
try {
final VCFHeader h2 = addMetaData(new VCFHeader(header));
final VCFFilterHeaderLine filterControlsHeader;
if (!StringUtil.isBlank(this.filterTag)) {
filterControlsHeader = new VCFFilterHeaderLine(this.filterTag.trim(), "Genes not in list " + this.geneFile);
h2.addMetaDataLine(filterControlsHeader);
} else {
filterControlsHeader = null;
}
final List<String> lookColumns = Arrays.asList("CCDS", "Feature", "ENSP", "Gene", "HGNC", "HGNC_ID", "SYMBOL", "RefSeq");
final VepPredictionParser vepParser = new VepPredictionParserFactory(header).get();
final AnnPredictionParser annParser = new AnnPredictionParserFactory(header).get();
final BcfToolsPredictionParser bcftoolsParser = new BcfToolsPredictionParserFactory(header).get();
JVarkitVersion.getInstance().addMetaData(this, h2);
out.writeHeader(h2);
while (in.hasNext()) {
final VariantContext ctx = in.next();
boolean keep = false;
final VariantContextBuilder vcb = new VariantContextBuilder(ctx);
// not just set FILTER ?
if (filterControlsHeader == null) {
vcb.rmAttribute(vepParser.getTag());
vcb.rmAttribute(annParser.getTag());
}
final List<String> newVepList = new ArrayList<>();
for (final String predStr : ctx.getAttributeAsStringList(vepParser.getTag(), "")) {
final VepPredictionParser.VepPrediction pred = vepParser.parseOnePrediction(ctx, predStr);
for (final String col : lookColumns) {
final String token = pred.getByCol(col);
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newVepList.add(predStr);
keep = true;
// break lookColumns
break;
}
}
}
final List<String> newEffList = new ArrayList<>();
for (final String predStr : ctx.getAttributeAsStringList(annParser.getTag(), "")) {
final AnnPredictionParser.AnnPrediction pred = annParser.parseOnePrediction(predStr);
String token = pred.getGeneName();
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newEffList.add(predStr);
keep = true;
continue;
}
token = pred.getGeneId();
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newEffList.add(predStr);
keep = true;
continue;
}
token = pred.getFeatureId();
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newEffList.add(predStr);
keep = true;
continue;
}
}
final List<String> newBcfList = new ArrayList<>();
for (final String predStr : ctx.getAttributeAsStringList(bcftoolsParser.getTag(), "")) {
final BcfToolsPredictionParser.BcfToolsPrediction pred = bcftoolsParser.parseOnePrediction(ctx, predStr);
String token = pred.getGeneName();
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newBcfList.add(predStr);
keep = true;
continue;
}
token = pred.getTranscript();
if (!StringUtil.isBlank(token) && this.geneNames.contains(token)) {
newBcfList.add(predStr);
keep = true;
continue;
}
}
// not just set FILTER ?
if (filterControlsHeader == null) {
if (!newVepList.isEmpty())
vcb.attribute(vepParser.getTag(), newVepList);
if (!newEffList.isEmpty())
vcb.attribute(annParser.getTag(), newEffList);
if (!newBcfList.isEmpty())
vcb.attribute(bcftoolsParser.getTag(), newBcfList);
}
if (filterControlsHeader != null) {
if (!keep) {
vcb.filter(filterControlsHeader.getID());
} else if (!ctx.isFiltered()) {
vcb.passFilters();
}
out.add(vcb.make());
} else {
if (keep)
out.add(vcb.make());
}
}
return 0;
} catch (final Throwable err) {
LOG.error(err);
return -1;
}
}
Aggregations