Mercurial > repos > dereeper > pangenome_explorer
view Snakemake_files/Snakefile_wget_orthofinder_heatmap_upset_COG @ 12:38c66e401040 draft
Uploaded
author | dereeper |
---|---|
date | Thu, 30 May 2024 19:59:16 +0000 |
parents | e42d30da7a74 |
children |
line wrap: on
line source
import glob import os import shutil import yaml configfile: "config.yaml" SAMPLES = [] with open("config.yaml", "r") as yaml_file: genome_data = yaml.safe_load(yaml_file) if "ids" in genome_data.keys(): for id in genome_data["ids"]: SAMPLES.append(id) if "input_genbanks" in genome_data.keys(): for gb_path in genome_data["input_genbanks"]: cmd = "grep 'ACCESSION' "+gb_path returned_value = subprocess.getoutput(cmd) words = returned_value.split() name = words[1] #words = returned_value.split() #SAMPLES.append(words[1]) words = gb_path.split("/") genbank_file_name = words[-1] x = genbank_file_name.replace(".", "_") cmd = "sed -i 's/ACCESSION "+name+"/ACCESSION "+x+"/g' "+gb_path subprocess.getoutput(cmd) cmd_locus = "grep 'LOCUS' "+gb_path returned_value = subprocess.getoutput(cmd_locus) words_locus = returned_value.split() name_locus = words_locus[1] cmd = "sed -i 's/LOCUS "+name_locus+"/LOCUS "+x+"/' "+gb_path subprocess.getoutput(cmd) cmd = "grep 'ACCESSION' "+gb_path returned_value = subprocess.getoutput(cmd) words = returned_value.split() SAMPLES.append(words[1]) rule final: input: "outputs/pav_matrix.tsv", "outputs/heatmap.svg", "outputs/rarefaction_curves.txt" rule ncbi_datasets: input: "config.yaml" output: expand("outputs/genomes/{sample}.fasta", sample=SAMPLES), expand("outputs/genomes/{sample}.gb", sample=SAMPLES), expand("outputs/genomes/{sample}.prt", sample=SAMPLES), expand("outputs/genomes/{sample}.nuc", sample=SAMPLES), expand("outputs/genomes/{sample}.pep", sample=SAMPLES), genomes="outputs/genomes/genomes.txt", strains="outputs/genomes/strains.txt" shell: """ perl $PANEX_PATH/Perl/get_data.pl {input} outputs/genomes """ rule genbank2gff3: input: "outputs/genomes/{sample}.gb" output: gff1="outputs/genomes/{sample}.gb.gff", gff2="outputs/genomes/{sample}.gb.rmdup.gff", shell: """ perl $PANEX_PATH/Perl/bp_genbank2gff3.pl -o outputs/genomes {input} perl $PANEX_PATH/Perl/remove_duplicates_in_gff.pl {output.gff1} {output.gff2} mv outputs/genomes/*.faa outputs/proteomes """ rule orthofinder: envmodules: "bioinfo/orthofinder/2.5.4" input: expand("outputs/genomes/{sample}.pep", sample=SAMPLES) params: identity=80 output: pav="outputs/Orthogroups.tsv" shell: """ mkdir -p outputs/proteomes cp -rf outputs/genomes/*.pep outputs/proteomes orthofinder -f outputs/proteomes mv outputs/proteomes/OrthoFinder/R*/Orthogroups/Orthogroups.tsv outputs/Orthogroups.tsv """ rule convert_matrix: input: pav="outputs/Orthogroups.tsv" output: "outputs/pav_matrix.tsv" shell: """ perl $PANEX_PATH/Perl/ConvertOrthofinderMatrix.pl outputs/genomes {input} {output} outputs/genomes/strains.txt """ rule cog: input: pav="outputs/pav_matrix.tsv" output: cog="outputs/cog_output.txt", cogstat="outputs/cog_stats.txt", cogstat2="outputs/cog_stats2.txt", cogofclusters="outputs/cog_of_clusters.txt" shell: """ perl $PANEX_PATH/Perl/GetCogOfCluster.pl {input} outputs/genomes {output.cog} {output.cogstat} {output.cogstat2} {output.cogofclusters} outputs/genomes/strains.txt """ rule heatmap_upset: input: pav="outputs/pav_matrix.tsv", cogofclusters="outputs/cog_of_clusters.txt" output: heatmap="outputs/heatmap.svg", upsetr="outputs/upsetr.svg", binpav="outputs/heatmap.svg.pangenes_01matrix.txt" shell: """ perl $PANEX_PATH/Perl/GenerateHeatmapFromPAV.pl {input.pav} {output.heatmap} mv {output.heatmap}.upsetr.svg {output.upsetr} """ rule micropan: input: binpav="outputs/heatmap.svg.pangenes_01matrix.txt" output: txt="outputs/rarefaction_curves.txt", pdf="outputs/rarefaction_curves.pdf", svg="outputs/rarefaction_curves.svg", heaps="outputs/heaps.tsv" shell: """ Rscript $PANEX_PATH/R/micropan_rarefaction.R -f {input.binpav} -p {output.pdf} -a {output.heaps} -o {output.txt} pdf2svg {output.pdf} {output.svg} """