Mercurial > repos > cbib > fibronectin
comparison fibronectin/fibronectin_wrapper.py @ 0:0c6cfb9906f3 draft default tip
Uploaded
author | cbib |
---|---|
date | Wed, 10 Nov 2021 15:15:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:0c6cfb9906f3 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 Wrapper for fibronectin.py | |
5 """ | |
6 import pkg_resources | |
7 import logging, os, string, sys, tempfile, glob, shutil, types, urllib | |
8 import shlex, subprocess | |
9 from optparse import OptionParser, OptionGroup | |
10 from stat import * | |
11 | |
12 | |
13 log = logging.getLogger( __name__ ) | |
14 | |
15 assert sys.version_info[:2] >= ( 2, 4 ) | |
16 | |
17 def stop_err( msg ): | |
18 sys.stderr.write("%s\n" % msg) | |
19 sys.exit() | |
20 | |
21 def __main__(): | |
22 #Parse Command Line | |
23 s = 'fibronectin_wrapper.py: argv = %s\n' % (sys.argv) | |
24 argcnt = len(sys.argv) | |
25 fasta_file = sys.argv[1] | |
26 pattern = sys.argv[2] | |
27 restriction_site_5 = sys.argv[3] | |
28 restriction_site_3 = sys.argv[4] | |
29 install_dir = sys.argv[5] | |
30 extra_file_path = sys.argv[6]+"/" | |
31 report = sys.argv[7] | |
32 tmp_file_path = sys.argv[8] | |
33 tool_file_path = sys.argv[9]+"/" | |
34 try:# for test - needs this done | |
35 os.makedirs(extra_file_path) | |
36 except Exception as e: | |
37 stop_err('1- Error running fibronectin ' + str(e)) | |
38 cmdline = 'python %sfibronectin.py -i %s -o %s -p %s -5 %s -3 %s > /dev/null' % (tool_file_path, fasta_file, extra_file_path, pattern, restriction_site_5, restriction_site_3) | |
39 try: | |
40 proc = subprocess.Popen(args=cmdline, shell=True, stderr=subprocess.PIPE) | |
41 returncode = proc.wait() | |
42 # get stderr, allowing for case where it's very large | |
43 stderr = b'' | |
44 buffsize = 1048576 | |
45 try: | |
46 while True: | |
47 stderr += proc.stderr.read(buffsize) | |
48 if not stderr or len(stderr) % buffsize != 0: | |
49 break | |
50 except OverflowError: | |
51 pass | |
52 if returncode != 0: | |
53 raise Exception(stderr) | |
54 except Exception as e: | |
55 stop_err('2 -Error running fibronectin ' + str(e)) | |
56 png_path = os.path.join(extra_file_path,'distrib.png') | |
57 shutil.move(extra_file_path+"/fibronectin_report.html", report) | |
58 #rval = ['<html><head><title>Fibronectin Galaxy Composite Dataset </title></head><p/>'] | |
59 #rval.append('<div>%s<p/></div>' % (cmdline) ) | |
60 #rval.append('<div>This composite dataset is composed of the following files:<p/><ul>') | |
61 #rval.append( '<li><a href="%s" type="text/plain">%s </a>%s</li>' % (png_path,'Sequences','Sequences' ) ) | |
62 #rval.append( '</ul></div></html>' ) | |
63 #f = file(html_file,'w') | |
64 #f.write("\n".join( rval )) | |
65 #f.write('\n') | |
66 #f.close() | |
67 | |
68 if __name__ == "__main__": __main__() |