-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
386 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/bash | ||
|
||
## output mapping qc results | ||
|
||
input_dir=$1 ## the directory where the mapping results are | ||
|
||
curr_dir=`dirname $0` | ||
source ${curr_dir}/read_conf.sh | ||
read_conf "$2" | ||
read_conf "$3" | ||
|
||
output_dir=${OUTPUT_DIR}/summary | ||
mkdir -p $output_dir | ||
|
||
ncore=$(nproc --all) | ||
ncore=$(($ncore - 1)) | ||
|
||
input_pre=${input_dir}/cell_barcodes | ||
output_pre=${output_dir}/cell_barcodes | ||
|
||
${SAMTOOLS_PATH}/samtools flagstat -@ $ncore ${input_pre}.bam > ${output_pre}.flagstat.txt | ||
${SAMTOOLS_PATH}/samtools idxstats -@ $ncore ${input_pre}.bam > ${output_pre}.idxstat.txt | ||
|
||
if [[ ! -f ${input_pre}.MAPQ${MAPQ}.bam ]];then | ||
${SAMTOOLS_PATH}/samtools view -@ $ncore -h -b -q ${MAPQ} ${input_pre}.bam > ${input_pre}.MAPQ${MAPQ}.bam | ||
fi | ||
|
||
if [[ ! -f ${input_pre}.MAPQ${MAPQ}.bam.bai ]];then | ||
${SAMTOOLS_PATH}/samtools index -@ $ncore ${input_pre}.MAPQ${MAPQ}.bam | ||
fi | ||
|
||
${SAMTOOLS_PATH}/samtools flagstat -@ $ncore ${input_pre}.MAPQ${MAPQ}.bam > ${output_pre}.MAPQ${MAPQ}.flagstat.txt | ||
${SAMTOOLS_PATH}/samtools idxstats -@ $ncore ${input_pre}.MAPQ${MAPQ}.bam > ${output_pre}.MAPQ${MAPQ}.idxstat.txt | ||
|
||
|
||
tmp_sam_file=${output_dir}/tmp.sam | ||
${SAMTOOLS_PATH}/samtools view -@ $ncore -q 5 ${input_pre}.bam > $tmp_sam_file | ||
|
||
if [ $MAPPING_METHOD == 'bwa' ]; then | ||
total_uniq_mapped=$( wc -l ${tmp_sam_file} | cut -d ' ' -f1 ) ## number of unique mapped reads | ||
elif [ $MAPPING_METHOD == 'bowtie' ]; then | ||
total_uniq_mapped=$( grep -E "@|NM:" $tmp_sam_file | grep -v "XS:" | wc -l ) | ||
else | ||
total_uniq_mapped=$( grep -E "@|NM:" $tmp_sam_file | grep -v "XS:" | wc -l ) | ||
fi | ||
|
||
|
||
total_uniq_mapped=$((${total_uniq_mapped}/2)) | ||
|
||
total_pairs=$(grep 'paired in' ${output_pre}.flagstat.txt | cut -d ' ' -f1) | ||
total_pairs=$((${total_pairs}/2)) | ||
total_pairs_mapped=$(grep 'with itself and mate mapped' ${output_pre}.flagstat.txt | cut -d ' ' -f1) | ||
total_pairs_mapped=$((${total_pairs_mapped}/2)) | ||
total_mito_mapped=$(grep chrM ${output_pre}.idxstat.txt | cut -f3) | ||
total_mito_unmapped=$(grep chrM ${output_pre}.idxstat.txt | cut -f4) | ||
total_mito=$((${total_mito_mapped}/2 + ${total_mito_unmapped}/2)) | ||
total_mito_mapped=$((${total_mito_mapped}/2)) | ||
total_dups=$(grep 'duplicates' ${output_pre}.flagstat.txt | cut -d ' ' -f1) | ||
total_dups=$((${total_dups}/2)) | ||
|
||
|
||
|
||
total_pairs_MAPQH=$(grep 'with itself and mate mapped' ${output_pre}.MAPQ${MAPQ}.flagstat.txt | cut -d ' ' -f1) | ||
total_pairs_MAPQH=$((${total_pairs_MAPQH}/2)) | ||
total_mito_MAPQH=$(grep chrM ${output_pre}.MAPQ${MAPQ}.idxstat.txt | cut -f3) | ||
total_mito_MAPQH=$((${total_mito_MAPQH}/2)) | ||
total_dups_MAPQH=$(grep 'duplicates' ${output_pre}.MAPQ${MAPQ}.flagstat.txt | cut -d ' ' -f1) | ||
total_dups_MAPQH=$((${total_dups_MAPQH}/2)) | ||
|
||
rm ${output_pre}.idxstat.txt | ||
rm ${output_pre}.flagstat.txt | ||
|
||
rm ${output_pre}.MAPQ${MAPQ}.idxstat.txt | ||
rm ${output_pre}.MAPQ${MAPQ}.flagstat.txt | ||
|
||
#print to file | ||
echo "Total_Pairs $total_pairs" > ${output_pre}.MappingStats | ||
echo "Total_Pairs_Mapped $total_pairs_mapped" >> ${output_pre}.MappingStats | ||
echo "Total_Uniq_Mapped $total_uniq_mapped" >> ${output_pre}.MappingStats | ||
#echo "Total_Mito $total_mito" >> ${output_pre}.MappingStats | ||
echo "Total_Mito_Mapped $total_mito_mapped" >> ${output_pre}.MappingStats | ||
echo "Total_Dups $total_dups" >> ${output_pre}.MappingStats | ||
|
||
|
||
echo "Total_Pairs_MAPQ${MAPQ} $total_pairs_MAPQH" >> ${output_pre}.MappingStats | ||
echo "Total_Mito_MAPQ${MAPQ} $total_mito_MAPQH" >> ${output_pre}.MappingStats | ||
echo "Total_Dups_MAPQ${MAPQ} $total_dups_MAPQH" >> ${output_pre}.MappingStats | ||
|
||
rm $tmp_sam_file | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
input_bam=$1 | ||
|
||
# reading configure file | ||
curr_dir=`dirname $0` | ||
source ${curr_dir}/read_conf.sh | ||
read_conf "$2" | ||
read_conf "$3" | ||
|
||
map_dir=${OUTPUT_DIR}/mapping_result | ||
signal_dir=${OUTPUT_DIR}/signal | ||
mkdir -p $map_dir | ||
mkdir -p $signal_dir | ||
|
||
ff=${OUTPUT_DIR}/filtered_matrix/${CELL_CALLER}/barcodes.txt ## cell barcodes | ||
|
||
curr_dir=`dirname $0` | ||
|
||
## extract bam for cell and non-cells | ||
if [[ ! -e "${map_dir}/cell_barcodes.bam" ]]; then | ||
${PERL_PATH}/perl ${curr_dir}/src/extract_bam4Cells.pl --cellbarcode_file $ff --bam_file $input_bam \ | ||
--output_dir $map_dir --samtools_path $SAMTOOLS_PATH | ||
echo "The bam file was split between cell and non-cell!" | ||
fi | ||
|
||
|
||
## QC using cell barcodes bam | ||
if [[ ! -e "${OUTPUT_DIR}/summary/cell_barcodes.MappingStats" ]]; then | ||
echo "generate mapping stats for aggregated cell barcodes file..." | ||
bash ${curr_dir}/cell_mapping_qc.sh $map_dir $2 $3 | ||
fi | ||
|
||
unset PYTHONHOME | ||
unset PYTHONPATH | ||
ncore=$(nproc --all) | ||
ncore=$((${ncore}/2)) | ||
for file0 in $(find $map_dir -name "cell_barcodes.bam") | ||
do | ||
echo "generate bw file..." | ||
pre=$(basename $file0) | ||
pre=${pre/.bam/} | ||
fname_bw=${signal_dir}/${pre}.bw | ||
${SAMTOOLS_PATH}/samtools index -@ $ncore $file0 | ||
${DEEPTOOLS_PATH}/bamCoverage --numberOfProcessors max --normalizeUsing BPM \ | ||
--bam $file0 --binSize 20 --skipNonCoveredRegions \ | ||
--outFileName $fname_bw & | ||
echo "generate count around TSS..." | ||
${DEEPTOOLS_PATH}/computeMatrix reference-point -S $fname_bw -R $TSS \ | ||
-a 1200 -b 1200 -o ${signal_dir}/${pre}.aggregated.mtx.gz & | ||
wait | ||
done | ||
|
||
rm ${map_dir}/non_cell_barcodes.bam | ||
|
||
echo "Aggregated signal was generated for cell barcodes and non-cell barcodes!" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.