Last active
May 15, 2021 22:08
-
-
Save anamariaelek/18218a213a360977395f1e07801f1354 to your computer and use it in GitHub Desktop.
Add unique cell identifiers, merge and split bams.
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
#!/bin/bash | |
#$ -N sinto | |
#$ -cwd | |
#$ -q long-sl7,mem_512_12h,mem_512 | |
#$ -l virtual_free=50G,h_rt=12:00:00,disk=50G | |
#$ -M anamaria.elek@crg.eu | |
#$ -o sinto.out | |
#$ -pe smp 16 | |
#$ -j y | |
NCORE=16 | |
WDIR="/users/asebe/aelek/proj/Ptf1A/scATAC/sinto" | |
NAMES="e10_WT e10_KO e13_KO_Sept2020 e13_WT_July2020" | |
OUTDIR="bam" | |
OUTBAM=$OUTDIR"/Ptf1A.RG.bam" | |
CELLS="../txt/CIClusters.txt" | |
BARCODE="CI" | |
SAMTOOLS_PATH="/users/asebe/aelek/bin/samtools-1.12" | |
sinto_addtags () { | |
local NAME=$1 | |
local BAM=../CellRanger/$NAME/outs/possorted_bam.bam | |
local OUTPUT=bam/$NAME.bam | |
local TAGFILE=../txt/$NAME.txt | |
echo $(date): Adding tags to $BAM | |
sinto addtags -p $NCORE -b $BAM -f $TAGFILE -o $OUTPUT | |
echo $(date): Added tags to $OUTPUT | |
} | |
echo $(date): Starting | |
cd $WDIR | |
mkdir $OUTDIR | |
for NAME in $NAMES; do sinto_addtags "$NAME" & done | |
wait | |
BAMS=$( ls $OUTDIR/*bam ) | |
for BAM in $BAMS; do | |
echo $(date): Indexing $BAM | |
${SAMTOOLS_PATH}/samtools index -@ $NCORE $BAM | |
echo $(date): Getting header from $BAM | |
RG=${BAM%%bam}txt | |
${SAMTOOLS_PATH}/samtools view -H $BAM | grep '@RG' > $RG | |
done | |
wait | |
echo $(date): Merging bams | |
${SAMTOOLS_PATH}/samtools view -H $BAM | grep '@RG' -v > $OUTDIR/header.txt | |
RGS=$( ls bam/*txt) | |
cat $RGS >> $OUTDIR/header.txt | |
${SAMTOOLS_PATH}/samtools merge -@ $NCORE -h $HEADER $OUTBAM $BAMS | |
${SAMTOOLS_PATH}/samtools index -@ $NCORE $OUTBAM | |
echo $(date): Filtering barcodes | |
sinto filterbarcodes -b $OUTBAM -c $CELLS --barcodetag $BARCODE | |
echo $(date): Done! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment