Or slightly more elegantly using SeqIO.write and a generator expression,
from Bio import SeqIO
import sys
fastafile, length = sys.argv[1], int(sys.argv[2])
trimmed = (entry[:length] for entry in SeqIO.parse(fastafile, "fasta"))
SeqIO.write(trimmed, sys.stdout, "fasta")
A simple sed command might do the trick if your fasta sequences are on one line (i.e. not wrapped):
sed --regexp-extended '/^>/! s/^(.{1,500}).*/\1/' input.fasta > output.fastaOr using awk (I like awk!):
awk '{print /^>/ ? $0 : substr($1, 1, 500)}' input.fasta > output.fastaThanks for the quick reply.
Can I use this command on CentOS Linux terminal directly or do I need to download any other package?
These commands should work on most Linux or Unix computers without installing any additional package.
Hi Frederic,
I have one more problem, Hope you can help me with that too
I have a single contig of around 5000 bp, which looks like
I want to have a multiple contigs of 100 bp, like
and so on...
What command should I use?
Best!
Hi, the thread A: How To Split One Big Sequence File Into Multiple Files With Less Than 1000 Seque might answer your question.
thanks Frederic, it works... thanks alot.
Cross posted (to Linkedin???)