10x 单细胞产生的BAM文件可以根据所需的barcode进行过滤。首先,将所需的cell barcode条形码放入 filter.txt中。并在barcode前面加上CB:Z:
,以确保专门过滤BAM文件中的该标记,格式如下所示:
其次,将$ BAM_FILE设置为要过滤的BAM文件的位置及名称。例如,如果BAM文件被命名为“ possorted_genome_bam.bam ” ,则使用以下命令。
代码语言:javascript复制export BAM_FILE='/your path /possorted_genome_bam.bam'
# Save the header lines
samtools view -@ 16 -H $BAM_FILE > SAM_header
# Filter alignments using filter.txt. Use LC_ALL=C to set C locale instead of UTF-8
samtools view -@ 16 $BAM_FILE | LC_ALL=C grep -F -f filter.txt > filtered_SAM_body
# Combine header and body
cat SAM_header filtered_SAM_body > filtered.sam
# Convert filtered.sam to BAM format
samtools view -@ 16 -b filtered.sam > filtered.bam
参考: https://kb.10xgenomics.com/hc/en-us/articles/360022448251-Is-there-way-to-filter-the-BAM-file-produced-by-10x-pipelines-with-a-list-of-barcodes-