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 if "ids" in genome_data.keys():
|
|
13 for id in genome_data["ids"]:
|
|
14 SAMPLES.append(id)
|
|
15 if "input_genbanks" in genome_data.keys():
|
|
16 for gb_path in genome_data["input_genbanks"]:
|
|
17 cmd = "grep 'ACCESSION' "+gb_path
|
|
18 returned_value = subprocess.getoutput(cmd)
|
|
19 words = returned_value.split()
|
|
20 name = words[1]
|
|
21 #words = returned_value.split()
|
|
22 #SAMPLES.append(words[1])
|
|
23 words = gb_path.split("/")
|
|
24 genbank_file_name = words[-1]
|
|
25 x = genbank_file_name.replace(".", "_")
|
|
26 cmd = "sed -i 's/ACCESSION "+name+"/ACCESSION "+x+"/g' "+gb_path
|
|
27 subprocess.getoutput(cmd)
|
|
28
|
|
29 cmd_locus = "grep 'LOCUS' "+gb_path
|
|
30 returned_value = subprocess.getoutput(cmd_locus)
|
|
31 words_locus = returned_value.split()
|
|
32 name_locus = words_locus[1]
|
|
33 cmd = "sed -i 's/LOCUS "+name_locus+"/LOCUS "+x+"/' "+gb_path
|
|
34 subprocess.getoutput(cmd)
|
|
35
|
|
36 cmd = "grep 'ACCESSION' "+gb_path
|
|
37 returned_value = subprocess.getoutput(cmd)
|
|
38 words = returned_value.split()
|
|
39 SAMPLES.append(words[1])
|
|
40
|
|
41
|
|
42 rule final:
|
|
43 input:
|
|
44 "outputs/GCskew.txt",
|
|
45 "outputs/pav_matrix.tsv",
|
|
46 "outputs/heatmap.svg.gz",
|
|
47 "outputs/cog_output.txt",
|
|
48 "outputs/fastani.out",
|
|
49 "outputs/rarefaction_curves.txt"
|
|
50
|
|
51
|
|
52 rule ncbi_datasets:
|
|
53 input:
|
|
54 "config.yaml"
|
|
55 output:
|
|
56 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
|
|
57 expand("outputs/genomes/{sample}.gb", sample=SAMPLES),
|
|
58 expand("outputs/genomes/{sample}.prt", sample=SAMPLES),
|
|
59 genomes="outputs/genomes/genomes.txt"
|
|
60 shell:
|
|
61 """
|
|
62 perl $PANEX_PATH/Perl/get_data.pl {input} outputs/genomes
|
|
63 """
|
|
64
|
|
65
|
|
66 rule gcskew:
|
|
67 input:
|
|
68 "outputs/genomes/{sample}.fasta"
|
|
69 output:
|
|
70 "outputs/genomes/{sample}.fasta.gcskew.txt"
|
|
71 shell:
|
|
72 """
|
|
73 python3 $PANEX_PATH/SkewIT/src/gcskew.py -i {input} -o {input}.gcskew.txt -k 1000 -w 1000
|
|
74 """
|
|
75
|
|
76 rule concat_gcskew:
|
|
77 input:
|
|
78 expand("outputs/genomes/{sample}.fasta.gcskew.txt", sample=SAMPLES)
|
|
79 output:
|
|
80 out2="outputs/GCskew.txt"
|
|
81 shell:
|
|
82 """
|
|
83 cat {input} >>{output.out2}
|
|
84 """
|
|
85
|
|
86 rule genbank2gff3:
|
|
87 input:
|
|
88 "outputs/genomes/{sample}.gb"
|
|
89 output:
|
|
90 gff1="outputs/genomes/{sample}.gb.gff",
|
|
91 gff2="outputs/genomes/{sample}.gb.rmdup.gff"
|
|
92 shell:
|
|
93 """
|
|
94 perl $PANEX_PATH/Perl/bp_genbank2gff3.pl -o outputs/genomes {input}
|
|
95 perl $PANEX_PATH/Perl/remove_duplicates_in_gff.pl {output.gff1} {output.gff2}
|
|
96 """
|
|
97
|
|
98 rule panacota:
|
|
99 input:
|
|
100 expand("outputs/genomes/{sample}.prt", sample=SAMPLES),
|
|
101 expand("outputs/genomes/{sample}.gb.gff", sample=SAMPLES)
|
|
102 output:
|
|
103 pav="outputs/panacota/PanGenome-mydataset.All.prt.lst"
|
|
104 params:
|
|
105 identity=80
|
|
106 shell:
|
|
107 """
|
|
108 cat outputs/genomes/*prt >outputs/genomes/mydataset.All.prt
|
|
109 PanACoTA pangenome -i 0.{params.identity} -l outputs/genomes/mydataset.All.prt -n mydataset -d outputs/genomes -o outputs/panacota
|
|
110 mv outputs/panacota/PanGenome-mydataset.All.prt-clust-*-mode1.lst {output}
|
|
111 """
|
|
112
|
|
113 rule convert_matrix:
|
|
114 input:
|
|
115 pav="outputs/panacota/PanGenome-mydataset.All.prt.lst"
|
|
116 output:
|
|
117 "outputs/pav_matrix.tsv"
|
|
118 shell:
|
|
119 """
|
|
120 perl $PANEX_PATH/Perl/ConvertPanacotaMatrix.pl outputs/genomes {input} {output} outputs/genomes/strains.txt
|
|
121 """
|
|
122
|
|
123
|
|
124 rule cog:
|
|
125 input:
|
|
126 pav="outputs/pav_matrix.tsv"
|
|
127 output:
|
|
128 cog="outputs/cog_output.txt",
|
|
129 cogstat="outputs/cog_stats.txt",
|
|
130 cogstat2="outputs/cog_stats2.txt",
|
|
131 cogofclusters="outputs/cog_of_clusters.txt"
|
|
132 shell:
|
|
133 """
|
|
134 perl $PANEX_PATH/Perl/GetCogOfCluster.pl {input} outputs/genomes {output.cog} {output.cogstat} {output.cogstat2} {output.cogofclusters} outputs/genomes/strains.txt
|
|
135 """
|
|
136
|
|
137 rule heatmap_upset:
|
|
138 input:
|
|
139 pav="outputs/pav_matrix.tsv"
|
|
140 output:
|
|
141 heatmap="outputs/heatmap.svg.gz",
|
|
142 html="outputs/heatmap.svg.heatmap_plotly.html",
|
|
143 upsetr="outputs/upsetr.svg",
|
|
144 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
|
|
145 shell:
|
|
146 """
|
|
147 perl $PANEX_PATH/Perl/GenerateHeatmapFromPAV.pl {input.pav} outputs/heatmap.svg
|
|
148 mv outputs/heatmap.svg.upsetr.svg {output.upsetr}
|
|
149 """
|
|
150
|
|
151 rule micropan:
|
|
152 input:
|
|
153 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
|
|
154 output:
|
|
155 txt="outputs/rarefaction_curves.txt",
|
|
156 pdf="outputs/rarefaction_curves.pdf",
|
|
157 svg="outputs/rarefaction_curves.svg",
|
|
158 heaps="outputs/heaps.tsv"
|
|
159 shell:
|
|
160 """
|
|
161 Rscript $PANEX_PATH/R/micropan_rarefaction.R -f {input.binpav} -p {output.pdf} -a {output.heaps} -o {output.txt}
|
|
162 pdf2svg {output.pdf} {output.svg}
|
|
163 """
|
|
164
|
|
165 rule fastani:
|
|
166 input:
|
|
167 "outputs/genomes/genomes.txt"
|
|
168 output:
|
|
169 out="outputs/fastani.out",
|
|
170 matrix="outputs/fastani.out.matrix",
|
|
171 completematrix="outputs/fastani.out.matrix.complete",
|
|
172 pdf="outputs/fastani.out.pdf",
|
|
173 svg="outputs/fastani.out.svg"
|
|
174 shell:
|
|
175 """
|
|
176 fastANI --rl {input} --ql {input} -o {output.out} -t 4 --matrix
|
|
177 perl $PANEX_PATH/Perl/convertANI.pl {output.matrix} outputs/genomes/genomes2.txt >{output.completematrix}
|
|
178 Rscript $PANEX_PATH/R/heatmap_ani.R -f {output.completematrix} -o {output.pdf}
|
|
179 pdf2svg {output.pdf} {output.svg}
|
|
180 """
|