5
$\begingroup$

I am trying to reproduce some results of a scRNASeq experiment. However I am new to the server-side aspect of such analyses and am very confused at the moment.

The data provided by the authors of the paper is in .BAM format and from there I wish to derive a gene expression matrix (UMI counts per gene per cell). The authors stated that they did this using the 10X genomics pipeline, however it seems that .BAM outputs are sort of the "final version" of the pipeline and, the pipeline only really deals with truly raw sequencing files (bcl/fastq). I am trying to learn how to do all this processing myself as I will need to eventually. Unfortunately, most of the documents I have read end up making me more confused. I know BAM files are technically already processed and aligned but, how would I get the counts from the file?

I have considered converting it back to fastq format and following the pipeline from the beginning, but it just seems like I would be moving backwards by doing such.

I have also found some R packages that can integrate BAM files in the environment like Rsamtools, but I would much rather do this on the server and then upload a csv into R for the downstream analysis as the files are +60GB each.

Essentially I am just asking for some advice, or a vignette/article I can read that would clear up how to proceed with the BAM outputs to derive the gene expression data. I have already read the cellranger pages on the 10X genomics website but they were of no help in answering this quesion.

Thank you for your time,

$\endgroup$
0

2 Answers 2

6
$\begingroup$

How to re-analyze 10X BAM files?

This is a great question and honestly, I don't think there was an easy way to do this at the time the question was asked. The reason is that if you want to re-do the authors' analysis to get the gene expression (gene-cell / feature-barcode) matrix and they used cellranger (the official 10X pipeline software) to do that, you will need FASTQ files as input - because "10x pipelines require sequencer FASTQs (with embedded barcodes) as input."

Therefore, to get FASTQ files from 10X BAM files, there's a relatively new tool provided by 10X Genomics: bamtofastq. Then you can simply use those FASTQ files as input to cellranger.

More info here: https://support.10xgenomics.com/docs/bamtofastq

How to correctly download 10X BAM files from NCBI?

The only caveat is that you need a BAM file generated directly by 10X's cellranger (or the respective 10X pipeline, if not dealing with gene expression) - that means that a BAM file obtained by downloading an SRA from NCBI and converting to BAM won't work; you need to get the original BAM file directly (often found among the originally submitted files, under "Original format").

To give you some additional help here (because figuring this out is also not trivial): an original 10X BAM file (if originally submitted in this format) can be downloaded from NCBI using prefetch from sra-tools, specifying the --type option - for example:

prefetch --type TenX --max-size 100000000 SRR5167880

Because the file was larger than the default limit of 20GB, I also had to increase it by specifying the --max-size option.

Alternatively, you can follow the official 10X Instructions to Download and Process BAM files of 1.3 Million Brain Cells.

I know this is an old thread but I'm hoping my answer will be helpful to anyone who has the same question (like me).

$\endgroup$
1
  • 1
    $\begingroup$ This is the simplest approach (if the process’s data is not available on GEO). Computing the UMI count matrix for 10x Genomics data is already implemented in Cell Ranger and if the same version is used it should reproduce the results of the study. $\endgroup$ Commented Mar 12, 2021 at 15:14
4
$\begingroup$

You should be able to parse out what you need using the tags in the .bam. 10xGenomics' website says what tags they add.

https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/output/bam

Going backwards would also involve parsing the tags, because you have to make two fastq files, and a simple bam -> fastq pipeline won't do that correctly.

$\endgroup$
9
  • $\begingroup$ Could you be more specific please? I'm very new to this procedure and bash scripting in general. $\endgroup$
    – h3ab74
    Commented Feb 21, 2019 at 22:13
  • 1
    $\begingroup$ Yes, 10xGenomics single cell bams have the genes called in the bam tags. support.10xgenomics.com/single-cell-gene-expression/software/… And no, samtools fastq will not make paired end fastqs suitable to rerun through cellranger, because the read data from the read containing the cell barcode and UMI will not have its own line in the bams. $\endgroup$
    – swbarnes2
    Commented Feb 25, 2019 at 16:45
  • $\begingroup$ @swbarnes2 There are indeed many tags, but isn't the UMI tag different than UMI counts? So how would I derive the expression matrix from these said tags? Thank you btw for your answer! $\endgroup$
    – h3ab74
    Commented Feb 25, 2019 at 18:50
  • $\begingroup$ Each read has its UMI as a bam tag. You can go through the bam line by line and figure out which reads were assigned to what cell barcode, UMI and gene. $\endgroup$
    – swbarnes2
    Commented Feb 25, 2019 at 20:18
  • $\begingroup$ This reverse process is also complicated by the fact that error-correction is performed on the barcodes and UMIs as well. For scRNA-seq, you typically start with 4 FASTQs: UMIs, barcodes, R1, and R2. There will likely be errors in those sequences, so barcodes/UMIs are corrected for by comparing to a whitelist of known input barcodes. You can take a look at the "Feature Barcoding Tags" section of the 10x support page @swbarnes2 listed to see what tags to look for. As mentioned, it's not a simple BAM -> FASTQ operation, but you should be able to do it $\endgroup$ Commented Sep 27, 2019 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.