How to split multi run bam files and add read groups
I have a few hundred WGS samples that came without read groups. I need to run GATK on these samples, but before running GATK, I would like to add read groups. So here is my approach:
Split input bam file by flowcell lane:
# for lane 6
samtools view -H infile.bam > header.sam
(cat header.sam; samtools view input.bam | grep 'HS2000-1015_160:6') | samtools view -S > lane6.bam
# then add read group
PICARD="/usr/local/genome/picard_latest/picard.jar"
java -jar ${PICARD} AddOrReplaceReadGroups \
I=lane6.bam \
O=output_lane6.bam \
RGID=${flowcell}.6 \
RGLB=lib1 \
RGPL=ILLUMINA \
RGPU=unit1 \
RGSM=20
# then merge all bam files
samtools merge output_lane6.bam output_lane7.bam output_lane8.bam
Is this approach valid? I was wondering if there is any efficient way to do this?
Particularly,
(cat header.sam; samtools view input.bam | grep 'HS2000-1015_160:6') | samtools view -S > lane6.bam ?
Is there a better way to split by lane without using grep as I do not have this HS2000-1015_160:6 information readily available?
• 66 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Can you explain if this question is substantially different than one you had previously posted here: How to assign read groups to bam files?
We went over an extensive discussion about this in that thread. If this question is not different then we may have to close it.
@genomax, It is the same question, I was wondering if this approach would be better.
Better in what way? Do you not know which samples were run on which lanes or was this a pooled sample run on multiple lanes?