This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BedtoBam error: Why is this?

Hello every one, I repeatedly encountered this error whie trying to get bam from bed using the command below. I have tried to see solutions from previous question but it hasnt worked. also consulted the command usage and no way.

bedtools bedtobam -i x.bed -g y.fasta > x.bam

the error is also shown below, what am I doing wrong or what is wrong with my fasta file?

Less than the req'd two fields were encountered in the genome file (y.fasta) at line 1. Exiting.

rna-seq bedtobam getfasta bedtools

What makes you think the argument to -g is a fasta file? Documentation suggests differently. Googling for "bedtools genome file" should put you on the right track.

Are you sure -g expects fasta? If I remember correct it only requires chromosome sizes file in 2 columns.

The usage says -g <genome> . then it say fai should work with bedtools in the documentation

fai is the index file of your reference sequence file. You can create it with samtools faidx <genome>. And this file works, because the first two columns in this file contain exactly the information bedtools expect - the sequence name and it's length.

fin swimmer

1 answer

a genome file is not a fasta file. https://bedtools.readthedocs.io/en/latest/content/general-usage.html#genome-file-format

which simply lists the names of the chromosomes (or scaffolds, etc.) and their size (in basepairs).

I was able to get the bam by first getting the genome file (from the command below) that has only chr name and length then using this in the bedtobam command.

cat file.fa | awk '$0 ~ ">" {print c; c=0;printf substr($0,2,100) "\t"; } $0 !~ ">" {c+=length($0);} END { print c; }' > xx.genome

Thanks

Log in to answer this question.