Search in sources :

Example 1 with Family

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;
}
Also used : WritingVariantsDelegate(com.github.lindenb.jvarkit.variant.variantcontext.writer.WritingVariantsDelegate) Genotype(htsjdk.variant.variantcontext.Genotype) Allele(htsjdk.variant.variantcontext.Allele) Arrays(java.util.Arrays) VCFIterator(htsjdk.variant.vcf.VCFIterator) Program(com.github.lindenb.jvarkit.util.jcommander.Program) Parameter(com.beust.jcommander.Parameter) VCFHeader(htsjdk.variant.vcf.VCFHeader) HashMap(java.util.HashMap) ParametersDelegate(com.beust.jcommander.ParametersDelegate) HashSet(java.util.HashSet) BiPredicate(java.util.function.BiPredicate) StringUtil(htsjdk.samtools.util.StringUtil) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) PedigreeParser(com.github.lindenb.jvarkit.pedigree.PedigreeParser) Map(java.util.Map) Path(java.nio.file.Path) VCFConstants(htsjdk.variant.vcf.VCFConstants) VCFHeaderLineType(htsjdk.variant.vcf.VCFHeaderLineType) JexlGenotypePredicate(com.github.lindenb.jvarkit.util.vcf.JexlGenotypePredicate) Pedigree(com.github.lindenb.jvarkit.pedigree.Pedigree) Family(com.github.lindenb.jvarkit.pedigree.Family) Logger(com.github.lindenb.jvarkit.util.log.Logger) Set(java.util.Set) JVarkitVersion(com.github.lindenb.jvarkit.util.JVarkitVersion) List(java.util.List) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VCFInfoHeaderLine(htsjdk.variant.vcf.VCFInfoHeaderLine) VariantContext(htsjdk.variant.variantcontext.VariantContext) OnePassVcfLauncher(com.github.lindenb.jvarkit.jcommander.OnePassVcfLauncher) VCFHeaderLineCount(htsjdk.variant.vcf.VCFHeaderLineCount) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) HashMap(java.util.HashMap) VariantContext(htsjdk.variant.variantcontext.VariantContext) PedigreeParser(com.github.lindenb.jvarkit.pedigree.PedigreeParser) Allele(htsjdk.variant.variantcontext.Allele) Pedigree(com.github.lindenb.jvarkit.pedigree.Pedigree) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Family(com.github.lindenb.jvarkit.pedigree.Family) VCFHeader(htsjdk.variant.vcf.VCFHeader)

Aggregations

Parameter (com.beust.jcommander.Parameter)1 ParametersDelegate (com.beust.jcommander.ParametersDelegate)1 OnePassVcfLauncher (com.github.lindenb.jvarkit.jcommander.OnePassVcfLauncher)1 Family (com.github.lindenb.jvarkit.pedigree.Family)1 Pedigree (com.github.lindenb.jvarkit.pedigree.Pedigree)1 PedigreeParser (com.github.lindenb.jvarkit.pedigree.PedigreeParser)1 JVarkitVersion (com.github.lindenb.jvarkit.util.JVarkitVersion)1 Program (com.github.lindenb.jvarkit.util.jcommander.Program)1 Logger (com.github.lindenb.jvarkit.util.log.Logger)1 JexlGenotypePredicate (com.github.lindenb.jvarkit.util.vcf.JexlGenotypePredicate)1 WritingVariantsDelegate (com.github.lindenb.jvarkit.variant.variantcontext.writer.WritingVariantsDelegate)1 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)1 StringUtil (htsjdk.samtools.util.StringUtil)1 Allele (htsjdk.variant.variantcontext.Allele)1 Genotype (htsjdk.variant.variantcontext.Genotype)1 VariantContext (htsjdk.variant.variantcontext.VariantContext)1 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)1 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)1 VCFConstants (htsjdk.variant.vcf.VCFConstants)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1