首页>itarticle>a simple python script to convert fasta file to csv format
a simple python script to convert fasta file to csv format
admin1月 30, 20210
I have searched online for converting FASTA file into CSV format for sequence visualization like the output from GPCRdb.org, but I didn’t find what I want. So I wrote this simple and dirty script to convert FASTA to CSV.
input = sys.argv[1] ifnot os.path.exists(input): print('nError: File "%s" is not exist!n' % input) sys.exit()
output = 'output.csv' if len(sys.argv) > 2: output = sys.argv[2]
# Read in FASTA file = open(input, 'r') lines_i = file.readlines() seq = ''
for l in lines_i: if l[0] == '>': 'Fasta head line' seq_id = l.strip() else: 'Sequence line' seq += l.strip()
file.close()
print('The Input file is: %s' %input)
# Convert FASTA to CSV l = [] lines = [str(seq_id) + 'n'] for i, c in enumerate(seq): l.append(c) if i % 60 == 59: lines.append(','.join(l) + 'n') l = []
This script is unmature but good for use. It can convert a FASTA file containing one sequence into a CSV file, each residue are a single elemnt of CSV file. It is verty straightfoward so anyone can simply modify it for their own purpose.
近期评论