This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filtering a 10X generated .bam file based on a list of barcodes

Hello everyone,

Basically, I have clustered and annotated the barcodes in R, then I wanted to look at reads in several particular clusters in IGV. I generated a barcode list following the 10X tutorial as the picture below shown, briefly subset the clusters in R then tagged the barcodes with CB:Z: and saved as filter.txt. While I could generate a 2 Kb header file, the later step always gives me a 0 Kb filtered_SAM_body file.

I tried:

(following another thread)

samtools view -D CB:FILTER.txt BAMFILE.bam -h -b -o FILTEREDBAM.bam

===

(following the a third thread...[lost the page])

samtools view BAMFILE.bam | LC_ALL=C grep -F -f FILTER.txt > filtered_SAM_body

===

(modified 10X)

samtools view -H BAMFILE.bam > SAM_header

samtools view BAMFILE.bam -X INDEX.bai | LC_ALL=C grep -F -f FILTER.txt > filtered_SAM_body

===

(10X)

samtools view -H BAMFILE.bam > SAM_header

samtools view BAMFILE.bam  | LC_ALL=C grep -F -f FILTER.txt > filtered_SAM_body

===

I also tried adding CB: prior to filter path or removing CB:Z from the filter.txt file... none worked all gave me the 0 Kb file.

Any Suggestions will be very very very much appreciated.

Thank you.

List of barcodes generated following 10X tutorial

snrna-seq scrna-seq samtools bam rna-seq

Just double checking, but for the first approach, did you ensure your samtools is <=1.17?

Yes. took me sometime.... I deleted 1.19, suppose I unzipped 1.17 (wherein I couldn't find sourceme.bash). Eventually I figured out I was using the 1.10 version originally by typing just "samtools", I then changed to use the CellRanger built in samtools, which is 1.12.

The results were the same, blank filtered bam files.

This code is weird:

samtools view 20230514_CellRanger_Output/Backup_before_filtering/20230511_Mut_7/outs/possorted_genome_bam.bam | LC_ALL=C grep -F -f SubsetBam/Filters/mut_7_L5ET_filter.txt > filtered_SAM_body

It should just be:

samtools view INPUT.BAM | grep -F -f headers.txt > filtered.sam

Also we don't need to see the file names. You should use placeholders like I have above. It makes it easier to debug the code.

Are you sure the LC_ALL=C is not required or is that change defeating the point of adding that modifier in the first place?

I think that might be relevant here (users on the forum don't go out of their way to add that setting unless something weird happened without that setting). But you could be right - maybe the OP on the original thread with this setting had some special requirement. I'll see if I can find that thread.

EDIT: I could not find that thread. I'd recommend trying it both with and without the LC_ALL=C (maybe a limited grep -m100) to see if anything changes.

Changed that, thank you very much and sorry for the inconvenience.

0 answers

No answers yet.

Log in to answer this question.