-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_folder.py
67 lines (40 loc) · 1.13 KB
/
convert_folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
from Bio import SeqIO
import sys
import os
import re
import glob
import sys
import subprocess as sp
digits = re.compile(r'(\d+)')
def tokenize(filename):
return tuple(int(token) if match else token
for token, match in
((fragment, digits.search(fragment))
for fragment in digits.split(filename)))
#get details on all seqs in a folder (with specified extension_
folder = sys.argv[1] #working folder
outfolder=sys.argv[2]
fmt = sys.argv[3]
outfmt = str(sys.argv[4])
if fmt=="fa" or fmt=="fna":
fmt="fasta"
if fmt=="fq":
fmt="fastq"
if fmt=="gbk":
fmt="genbank"
print 'in format:', fmt, 'out format', outfmt
filelist=glob.glob(folder)
filelist.sort(key=tokenize)
print filelist
#Theo Allnutt 2016
#Converts files of different sequence format
#usage: convert.py infile informat outformat [see http://biopython.org/wiki/SeqIO]
for i in filelist:
'''
f = open(i,'rb')
outputfile = outfolder+"/"+i.split("/")[-1].split(".")[0] + "."+outfmt
g = open(outputfile,'w')
count = SeqIO.convert(f, fmt,g, outfmt)
print("Converted %i records" % count)
'''