Skip to content
Snippets Groups Projects
Commit 66132b99 authored by christine.tranchant_ird.fr's avatar christine.tranchant_ird.fr
Browse files

Code Review + code and logs harmonization

parent 5fbe2e62
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 83 deletions
......@@ -15,13 +15,13 @@ rule abyss:
f"""--------------------
-Running {{rule}}
|-- Input:
| - bam file : {{input.bam_file}}
| - bam file : {input.bam_file}
|-- Output:
| - Abyss dir: {f"{frangipane_obj.path_contigs}"}
| - Abyss dir: {frangipane_obj.path_contigs}
|-- Others infos :
| - Threads : {{threads}}
| - LOG error: {{log.error}}
| - other_options : {{params.other_options}}
| - Threads : {threads}
| - LOG output : {log.output}
| - other_options : {params.other_options}
--------------------
"""
singularity:
......
......@@ -5,9 +5,7 @@ rule abyss_merge:
merged_fasta = f"{frangipane_obj.path_merged_contigs}/all-contigs.fa"
log:
output = f"{frangipane_obj.path_logs}/post-abyss/abyss-merged.log.o",
error = f"{frangipane_obj.path_logs}/post-abyss/abyss-merged.log.e",
params:
dir_merged = f"{frangipane_obj.path_merged_contigs}"
error = f"{frangipane_obj.path_logs}/post-abyss/abyss-merged.log.e"
message:
f"""--------------------
-Running {{rule}}
......@@ -15,6 +13,8 @@ rule abyss_merge:
| - dir : f"{frangipane_obj.path_merged_contigs}"
|-- Output:
| - fasta merged file : {{output.merged_fasta}}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
......
......@@ -16,7 +16,6 @@ rule bwa_index:
|-- Output:
| - index_file: {{output}}
|-- Others infos :
| -LOG error: {{log.error}}
| -LOG output: {{log.output}}
| -Other options: {{params.other_options}}
--------------------
......
......@@ -26,7 +26,6 @@ rule bwa_mem:
| - bam file: {{output}}
|-- Others infos :
| - Threads : {{threads}}
| - LOG error: {{log.error}}
| - LOG output: {{log.output}}
| - Other options bwa: {{params.other_options_bwaMem}}
| - Other options samtools sort: {{params.other_options_samtoolsSort}}
......
......@@ -17,8 +17,6 @@ rule cdhit:
|-- Output:
| - Fasta file: {{output.fasta_file}}
|-- Others infos :
| -Threads : 6
| -LOG error: {{log.error}}
| -LOG output: {{log.output}}
| -Other options: {{params.other_options}}
--------------------
......
......@@ -16,7 +16,6 @@ rule create_panref:
|-- Output:
| - Fasta file: {{output.fasta_file}}
|-- Others infos :
| -LOG error: {{log.error}}
| -LOG output: {{log.output}}
--------------------
"""
......
......@@ -4,8 +4,8 @@ rule fasta_stats:
output:
stat_file = f"{frangipane_obj.path_stat_sum}/03_all_fasta-filtered-stats.csv"
log:
output = f"{frangipane_obj.path_logs}/report/fasta_stats.log.o",
error = f"{frangipane_obj.path_logs}/report/fasta_stats.log.e"
output = f"{frangipane_obj.path_logs}/stats/fasta_stats.o",
error = f"{frangipane_obj.path_logs}/stats/fasta_stats.e"
params:
dir = f"{frangipane_obj.path_filtered_contigs}",
other_option = frangipane_obj.get_config_value("PARAMS","assembly_stats")
......@@ -13,9 +13,9 @@ rule fasta_stats:
f"""--------------------
-Running {{rule}}
|-- Input:
| - Fasta dir : f"{{params.dir}}"
| - Fasta dir : {{params.dir}}
|-- Output:
| - stat file: f"{{output.stat_file}}"
| - stat file: {{output.stat_file}}
|-- Others infos :
| -LOG error: {{log.error}}
--------------------
......@@ -27,6 +27,6 @@ rule fasta_stats:
shell:
"""
cmd="assembly-stats {params.other_option} {params.dir}/*.fa";
(echo $cmd) > {log.error};
(echo $cmd) > {log.output};
($cmd) 1>> {output.stat_file} 2>> {log.error};
"""
\ No newline at end of file
......@@ -4,17 +4,17 @@ rule fasta_stats2:
output:
stat_file = f"{frangipane_obj.path_stat_sum}/04_all_contigs-merged-stats.csv"
log:
output = f"{ frangipane_obj.path_logs}/fasta_stats/fasta_stats_contigs_merged.log.o",
error = f"{ frangipane_obj.path_logs}/fasta_stats/fasta_stats_contigs_merged.log.e"
output = f"{ frangipane_obj.path_logs}/stats/fasta_stats_contigs_merged.o",
error = f"{ frangipane_obj.path_logs}/stats/fasta_stats_contigs_merged.e"
params:
other_option = frangipane_obj.get_config_value("PARAMS","assembly_stats2") #config['PARAMS']['assembly_stats2'] if "assembly_stats2" in config['PARAMS'] else ""
other_option = frangipane_obj.get_config_value("PARAMS","assembly_stats2")
message:
f"""--------------------
-Running {{rule}}
|-- Input:
| - Fasta dir : f"{{input}}"
| - Fasta dir : {{input}}
|-- Output:
| - stat file: f"{{output}}"
| - stat file: {{output}}
|-- Others infos :
| -LOG error: {{log.error}}
--------------------
......@@ -26,7 +26,7 @@ rule fasta_stats2:
shell:
"""
cmd="assembly-stats {params.other_option} {input.fasta_file}";
(echo $cmd) > {log.error};
(echo $cmd) > {log.output};
($cmd) 1>> {output.stat_file} 2>> {log.error};
"""
\ No newline at end of file
......@@ -4,17 +4,17 @@ rule fastq_stats:
output:
stat_file = f"{frangipane_obj.path_stat_fastq}/{{fastq_file}}.stats"
log:
output = f"{frangipane_obj.path_logs}/fastq_stats/{{fastq_file}}.o",
error = f"{frangipane_obj.path_logs}/fastq_stats/{{fastq_file}}.e"
output = f"{frangipane_obj.path_logs}/stats/{{fastq_file}}.o",
error = f"{frangipane_obj.path_logs}/stats/{{fastq_file}}.e"
message:
f"""--------------------
-Running {{rule}}
-Running {rule}
|-- Input:
| - Fastq dir : f"{frangipane_obj.path_fastq}"
| - Fastq dir : {frangipane_obj.path_fastq}
|-- Output:
| - Fastq stat dir: f"{frangipane_obj.path_stat_fastq}"
|-- Others infos :
| -LOGs: f"{frangipane_obj.path_logs}/fastq_stats/"
| - Fastq stat dir: {frangipane_obj.path_stat_fastq}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
singularity:
......@@ -25,5 +25,5 @@ rule fastq_stats:
"""
cmd='fastq-stats -D {input.fastq_file} > {output.stat_file}' ;
echo $cmd > {log.output};
(fastq-stats -D {input.fastq_file}) 1> {output.stat_file} 2>> {log.output}"""
(fastq-stats -D {input.fastq_file}) 1> {output.stat_file} 2>> {log.error}"""
......@@ -4,35 +4,37 @@ rule filter_length:
output:
fasta_file = f"{frangipane_obj.path_filtered_contigs}/{{sample_name}}-{{ref_name}}-contigs.fa"
log:
output = f"{frangipane_obj.path_logs}/abyss-filtered/{{sample_name}}-{{ref_name}}-filtered.log.o",
error = f"{frangipane_obj.path_logs}/abyss-filtered/{{sample_name}}-{{ref_name}}-filtered.log.e"
output = f"{frangipane_obj.path_logs}/post-abyss/filtered-{{sample_name}}-{{ref_name}}.o",
error = f"{frangipane_obj.path_logs}/post-abyss/filtered-{{sample_name}}-{{ref_name}}.e"
params:
length = frangipane_obj.get_config_value("CONTIGS","minLength"),
dirout = frangipane_obj.path_filtered_contigs
length = frangipane_obj.get_config_value("CONTIGS","minLength")
message:
f"""--------------------
-Running {{rule}}
-Running {rule}
|-- Input:
| - fasta files: {frangipane_obj.path_contigs}
|-- Output:
| - fasta dir: {frangipane_obj.path_filtered_contigs}
|-- Others infos :
| -LOG error:
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
from Bio import SeqIO
with open(output.fasta_file, 'w') as o:
for seq in SeqIO.parse(input.fasta_file, "fasta"):
if len(seq) >= params.length:
o.write('>' + str(seq.description) + '\n')
txt = str(seq.seq)
lines = txt.split('\n')
for line in lines:
if len(line) > 0:
if line[0] == '>':
o.write(line + '\n')
else:
o.write(gs.format_60(line) + '\n')
\ No newline at end of file
try:
with open(output.fasta_file, 'w') as o:
for seq in SeqIO.parse(input.fasta_file, "fasta"):
if len(seq) >= params.length:
o.write('>' + str(seq.description) + '\n')
txt = str(seq.seq)
lines = txt.split('\n')
for line in lines:
if len(line) > 0:
if line[0] == '>':
o.write(line + '\n')
else:
o.write(gs.format_60(line) + '\n')
except Exception as e:
raise ValueError(f"Error during filtering on contig legth: {e}")
\ No newline at end of file
......@@ -10,9 +10,11 @@ rule merge_fastq_stats:
f"""--------------------
-Running {{rule}}
|-- Input:
| - Fastq stats : f"{frangipane_obj.path_stat_fastq}"
| - Fastq stats : {frangipane_obj.path_stat_fastq}
|-- Output:
| - stat file: {{output.stat_file}}
| - stat file: {output.stat_file}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
......@@ -21,6 +23,7 @@ rule merge_fastq_stats:
# open the file merging the fastq-stat results on the whole set of samples
f = open(output.stat_file, "a+")
header = "sample\tfile\treads\tlen\tlen_mean\tlen_stdev\tlen_min\tphred\twindow-size\tcycle-max\tqual_min\tqual_max\tqual_mean\tqual_stdev\t%A\t%C\t%G\t%T\t%N\ttotal_bases"
f.write(header + "\n")
......
......@@ -13,6 +13,8 @@ rule merge_flagstat:
| - Bam stat directory : f"{frangipane_obj.path_bam}"
|-- Output:
| - Stat file: {{output.stat_file}}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
......
## RULE
rule plot_fasta:
input:
ref=rules.bwa_index.input.ref,
ref=rules.bwa_index.input.ref
output:
png = f"{path_dico['plot']}/00_{ref_basename}.png",
csv = f"{path_dico['sum']}/00_{ref_basename}.txt",
log:
output = f"{frangipane_obj.path_logs}/plot/plot_fasta.o"
error = f"{frangipane_obj.path_logs}/plot/plot_fasta.e"
output = f"{frangipane_obj.path_logs}/report/plot_fasta.o"
error = f"{frangipane_obj.path_logs}/report/plot_fasta.e"
message:
f"""--------------------
-Running {{rule}}
|-- Input:
|----- Fasta : {{input.ref}}
|----- Plot : {{output.png}}
|----- Csv : {{output.csv}}
| - Fasta : {input.ref}
|-- Output:
| - Plot : {output.png}
| - Csv : {output.csv}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
gs.dashboard_genome(input.ref, output.png, output.csv)
......@@ -12,14 +12,17 @@ rule plot_fastq:
params:
plot_dir = frangipane_obj.path_stat_plot
log:
output = f"{frangipane_obj.path_logs}/plot/plot_fastq.o",
error = f"{frangipane_obj.path_logs}/plot/plot_fastq.e",
output = f"{frangipane_obj.path_logs}/report/plot_fastq.o",
error = f"{frangipane_obj.path_logs}/report/plot_fastq.e",
message:
f"""--------------------
-Running {{rule}}
|-- Input:
|----- Stat file : {{input.csv}}
|----- Plots : {{params.plot_dir}}
| - Stat file : {input.csv}
|-- Output:
| - Plot : {params.plot_dir}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
......
......@@ -5,13 +5,17 @@ rule plot_mapping:
output:
png_mapping=f"{frangipane_obj.path_stat_plot}/mapping_read_ratio-{frangipane_obj.reference_basename}.png",
log:
output = f"{frangipane_obj.path_logs}/plot/plot_mapping.o",
error = f"{frangipane_obj.path_logs}/plot/plot_mapping.e"
output = f"{frangipane_obj.path_logs}/report/plot_mapping.o",
error = f"{frangipane_obj.path_logs}/report/plot_mapping.e"
message:
f"""--------------------
-Running {{rule}}
|-- Input:
|----- Stat : {{input.csv}}
| - Stat file : {input.csv}
|-- Output:
| - Plot : {output.png_mapping}
|-- Other infos:
| - LOG output : {log.output}
--------------------
"""
run:
......
......@@ -5,8 +5,8 @@ rule samtools_flagstat:
output:
stat_file = f"{frangipane_obj.path_bam}/{{ref_name}}/{{sample_name}}-{{ref_name}}.flagstat"
log:
output = f"{frangipane_obj.path_logs}/samtools_flagstat/{{sample_name}}-{{ref_name}}.o",
error = f"{frangipane_obj.path_logs}/samtools_flagstat/{{sample_name}}-{{ref_name}}.e"
output = f"{frangipane_obj.path_logs}/stats/flagstat-{{sample_name}}-{{ref_name}}.o",
error = f"{frangipane_obj.path_logs}/stats/flagstat-{{sample_name}}-{{ref_name}}.e"
threads: get_threads('samtools_flagstat', 1)
message:
f"""--------------------
......
......@@ -9,20 +9,20 @@ rule samtools_view:
error = f"{frangipane_obj.path_logs}/samtools_view/{{sample_name}}-{{ref_name}}.e",
output = f"{frangipane_obj.path_logs}/samtools_view/{{sample_name}}-{{ref_name}}.o"
params:
other_options = frangipane_obj.get_config_value("PARAMS","samtools_view"), #config['PARAMS']['samtools_view'] if "samtools_view" in config['PARAMS'] else "",
other_options = frangipane_obj.get_config_value("PARAMS","samtools_view"),
threads: get_threads('samtools_view', 1)
message:
f"""--------------------
-Running {{rule}}
|-- Input:
| - bam file : {{input.bam_file}}
| - bam file : {input.bam_file}
|-- Output:
| - bam file: {{output.bam_file}}
| - bam file: {output.bam_file}
|-- Others infos :
| -Threads : {{threads}}
| -LOG output: {{log.output}}
| -LOG error: {{log.error}}
| -Other options: {{params.other_options}}
| -Threads : {threads}
| -LOG output: {log.output}
| -LOG error: {log.error}
| -Other options: {params.other_options}
--------------------
"""
singularity:
......@@ -35,6 +35,6 @@ rule samtools_view:
(echo $cmd) > {log.output};
($cmd) 1>> {log.output} 2>> {log.error};
cmd="samtools index -@ {threads} {output.bam_file}";
(echo $cmd) >> {log.output};
($cmd) 1>> {log.output} 2>> {log.error}"""
\ No newline at end of file
cmd2="samtools index -@ {threads} {output.bam_file}";
(echo $cmd2) >> {log.output};
($cmd2) 1>> {log.output} 2>> {log.error}"""
\ No newline at end of file
......@@ -8,16 +8,16 @@ rule vecscreen:
error = f"{frangipane_obj.path_logs}/vecscreen/{{sample_name}}-{{ref_name}}.log.e",
output = f"{frangipane_obj.path_logs}/vecscreen/{{sample_name}}-{{ref_name}}.log.o"
params:
length = frangipane_obj.get_config_value('CONTIGS','minLength') #config['CONTIGS']['minLength']
length = frangipane_obj.get_config_value('CONTIGS','minLength')
message:
f"""--------------------
-Running {{rule}}
|-- Input:
| - fasta files: {{input.fasta_file}}
| - fasta files: {input.fasta_file}
|-- Output:
| - fasta dir: {{output.fasta_file}}
| - fasta dir: {output.fasta_file}
|-- Others infos :
| - Filtering on sequences longer than : {{params.length}}
| - Filtering on sequences longer than : {params.length}
--------------------
"""
run:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment