annotate Snakemake_files/Snakefile_cactus_heatmap_upset @ 13:152d7c43478b draft default tip

Uploaded
author dereeper
date Thu, 30 May 2024 20:07:55 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 import glob
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2 import os
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 import shutil
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 import yaml
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6 configfile: "config.yaml"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 SAMPLES = []
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 with open("config.yaml", "r") as yaml_file:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 genome_data = yaml.safe_load(yaml_file)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 for genome_name, genome_info in genome_data["input_genomes"].items():
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 name = genome_info["name"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 SAMPLES.append(name)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 rule all:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 "outputs/seqfile",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 "outputs/cactus_outdir/output_cactus.sv.gfa.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 "outputs/pav_matrix.tsv",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 "outputs/heatmap.svg.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 "outputs/rarefaction_curves.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 rule get_data:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 "config.yaml"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 "outputs/seqfile",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 expand("outputs/genomes/{sample}.gff", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 run:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 with open(input[0], "r") as yaml_file, open(output[0], "w") as output_file:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 genome_data = yaml.safe_load(yaml_file)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 for genome_name, genome_info in genome_data["input_genomes"].items():
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 fasta_file = genome_info["fasta"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 name = genome_info["name"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 gff_file = genome_info["gff3"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 shutil.copy(gff_file, "outputs/genomes/"+str(name)+".gff")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 shutil.copy(fasta_file, "outputs/genomes/"+str(name)+".fasta")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 output_file.write(f"{genome_name}\toutputs/genomes/"+str(name)+".fasta\n")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 rule gffread:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 fasta = "outputs/genomes/{sample}.fasta",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 gff = "outputs/genomes/{sample}.gff"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 "outputs/genomes/{sample}.nuc"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 gffread -x {output} -g {input.fasta} {input.gff}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 rule cactus:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 expand("outputs/genomes/{sample}.gff", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 params:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 reference=SAMPLES[0]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 gfasv="outputs/cactus_outdir/output_cactus.sv.gfa.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 gfafull="outputs/cactus_outdir/full.gfa"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 mkdir outputs/cactus_work
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 cactus-pangenome outputs/jobstore outputs/seqfile --outDir outputs/cactus_outdir --outName output_cactus --reference {params.reference} --workDir outputs/cactus_work --vcf --mapCores 12 --gfa clip full --viz
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 zcat outputs/cactus_outdir/output_cactus.full.gfa.gz >{output.gfafull}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 rule gfatools:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 "outputs/cactus_outdir/output_cactus.sv.gfa.gz"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 "outputs/cactus_outdir/output_cactus.sv.gfa.pangenome.fasta"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 gfatools gfa2fa -s {input} > {output}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 rule minigraph:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 cds_fasta="outputs/genomes/{sample}.nuc",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 gfa="outputs/cactus_outdir/output_cactus.sv.gfa.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 gaf="outputs/genomes/{sample}.nuc.pangenome.gaf",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 minigraph -x lr {input.gfa} {input.cds_fasta} > {output.gaf}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 rule odgi:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 "outputs/cactus_outdir/full.gfa"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 og="outputs/cactus_outdir/full.gfa.og",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 png="outputs/cactus_outdir/full.gfa.png",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 odgi build -g {input} -o {output.og}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102 odgi viz -i {output.og} -o {output.png}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 rule gaf2bed:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 "outputs/genomes/{sample}.nuc.pangenome.gaf"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
109 "outputs/genomes/{sample}.nuc.pangenome.gaf.bed",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
110 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
111 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
112 awk '{{print $6"\\t"$8"\\t"$9"\\t"$1}}' {input} >{output}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
113 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
114
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
115 rule bedtools_intersect:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
116 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
117 strains="outputs/seqfile",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
118 bedfiles=expand("outputs/genomes/{sample}.nuc.pangenome.gaf.bed", sample=SAMPLES)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
119 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
120 "outputs/pav_matrix.tsv",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
121 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
122 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
123 perl $PANEX_PATH/Perl/GeneratePAVfromBed.pl {input.strains} outputs/genomes {output}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
124 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
125
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
126 rule heatmap_upset:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
127 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
128 pav="outputs/pav_matrix.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
129 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
130 heatmap="outputs/heatmap.svg.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
131 html="outputs/heatmap.svg.heatmap_plotly.html",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
132 upsetr="outputs/upsetr.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
133 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
134 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
135 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
136 perl $PANEX_PATH/Perl/GenerateHeatmapFromPAV.pl {input.pav} outputs/heatmap.svg
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
137 mv outputs/heatmap.svg.upsetr.svg {output.upsetr}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
138 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
139
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
140 rule micropan:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
141 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
142 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
143 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
144 txt="outputs/rarefaction_curves.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
145 pdf="outputs/rarefaction_curves.pdf",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
146 svg="outputs/rarefaction_curves.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
147 heaps="outputs/heaps.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
148 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
149 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
150 Rscript $PANEX_PATH/R/micropan_rarefaction.R -f {input.binpav} -p {output.pdf} -a {output.heaps} -o {output.txt}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
151 pdf2svg {output.pdf} {output.svg}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
152 """