This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I Download a Portion of a Random Bacterial Genome

I wish to download a snippet ~ 20kb - 60kb in length of a random bacterial genome. How would I go about randomizing it? I think that once I understand how to pick from the consortium of bacteria I should be able to figure out how to take a random portion of the genome.

Cheers, Dragos

python biopython

Once you have a bacterial genome, you can grab a random piece of it with BBMap like this:

mutate.sh in=bacteria.fa out=snippet.fa fraction=0.01

That will yield a piece of the genome 1% of the original genome size. You can also add snps and indels with that tool if you want. If you just want one piece of the primary chromosome add the flag "reads=1" to stop processing after the first contig; otherwise it will give you a random 1% of every contig.

1 answer

This gives random bacterial genome to stdout.

awk 'BEGIN{OFS=FS="\t"}NR>3{print $20}' \
    <(wget -qO- ftp://ftp.ncbi.nlm.nih.gov/genomes/refseq/bacteria/assembly_summary.txt) \
    | shuf -n1 \
    | awk 'BEGIN{OFS=FS="/"}{print $0,$NF"_genomic.fna.gz"}' \
    | wget -i - -qO- \
    | gunzip

@Brian's solution can be tacked on at the end to get a random piece of that random genome :)

Log in to answer this question.