<p>After contacting 10X genomics directly, I received the following response:</p>
<p>Please note that this is not 10x supported and is an untested work around.</p>
<p>Basically, what you can do is insert information from the gene expression BAM header into the VDJ BAM header and 'trick' bamtofastq to take the VDJ BAM. Let me outline the steps I took using the public data from <a href="https://www.10xgenomics.com/resources/datasets/integrated-gex-and-vdj-analysis-of-connect-generated-library-from-mouse-pbm-cs-2-standard-6-0-1" rel="nofollow noreferrer">https://www.10xgenomics.com/resources/datasets/integrated-gex-and-vdj-analysis-of-connect-generated-library-from-mouse-pbm-cs-2-standard-6-0-1</a>.</p>
<h1>Transfer VDJ BAM header to textfile</h1>
<p><code>samtools view -H SC5v2_mousePBMCs_1Kcells_Connect_single_channel_Multiplex_vdj_b_all_contig.bam &gt; vdj_b_all_contig.header </code></p>
<h1>Transfer @RG and @CO GEX BAM header lines to textfile</h1>
<p><code>samtools view -H SC5v2_mousePBMCs_1Kcells_Connect_single_channel_SC5v2_mousePBMCs_1Kcells_Connect_single_channel_count_sample_alignments.bam | grep -v '@SQ' | grep -v '@HD' | grep -v '@PG' &gt; gex-rg-co.header </code></p>
<h1>Concatenate the two text files</h1>
<p><code>cat vdj_b_all_contig.header gex-rg-co.header &gt; fixed.header </code></p>
<h1>Replace the VDJ BAM header with the fixed header</h1>
<p><code>samtools reheader fixed.header SC5v2_mousePBMCs_1Kcells_Connect_single_channel_Multiplex_vdj_b_all_contig.bam &gt; fixed.bam</code></p>
<h1>View the @RG line id field</h1>
<p><code>grep '@RG' gex-rg-co.header</code>
This will show the @RG line as follows for this public data I am using.</p>
<p>We need the highlighted content in the ID: field in the next step.</p>
<h1>Add RG tags to each read</h1>
<p><code>samtools addreplacerg -R SC5v2_mousePBMCs_1Kcells_Connect_single_channel:0:1:H3T2JDSX2:4 -o readgroup.bam fixed.bam </code></p>
<h1>Run 10x bamtofastq on the readgroup.bam /Users/Documents/tools/bamtofastq_macos readgroup.bam testbamtofastqonvdj</h1>
<p>This gives us matched R1 and R2 reads in the testbamtofastqonvdj folder.</p>
<p>One final note, in the final FASTQ set, be sure the R1 and R2 reads are written in the same order, i.e. the readnames match as you go down both. If you will map the reads with an aligner that uses insert size metrics, then it is important that the reads are not sorted by any genomic coordinate but rather are randomly sorted (samtools collate) or queryname sorted (samtools sort -n).</p>

CC BY-SA 4.0
2024-07-30T20:00:26.943Z
2024-07-30T20:00:26.943Z
h3ab74
<p>I asked <a href="https://bioinformatics.stackexchange.com/questions/7096/bam-to-gene-expression-matrix-umi-counts-per-gene-per-cell-10x">a similar question</a> in the past regarding the conversion of scRNASeq bam files to fastqs. I am familiar with the <code>bamtofastq</code> functionality in the cellranger pipeline. However, it seems to not work with bam files from my VDJ samples (i.e. T-cell and B-cell receptor sequences), returning the following error with no other output:</p>
<blockquote>
<p>bamtofastq v1.4.1
WARNING: no @RG (read group) headers found in BAM file. Splitting data by the GEM well marked in the corrected barcode tag.
Reads without a corrected barcode will not appear in output FASTQs'</p>
</blockquote>
<p>Now, I read <a href="https://www.biostars.org/p/9556827/" rel="nofollow noreferrer">this biostars post</a> indicating that this could be due to the fact that the bam file was not generated by cellranger, but I find that very unlikely given that it worked fine with the equivalent GEX (gene expression) sample.</p>
<p>So my question: how do I convert this VDJ bam to fastq? Most of the documentation I've read works primarily with GEX data, rather than VDJ, and given that <code>bamtofastq</code> worked fine for the GEX, why not with the VDJ? Is there a way around this?</p>
<p>Thanks,</p>
<p>UPDATE: I was able to edit the header of the file to add an @RG tag, however this did not fix the issue, and I got the following error instead:
Unrecognized 10x BAM file. For BAM files produced by older pipelines, use one of the following flags:
--gemcode   BAM files created with GemCode data using Longranger 1.0 - 1.3
--lr20      BAM files created with Longranger 2.0 using Chromium Genome data
--cr11      BAM files created with Cell Ranger 1.0-1.1 using Single Cell 3' v1 data</p>
<p>I'm beginning to question if this is even possible with VDJ data ..</p>
<p>P.S. This is the output of <code>samtools view -h file_vdj.bam | head</code> on the original bam file:</p>
<pre><code>@HD     VN:1.6  SO:coordinate
@SQ     SN:clonotype1_consensus_1       LN:524
@SQ     SN:clonotype1_consensus_2       LN:570
@SQ     SN:clonotype2_consensus_1       LN:485
@SQ     SN:clonotype2_consensus_2       LN:514
@SQ     SN:clonotype2_consensus_3       LN:507
@SQ     SN:clonotype2_consensus_4       LN:521
@SQ     SN:clonotype3_consensus_1       LN:563
@SQ     SN:clonotype3_consensus_2       LN:507
@SQ     SN:clonotype4_consensus_1       LN:524
@SQ     SN:clonotype5_consensus_1       LN:563
@SQ     SN:clonotype6_consensus_1       LN:719
@SQ     SN:clonotype7_consensus_1       LN:501
@SQ     SN:clonotype7_consensus_2       LN:630
@SQ     SN:clonotype7_consensus_3       LN:511
@SQ     SN:clonotype8_consensus_1       LN:549
@SQ     SN:clonotype8_consensus_2       LN:557
@SQ     SN:clonotype8_consensus_3       LN:495
@SQ     SN:clonotype9_consensus_1       LN:524
@SQ     SN:clonotype9_consensus_2       LN:524
@SQ     SN:clonotype9_consensus_3       LN:587
@SQ     SN:clonotype10_consensus_1      LN:580
@SQ     SN:clonotype11_consensus_1      LN:570
@SQ     SN:clonotype11_consensus_2      LN:574
@SQ     SN:clonotype12_consensus_1      LN:563
@SQ     SN:clonotype12_consensus_2      LN:517
@SQ     SN:clonotype12_consensus_3      LN:568
@SQ     SN:clonotype13_consensus_1      LN:526
@SQ     SN:clonotype13_consensus_2      LN:563
@SQ     SN:clonotype14_consensus_1      LN:538
@SQ     SN:clonotype15_consensus_1      LN:524
@SQ     SN:clonotype15_consensus_2      LN:524
@SQ     SN:clonotype15_consensus_3      LN:571
@SQ     SN:clonotype16_consensus_1      LN:500
@SQ     SN:clonotype16_consensus_2      LN:562
@SQ     SN:clonotype17_consensus_1      LN:570
@SQ     SN:clonotype17_consensus_2      LN:753
@SQ     SN:clonotype17_consensus_3      LN:586
@SQ     SN:clonotype18_consensus_1      LN:524
@SQ     SN:clonotype18_consensus_2      LN:538
@SQ     SN:clonotype19_consensus_1      LN:556
@SQ     SN:clonotype19_consensus_2      LN:560
@SQ     SN:clonotype20_consensus_1      LN:456
@SQ     SN:clonotype20_consensus_2      LN:568
@SQ     SN:clonotype21_consensus_1      LN:524
@SQ     SN:clonotype21_consensus_2      LN:538
@SQ     SN:clonotype22_consensus_1      LN:432
@SQ     SN:clonotype22_consensus_2      LN:448
@SQ     SN:clonotype22_consensus_3      LN:580
@SQ     SN:clonotype23_consensus_1      LN:539
@SQ     SN:clonotype23_consensus_2      LN:621
@SQ     SN:clonotype24_consensus_1      LN:552
@SQ     SN:clonotype24_consensus_2      LN:489
@SQ     SN:clonotype25_consensus_1      LN:502
@SQ     SN:clonotype25_consensus_2      LN:512
@SQ     SN:clonotype25_consensus_3      LN:469
@SQ     SN:clonotype26_consensus_1      LN:654
@SQ     SN:clonotype26_consensus_2      LN:519
@SQ     SN:clonotype27_consensus_1      LN:527
@SQ     SN:clonotype27_consensus_2      LN:504
@SQ     SN:clonotype28_consensus_1      LN:508
@SQ     SN:clonotype28_consensus_2      LN:589
@SQ     SN:clonotype29_consensus_1      LN:501
@SQ     SN:clonotype29_consensus_2      LN:523
@SQ     SN:clonotype29_consensus_3      LN:618
@SQ     SN:clonotype30_consensus_1      LN:495
@SQ     SN:clonotype30_consensus_2      LN:517
@SQ     SN:clonotype30_consensus_3      LN:546
@SQ     SN:clonotype31_consensus_1      LN:563
@SQ     SN:clonotype31_consensus_2      LN:563
@SQ     SN:clonotype31_consensus_3      LN:507
@SQ     SN:clonotype32_consensus_1      LN:486
@SQ     SN:clonotype32_consensus_2      LN:577
@SQ     SN:clonotype33_consensus_1      LN:521
@SQ     SN:clonotype33_consensus_2      LN:538
@SQ     SN:clonotype34_consensus_1      LN:552
@SQ     SN:clonotype34_consensus_2      LN:647
@SQ     SN:clonotype35_consensus_1      LN:501
@SQ     SN:clonotype35_consensus_2      LN:514
@SQ     SN:clonotype36_consensus_1      LN:499
@SQ     SN:clonotype36_consensus_2      LN:618
@SQ     SN:clonotype37_consensus_1      LN:656
@SQ     SN:clonotype37_consensus_2      LN:525
@SQ     SN:clonotype38_consensus_1      LN:524
@SQ     SN:clonotype38_consensus_2      LN:526
@SQ     SN:clonotype39_consensus_1      LN:705
@SQ     SN:clonotype39_consensus_2      LN:482
@SQ     SN:clonotype40_consensus_1      LN:431
@SQ     SN:clonotype40_consensus_2      LN:580
@SQ     SN:clonotype41_consensus_1      LN:481
@SQ     SN:clonotype41_consensus_2      LN:535
@SQ     SN:clonotype42_consensus_1      LN:509
@SQ     SN:clonotype42_consensus_2      LN:489
@SQ     SN:clonotype43_consensus_1      LN:663
@SQ     SN:clonotype43_consensus_2      LN:589
@SQ     SN:clonotype44_consensus_1      LN:540
@SQ     SN:clonotype44_consensus_2      LN:508
@SQ     SN:clonotype44_consensus_3      LN:508
@SQ     SN:clonotype45_consensus_1      LN:479
@SQ     SN:clonotype45_consensus_2      LN:501
@SQ     SN:clonotype45_consensus_3      LN:456
@SQ     SN:clonotype45_consensus_4      LN:476
@SQ     SN:clonotype46_consensus_1      LN:662
@SQ     SN:clonotype46_consensus_2      LN:506
@SQ     SN:clonotype47_consensus_1      LN:458
@SQ     SN:clonotype47_consensus_2      LN:529
@SQ     SN:clonotype48_consensus_1      LN:484
@SQ     SN:clonotype48_consensus_2      LN:547
@SQ     SN:clonotype49_consensus_1      LN:532
@SQ     SN:clonotype49_consensus_2      LN:526
@SQ     SN:clonotype49_consensus_3      LN:508
@SQ     SN:clonotype50_consensus_1      LN:481
@SQ     SN:clonotype50_consensus_2      LN:495
@SQ     SN:clonotype51_consensus_1      LN:502
@SQ     SN:clonotype52_consensus_1      LN:502
@SQ     SN:clonotype53_consensus_1      LN:502
@SQ     SN:clonotype54_consensus_1      LN:552
@SQ     SN:clonotype55_consensus_1      LN:552
@SQ     SN:clonotype55_consensus_2      LN:500
@SQ     SN:clonotype55_consensus_3      LN:489
@SQ     SN:clonotype55_consensus_4      LN:551
@SQ     SN:clonotype56_consensus_1      LN:489
@SQ     SN:clonotype57_consensus_1      LN:540
@SQ     SN:clonotype57_consensus_2      LN:542
@SQ     SN:clonotype58_consensus_1      LN:541
@SQ     SN:clonotype59_consensus_1      LN:541
@SQ     SN:clonotype60_consensus_1      LN:541
@SQ     SN:clonotype61_consensus_1      LN:541
@SQ     SN:clonotype62_consensus_1      LN:512
@SQ     SN:clonotype63_consensus_1      LN:440
@SQ     SN:clonotype64_consensus_1      LN:500
@SQ     SN:clonotype65_consensus_1      LN:505
@SQ     SN:clonotype65_consensus_2      LN:533
@SQ     SN:clonotype66_consensus_1      LN:505
@SQ     SN:clonotype66_consensus_2      LN:458
@SQ     SN:clonotype67_consensus_1      LN:495
@SQ     SN:clonotype68_consensus_1      LN:495
@SQ     SN:clonotype69_consensus_1      LN:657
@SQ     SN:clonotype70_consensus_1      LN:645
@SQ     SN:clonotype71_consensus_1      LN:645
@SQ     SN:clonotype72_consensus_1      LN:495
@SQ     SN:clonotype73_consensus_1      LN:492
@SQ     SN:clonotype74_consensus_1      LN:492
@SQ     SN:clonotype75_consensus_1      LN:535
@SQ     SN:clonotype76_consensus_1      LN:534
@SQ     SN:clonotype77_consensus_1      LN:471
@SQ     SN:clonotype78_consensus_1      LN:540
@SQ     SN:clonotype79_consensus_1      LN:540
@SQ     SN:clonotype80_consensus_1      LN:473
@SQ     SN:clonotype80_consensus_2      LN:458
@SQ     SN:clonotype80_consensus_3      LN:502
@SQ     SN:clonotype80_consensus_4      LN:515
@SQ     SN:clonotype81_consensus_1      LN:522
@SQ     SN:clonotype81_consensus_2      LN:560
@SQ     SN:clonotype82_consensus_1      LN:492
@SQ     SN:clonotype82_consensus_2      LN:436
@SQ     SN:clonotype83_consensus_1      LN:657
@SQ     SN:clonotype83_consensus_2      LN:544
@SQ     SN:clonotype84_consensus_1      LN:547
@SQ     SN:clonotype85_consensus_1      LN:547
@SQ     SN:clonotype86_consensus_1      LN:557
@SQ     SN:clonotype87_consensus_1      LN:562
@SQ     SN:clonotype88_consensus_1      LN:562
@SQ     SN:clonotype89_consensus_1      LN:562
@SQ     SN:clonotype90_consensus_1      LN:465
@SQ     SN:clonotype91_consensus_1      LN:504
@SQ     SN:clonotype92_consensus_1      LN:498
@SQ     SN:clonotype93_consensus_1      LN:716
@SQ     SN:clonotype93_consensus_2      LN:511
@SQ     SN:clonotype93_consensus_3      LN:471
@SQ     SN:clonotype94_consensus_1      LN:485
@SQ     SN:clonotype94_consensus_2      LN:529
@SQ     SN:clonotype95_consensus_1      LN:519
@SQ     SN:clonotype96_consensus_1      LN:507
@SQ     SN:clonotype97_consensus_1      LN:521
@SQ     SN:clonotype97_consensus_2      LN:529
@SQ     SN:clonotype98_consensus_1      LN:536
@SQ     SN:clonotype98_consensus_2      LN:577
@SQ     SN:clonotype99_consensus_1      LN:502
@SQ     SN:clonotype99_consensus_2      LN:502
@SQ     SN:clonotype100_consensus_1     LN:471
@SQ     SN:clonotype101_consensus_1     LN:580
@SQ     SN:clonotype102_consensus_1     LN:580
@SQ     SN:clonotype103_consensus_1     LN:580
@SQ     SN:clonotype104_consensus_1     LN:580
@SQ     SN:clonotype105_consensus_1     LN:553
@SQ     SN:clonotype106_consensus_1     LN:553
@SQ     SN:clonotype107_consensus_1     LN:490
@SQ     SN:clonotype108_consensus_1     LN:491
@SQ     SN:clonotype109_consensus_1     LN:517
@SQ     SN:clonotype110_consensus_1     LN:501
@SQ     SN:clonotype110_consensus_2     LN:508
@SQ     SN:clonotype111_consensus_1     LN:510
@SQ     SN:clonotype111_consensus_2     LN:453
@SQ     SN:clonotype112_consensus_1     LN:494
@SQ     SN:clonotype112_consensus_2     LN:473
@SQ     SN:clonotype113_consensus_1     LN:545
@SQ     SN:clonotype113_consensus_2     LN:508
@SQ     SN:clonotype114_consensus_1     LN:505
@SQ     SN:clonotype114_consensus_2     LN:514
@SQ     SN:clonotype115_consensus_1     LN:659
@SQ     SN:clonotype115_consensus_2     LN:681
@SQ     SN:clonotype116_consensus_1     LN:491
@SQ     SN:clonotype116_consensus_2     LN:621
@SQ     SN:clonotype117_consensus_1     LN:517
@SQ     SN:clonotype117_consensus_2     LN:573
@SQ     SN:clonotype118_consensus_1     LN:513
@SQ     SN:clonotype119_consensus_1     LN:535
@SQ     SN:clonotype119_consensus_2     LN:537
@SQ     SN:clonotype120_consensus_1     LN:497
@SQ     SN:clonotype120_consensus_2     LN:579
@SQ     SN:clonotype121_consensus_1     LN:507
@SQ     SN:clonotype121_consensus_2     LN:519
@SQ     SN:clonotype122_consensus_1     LN:548
@SQ     SN:clonotype122_consensus_2     LN:526
@SQ     SN:clonotype123_consensus_1     LN:572
@SQ     SN:clonotype123_consensus_2     LN:565
@SQ     SN:clonotype124_consensus_1     LN:449
@SQ     SN:clonotype125_consensus_1     LN:490
@SQ     SN:clonotype126_consensus_1     LN:494
@SQ     SN:clonotype127_consensus_1     LN:578
@SQ     SN:clonotype127_consensus_2     LN:574
@SQ     SN:clonotype128_consensus_1     LN:571
@SQ     SN:clonotype129_consensus_1     LN:526
@SQ     SN:clonotype129_consensus_2     LN:571
@PG     ID:cellranger
@PG     ID:samtools     PN:samtools     PP:cellranger   VN:1.12 CL:samtools sort -o /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam.sorted /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam
@PG     ID:samtools.1   PN:samtools     PP:samtools     VN:1.12 CL:samtools view -bS -o /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.bam /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam.sorted
@PG     ID:samtools.2   PN:samtools     PP:samtools.1   VN:1.20 CL:samtools view -H NS.2155.001.SI-TT-A1_i7---SI-TT-A1_i5.CD8_VDJ.bam
</code></pre>

CC BY-SA 4.0
2024-07-22T22:17:46.570Z
Sorry, needs a few more lines, might be a lot more names depending on how many chromosomes there are. `samtools view -h file_vdj.bam | head -n <linecount>`. I'm interested in either a read group tag, or the first aligned sequence.
gringer
CC BY-SA 4.0
2024-07-23T14:59:45.033Z
Thanks for your responses. I just added a little more! @gringer
h3ab74
CC BY-SA 4.0
2024-07-23T21:42:40.530Z
This header doesn't look complete. You had SN tags previously, but they're gone now. Can you please show the full header? I expect it'll be relevant because the header is mentioned in the warning message.
gringer
CC BY-SA 4.0
2024-07-24T18:56:19.027Z
I added the full header now @gringer
h3ab74
<sam><fastq><cellranger><10x><vdj>
Convert 10X VDJ .bam file to .fastq
# Convert 10X VDJ .bam file to .fastq

(Asked by: username_0 on 2024-07-18)

I asked a similar question in the past regarding the conversion of scRNASeq bam files to fastqs. I am familiar with the bamtofastq functionality in the cellranger pipeline. However, it seems to not work with bam files from my VDJ samples (i.e. T-cell and B-cell receptor sequences), returning the following error with no other output:

bamtofastq v1.4.1
WARNING: no @RG (read group) headers found in BAM file. Splitting data by the GEM well marked in the corrected barcode tag.
Reads without a corrected barcode will not appear in output FASTQs'

Now, I read this biostars post indicating that this could be due to the fact that the bam file was not generated by cellranger, but I find that very unlikely given that it worked fine with the equivalent GEX (gene expression) sample.
So my question: how do I convert this VDJ bam to fastq? Most of the documentation I've read works primarily with GEX data, rather than VDJ, and given that bamtofastq worked fine for the GEX, why not with the VDJ? Is there a way around this?
Thanks,
UPDATE: I was able to edit the header of the file to add an @RG tag, however this did not fix the issue, and I got the following error instead:
Unrecognized 10x BAM file. For BAM files produced by older pipelines, use one of the following flags:
--gemcode   BAM files created with GemCode data using Longranger 1.0 - 1.3
--lr20      BAM files created with Longranger 2.0 using Chromium Genome data
--cr11      BAM files created with Cell Ranger 1.0-1.1 using Single Cell 3' v1 data
I'm beginning to question if this is even possible with VDJ data ..
P.S. This is the output of samtools view -h file_vdj.bam | head on the original bam file:
@HD     VN:1.6  SO:coordinate
@SQ     SN:clonotype1_consensus_1       LN:524
@SQ     SN:clonotype1_consensus_2       LN:570
@SQ     SN:clonotype2_consensus_1       LN:485
@SQ     SN:clonotype2_consensus_2       LN:514
@SQ     SN:clonotype2_consensus_3       LN:507
@SQ     SN:clonotype2_consensus_4       LN:521
@SQ     SN:clonotype3_consensus_1       LN:563
@SQ     SN:clonotype3_consensus_2       LN:507
@SQ     SN:clonotype4_consensus_1       LN:524
@SQ     SN:clonotype5_consensus_1       LN:563
@SQ     SN:clonotype6_consensus_1       LN:719
@SQ     SN:clonotype7_consensus_1       LN:501
@SQ     SN:clonotype7_consensus_2       LN:630
@SQ     SN:clonotype7_consensus_3       LN:511
@SQ     SN:clonotype8_consensus_1       LN:549
@SQ     SN:clonotype8_consensus_2       LN:557
@SQ     SN:clonotype8_consensus_3       LN:495
@SQ     SN:clonotype9_consensus_1       LN:524
@SQ     SN:clonotype9_consensus_2       LN:524
@SQ     SN:clonotype9_consensus_3       LN:587
@SQ     SN:clonotype10_consensus_1      LN:580
@SQ     SN:clonotype11_consensus_1      LN:570
@SQ     SN:clonotype11_consensus_2      LN:574
@SQ     SN:clonotype12_consensus_1      LN:563
@SQ     SN:clonotype12_consensus_2      LN:517
@SQ     SN:clonotype12_consensus_3      LN:568
@SQ     SN:clonotype13_consensus_1      LN:526
@SQ     SN:clonotype13_consensus_2      LN:563
@SQ     SN:clonotype14_consensus_1      LN:538
@SQ     SN:clonotype15_consensus_1      LN:524
@SQ     SN:clonotype15_consensus_2      LN:524
@SQ     SN:clonotype15_consensus_3      LN:571
@SQ     SN:clonotype16_consensus_1      LN:500
@SQ     SN:clonotype16_consensus_2      LN:562
@SQ     SN:clonotype17_consensus_1      LN:570
@SQ     SN:clonotype17_consensus_2      LN:753
@SQ     SN:clonotype17_consensus_3      LN:586
@SQ     SN:clonotype18_consensus_1      LN:524
@SQ     SN:clonotype18_consensus_2      LN:538
@SQ     SN:clonotype19_consensus_1      LN:556
@SQ     SN:clonotype19_consensus_2      LN:560
@SQ     SN:clonotype20_consensus_1      LN:456
@SQ     SN:clonotype20_consensus_2      LN:568
@SQ     SN:clonotype21_consensus_1      LN:524
@SQ     SN:clonotype21_consensus_2      LN:538
@SQ     SN:clonotype22_consensus_1      LN:432
@SQ     SN:clonotype22_consensus_2      LN:448
@SQ     SN:clonotype22_consensus_3      LN:580
@SQ     SN:clonotype23_consensus_1      LN:539
@SQ     SN:clonotype23_consensus_2      LN:621
@SQ     SN:clonotype24_consensus_1      LN:552
@SQ     SN:clonotype24_consensus_2      LN:489
@SQ     SN:clonotype25_consensus_1      LN:502
@SQ     SN:clonotype25_consensus_2      LN:512
@SQ     SN:clonotype25_consensus_3      LN:469
@SQ     SN:clonotype26_consensus_1      LN:654
@SQ     SN:clonotype26_consensus_2      LN:519
@SQ     SN:clonotype27_consensus_1      LN:527
@SQ     SN:clonotype27_consensus_2      LN:504
@SQ     SN:clonotype28_consensus_1      LN:508
@SQ     SN:clonotype28_consensus_2      LN:589
@SQ     SN:clonotype29_consensus_1      LN:501
@SQ     SN:clonotype29_consensus_2      LN:523
@SQ     SN:clonotype29_consensus_3      LN:618
@SQ     SN:clonotype30_consensus_1      LN:495
@SQ     SN:clonotype30_consensus_2      LN:517
@SQ     SN:clonotype30_consensus_3      LN:546
@SQ     SN:clonotype31_consensus_1      LN:563
@SQ     SN:clonotype31_consensus_2      LN:563
@SQ     SN:clonotype31_consensus_3      LN:507
@SQ     SN:clonotype32_consensus_1      LN:486
@SQ     SN:clonotype32_consensus_2      LN:577
@SQ     SN:clonotype33_consensus_1      LN:521
@SQ     SN:clonotype33_consensus_2      LN:538
@SQ     SN:clonotype34_consensus_1      LN:552
@SQ     SN:clonotype34_consensus_2      LN:647
@SQ     SN:clonotype35_consensus_1      LN:501
@SQ     SN:clonotype35_consensus_2      LN:514
@SQ     SN:clonotype36_consensus_1      LN:499
@SQ     SN:clonotype36_consensus_2      LN:618
@SQ     SN:clonotype37_consensus_1      LN:656
@SQ     SN:clonotype37_consensus_2      LN:525
@SQ     SN:clonotype38_consensus_1      LN:524
@SQ     SN:clonotype38_consensus_2      LN:526
@SQ     SN:clonotype39_consensus_1      LN:705
@SQ     SN:clonotype39_consensus_2      LN:482
@SQ     SN:clonotype40_consensus_1      LN:431
@SQ     SN:clonotype40_consensus_2      LN:580
@SQ     SN:clonotype41_consensus_1      LN:481
@SQ     SN:clonotype41_consensus_2      LN:535
@SQ     SN:clonotype42_consensus_1      LN:509
@SQ     SN:clonotype42_consensus_2      LN:489
@SQ     SN:clonotype43_consensus_1      LN:663
@SQ     SN:clonotype43_consensus_2      LN:589
@SQ     SN:clonotype44_consensus_1      LN:540
@SQ     SN:clonotype44_consensus_2      LN:508
@SQ     SN:clonotype44_consensus_3      LN:508
@SQ     SN:clonotype45_consensus_1      LN:479
@SQ     SN:clonotype45_consensus_2      LN:501
@SQ     SN:clonotype45_consensus_3      LN:456
@SQ     SN:clonotype45_consensus_4      LN:476
@SQ     SN:clonotype46_consensus_1      LN:662
@SQ     SN:clonotype46_consensus_2      LN:506
@SQ     SN:clonotype47_consensus_1      LN:458
@SQ     SN:clonotype47_consensus_2      LN:529
@SQ     SN:clonotype48_consensus_1      LN:484
@SQ     SN:clonotype48_consensus_2      LN:547
@SQ     SN:clonotype49_consensus_1      LN:532
@SQ     SN:clonotype49_consensus_2      LN:526
@SQ     SN:clonotype49_consensus_3      LN:508
@SQ     SN:clonotype50_consensus_1      LN:481
@SQ     SN:clonotype50_consensus_2      LN:495
@SQ     SN:clonotype51_consensus_1      LN:502
@SQ     SN:clonotype52_consensus_1      LN:502
@SQ     SN:clonotype53_consensus_1      LN:502
@SQ     SN:clonotype54_consensus_1      LN:552
@SQ     SN:clonotype55_consensus_1      LN:552
@SQ     SN:clonotype55_consensus_2      LN:500
@SQ     SN:clonotype55_consensus_3      LN:489
@SQ     SN:clonotype55_consensus_4      LN:551
@SQ     SN:clonotype56_consensus_1      LN:489
@SQ     SN:clonotype57_consensus_1      LN:540
@SQ     SN:clonotype57_consensus_2      LN:542
@SQ     SN:clonotype58_consensus_1      LN:541
@SQ     SN:clonotype59_consensus_1      LN:541
@SQ     SN:clonotype60_consensus_1      LN:541
@SQ     SN:clonotype61_consensus_1      LN:541
@SQ     SN:clonotype62_consensus_1      LN:512
@SQ     SN:clonotype63_consensus_1      LN:440
@SQ     SN:clonotype64_consensus_1      LN:500
@SQ     SN:clonotype65_consensus_1      LN:505
@SQ     SN:clonotype65_consensus_2      LN:533
@SQ     SN:clonotype66_consensus_1      LN:505
@SQ     SN:clonotype66_consensus_2      LN:458
@SQ     SN:clonotype67_consensus_1      LN:495
@SQ     SN:clonotype68_consensus_1      LN:495
@SQ     SN:clonotype69_consensus_1      LN:657
@SQ     SN:clonotype70_consensus_1      LN:645
@SQ     SN:clonotype71_consensus_1      LN:645
@SQ     SN:clonotype72_consensus_1      LN:495
@SQ     SN:clonotype73_consensus_1      LN:492
@SQ     SN:clonotype74_consensus_1      LN:492
@SQ     SN:clonotype75_consensus_1      LN:535
@SQ     SN:clonotype76_consensus_1      LN:534
@SQ     SN:clonotype77_consensus_1      LN:471
@SQ     SN:clonotype78_consensus_1      LN:540
@SQ     SN:clonotype79_consensus_1      LN:540
@SQ     SN:clonotype80_consensus_1      LN:473
@SQ     SN:clonotype80_consensus_2      LN:458
@SQ     SN:clonotype80_consensus_3      LN:502
@SQ     SN:clonotype80_consensus_4      LN:515
@SQ     SN:clonotype81_consensus_1      LN:522
@SQ     SN:clonotype81_consensus_2      LN:560
@SQ     SN:clonotype82_consensus_1      LN:492
@SQ     SN:clonotype82_consensus_2      LN:436
@SQ     SN:clonotype83_consensus_1      LN:657
@SQ     SN:clonotype83_consensus_2      LN:544
@SQ     SN:clonotype84_consensus_1      LN:547
@SQ     SN:clonotype85_consensus_1      LN:547
@SQ     SN:clonotype86_consensus_1      LN:557
@SQ     SN:clonotype87_consensus_1      LN:562
@SQ     SN:clonotype88_consensus_1      LN:562
@SQ     SN:clonotype89_consensus_1      LN:562
@SQ     SN:clonotype90_consensus_1      LN:465
@SQ     SN:clonotype91_consensus_1      LN:504
@SQ     SN:clonotype92_consensus_1      LN:498
@SQ     SN:clonotype93_consensus_1      LN:716
@SQ     SN:clonotype93_consensus_2      LN:511
@SQ     SN:clonotype93_consensus_3      LN:471
@SQ     SN:clonotype94_consensus_1      LN:485
@SQ     SN:clonotype94_consensus_2      LN:529
@SQ     SN:clonotype95_consensus_1      LN:519
@SQ     SN:clonotype96_consensus_1      LN:507
@SQ     SN:clonotype97_consensus_1      LN:521
@SQ     SN:clonotype97_consensus_2      LN:529
@SQ     SN:clonotype98_consensus_1      LN:536
@SQ     SN:clonotype98_consensus_2      LN:577
@SQ     SN:clonotype99_consensus_1      LN:502
@SQ     SN:clonotype99_consensus_2      LN:502
@SQ     SN:clonotype100_consensus_1     LN:471
@SQ     SN:clonotype101_consensus_1     LN:580
@SQ     SN:clonotype102_consensus_1     LN:580
@SQ     SN:clonotype103_consensus_1     LN:580
@SQ     SN:clonotype104_consensus_1     LN:580
@SQ     SN:clonotype105_consensus_1     LN:553
@SQ     SN:clonotype106_consensus_1     LN:553
@SQ     SN:clonotype107_consensus_1     LN:490
@SQ     SN:clonotype108_consensus_1     LN:491
@SQ     SN:clonotype109_consensus_1     LN:517
@SQ     SN:clonotype110_consensus_1     LN:501
@SQ     SN:clonotype110_consensus_2     LN:508
@SQ     SN:clonotype111_consensus_1     LN:510
@SQ     SN:clonotype111_consensus_2     LN:453
@SQ     SN:clonotype112_consensus_1     LN:494
@SQ     SN:clonotype112_consensus_2     LN:473
@SQ     SN:clonotype113_consensus_1     LN:545
@SQ     SN:clonotype113_consensus_2     LN:508
@SQ     SN:clonotype114_consensus_1     LN:505
@SQ     SN:clonotype114_consensus_2     LN:514
@SQ     SN:clonotype115_consensus_1     LN:659
@SQ     SN:clonotype115_consensus_2     LN:681
@SQ     SN:clonotype116_consensus_1     LN:491
@SQ     SN:clonotype116_consensus_2     LN:621
@SQ     SN:clonotype117_consensus_1     LN:517
@SQ     SN:clonotype117_consensus_2     LN:573
@SQ     SN:clonotype118_consensus_1     LN:513
@SQ     SN:clonotype119_consensus_1     LN:535
@SQ     SN:clonotype119_consensus_2     LN:537
@SQ     SN:clonotype120_consensus_1     LN:497
@SQ     SN:clonotype120_consensus_2     LN:579
@SQ     SN:clonotype121_consensus_1     LN:507
@SQ     SN:clonotype121_consensus_2     LN:519
@SQ     SN:clonotype122_consensus_1     LN:548
@SQ     SN:clonotype122_consensus_2     LN:526
@SQ     SN:clonotype123_consensus_1     LN:572
@SQ     SN:clonotype123_consensus_2     LN:565
@SQ     SN:clonotype124_consensus_1     LN:449
@SQ     SN:clonotype125_consensus_1     LN:490
@SQ     SN:clonotype126_consensus_1     LN:494
@SQ     SN:clonotype127_consensus_1     LN:578
@SQ     SN:clonotype127_consensus_2     LN:574
@SQ     SN:clonotype128_consensus_1     LN:571
@SQ     SN:clonotype129_consensus_1     LN:526
@SQ     SN:clonotype129_consensus_2     LN:571
@PG     ID:cellranger
@PG     ID:samtools     PN:samtools     PP:cellranger   VN:1.12 CL:samtools sort -o /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam.sorted /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam
@PG     ID:samtools.1   PN:samtools     PP:samtools     VN:1.12 CL:samtools view -bS -o /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.bam /lustre03/project/6033481/4nanuq2/platform/novaseqRuns/230605_A00977_0647_AH53N7DSX7_2155NS01A/10x_cellcount_1/CD8VDJ_MPS12349777_F10_2/SC_VDJ_ASSEMBLER_CS/SC_MULTI_CORE/VDJ_T_CLONOTYPE_ASSIGNER/CLONOTYPE_ASSIGNER/WRITE_CONSENSUS_BAM/fork0/chnk0-u059a808644/files/consensus.sam.sorted
@PG     ID:samtools.2   PN:samtools     PP:samtools.1   VN:1.20 CL:samtools view -H NS.2155.001.SI-TT-A1_i7---SI-TT-A1_i5.CD8_VDJ.bam

**Tags:** sam, fastq, cellranger, 10x, vdj
> **Comments:**
> **username_1**: Sorry, needs a few more lines, might be a lot more names depending on how many chromosomes there are. `samtools view -h file_vdj.bam | head -n <linecount>`. I'm interested in either a read group tag, or the first aligned sequence.  
> **username_0**: Thanks for your responses. I just added a little more! @gringer  
> **username_1**: This header doesn't look complete. You had SN tags previously, but they're gone now. Can you please show the full header? I expect it'll be relevant because the header is mentioned in the warning message.  
> **username_0**: I added the full header now @gringer  

---

## 1 answers

### Answer by username_0 on 2024-07-30. Score: 1 | Accepted answer

After contacting 10X genomics directly, I received the following response:

Please note that this is not 10x supported and is an untested work around.

Basically, what you can do is insert information from the gene expression BAM header into the VDJ BAM header and 'trick' bamtofastq to take the VDJ BAM. Let me outline the steps I took using the public data from <https://www.10xgenomics.com/resources/datasets/integrated-gex-and-vdj-analysis-of-connect-generated-library-from-mouse-pbm-cs-2-standard-6-0-1>.

# Transfer VDJ BAM header to textfile

`samtools view -H SC5v2_mousePBMCs_1Kcells_Connect_single_channel_Multiplex_vdj_b_all_contig.bam > vdj_b_all_contig.header`

# Transfer @RG and @CO GEX BAM header lines to textfile

`samtools view -H SC5v2_mousePBMCs_1Kcells_Connect_single_channel_SC5v2_mousePBMCs_1Kcells_Connect_single_channel_count_sample_alignments.bam | grep -v '@SQ' | grep -v '@HD' | grep -v '@PG' > gex-rg-co.header`

# Concatenate the two text files

`cat vdj_b_all_contig.header gex-rg-co.header > fixed.header`

# Replace the VDJ BAM header with the fixed header

`samtools reheader fixed.header SC5v2_mousePBMCs_1Kcells_Connect_single_channel_Multiplex_vdj_b_all_contig.bam > fixed.bam`

# View the @RG line id field

`grep '@RG' gex-rg-co.header`
This will show the @RG line as follows for this public data I am using.

We need the highlighted content in the ID: field in the next step.

# Add RG tags to each read

`samtools addreplacerg -R SC5v2_mousePBMCs_1Kcells_Connect_single_channel:0:1:H3T2JDSX2:4 -o readgroup.bam fixed.bam`

# Run 10x bamtofastq on the readgroup.bam /Users/Documents/tools/bamtofastq\_macos readgroup.bam testbamtofastqonvdj

This gives us matched R1 and R2 reads in the testbamtofastqonvdj folder.

One final note, in the final FASTQ set, be sure the R1 and R2 reads are written in the same order, i.e. the readnames match as you go down both. If you will map the reads with an aligner that uses insert size metrics, then it is important that the reads are not sorted by any genomic coordinate but rather are randomly sorted (samtools collate) or queryname sorted (samtools sort -n).


---

