Or with sed:
$ samtools view -H file.bam|grep @SQ|sed 's/@SQ\tSN:\|LN://g'' > genome.txt
I am using BEDTOOLS and the following command to get the coverage file:
$ ./genomeCoverageBed -ibam ~/GG_project/trim/ecoli.bam -g <genome file=""> > ~/GG_project/trim/coverage
where ecoli.bam is my sorted bam file, and coverage is my output file
From where do I get the genome file? How do I create a genome file?? Specifically I would need a ecoli.genome file.
To make a genome file (for bed tools) using reference genome
1) Use samtools to generate fasta index
samtools faidx lyrata_genome.fa
- this will create a lyrata_genome.fa.fai (index file)
But, this index file won't work as genome file due to file format issue (mainly more than required number of columns).
2) take the index file, then use awk
awk -v OFS='\t' {'print $1,$2'} lyrata_genome.fa.fai > lyrata_genomeFile.txt
if space desired between columns do this
awk {'print $1,"",$2'} lyrata_genome.fa.fai > lyrata_genomeFile.txt
if 'chr' needs to be added infront of the chromosome/scaffold names do this
awk {'print "chr"$1,"",$2'} lyrata_genome.fa.fai > lyrata_genomeFile.txt
If you are referring to the '-g' flag you can simply use the 'fetchChromSizes' script (link is to a 64bit Linux binary).
fetchChromSizes hg19 > hg19.chrom.sizes
'hg19' is an example, but any of the other UCSC genomes can be used, e.g. mm9, sacCer3, etc.
The '>' is a redirect to a new file.
The output is a tab-delimited file of chromosome name followed by it length.
I hope that helps.
This is too old , but I just saw it :)
you can use this with the bam file itself if it has the header:
samtools view -H my.bam | grep -P '^@SQ' | cut -f 2,3 | awk 'BEGIN{OFS="\t"}{split($1, a, ":"); split($2, b, ":"); print a[2], b[2] }'
Or with sed:
$ samtools view -H file.bam|grep @SQ|sed 's/@SQ\tSN:\|LN://g'' > genome.txt
Actually I found also using genomeCoverageBed with Ibam do not require -g :D
Thanks, though newer versions of many bedtools seem generally more forgiving with regard to the -g option. Being stuck with 2.25 it's still required and the samtools faidx option requires htslib...
There is an unnecessary single quote at the end. Should be:
$ samtools view -H file.bam|grep @SQ|sed 's/@SQ\tSN:\|LN://g' > genome.txt
I think this answer might be helpful although I am late.
I saw this from the help page of genomeCoverageBed:
Tips:
One can use the UCSC Genome Browser's MySQL database to extract
chromosome sizes. For example, H. sapiens:
mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \
"select chrom, size from hg19.chromInfo" > hg19.genome
samtools faidx output is pretty much what a genome file looks like. So run that on your reference genome.
Log in to answer this question.