Skip to content

Commit

Permalink
correct a bug in process_with_bam module
Browse files Browse the repository at this point in the history
  • Loading branch information
wbaopaul committed Feb 17, 2022
1 parent b951aa5 commit db30e00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion complete_update_history.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## Complete Update History
- Version 1.4.2 released
* correct bugs in processing single-end sequencing data
* correct minor underestimate of overall FrIP in the qc report
* correct minor underestimate of overall FrIP in the qc *report*
* correst a bug in *process_with_bam* module
- Version 1.4.1 released
* *qc_per_barcode*: add tss enrichment score per cell into the QC metrics
* update tutorial
Expand Down
25 changes: 18 additions & 7 deletions scripts/bam2qc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ mapRes_dir="${OUTPUT_DIR}/mapping_result"
mkdir -p $mapRes_dir
curr_dir=`dirname $0`

## if input bam not under default scatac-pro output file path,
## create a soft link for it
position_sort_bam=${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.bam
if [[ ! -f $position_sort_bam ]]; then
ln -s $bam_file $position_sort_bam
fi

## check whether the bam file is position sorted or not
isort=`samtools view $bam_file -H | grep HD | cut -f3`
isort=`samtools view $position_sort_bam -H | grep HD | cut -f3`
ncore=$(nproc --all)
ncore=$(($ncore - 1))
## if the input is position sorted, suppose it's duplicates marked
Expand All @@ -37,21 +44,25 @@ if [[ "$isort" != "SO:coordinate" ]]; then
## mark duplicates
${SAMTOOLS_PATH}/samtools markdup -@ $ncore ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort0.bam ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.bam
rm ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort0.bam
position_sort_bam=${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.bam
else
position_sort_bam=$bam_file
fi

${SAMTOOLS_PATH}/samtools index -@ $ncore $position_sort_bam
if [[ ! -f ${position_sort_bam}.bai ]];then
${SAMTOOLS_PATH}/samtools index -@ $ncore $position_sort_bam
fi


## filtering low quality and/or deplicates for downstreame analysis
${SAMTOOLS_PATH}/samtools view -f 0x2 -b -h -q 30 -@ $ncore $position_sort_bam -o ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.MAPQ30.bam
flag0=0x2
if [ ${isSingleEnd} = 'TRUE' ]; then
flag0=0x1
fi

${SAMTOOLS_PATH}/samtools view -f $flag0 -b -h -q 30 -@ $ncore $position_sort_bam -o ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.MAPQ30.bam
${SAMTOOLS_PATH}/samtools index -@ $ncore ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.MAPQ30.bam


if [ $MAPQ -ne 30 ]; then
${SAMTOOLS_PATH}/samtools view -f 0x2 -b -h -q $MAPQ -@ $ncore $position_sort_bam -o ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.MAPQ${MAPQ}.bam
${SAMTOOLS_PATH}/samtools view -f $flag0 -b -h -q $MAPQ -@ $ncore $position_sort_bam -o ${mapRes_dir}/${OUTPUT_PREFIX}.positionsort.MAPQ${MAPQ}.bam
fi


Expand Down

0 comments on commit db30e00

Please sign in to comment.