finswimmer pointed out adding RG tags is best practice but technically not necessary. In any case I will give it a go as it is not working for me as it is.
Hi All,
I am running freebayes as:
freebayes -f Gasterosteus_aculeatus.BROADS1.dna.toplevel.fa -C 5 -L p1list.txt --populations p1pops.txt> plate1.vcf
with p1list.txt (the path is the same for all files):
/path/to/S-176.sorted.bam
/path/to/S-177.sorted.bam
/path/to/S-178.sorted.bam
/path/to/S-179.sorted.bam
/path/to/S-180.sorted.bam
/path/to/S-181.sorted.bam
/path/to/S-182.sorted.bam
/path/to/S-184.sorted.bam
/path/to/S-185.sorted.bam
/path/to/S-186.sorted.bam
...
and p1pops.txt:
S-176.sorted pop1
S-177.sorted pop1
S-178.sorted pop1
S-179.sorted pop1
S-180.sorted pop1
S-181.sorted pop2
S-182.sorted pop2
S-184.sorted pop2
S-185.sorted pop2
S-186.sorted pop2
...
yet if I do
awk '{if ($1 == "#CHROM"){print NF-9; exit}}' plate1.vcf
1
which means most of my samples have been ignored or discarded. Freebayes is version: v1.2.0-2-g29c4002.
I'd be grateful for any idea of what is going on.
1 answer
As finswimmer said, you need to add read group tags to each bam:
To call variants in a population of samples, each alignment must have a read group identifier attached to it (RG tag), and the header of the BAM file in which it resides must map the RG tags to sample names (SM). Furthermore, read group IDs must be unique across all the files used in the analysis. One read group cannot map to multiple samples. The reason this is required is that freebayes operates on a virtually merged BAM stream provided by the BamTools API. If merging the files in your analysis using bamtools merge would generate a file in which multiple samples map to the same RG, the files are not suitable for use in population calling, and they must be modified.
The freebayes readme also suggests a solution in case your bam don't have RG tags: you can stream your bam through bamaddrg and pipe directly to freebayes.
Technically it is not neccessary because even without a ReadGroup it is a valid bam file. But there are many downstream analyse programs that need this information, e.g. for joint variant calling, like you like to do, that need this information. So it is best practice to include this information from the beginning regardless what your final goal is.
Saying this you can of course use bamaddrg as a workaround. But I would recommend to fix your bam file by adding the readgroup with the sample name using samtools addreplacerg or picard AddOrReplaceReadGroups.
fin swimmer
One thing that is not clear from bamaddrg is whether the option -L (list of files) is then needed. Is it?
Log in to answer this question.
With yourI you havent't passed a sample name via ReadGroup during alignment, freebayes will just enumerate them. I guess this is not what you like to do?awkcommand, you just print out the content of the 9th column before the last column, in the line where the first column is#CHROM. Saying this you will print out the sample name of the first sample in your vcf.fin swimmer
EDIT: Sorry, your command should print the number of samples and not the content of the column. Therefore there had to in
$.are you saying I should have set a ReadGroup tag to each bam file (corresponding to the IDs in the populations file?) for freebayes to correctly ID the bam files as belonging to different IDs?
This would be best-practice, yes. But it isn't neccessary.
What's the output of:
fin swimmer
Ok, I tried to add RG tags and it is just basically a fail. I can add tags, but freebayes still does not like them. Given a file for ID x
adds a tag (at least, I can see a tag in the file and I get no error), but to no avail:
so either there is no pleasing freebayes or samtools is not adding all the tags I am specifying.
What's the output from:
and
?
Have you used
x.bamin yourfreebayescommand?fin swimmer
technically I used not just x.bam but w whole lot of bams (sorted) generated by bowtie2. Using a real sample name:
Here the sample name is missing. If you really used the command you used above this line should look like this:
(Or whatever you take for
x)Try using
'around the the values in thesamtoolscommand (even if it wasn't necessary in my test)fin swimmer
and