use of com.github.lindenb.jvarkit.pedigree.Family in project jvarkit by lindenb.
the class VCFFamilies method doVcfToVcf.
@Override
public int doVcfToVcf(final String inputName, VCFIterator r, final VariantContextWriter w) {
final VCFHeader header = r.getHeader();
final Pedigree pedigree;
try {
pedigree = new PedigreeParser().parse(this.pedigreeFile);
} catch (final Throwable err) {
throw new RuntimeIOException(err);
}
if (pedigree == null || pedigree.isEmpty()) {
throw new RuntimeIOException("Pedigree null/empty");
}
final VCFHeader h2 = new VCFHeader(header);
final Map<String, FamilyInfo> famidToFamilyInfo = new HashMap<>();
pedigree.getSamplesInVcfHeader(header).forEach(P -> {
final Family pedFamily = P.getFamily();
FamilyInfo finfo = famidToFamilyInfo.get(pedFamily.getId());
if (finfo == null) {
finfo = new FamilyInfo(pedFamily);
famidToFamilyInfo.put(pedFamily.getId(), finfo);
}
finfo.samples.add(P.getId());
});
famidToFamilyInfo.values().stream().flatMap(F -> F.getMetaDataLines().stream()).forEach(H -> h2.addMetaDataLine(H));
JVarkitVersion.getInstance().addMetaData(this, h2);
w.writeHeader(h2);
while (r.hasNext()) {
final VariantContext ctx = r.next();
final VariantContextBuilder vcb = new VariantContextBuilder(ctx);
final List<Allele> alts = ctx.getAlternateAlleles();
famidToFamilyInfo.values().forEach(F -> F.visit(vcb, ctx, alts));
w.add(vcb.make());
}
w.close();
return 0;
}
Aggregations