0
|
1 import sys
|
|
2
|
|
3 if len(sys.argv) < 3:
|
|
4 exit("Not enough arguments passed, pleas provide names of input- and output file")
|
|
5
|
|
6 input_name = sys.argv[1]
|
|
7 output_name = sys.argv[2]
|
|
8
|
|
9 from Bio import GenBank
|
|
10
|
|
11 try: seq_record = GenBank.RecordParser().parse(open(input_name))
|
|
12 except: exit("Error reading %s, check file correctness." % input_name)
|
|
13
|
|
14 try: out_file = open(output_name, 'w')
|
|
15 except IOError as e:
|
|
16 exit("Error trying to open '%s': {1}".format(e.errno, e.strerror))
|
|
17
|
|
18 accession = definition = ''
|
|
19 if seq_record.accession[0] != '': accession = '|gb|'+seq_record.accession[0]
|
|
20 if seq_record.definition != '': definition = '|'+seq_record.definition
|
|
21
|
|
22 out_file.write(">gi|%s%s%s\n" % (seq_record.gi,accession,definition))
|
|
23
|
|
24 i = 0
|
|
25 while i < len(seq_record.sequence):
|
|
26 out_file.write(seq_record.sequence[i:i+70]+"\n")
|
|
27 i += 70
|
|
28
|
|
29 out_file.close()
|