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