Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### DEFAULTS (FEEL FREE TO EDIT THESE) ##################
  4. MIN_CONTIG_SIZE_FOR_ASSEMBLY=1000
  5. MIN_CONTIG_SIZE_FOR_CONTIGS_DB=2500
  6. MIN_CONTIG_SIZE_FOR_PROFILE_DB=2500
  7. NUM_THREADS_FOR_ASSEMBLY=70
  8. NUM_THREADS_FOR_BLASTN=80
  9. NUM_THREADS_FOR_MAPPING=10
  10. NUM_THREADS_FOR_HMMSCAN=20
  11. # if you want to skip SNV analysis to make things faster then set the following variable to --skip-SNV-profiling
  12. SNV_ANALYSIS_CONFIGURATION=
  13. #########################################################
  14.  
  15. # setting the pipeline to stop in case a command returns a non-zero status
  16. set -e
  17.  
  18. job=$1
  19. email=$2
  20.  
  21. if [ ! -f "samples.txt" ]
  22. then
  23. echo "
  24. You must have a samples.txt in this directory. The format of the
  25. samples.txt is identical to the input file of iu-gen-configs. For
  26. details, see iu-gen-congigs -h
  27. "
  28. exit 1
  29. fi
  30.  
  31. if [ ! -f "references.txt" ]
  32. then
  33. echo "
  34. You must have a references.txt in this directory. "
  35. exit 1
  36. fi
  37.  
  38. C() {
  39. echo -e "\033[0;30m\033[46m$1\033[0m"
  40. }
  41.  
  42. INFO() {
  43. echo
  44. C "#"
  45. C "#"
  46. C "# $1"
  47. C "#"
  48. C "#"
  49. echo
  50. }
  51.  
  52.  
  53. WAIT () {
  54. python /workspace/meren/wait_for_cluster.py $1
  55. }
  56.  
  57. CHECK_FILE () {
  58. if [ -s $1 ]
  59. then
  60. :
  61. else
  62. echo "Error: Expected to find $1, but it is not there!"
  63. exit 1
  64. fi
  65. }
  66.  
  67. LOG () {
  68. msg="[`date`] $1"
  69. echo $msg >> $job-log.txt
  70. echo $msg | mail -s "Update on $job" $email
  71. }
  72.  
  73. DO_INIT() {
  74. rm -rf 00_LOGS
  75. mkdir 00_LOGS
  76.  
  77. LOG "Hi!"
  78. LOG `anvi-interactive -v`
  79.  
  80. }
  81. DO_GEN_CONTIG () {
  82. ref_genome=$1
  83. ref_genome_path=$2
  84. DIR="03_CONTIGS"
  85. INFO $DIR && mkdir -p $DIR
  86.  
  87. clusterize -n 4 -log 00_LOGS/gen-contigs.log anvi-gen-contigs-database -f $ref_genome_path -o $DIR/${ref_genome}.db
  88. WAIT anvi-gen-contigs-database
  89. echo "anvi-gen-contigs-database for $ref_genome in $job on `hostname` is done." | mail -s "Update on $job!" $email
  90.  
  91. }
  92. DO_BOWTIE2_MAPPING () {
  93. ref_genome=$1
  94. ref_genome_path=$2
  95. DIR="04_MAPPING/$ref_genome"
  96.  
  97. INFO $DIR
  98. # I'm not deleting the folder since I might map reads from new metagenomes to the same reference and so I wouldn't want to delete the folder
  99. # it is the user's responsibility to check if they are mapping metagenoms genomes that were already mapped
  100. mkdir -p $DIR
  101.  
  102. clusterize -n 4 -log 00_LOGS/$ref_genome\_bowtie-build.log bowtie2-build $ref_genome_path $DIR/$ref_genome
  103. WAIT bowtie2-build
  104.  
  105. while read sample R1 R2; do
  106. if [ "$sample" == "sample" ]; then continue; fi
  107. clusterize -n $NUM_THREADS_FOR_MAPPING -log 00_LOGS/$ref_genome\_$sample-bowtie2.log bowtie2 --threads $NUM_THREADS_FOR_MAPPING -x $DIR/$ref_genome -1 $R1 -2 $R2 -S $DIR/$sample.sam --no-unal
  108. done < samples.txt
  109. WAIT bowtie2
  110.  
  111. while read sample R1 R2; do
  112. if [ "$sample" == "sample" ]; then continue; fi
  113. clusterize -n 4 -log 00_LOGS/$ref_genome\_$sample-samtools-view.log samtools view -F 4 -bS $DIR/$sample.sam -o $DIR/$sample-RAW.bam
  114. done < samples.txt
  115. WAIT samtools
  116.  
  117. while read sample R1 R2; do
  118. if [ "$sample" == "sample" ]; then continue; fi
  119. clusterize -n 4 -log 00_LOGS/$ref_genome\_$sample-anvi-init-bam.log anvi-init-bam $DIR/$sample-RAW.bam -o $DIR/$sample\.bam
  120. done < samples.txt
  121. WAIT anvi-init-bam
  122.  
  123. while read sample R1 R2; do
  124. if [ "$sample" == "sample" ]; then continue; fi
  125. CHECK_FILE $DIR/$sample.bam
  126. done < samples.txt
  127.  
  128. while read sample R1 R2; do
  129. if [ "$sample" == "sample" ]; then continue; fi
  130. if [ -s $DIR/$sample.bam ]
  131. then
  132. clusterize -log 00_LOGS/$ref_genome\_$sample-rm-SAMs.log rm $DIR/$sample.sam $DIR/$sample-RAW.bam
  133. fi
  134. done < samples.txt
  135.  
  136. echo "Bowtie mapping for $job on `hostname` is done." | mail -s "Update on $job!" $email
  137. }
  138.  
  139.  
  140. DO_ANVI_PROFILE () {
  141. ref_genome=$1
  142. DIR="05_ANVIO_PROFILE/$ref_genome"
  143. MAPPING_DIR="04_MAPPING/$ref_genome"
  144. INFO $DIR && mkdir -p $DIR
  145.  
  146. while read sample R1 R2; do
  147. if [ "$sample" == "sample" ]; then continue; fi
  148. clusterize -n 4 -log 00_LOGS/$ref_genome\_$sample-anvi-profile.log anvi-profile $SNV_ANALYSIS_CONFIGURATION -i $MAPPING_DIR/$sample.bam -c 03_CONTIGS/${ref_genome}.db -o $DIR/$sample -M $MIN_CONTIG_SIZE_FOR_PROFILE_DB
  149. done < samples.txt
  150. WAIT anvi-profile
  151.  
  152. echo "Anvi'o profiling of samples for $ref_genome in $job on `hostname` is done." | mail -s "Update on $job!" $email
  153. }
  154.  
  155.  
  156. DO_ANVI_MERGE () {
  157. ref_genome=$1
  158. mkdir -p 06-$job-MERGED
  159. DIR="06-$job-MERGED/$ref_genome"
  160. # this is the only place where I leave the delete folder
  161. INFO $DIR && rm -rf $DIR
  162.  
  163. clusterize -n 4 -log 00_LOGS/$ref_genome\_anvi-merge.log anvi-merge 05_ANVIO_PROFILE/${ref_genome}/*/RUNINFO.cp -o $DIR -c 03_CONTIGS/${ref_genome}.db
  164. WAIT anvi-merge
  165. #CHECK_FILE $DIR/RUNINFO.mcp #FIXME: I don't know why this keeps on failing to find this file!!
  166. echo "Anvi'o merge for $ref_genome in $job on `hostname` is done." | mail -s "Update on $job!" $email
  167. }
  168.  
  169. #DO_INIT
  170.  
  171. while read reference path; do
  172. if [ "$reference" == "reference" ]; then continue; fi
  173. # Generate contigs db
  174. DO_GEN_CONTIG $reference $path
  175. # Map reads with bowtie
  176. DO_BOWTIE2_MAPPING $reference $path
  177. # Do anvi profile
  178. DO_ANVI_PROFILE $reference
  179. # Do anvi merge
  180. DO_ANVI_MERGE $reference
  181. done < references.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement