@@ -41,6 +41,7 @@ contrast_manifest = config['contrastManifest']
4141# user parameters
4242multiplex_flag = config ['multiplexflag' ].capitalize ()
4343mismatch = config ['mismatch' ]
44+ barcode_qc_flag = config ['barcode_qc_flag' ]
4445species_ref = config ['reference' ]
4546filter_length = config ['filterlength' ]
4647phredQuality = config ['phredQuality' ]
@@ -219,6 +220,28 @@ def rename_cmd(wildcards):
219220 cmd = 'mv ' + source + ' ' + destination + '; ' + cmd
220221 return (cmd )
221222
223+ def get_input_qc_troubleshoot (wildcards ):
224+ print ("HERE" )
225+ d = dict ()
226+
227+ l = "log_list"
228+ t = "txt_bc"
229+ p = "png_bc"
230+
231+ if (multiplex_flag == 'Y' ):
232+ print ("m flag on" )
233+ d [l ] = expand (join (out_dir ,'log' ,'STAR' ,'{sp}.log' ),sp = sp_list ),
234+ d [t ] = expand (join (out_dir ,'{mp}' , '01_qc_post' ,'{mp}_barcode_passed.txt' ),mp = samp_dict .keys ())
235+ if (barcode_qc_flag == "PROCESS" ):
236+ print ("b flag on" )
237+ d [p ] = expand (join (out_dir ,'{mp}' , '01_qc_post' ,'{mp}_barcode.png' ),mp = samp_dict .keys ())
238+ else :
239+ print ("m flag off" )
240+ d [l ] = expand (join (out_dir ,'log' ,'STAR' ,'{sp}.log' ),sp = sp_list ),
241+ print (d )
242+ d = "YO"
243+ return (d )
244+
222245#read in contrast list for manorm
223246def get_de_list ():
224247
@@ -381,7 +404,7 @@ rule all:
381404 # multiqc
382405 join (out_dir ,'qc' ,'multiqc_report.html' ),
383406
384- # qc_troubleshoot
407+ # # qc_troubleshoot
385408 join (out_dir ,'qc' ,'qc_report_troubleshooting.html' ),
386409
387410 # dedup
@@ -408,7 +431,7 @@ rule all:
408431 # # qc barcode
409432 # expand(join(out_dir,'{mp}','01_qc_post','{mp}_barcode_counts.txt'),mp=mp_list),
410433 # expand(join(out_dir,'{mp}','01_qc_post','{mp}_barcode.png'),mp=mp_list),
411- # expand(join(out_dir,'{mp}','01_qc_post','{mp}_barcode .txt'),mp=mp_list),
434+ # expand(join(out_dir,'{mp}','01_qc_post','{mp}_barcode_passed .txt'),mp=mp_list),
412435
413436 # # demux OR nondemux
414437 # expand(join(out_dir,'{mp}', '02_preprocess','ultraplex_demux_5bc_no_match.fastq.gz'), mp=samp_dict.keys()),
@@ -462,9 +485,11 @@ else:
462485if (multiplex_flag == 'Y' ):
463486 rule qc_barcode :
464487 """
465- generate counts of barcodes and output to text file
466- will run python script that determines barcode expected and generates mismatches based on input
467- output barplot with top barcode counts
488+ if the flag in the config file is set to process, barcodes will be reviewed to ensure uniformtiy amongst samples.
489+ - generate counts of barcodes and output to text file
490+ - will run python script that determines barcode expected and generates mismatches based on input
491+ - output barplot with top barcode counts
492+ If it's set to IGNORE, then it will skip this processing and create the needed QC file
468493 """
469494 input :
470495 fq = get_fq_names ,
@@ -473,30 +498,40 @@ if (multiplex_flag == 'Y'):
473498 memG = getmemG_80perc ("qc_barcode" ),
474499 R = join (source_dir ,'workflow' , 'scripts' , '02_barcode_qc.R' ),
475500 base = join (out_dir ,'{mp}' ,'01_qc_post' ),
501+ qc_dir = join (out_dir ,'qc' ),
476502 mm = mismatch ,
477503 bc_len = barcode_length ,
478- start_pos = 6 if barcode_length == 6 else 4
504+ start_pos = 6 if barcode_length == 6 else 4 ,
505+ b_qc_flag = barcode_qc_flag
479506 threads : getthreads ("qc_barcode" )
480507 envmodules :
481508 config ['R' ],
482509 output :
483510 counts = temp (join (out_dir ,'{mp}' ,'01_qc_post' ,'{mp}_barcode_counts.txt' )),
484511 png = temp (join (out_dir ,'{mp}' ,'01_qc_post' ,'{mp}_barcode.png' )),
485- txt = temp ( join (out_dir ,'{mp}' ,'01_qc_post' ,'{mp}_barcode .txt' ) )
512+ txt = join (out_dir ,'{mp}' ,'01_qc_post' ,'{mp}_barcode_passed .txt' )
486513 shell :
487514 """
488515 set -exo pipefail
489- gunzip -c {input.fq} \\
490- | awk 'NR%4==2 {{print substr($0, {params.start_pos}, {params.bc_len});}}' \\
491- | LC_ALL=C sort --buffer-size={params.memG} --parallel={threads} --temporary-directory=/lscratch/${{SLURM_JOB_ID}} -n \\
492- | uniq -c > {output.counts};
493-
494- Rscript {params.R} --sample_manifest {sample_manifest} \\
495- --multiplex_manifest {multiplex_manifest} \\
496- --barcode_input {output.counts} \\
497- --mismatch {params.mm} \\
498- --mpid {wildcards.mp} \\
499- --output_dir {params.base}
516+
517+ if [[ {params.b_qc_flag} == "PROCESS" ]]; then
518+ gunzip -c {input.fq} \\
519+ | awk 'NR%4==2 {{print substr($0, {params.start_pos}, {params.bc_len});}}' \\
520+ | LC_ALL=C sort --buffer-size={params.memG} --parallel={threads} --temporary-directory=/lscratch/${{SLURM_JOB_ID}} -n \\
521+ | uniq -c > {output.counts};
522+
523+ Rscript {params.R} --sample_manifest {sample_manifest} \\
524+ --multiplex_manifest {multiplex_manifest} \\
525+ --barcode_input {output.counts} \\
526+ --mismatch {params.mm} \\
527+ --mpid {wildcards.mp} \\
528+ --output_dir {params.base} \\
529+ --qc_dir {params.base}
530+ else
531+ echo "Barcode QC checking was skipped for this run" > {output.txt}
532+ touch {output.png}
533+ touch {output.counts}
534+ fi
500535 """
501536
502537 rule demultiplex :
@@ -785,7 +820,7 @@ rule star:
785820 --sjdbScore {params.s_sj} \
786821 --winAnchorMultimapNmax {params.s_anchor}
787822
788- # sort file\
823+ # sort file
789824 samtools sort -m 80G -T $tmp_dir $tmp_dir/{params.out_prefix}Aligned.out.bam -o $tmp_dir/{params.out_prefix}Aligned.sortedByCoord.out.bam
790825
791826 # move STAR files and final log file to output
@@ -861,66 +896,44 @@ rule multiqc:
861896 -o {params.out_dir}
862897 """
863898
864- # Pipeline splits to handle multiplexed QC vs non-multiplexed QC
865- if (multiplex_flag == 'Y' ):
866- rule qc_troubleshoot :
867- """
868- generates a PDF of barcode plots and alignment plots for qc troubleshooting
899+ rule qc_troubleshoot :
900+ """
901+ generates a PDF of barcode plots and alignment plots for qc troubleshooting
902+ """
903+ input :
904+ log_list = expand (join (out_dir ,'log' ,'STAR' ,'{sp}.log' ),sp = sp_list ),
905+ params :
906+ rname = "08_qc_troubleshoot" ,
907+ R = join (source_dir ,'workflow' ,'scripts' ,'03_qc_report.Rmd' ),
908+ qc = join (source_dir ,'workflow' ,'scripts' ,'03_qc_unmapped_check.sh' ),
909+ log_dir = join (out_dir ,'log' ,'STAR' ),
910+ single_qc = single_qc_threshold ,
911+ proj_qc = project_qc_threshold ,
912+ m_flag = multiplex_flag ,
913+ b_flag = barcode_qc_flag ,
914+ txt_bc = expand (join (out_dir ,'{mp}' , '01_qc_post' ,'{mp}_barcode_passed.txt' ),mp = samp_dict .keys ())
915+ envmodules :
916+ config ['R' ]
917+ output :
918+ html = join (out_dir ,'qc' ,'qc_report_troubleshooting.html' ),
919+ qc = join (out_dir , 'log' ,'STAR' ,'qc_pass.txt' )
920+ shell :
869921 """
870- input :
871- log_list = expand (join (out_dir ,'log' ,'STAR' ,'{sp}.log' ),sp = sp_list ),
872- txt_bc = expand (join (out_dir ,'{mp}' , '01_qc_post' ,'{mp}_barcode.txt' ),mp = samp_dict .keys ()),
873- png_bc = expand (join (out_dir ,'{mp}' , '01_qc_post' ,'{mp}_barcode.png' ),mp = samp_dict .keys ())
874- params :
875- rname = "08_qc_troubleshoot" ,
876- R = join (source_dir ,'workflow' ,'scripts' ,'03_qc_report.Rmd' ),
877- qc = join (source_dir ,'workflow' ,'scripts' ,'03_qc_unmapped_check.sh' ),
878- log_dir = join (out_dir ,'log' ,'STAR' ),
879- single_qc = single_qc_threshold ,
880- proj_qc = project_qc_threshold
881- envmodules :
882- config ['R' ]
883- output :
884- html = join (out_dir ,'qc' ,'qc_report_troubleshooting.html' ),
885- qc = join (out_dir , 'log' ,'STAR' ,'qc_pass.txt' )
886- shell :
887- """
922+ if [[ {params.m_flag} == "Y" ]] && [[ {params.b_flag} == "PROCESS" ]] ; then
888923 Rscript -e 'library(rmarkdown); \
889924 rmarkdown::render("{params.R}",
890925 output_file = "{output.html}", \
891- params= list(log_list = "{input.log_list}", \
892- b_txt = "{input.txt_bc}"))'
893-
894- sh {params.qc} {params.log_dir} {params.single_qc} {params.proj_qc}
895- """
896- else :
897- rule qc_troubleshoot :
898- """
899- generates a PDF of barcode plots and alignment plots for qc troubleshooting
900- """
901- input :
902- log_list = expand (join (out_dir ,'log' ,'STAR' ,'{sp}.log' ),sp = sp_list ),
903- params :
904- rname = "08_qc_troubleshoot" ,
905- R = join (source_dir ,'workflow' ,'scripts' ,'03_qc_report.Rmd' ),
906- qc = join (source_dir ,'workflow' ,'scripts' ,'03_qc_unmapped_check.sh' ),
907- log_dir = join (out_dir ,'log' ,'STAR' ),
908- single_qc = single_qc_threshold ,
909- proj_qc = project_qc_threshold
910- envmodules :
911- config ['R' ]
912- output :
913- html = join (out_dir ,'qc' ,'qc_report_troubleshooting.html' ),
914- qc = join (out_dir , 'log' ,'STAR' ,'qc_pass.txt' )
915- shell :
916- """
926+ params= list(log_list = "{input.log_list}", \
927+ b_txt = "{params.txt_bc}"))'
928+ else
917929 Rscript -e 'library(rmarkdown); \
918- rmarkdown::render("{params.R}",
930+ rmarkdown::render("{params.R}",
919931 output_file = "{output.html}", \
920- params= list(log_list = "{input.log_list}"))'
921-
922- sh {params.qc} {params.log_dir} {params.single_qc} {params.proj_qc}
923- """
932+ params= list(log_list = "{input.log_list}"))'
933+ fi
934+
935+ sh {params.qc} {params.log_dir} {params.single_qc} {params.proj_qc}
936+ """
924937
925938rule dedup :
926939 """
0 commit comments