annotate Snakemake_files/Snakefile_pggb_heatmap_upset @ 3:e42d30da7a74 draft

Uploaded
author dereeper
date Thu, 30 May 2024 11:52:25 +0000
parents
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/pggb_out/all_genomes.fa.smooth.final.gfa",
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 output_file.write(f"{genome_name}\t{genome_name}\t{fasta_file}\n")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 cmd = "sed 's/>/>"+str(name)+"#/g' "+fasta_file+" >outputs/genomes/"+str(name)+".fasta"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 os.system(cmd)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 gff_file = genome_info["gff3"]
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 shutil.copy(gff_file, "outputs/genomes/"+str(name)+".gff")
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 rule pggb:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 expand("outputs/genomes/{sample}.fasta", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 expand("outputs/genomes/{sample}.gff", sample=SAMPLES),
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 gfa="outputs/pggb_out/all_genomes.fa.smooth.final.gfa",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 png1="outputs/pggb_out/all_genomes.fa.lay.draw.png",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 png2="outputs/pggb_out/all_genomes.fa.og.viz_multiqc.png",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 cat outputs/genomes/*fasta >outputs/genomes/all_genomes.fa
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 samtools faidx outputs/genomes/all_genomes.fa
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 reference=$(head -1 outputs/genomes/strains.txt | awk '{{print $2}}')
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 pggb -i outputs/genomes/all_genomes.fa -o outputs/pggb_out -V $reference -m
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 mv outputs/pggb_out/all_genomes.*smooth.final.gfa {output.gfa}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 mv outputs/pggb_out/all_genomes.*lay.draw.png {output.png1}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 mv outputs/pggb_out/all_genomes.fa.*.og.viz_multiqc.png {output.png2}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 rule create_gene_paths:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 gff="outputs/genomes/{sample}.gff",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 gfa="outputs/pggb_out/all_genomes.fa.smooth.final.gfa",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 basename="outputs/genomes/{sample}.gene_segments",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 gene_length="outputs/genomes/{sample}.gene_segments.gene_length.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 bed="outputs/genomes/{sample}.gene_segments.bed",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 perl $PANEX_PATH/Perl/CreateGenePathsFromGFA.pl {input.gfa} {input.gff} {output.basename}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 rule bedtools_intersect:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 samples="outputs/seqfile",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 bedfiles=expand("outputs/genomes/{sample}.gene_segments.bed", sample=SAMPLES)
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 params:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 identity=30
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 "outputs/pav_matrix.tsv",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86 perl $PANEX_PATH/Perl/GeneratePAVfromBed.pl {input.samples} outputs/genomes {output} {params.identity}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 rule heatmap_upset:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91 pav="outputs/pav_matrix.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 heatmap="outputs/heatmap.svg.gz",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94 html="outputs/heatmap.svg.heatmap_plotly.html",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 upsetr="outputs/upsetr.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99 perl $PANEX_PATH/Perl/GenerateHeatmapFromPAV.pl {input.pav} outputs/heatmap.svg
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100 mv outputs/heatmap.svg.upsetr.svg {output.upsetr}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 rule micropan:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104 input:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 binpav="outputs/heatmap.svg.pangenes_01matrix.txt"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106 output:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 txt="outputs/rarefaction_curves.txt",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108 pdf="outputs/rarefaction_curves.pdf",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
109 svg="outputs/rarefaction_curves.svg",
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
110 heaps="outputs/heaps.tsv"
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
111 shell:
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
112 """
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
113 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
114 pdf2svg {output.pdf} {output.svg}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
115 """