Commit 6c0dd0ab authored by Gonzalo S Nido's avatar Gonzalo S Nido
Browse files

Fixed number of cores for alignment based on RAM

parent c515c520
......@@ -34,12 +34,12 @@ psrecord="psrecord"
########################################
# To activate CPU and RAM monitoring
MONITOR=false
#MONITOR=true
#MONITOR=false
MONITOR=true
# To subset reads to 10,000 (debug)
SUBSET_READS=false
#SUBSET_READS=true
#SUBSET_READS=false
SUBSET_READS=true
########################################
......@@ -53,6 +53,8 @@ set -e
# Get number of processors in the machine
N_proc=$( grep -c processor /proc/cpuinfo )
# Get RAM in the machine
RAM=$( free -g | grep '^Mem' | awk '{print $2}' )
# Ensure reference files/indices are there, download and index otherwise
if [[ ! -s ${b38_ref}/Bisulfite_Genome/GA_conversion/genome_mfa.GA_conversion.fa ]]; then
......@@ -159,8 +161,8 @@ if $MONITOR; then
fi
if $SUBSET_READS; then
SUBSET_READS="-u 10000"
echo "SUBSETTING TO 10000 READS ONLY!!!!"
SUBSET_READS="-u 100000"
echo "SUBSETTING TO 100000 READS ONLY!!!!"
echo
fi
......@@ -176,8 +178,10 @@ echo "##################################################"
echo -ne " 1.1 Aligning... "
cpus=`expr ${N_proc} / 4`
#CMD="${bismark} ${b38_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} -u 100000 \
cpus=`expr ${RAM} / 16`
if [[ $cpus -eq 0 ]]; then cpus=1; fi
CMD="${bismark} ${b38_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} ${SUBSET_READS} \
-o ${output_dir} --prefix b38 --path_to_bowtie ${bowtie_path} \
--samtools_path ${samtools_path} --temp_dir ${tmp_dir} > \
......@@ -199,6 +203,7 @@ else
fi
echo -ne " 1.2 Merging bamfiles... "
bamfile_list=""
IFS=',' read -r -a array <<< "${R1}"
for element in "${array[@]}"; do
......@@ -207,9 +212,7 @@ for element in "${array[@]}"; do
bamfile_list="${bamfile_list} ${bamfile}"
done
cpus=`expr ${N_proc} / 2`
#CMD="${samtools} merge -n -r -@ ${cpus} ${output_dir}/b38_${sample_id}.bam ${bamfile_list} > \
CMD="${samtools} cat -@ ${cpus} -o ${output_dir}/b38_${sample_id}.bam ${bamfile_list} > \
CMD="${samtools} cat -o ${output_dir}/b38_${sample_id}.bam ${bamfile_list} > \
${log_dir}/1_2_merge.stdout 2> \
${log_dir}/1_2_merge.stderr"
echo -e ${CMD} > ${log_dir}/1_2_merge.cmd
......@@ -234,6 +237,7 @@ fi
echo -ne " 1.3 Dedupping alignment... "
CMD="${deduplicate_bismark} --paired --samtools_path ${samtools_path} \
--output_dir ${output_dir} ${output_dir}/b38_${sample_id}.bam > \
${log_dir}/1_3_dedup.stdout 2> \
......@@ -257,10 +261,11 @@ if [ -s "${output_dir}/b38_${sample_id}.deduplicated.bam" ]; then
mv ${output_dir}/b38_${sample_id}.deduplicated.bam ${output_dir}/b38_${sample_id}.dedup.bam
fi
exit 1
echo -ne " 1.4 Extracting methylation... "
cpus=`expr ${N_proc} / 3`
CMD="${bismark_meth_extract} -p --comprehensive --output ${output_dir} \
--multicore ${cpus} \
--samtools_path ${samtools_path} \
......@@ -283,6 +288,7 @@ else
fi
echo -ne " 1.5 Extracting MT and Lambda methylation... "
CMD="cat ${output_dir}/CpG_context_b38_${sample_id}.dedup.txt | python3 ${ext_chr_srt} ${MT_chr_name} | gzip -nc > \
${output_dir}/CpG_context_chrM_${sample_id}.dedup.txt.gz && \
cat ${output_dir}/CpG_context_b38_${sample_id}.dedup.txt | python3 ${ext_chr_srt} ${LAMBDA_chr_name} | gzip -nc > \
......@@ -317,6 +323,8 @@ fi
echo
exit 1
......@@ -332,8 +340,10 @@ echo "##################################################"
echo -ne " 2.1 Aligning... "
cpus=`expr ${N_proc} / 4`
#CMD="${bismark} ${mt_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} -u 100000 \
cpus=`expr ${RAM} / 16`
if [[ $cpus -eq 0 ]]; then cpus=1; fi
CMD="${bismark} ${mt_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} ${SUBSET_READS} \
-o ${output_dir} --prefix MT --path_to_bowtie ${bowtie_path} \
--samtools_path ${samtools_path} --temp_dir ${tmp_dir} > \
......@@ -355,6 +365,9 @@ else
fi
echo -ne " 2.2 Merging bamfiles... "
cpus=`expr ${N_proc} / 2`
bamfile_list=""
IFS=',' read -r -a array <<< "${R1}"
for element in "${array[@]}"; do
......@@ -363,7 +376,6 @@ for element in "${array[@]}"; do
bamfile_list="${bamfile_list} ${bamfile}"
done
cpus=`expr ${N_proc} / 2`
CMD="${samtools} merge -n -r -@ ${cpus} ${output_dir}/MT_${sample_id}.bam ${bamfile_list} > \
${log_dir}/2_2_merge.stdout 2> \
${log_dir}/2_2_merge.stderr"
......@@ -414,7 +426,9 @@ fi
echo -ne " 2.4 Extracting methylation... "
cpus=`expr ${N_proc} / 3`
CMD="${bismark_meth_extract} -p --comprehensive --output ${output_dir} \
--gzip --multicore ${cpus} \
--samtools_path ${samtools_path} \
......@@ -456,8 +470,11 @@ echo "##################################################"
echo -ne " 3.1 Aligning vs nuclear DNA... "
cpus=`expr ${N_proc} / 4`
#CMD="${bismark} ${nuc_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} -u 100000 \
cpus=`expr ${RAM} / 16`
if [[ $cpus -eq 0 ]]; then cpus=1; fi
CMD="${bismark} ${nuc_ref} -1 ${R1} -2 ${R2} --multicore ${cpus} ${SUBSET_READS} \
--un --ambiguous -o ${output_dir} --prefix b38_noMT --path_to_bowtie ${bowtie_path} \
--samtools_path ${samtools_path} --temp_dir ${tmp_dir} > \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment