annotate Snakemake_files/Snakefile_orthofinder_heatmap_upset @ 12:38c66e401040 draft

Uploaded
author dereeper
date Thu, 30 May 2024 19:59:16 +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 SAMPLES = []
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 with open("config.yaml", "r") as yaml_file:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 genome_data = yaml.safe_load(yaml_file)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 for genome_name, genome_info in genome_data["input_genomes"].items():
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 name = genome_info["name"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 SAMPLES.append(name)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 rule final:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 expand("outputs/genomes/{sample}.gff", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 expand("outputs/genomes/{sample}.pep", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 "outputs/pav_matrix.tsv",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 "outputs/heatmap.svg.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 "outputs/rarefaction_curves.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 rule get_data:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 "config.yaml"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 "outputs/genomes/strains.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 expand("outputs/genomes/{sample}.gff", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 run:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 with open(input[0], "r") as yaml_file, open(output[0], "w") as output_file:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 genome_data = yaml.safe_load(yaml_file)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 for genome_name, genome_info in genome_data["input_genomes"].items():
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 fasta_file = genome_info["fasta"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 name = genome_info["name"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 gff_file = genome_info["gff3"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 shutil.copy(gff_file, "outputs/genomes/"+str(name)+".gff")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 shutil.copy(fasta_file, "outputs/genomes/"+str(name)+".fasta")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 output_file.write(f"{name}\t{name}\n")
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}.pep"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 gffread -y {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 orthofinder:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 expand("outputs/genomes/{sample}.pep", sample=SAMPLES)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 params:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 identity=80
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 pav="outputs/Orthogroups.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 mkdir -p outputs/proteomes
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 sed -i '/^>/! s/\./N/g' outputs/genomes/*.pep
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 cp -rf outputs/genomes/*.pep outputs/proteomes
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 orthofinder -f outputs/proteomes
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 mv outputs/proteomes/OrthoFinder/R*/Orthogroups/Orthogroups.tsv outputs/Orthogroups.tsv
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 rule convert_matrix:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 pav="outputs/Orthogroups.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 "outputs/pav_matrix.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 perl $PANEX_PATH/Perl/ConvertOrthofinderMatrix.pl outputs/genomes {input} {output} outputs/genomes/strains.txt
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 rule heatmap_upset:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 pav="outputs/pav_matrix.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 heatmap="outputs/heatmap.svg.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 html="outputs/heatmap.svg.heatmap_plotly.html",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 upsetr="outputs/upsetr.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 perl $PANEX_PATH/Perl/GenerateHeatmapFromPAV.pl {input.pav} outputs/heatmap.svg
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92 mv outputs/heatmap.svg.upsetr.svg {output.upsetr}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 rule micropan:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 txt="outputs/rarefaction_curves.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100 pdf="outputs/rarefaction_curves.pdf",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 svg="outputs/rarefaction_curves.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102 heaps="outputs/heaps.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 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
106 pdf2svg {output.pdf} {output.svg}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108