title | layout | header | ||||
---|---|---|---|---|---|---|
Introduction to Data Wrangling |
single |
|
Sometimes it is essential to know the length distribution of your sequences. It may be your newly assembled scaffolds or it might be a genome, that you wish to know the size of chromosomes, or it could just be any multi fasta sequence file.
Save this as a script, make it an executable and run on a fasta file:
#!/usr/bin/python
from Bio import SeqIO
import sys
cmdargs = str(sys.argv)
for seq_record in SeqIO.parse(str(sys.argv[1]), "fasta"):
output_line = '%s\t%i' % \
(seq_record.id, len(seq_record))
print(output_line)
To run:
chmod +x seq_length.py
seq_length.py input_file.fasta
This will print length for all the sequences in that file.
Bioawk is an extension of the awk written by Heng Li. It is available to donwload from this link. Installation is easy too. To get sequence length, run it as:
bioawk -c fastx '{print $name length($seq)}' input.fasta
Output will be similar to the above script and can be redicrected to any file if you want.