forked from synbiochem/galaxytools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrainWriter.py
79 lines (73 loc) · 2.83 KB
/
strainWriter.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 19 09:29:08 2019
@author: Pablo Carbonell, SYNBIOCHEM
@description: Run the plasmid writer
"""
import argparse
import pandas as pd
import csv
import os
import re
import subprocess
import shutil
def configureTool(args):
template = os.path.join( os.path.dirname( __file__), 'primers.sh' )
if not os.path.exists( args.tempFolder ):
os.makedirs( args.tempFolder )
script = os.path.join( args.tempFolder, 'job.sh' )
log = os.path.join( args.tempFolder, 'log.sh' )
if args.plate is not None:
plate = args.plate
else:
plate = 'None'
df = pd.read_csv(args.plasmids)
icelist = [str(x) for x in df['ICE']]
icelist = ' '.join( icelist )
with open( template ) as hin, open( script, 'w' ) as hout:
for line in hin:
line = re.sub( '{{enzymes}}', args.enzymes, line )
line = re.sub( '{{temp}}', args.temp, line )
line = re.sub( '{{plates}}', plate, line )
line = re.sub( '{{plasmids}}', icelist, line )
hout.write( line )
return script, log
def arguments():
parser = argparse.ArgumentParser(description='Read list of primers and output primer plate. Pablo Carbonell, SYNBIOCHEM, 2019')
parser.add_argument('-iceServer', default=os.getenv('ICE_SERVER'),
help='ICE server url.')
parser.add_argument('-iceUser', default=os.getenv('ICE_USERNAME'),
help='ICE user.')
parser.add_argument('-icePass', default=os.getenv('ICE_PASSWORD'),
help='ICE password.')
parser.add_argument('-enzymes', default="MlyI",
help='Comma separated restriction enzymes.')
parser.add_argument('-temp', default="60",
help='Melting temperature.')
parser.add_argument('-plate',
help='Existing plate.')
parser.add_argument('-plasmids',
help='Plasmid csv file.')
parser.add_argument('-output',
help='Output csv file.')
parser.add_argument('-tempFolder',
help='Tool temporary folder.')
return parser
if __name__ == '__main__':
raise Exception('Tool not implemented yet')
parser = arguments()
args = parser.parse_args()
script, log = configureTool( args )
logout = open(log, 'w')
print('Running primers script...')
subprocess.call( "bash "+script, shell=True, stdout=logout, stderr=logout )
print('Done.')
os.chdir(os.getenv( 'SBC_ASSEMBLY_PATH' ))
outfile1 = 'primer_1_primer_phospho.csv'
outfile2 = 'primer_1_primer_nonphospho.csv'
if os.path.exists( outfile1 ):
shutil.copyfile( outfile1, args.output )
os.unlink( outfile1 )
if os.path.exists( outfile2 ):
os.unlink( outfile2 )