Mercurial > repos > cstrittmatter > test_eurl_vtec_wgs_pt
diff EURL_VTEC_WGS_PT.py @ 3:0cbed1c0a762 draft default tip
planemo upload commit 15239f1674081ab51ab8dd75a9a40cf1bfaa93e8
author | cstrittmatter |
---|---|
date | Tue, 28 Jan 2020 10:42:31 -0500 |
parents | 965517909457 |
children |
line wrap: on
line diff
--- a/EURL_VTEC_WGS_PT.py Wed Jan 22 09:10:12 2020 -0500 +++ b/EURL_VTEC_WGS_PT.py Tue Jan 28 10:42:31 2020 -0500 @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ ############################################################################ @@ -44,6 +45,7 @@ parser.add_argument('--serotyping', dest='serotyping', help='perform serotyping', action='store_true') parser.add_argument('--virulotyping', dest='virulotyping', help='perform virulotyping', action='store_true') parser.add_argument('--shigatoxintyping', dest='shigatoxintyping', help='perform shigatoxintyping', action='store_true') + parser.add_argument('--amrtyping', dest='amrtyping', help='perform amrtyping', action='store_true') parser.add_argument('-1', '--input1', dest='input1', help='forward or single-end reads file in Sanger FASTQ format') parser.add_argument('--input1_ext', dest='input1_ext', help='extension of forward or single-end reads file in Sanger FASTQ format') parser.add_argument('--input1_name', dest='input1_name', help='name of forward or single-end reads file in Sanger FASTQ format') @@ -58,197 +60,106 @@ parser.add_argument('--html2_id', dest='html2_id', help='html FASTQC file id') parser.add_argument('--html2_path', dest='html2_path', help='html FASTQC file path') parser.add_argument('--text2', dest='text2', help='text FASTQC file') - parser.add_argument('--trimmed1', dest='trimmed1', help='trimmed forward FASTQ file') - parser.add_argument('--trimmed2', dest='trimmed2', help='trimmed reverse FASTQ file') - parser.add_argument('--trimmedunpaired', dest='trimmedunpaired', help='trimmed unpaired FASTQ file') parser.add_argument('--log', dest='logfile', help='log file') parser.add_argument('--virulotyper', dest='virulotyper', help='Virulotyping Mapping reads') parser.add_argument('--virulotyper_id', dest='virulotyper_id', help='Virulotyping Mapping reads id') - parser.add_argument('--blastn_STX', dest='blastn_STX', help='Blastn for Shiga toxin') + parser.add_argument('--stx', dest='stx', help='Shiga toxin') parser.add_argument('--mlstsevenloci', dest='mlstsevenloci', help='Multi Locus Alleles table') - parser.add_argument('--spades_log', dest='spades_log', help='SPAdes log') - parser.add_argument('--blastn_O', dest='blastn_O', help='Blastn for O') - parser.add_argument('--blastn_H', dest='blastn_H', help='Blastn for H') + parser.add_argument('--amr', dest='amr', help='SPAdes log') + parser.add_argument('--amr_id', dest='amr_id', help='AMR file id') + parser.add_argument('--antigen_O', dest='antigen_O', help='Antigen for O') + parser.add_argument('--antigen_H', dest='antigen_H', help='Antigen for H') parser.add_argument('--output', dest='output', help='output report html file') args = parser.parse_args() - os.system("printf 'EURL VTEC WGS PT v2.3\n\nTool versions\n=============\n' > " + args.logfile) + log = open(args.logfile, 'w') + log.write("EURL VTEC WGS PT v3.0\n\nTool versions\n=============\n") if args.input2: # FASTQC os.system("python " + TOOL_DIR + "/scripts/rgFastQC.py -i " + args.input1 + " -d " + args.html1_path + " -o " + args.html1 + " -t " + args.text1 + " -f " + args.input1_ext + " -j " + args.input1_name + " -e " + "fastqc") os.system("rm -r " + args.html1_path) os.system("python " + TOOL_DIR + "/scripts/rgFastQC.py -i " + args.input2 + " -d " + args.html2_path + " -o " + args.html2 + " -t " + args.text2 + " -f " + args.input2_ext + " -j " + args.input2_name + " -e " + "fastqc") os.system("rm -r " + args.html2_path) - os.system("fastqc -v >> " + args.logfile) + log.write(os.popen("fastqc -v").read()) # TRIMMING - os.system("python " + TOOL_DIR + "/scripts/fastq_positional_quality_trimming.py -1 " + args.input1 + " --maxlt 300 --lt 17 --rt 0 --minqt 25 --avgqt 27.0 --minlf -1 --trimmed1 " + args.trimmed1 + " --log trimming_logfile -2 " + args.input2 + " --trimmed2 " + args.trimmed2 + " --trimmedunpaired " + args.trimmedunpaired) - os.system("ln -s " + args.trimmed1 + " input_1.fq") - os.system("ln -s " + args.trimmed2 + " input_2.fq") - os.system("printf '\nfastq_positional_quality_trimming v1.0\n' >> " + args.logfile) - os.system("printf 'parameters: maxlt=300, lt=17, rt=0, minqt=25, avgqt=27.0, minlf=-1\n' >> " + args.logfile) + os.system("python " + TOOL_DIR + "/scripts/fastq_positional_quality_trimming.py -1 " + args.input1 + " --maxlt 300 --lt 17 --rt 0 --minqt 25 --avgqt 27.0 --minlf -1 --trimmed1 input_t1.fq --log trimming_logfile -2 " + args.input2 + " --trimmed2 input_t2.fq --trimmedunpaired trimmedunpaired") + log.write("\nfastq_positional_quality_trimming v1.0\n") + log.write("parameters: maxlt=300, lt=17, rt=0, minqt=25, avgqt=27.0, minlf=-1\n") + if args.shigatoxintyping or args.serotyping: + # ASSEMBLY + os.system("perl " + TOOL_DIR + "/scripts/spades.pl contigs.fa spades_contig_stats spades_scaffolds spades_scaffold_stats spades_log NODE spades.py --disable-gzip-output --isolate -t \${GALAXY_SLOTS:-16} --pe1-ff --pe1-1 fastq:input_t1.fq --pe1-2 fastq:input_t2.fq") + log.write(os.popen("spades.py -v").read()) + log.write("parameters: --isolate, pe1-ff, pe1-1, pe1-2\n\n") if args.virulotyping: # VIRULOTYPER - os.system("perl " + TOOL_DIR + "/scripts/patho_typing_pt.pl 'python " + TOOL_DIR + "/scripts/patho_typing.py -s Escherichia coli -f " + args.input1 + " " + args.input2 + " -o output_dir -j 1 --minGeneCoverage 90 --minGeneIdentity 90 --minGeneDepth 15'") + os.system("perl " + TOOL_DIR + "/scripts/patho_typing.pl 'python " + TOOL_DIR + "/scripts/patho_typing.py -s Escherichia coli -f " + args.input1 + " " + args.input2 + " -o output_dir -j 1 --minGeneCoverage 90 --minGeneIdentity 90 --minGeneDepth 15'") os.system("cat pathotyper_rep_tot_tab > " + args.virulotyper) - os.system("printf '\n\nViruloTyper\n===========\npatho_typing v0.3\n' >> " + args.logfile) - os.system("printf 'parameters: minGeneCoverage=90, minGeneIdentity=90, minGeneDepth=15\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/ViruloTyping_db.txt >> " + args.logfile) - if args.shigatoxintyping: - # SHIGATOXIN FILTERING - os.system(TOOL_DIR + "/scripts/duk -m filtered1STX.fq -k 23 " + TOOL_DIR + "/data/stx.fa input_1.fq") - os.system(TOOL_DIR + "/scripts/duk -m filtered2STX.fq -k 23 " + TOOL_DIR + "/data/stx.fa input_2.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filtered1STX.fq filtered2STX.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filtered1STX.fq.single.fq input_2.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filtered2STX.fq.single.fq input_1.fq") - os.system("cat filtered1STX.fq.paired.fq > filtered1STX_paired.fq") - os.system("cat filtered1STX.fq.single.fq.paired.fq >> filtered1STX_paired.fq") - os.system("cat input_1.fq.paired.fq >> filtered1STX_paired.fq") - os.system("cat filtered2STX.fq.paired.fq > filtered2STX_paired.fq") - os.system("cat input_2.fq.paired.fq >> filtered2STX_paired.fq") - os.system("cat filtered2STX.fq.single.fq.paired.fq >> filtered2STX_paired.fq") - os.system("printf '\n\nShigatoxinTyper\n===============\nduk v20110303\n' >> " + args.logfile) - os.system("printf 'parameters: k=23\n\n' >> " + args.logfile) - # SHIGATOXIN ASSEMBLY: SPADES - os.system("perl " + TOOL_DIR + "/scripts/spades.pl spades_contigs_stx spades_contig_stats_stx spades_scaffolds_stx spades_scaffold_stats_stx spades_log_stx NODE spades.py --disable-gzip-output --careful -t \${GALAXY_SLOTS:-16} -k '21,33,55' --pe1-ff --pe1-1 fastq:filtered1STX_paired.fq --pe1-2 fastq:filtered2STX_paired.fq") - os.system("spades.py -v >> " + args.logfile) - os.system("printf 'parameters: careful, k=21,33,55, pe1-ff, pe1-1, pe1-2\n\n' >> " + args.logfile) - # SHIGATOXIN NCBI BLAST+ blastn - os.system("blastn -query 'spades_contigs_stx' -db '" + TOOL_DIR + "/data/stx' -task blastn -evalue 0.001 -out '" + args.blastn_STX + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0") - os.system("blastn -version >> " + args.logfile) - os.system("printf 'parameters: evalue=0.001, strand=both, dust=yes, max_target_seqs=10, perc_identity=95.0\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/ShigatoxinTyping_db.txt >> " + args.logfile) - # SHIGATOXINTYPER: FILTER, CUT AND CONCATENATE BLASTN OUTPUT - os.system("echo 'sseqid\tpident\tlength\tpositive' > blastn_shigatoxin_fct") - os.system("awk -F '\t' '($3>99 && $4>1200) { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_STX + " > blastn_shigatoxin_fc") - shigatoxin_typing = openFileAsTable("blastn_shigatoxin_fc") - os.system("cat blastn_shigatoxin_fc >> blastn_shigatoxin_fct") - if os.stat('blastn_shigatoxin_fc').st_size == 0: - os.system("echo '-\t-\t-\t-' >> blastn_shigatoxin_fct") - # SEQUENCETYPER - os.system("mentalist call --output_votes -o 'mentalist_out' --db '/afs/galaxy/tool-data/mentalist_databases/escherichia_coli_pubmlst_k31_2018-10-09/escherichia_coli_pubmlst_k31_m023_2018-10-09.jld' -1 input_1.fq -2 input_2.fq") - os.system("mv mentalist_out.byvote " + args.mlstsevenloci) - sequence_typing = openFileAsTable(args.mlstsevenloci) - sequence_qc = openFileAsTable("mentalist_out.coverage.txt") - os.system("printf '\n\nSequenceTyper\n=============\n' >> " + args.logfile) - os.system("mentalist -v | grep MentaLiST >> " + args.logfile) - os.system("printf '\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/SequenceTyping_db.txt >> " + args.logfile) - if args.serotyping: - # SEROTYPE FILTERING - os.system(TOOL_DIR + "/scripts/duk -m filteredO1.fq -k 23 " + TOOL_DIR + "/data/O_type.fsa input_1.fq") - os.system(TOOL_DIR + "/scripts/duk -m filteredH1.fq -k 23 " + TOOL_DIR + "/data/H_type.fsa input_1.fq") - os.system("cat filteredO1.fq > filteredOH1.fq") - os.system("cat filteredH1.fq >> filteredOH1.fq") - os.system(TOOL_DIR + "/scripts/duk -m filteredO2.fq -k 23 " + TOOL_DIR + "/data/O_type.fsa input_2.fq") - os.system(TOOL_DIR + "/scripts/duk -m filteredH2.fq -k 23 " + TOOL_DIR + "/data/H_type.fsa input_2.fq") - os.system("cat filteredO2.fq > filteredOH2.fq") - os.system("cat filteredH2.fq >> filteredOH2.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filteredOH1.fq filteredOH2.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filteredOH1.fq.single.fq input_2.fq") - os.system(TOOL_DIR + "/scripts/fastq_pair filteredOH2.fq.single.fq input_1.fq") - os.system("cat filteredOH1.fq.paired.fq > filteredOH1_paired.fq") - os.system("cat filteredOH1.fq.single.fq.paired.fq >> filteredOH1_paired.fq") - os.system("cat input_1.fq.paired.fq >> filteredOH1_paired.fq") - os.system("cat filteredOH2.fq.paired.fq > filteredOH2_paired.fq") - os.system("cat input_2.fq.paired.fq >> filteredOH2_paired.fq") - os.system("cat filteredOH2.fq.single.fq.paired.fq >> filteredOH2_paired.fq") - os.system("printf '\n\nSeroTyper\n=========\nduk v20110303\n' >> " + args.logfile) - os.system("printf 'parameters: k=23\n\n' >> " + args.logfile) - # SEROTYPE ASSEMBLY: SPADES - os.system("perl " + TOOL_DIR + "/scripts/spades.pl spades_contigs_oh spades_contig_stats_oh spades_scaffolds_oh spades_scaffold_stats_oh " + args.spades_log + " NODE spades.py --disable-gzip-output --careful -t \${GALAXY_SLOTS:-16} -k '21,33,55' --pe1-ff --pe1-1 fastq:filteredOH1_paired.fq --pe1-2 fastq:filteredOH2_paired.fq") - os.system("spades.py -v >> " + args.logfile) - os.system("printf 'parameters: careful, k=21,33,55, pe1-ff, pe1-1, pe1-2\n\n' >> " + args.logfile) - # SEROTYPE NCBI BLAST+ blastn - os.system("blastn -query 'spades_contigs_oh' -db '" + TOOL_DIR + "/data/O_type' -task blastn -evalue 0.001 -out '" + args.blastn_O + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0") - os.system("blastn -query 'spades_contigs_oh' -db '" + TOOL_DIR + "/data/H_type' -task blastn -evalue 0.001 -out '" + args.blastn_H + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0 -ungapped") - os.system("blastn -version >> " + args.logfile) - os.system("printf 'parameters: evalue=0.001, strand=both, dust=yes, max_target_seqs=10, perc_identity=95.0\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/SeroTyping_db.txt >> " + args.logfile) - # SEROTYPER: FILTER, CUT AND CONCATENATE BLASTN OUTPUT - os.system("echo 'sseqid\tpident\tlength\tpositive' > blastn_OH_fc") - os.system("awk -F '\t' '$4>800 { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_O + " | sort -nrk 2 -nrk 3 > blastn_O_fc") - sero_typing_o = openFileAsTable("blastn_O_fc") - os.system("cat blastn_O_fc >> blastn_OH_fc") - os.system("awk -F '\t' '$4>800 { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_H + " | sort -nrk 2 -nrk 3 > blastn_H_fc") - sero_typing_h = openFileAsTable("blastn_H_fc") - os.system("cat blastn_H_fc >> blastn_OH_fc") - if os.stat('blastn_O_fc').st_size == 0 and os.stat('blastn_H_fc').st_size == 0: - os.system("echo '-\t-\t-\t-' >> blastn_OH_fc") + log.write("\n\nViruloTyper\n===========\npatho_typing v1.0\n") + log.write("parameters: minGeneCoverage=90, minGeneIdentity=90, minGeneDepth=15\n\n") + log.write(os.popen("cat " + TOOL_DIR + "/data/ViruloTyping_db.txt").read()) else: # FASTQC os.system("python " + TOOL_DIR + "/scripts/rgFastQC.py -i " + args.input1 + " -d " + args.html1_path + " -o " + args.html1 + " -t " + args.text1 + " -f " + args.input1_ext + " -j " + args.input1_name + " -e " + "fastqc") os.system("rm -r " + args.html1_path) - os.system("fastqc -v >> " + args.logfile) + log.write(os.popen("fastqc -v").read()) # TRIMMING - os.system("python " + TOOL_DIR + "/scripts/fastq_positional_quality_trimming.py -1 " + args.input1 + " --maxlt 360 --lt 10 --rt 0 --minqt 25 --avgqt 27.0 --minlf 50 --trimmed1 " + args.trimmed1 + " --log trimming_logfile") - os.system("ln -s " + args.trimmed1 + " input_1.fq") - os.system("echo 'fastq_positional_quality_trimming v1.0' >> " + args.logfile) - os.system("printf 'parameters: maxlt=360, lt=10, rt=0, minqt=25, avgqt=27.0, minlf=50\n' >> " + args.logfile) + os.system("python " + TOOL_DIR + "/scripts/fastq_positional_quality_trimming.py -1 " + args.input1 + " --maxlt 360 --lt 10 --rt 0 --minqt 25 --avgqt 27.0 --minlf 50 --trimmed1 input_t1.fq --log trimming_logfile") + log.write("\nfastq_positional_quality_trimming v1.0\n") + log.write("parameters: maxlt=360, lt=10, rt=0, minqt=25, avgqt=27.0, minlf=50\n") + if args.shigatoxintyping or args.serotyping: + # ASSEMBLY + os.system("perl " + TOOL_DIR + "/scripts/spades.pl contigs.fa spades_contig_stats spades_scaffolds spades_scaffold_stats spades_log NODE spades.py --disable-gzip-output --isolate -t ${GALAXY_SLOTS:-16} --iontorrent -s fastq:input_t1.fq") + log.write(os.popen("spades.py -v").read()) + log.write("parameters: --isolate, --iontorrent\n\n") if args.virulotyping: # VIRULOTYPER - os.system("perl " + TOOL_DIR + "/scripts/patho_typing_pt.pl 'python " + TOOL_DIR + "/scripts/patho_typing.py -s Escherichia coli -f " + args.input1 + " -o output_dir -j 1 --minGeneCoverage 90 --minGeneIdentity 90 --minGeneDepth 15'") + os.system("perl " + TOOL_DIR + "/scripts/patho_typing.pl 'python " + TOOL_DIR + "/scripts/patho_typing.py -s Escherichia coli -f " + args.input1 + " -o output_dir -j 1 --minGeneCoverage 90 --minGeneIdentity 90 --minGeneDepth 15'") os.system("cat pathotyper_rep_tot_tab > " + args.virulotyper) - os.system("printf '\n\nViruloTyper\n===========\npatho_typing v0.3\n' >> " + args.logfile) - os.system("printf 'parameters: minGeneCoverage=90, minGeneIdentity=90, minGeneDepth=15\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/ViruloTyping_db.txt >> " + args.logfile) - if args.shigatoxintyping: - # SHIGATOXIN FILTERING - os.system(TOOL_DIR + "/scripts/duk -m filtered1STX.fq -k 23 " + TOOL_DIR + "/data/stx.fa input_1.fq") - os.system("printf '\n\nShigatoxinTyper\n===============\nduk v20110303\n' >> " + args.logfile) - os.system("printf 'parameters: k=23\n\n' >> " + args.logfile) - # SHIGATOXIN ASSEMBLY: SPADES - os.system("perl " + TOOL_DIR + "/scripts/spades.pl spades_contigs_stx spades_contig_stats_stx spades_scaffolds_stx spades_scaffold_stats_stx spades_log_stx NODE spades.py --disable-gzip-output --careful -t \${GALAXY_SLOTS:-16} -k '21,33,55' --iontorrent --pe1-ff --pe1-s fastq:filtered1STX.fq") - os.system("spades.py -v >> " + args.logfile) - os.system("printf 'parameters: careful, k=21,33,55, iontorrent, pe1-ff, pe1-s\n\n' >> " + args.logfile) - # SHIGATOXIN NCBI BLAST+ blastn - os.system("blastn -query 'spades_contigs_stx' -db '" + TOOL_DIR + "/data/stx' -task blastn -evalue 0.001 -out '" + args.blastn_STX + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0") - os.system("blastn -version >> " + args.logfile) - os.system("printf 'parameters: evalue=0.001, strand=both, dust=yes, max_target_seqs=10, perc_identity=95.0\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/ShigatoxinTyping_db.txt >> " + args.logfile) - # SHIGATOXINTYPER: FILTER, CUT AND CONCATENATE BLASTN OUTPUT - os.system("echo 'sseqid\tpident\tlength\tpositive' > blastn_shigatoxin_fct") - os.system("awk -F '\t' '($3>99 && $4>1200) { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_STX + " > blastn_shigatoxin_fc") - shigatoxin_typing = openFileAsTable("blastn_shigatoxin_fc") - os.system("cat blastn_shigatoxin_fc >> blastn_shigatoxin_fct") - if os.stat('blastn_shigatoxin_fc').st_size == 0: - os.system("echo '-\t-\t-\t-' >> blastn_shigatoxin_fct") - # SEQUENCETYPER - os.system("mentalist call --output_votes -o 'mentalist_out' --db '/afs/galaxy/tool-data/mentalist_databases/escherichia_coli_pubmlst_k31_2018-10-09/escherichia_coli_pubmlst_k31_m023_2018-10-09.jld' -1 input_1.fq") - os.system("mv mentalist_out.byvote " + args.mlstsevenloci) - sequence_typing = openFileAsTable(args.mlstsevenloci) - sequence_qc = openFileAsTable("mentalist_out.coverage.txt") - os.system("printf '\n\nSequenceTyper\n=============\n' >> " + args.logfile) - os.system("mentalist -v | grep MentaLiST >> " + args.logfile) - os.system("printf '\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/SequenceTyping_db.txt >> " + args.logfile) - if args.serotyping: - # SEROTYPE FILTERING - os.system(TOOL_DIR + "/scripts/duk -m filteredO1.fq -k 23 " + TOOL_DIR + "/data/O_type.fsa input_1.fq") - os.system(TOOL_DIR + "/scripts/duk -m filteredH1.fq -k 23 " + TOOL_DIR + "/data/H_type.fsa input_1.fq") - os.system("cat filteredO1.fq > filteredOH1.fq") - os.system("cat filteredH1.fq >> filteredOH1.fq") - os.system("printf '\n\nSeroTyper\n=========\nduk v20110303\n' >> " + args.logfile) - os.system("printf 'parameters: k=23\n\n' >> " + args.logfile) - # SEROTYPE ASSEMBLY: SPADES - os.system("perl " + TOOL_DIR + "/scripts/spades.pl spades_contigs_oh spades_contig_stats_oh spades_scaffolds_oh spades_scaffold_stats_oh " + args.spades_log + " NODE spades.py --disable-gzip-output --careful -t \${GALAXY_SLOTS:-16} -k '21,33,55' --iontorrent --pe1-ff --pe1-s fastq:filteredOH1.fq") - os.system("spades.py -v >> " + args.logfile) - os.system("printf 'parameters: careful, k=21,33,55, iontorrent, pe1-ff, pe1-s\n\n' >> " + args.logfile) - # SEROTYPE NCBI BLAST+ blastn - os.system("blastn -query 'spades_contigs_oh' -db '" + TOOL_DIR + "/data/O_type' -task blastn -evalue 0.001 -out '" + args.blastn_O + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0") - os.system("blastn -query 'spades_contigs_oh' -db '" + TOOL_DIR + "/data/H_type' -task blastn -evalue 0.001 -out '" + args.blastn_H + "' -outfmt '6 std sallseqid score nident positive gaps ppos qframe sframe qseq sseq qlen slen salltitles' -num_threads ${GALAXY_SLOTS:-8} -strand both -dust yes -max_target_seqs 10 -perc_identity 95.0 -ungapped") - os.system("blastn -version >> " + args.logfile) - os.system("printf 'parameters: evalue=0.001, strand=both, dust=yes, max_target_seqs=10, perc_identity=95.0\n\n' >> " + args.logfile) - os.system("cat " + TOOL_DIR + "/data/SeroTyping_db.txt >> " + args.logfile) - # SEROTYPER: FILTER, CUT AND CONCATENATE BLASTN OUTPUT - os.system("echo 'sseqid\tpident\tlength\tpositive' > blastn_OH_fc") - os.system("awk -F '\t' '$4>800 { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_O + " | sort -nrk 2 -nrk 3 > blastn_O_fc") - sero_typing_o = openFileAsTable("blastn_O_fc") - os.system("cat blastn_O_fc >> blastn_OH_fc") - os.system("awk -F '\t' '$4>800 { print $2 FS $3 FS $4 FS $16 }' " + args.blastn_H + " | sort -nrk 2 -nrk 3 > blastn_H_fc") - sero_typing_h = openFileAsTable("blastn_H_fc") - os.system("cat blastn_H_fc >> blastn_OH_fc") - if os.stat('blastn_O_fc').st_size == 0 and os.stat('blastn_H_fc').st_size == 0: - os.system("echo '-\t-\t-\t-' >> blastn_OH_fc") + log.write("\n\nViruloTyper\n===========\npatho_typing v1.0\n") + log.write("parameters: minGeneCoverage=90, minGeneIdentity=90, minGeneDepth=15\n\n") + log.write(os.popen("cat " + TOOL_DIR + "/data/ViruloTyping_db.txt").read()) + # SEQUENCETYPER + if args.input2: + os.system("mentalist call --output_votes -o 'mentalist_out' --db '" + TOOL_DIR + "/data/escherichia_coli_pubmlst_k31_2018-10-09/escherichia_coli_pubmlst_k31_m023_2018-10-09.jld' -1 input_t1.fq -2 input_t2.fq") + else: + os.system("mentalist call --output_votes -o 'mentalist_out' --db '" + TOOL_DIR + "/data/escherichia_coli_pubmlst_k31_2018-10-09/escherichia_coli_pubmlst_k31_m023_2018-10-09.jld' -1 input_t1.fq") + os.system("mv mentalist_out.byvote " + args.mlstsevenloci) + sequence_typing = openFileAsTable(args.mlstsevenloci) + sequence_qc = openFileAsTable("mentalist_out.coverage.txt") + log.write("\n\nSequenceTyper\n=============\n") + log.write(os.popen("mentalist -v | grep MentaLiST").read()) + log.write("\n") + log.write(os.popen("cat " + TOOL_DIR + "/data/SequenceTyping_db.txt").read()) + if args.shigatoxintyping: + # SHIGATOXIN TYPER + os.system("echo 'sseqid\tpident\tlength\tpositive' > mmseqs_shigatoxin_fct") + os.system("mmseqs easy-search --search-type 3 --format-output query,target,pident,alnlen,tlen contigs.fa " + TOOL_DIR + "/data/stxDB mmseqs_STX /tmp") + os.system(TOOL_DIR + "/scripts/extract_shigatoxin.sh") + os.system("cat mmseqs_shigatoxin_fc >> mmseqs_shigatoxin_fct") + shigatoxin_typing = openFileAsTable("mmseqs_shigatoxin_fc") + log.write("\n\nShigatoxinTyper\n=============\n") + log.write(os.popen("cat " + TOOL_DIR + "/data/ShigatoxinTyping_db.txt").read()) + if args.serotyping: + # SEROTYPER + os.system("echo 'sseqid\tpident\tlength\tpositive' > mmseqs_OH_fc") + # SEROTYPER O + os.system("mmseqs easy-search --search-type 3 --format-output target,pident,alnlen,tlen contigs.fa " + TOOL_DIR + "/data/O_typeDB mmseqs_O /tmp") + os.system("awk -F '\t' '($3>800 && $4>800) { print $1 FS $2 FS $3 FS $4 }' mmseqs_O | sort -nrk 2 -nrk 3 > mmseqs_O_fc") + sero_typing_o = openFileAsTable("mmseqs_O_fc") + os.system("cat mmseqs_O_fc >> mmseqs_OH_fc") + # SEROTYPER H + os.system("mmseqs easy-search --search-type 3 --format-output target,pident,alnlen,tlen contigs.fa " + TOOL_DIR + "/data/H_typeDB mmseqs_H /tmp") + os.system("awk -F '\t' '($3>800 && $4>800) { print $1 FS $2 FS $3 FS $4 }' mmseqs_H | sort -nrk 2 -nrk 3 > mmseqs_H_fc") + sero_typing_h = openFileAsTable("mmseqs_H_fc") + os.system("cat mmseqs_H_fc >> mmseqs_OH_fc") + if os.stat('mmseqs_O_fc').st_size == 0 and os.stat('mmseqs_H_fc').st_size == 0: + os.system("echo '-\t-\t-\t-' >> mmseqs_OH_fc") + log.write("\n\nSeroTyper\n=============\n") + log.write(os.popen("cat " + TOOL_DIR + "/data/SeroTyping_db.txt").read()) + if args.amrtyping: + # AMRGENES + os.system("amrfinder --threads 4 --database " + TOOL_DIR + "/data/amrfinder -n contigs.fa -O Escherichia -o " + args.amr) + # REPORT try: report = open(args.output, 'w') # write head html @@ -279,13 +190,13 @@ if args.virulotyping: os.system("sort " + args.virulotyper + " | awk '/eae_|stx1._|stx2._|ehxa_/ && $2>50 && !seen[substr($1, 1, index($1, \"_\")-2)]++ { printf(\"%s%s\",sep,substr($1, 1, index($1, \"_\")-1));sep=\", \" }END{print \"\"}' > virulotyper_rep") for line in fileinput.input("virulotyper_rep", inplace=True): - print line.replace("1a", "1"), + print(line.replace("1a", "1"),) for line in fileinput.input("virulotyper_rep", inplace=True): - print line.replace("2a", "2"), + print(line.replace("2a", "2"),) for line in fileinput.input("virulotyper_rep", inplace=True): - print line.replace("1b", "1"), + print(line.replace("1b", "1"),) for line in fileinput.input("virulotyper_rep", inplace=True): - print line.replace("2b", "2"), + print(line.replace("2b", "2"),) report.write("<p>Virulotypes: ") insertFile("virulotyper_rep", report) report.write("</p>\n") @@ -325,7 +236,7 @@ report.write("<p>FASTQC result: <a href='%s/datasets/%s/display/?preview=True'>Webpage</a></p>\n" % (BASE_URL, args.html1_id)) if args.serotyping: report.write("<br/><hr/><h3>Serotyping</h3>\n") - insertFileAsTable("blastn_OH_fc", report, True) + insertFileAsTable("mmseqs_OH_fc", report, True) report.write("<br/><hr/><h3>Multi Locus Sequence Typing</h3>\n") if len(sequence_typing) > 1: insertTable(sequence_typing, report, True) @@ -335,7 +246,10 @@ insertFileAsTable("pathotyper_rep_tab", report, True, "table table-cross") if args.shigatoxintyping: report.write("<br/><hr/><h3>Shiga toxin typing</h3>\n") - insertFileAsTable("blastn_shigatoxin_fct", report, True) + insertFileAsTable("mmseqs_shigatoxin_fct", report, True) + if args.amrtyping: + report.write("<br/><hr/><h3>AMR typing</h3>\n") + report.write("<p>AMR result: <a href='%s/datasets/%s/display/?preview=True'>Webpage</a></p>\n" % (BASE_URL, args.amr_id)) # write tail html insertFile(TOOL_DIR + "/report_tail.html", report) finally: @@ -343,5 +257,3 @@ if __name__ == "__main__": __main__() - -