Skip to content
Snippets Groups Projects
relatedness_ancestry.smk 3.17 KiB
Newer Older
TARGETS_SOMALIER = [
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
    get_targets('somalier') if {'all', 'somalier'}.intersection(MODULES_TO_RUN) else [],
rule somalier_extract:
        bam = PROJECTS_PATH / PROJECT_NAME / "analysis" / "{sample}" / "bam" / "{sample}.bam",
        bam_index = PROJECTS_PATH / PROJECT_NAME / "analysis" / "{sample}" / "bam" / "{sample}.bam.bai",
        somalier_tool = config['somalier']['tool'],
        sites = config['somalier']['sites'],
        ref_genome = config['ref'],
        OUT_DIR / "somalier/extract/{sample}.somalier",
    message:
        "Running somalier extract. Sample: {wildcards.sample}"
        outdir = lambda wildcards, output: Path(output[0]).parent,
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        r"""
        {input.somalier_tool} extract \
            --sites {input.sites} \
            --fasta {input.ref_genome} \
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
            --out-dir {params.outdir} \
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        """
rule somalier_relate:
        extracted = expand(str(OUT_DIR / "somalier" / "extract" / "{sample}.somalier"),
                sample=SAMPLES),
        ped = PEDIGREE_FPATH,
        somalier_tool = config['somalier']['tool'],
    output:
        out = expand(str(OUT_DIR / "somalier" / "relatedness" / "somalier.{ext}"),
                ext=['html', 'groups.tsv', 'pairs.tsv', 'samples.tsv']),
        log = OUT_DIR / "somalier" / "relatedness" / "somalier.log",
    message:
        outdir = lambda wildcards, output: Path(output['out'][0]).parent,
        indir = lambda wildcards, input: Path(input[0]).parent,
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        r"""
        echo "Heads up: Somalier is run on all samples in the input directory; Not just the files mentioned in the rule's input."
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        {input.somalier_tool} relate \
            --ped {input.ped} \
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
            --infer \
            --output-prefix {params.outdir}/somalier \
            {params.indir}/*.somalier \
            > {output.log} 2>&1
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        """
rule somalier_ancestry:
        extracted = expand(str(OUT_DIR / "somalier" / "extract" / "{sample}.somalier"),
                sample=SAMPLES),
        somalier_tool = config['somalier']['tool'],
        labels_1kg = config['somalier']['labels_1kg'],
        somalier_1kg = directory(config['somalier']['somalier_1kg']),
        out = expand(str(OUT_DIR / "somalier" / "ancestry" / "somalier.somalier-ancestry.{ext}"),
                ext=['html', 'tsv']),
        log = OUT_DIR / "somalier" / "relatedness" / "somalier.log",
    message:
        outdir = lambda wildcards, output: Path(output['out'][0]).parent,
        indir = lambda wildcards, input: Path(input[0]).parent,
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        r"""
        echo "Heads up: Somalier is run on all samples in the input directory; Not just the files mentioned in the rule's input."
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        {input.somalier_tool} ancestry \
            --output-prefix {params.outdir}/somalier \
            --labels {input.labels_1kg} \
            {input.somalier_1kg}*.somalier ++ \
            {params.indir}/*.somalier \
            > {output.log} 2>&1
Manavalan Gajapathy's avatar
Manavalan Gajapathy committed
        """