Mercurial > repos > konradpaszkiewicz > interproscan
comparison interproscan.py @ 0:49e20fa2c66d
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
| author | konradpaszkiewicz |
|---|---|
| date | Tue, 07 Jun 2011 17:27:16 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:49e20fa2c66d |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 """ | |
| 4 Classes encapsulating decypher tool. | |
| 5 James E Johnson - University of Minnesota | |
| 6 """ | |
| 7 import pkg_resources; | |
| 8 import logging, os, string, sys, tempfile, glob, shutil, types, urllib | |
| 9 import shlex, subprocess | |
| 10 from optparse import OptionParser, OptionGroup | |
| 11 from stat import * | |
| 12 | |
| 13 | |
| 14 log = logging.getLogger( __name__ ) | |
| 15 | |
| 16 assert sys.version_info[:2] >= ( 2, 4 ) | |
| 17 | |
| 18 def stop_err( msg ): | |
| 19 sys.stderr.write( "%s\n" % msg ) | |
| 20 sys.exit() | |
| 21 | |
| 22 def __main__(): | |
| 23 #Parse Command Line | |
| 24 s = 'interproscan.py: argv = %s\n' % (sys.argv) | |
| 25 # print >> sys.stderr, s # so will appear as blurb for file | |
| 26 argcnt = len(sys.argv) | |
| 27 working_dir = sys.argv[1] | |
| 28 input = sys.argv[2] | |
| 29 format = sys.argv[3] | |
| 30 output = sys.argv[4] | |
| 31 #Convert all spaces in ORF header to underscores | |
| 32 cmdline = 'sed \'s/ /_/\' %s > temp.fa' % (input) | |
| 33 #print >> sys.stderr, cmdline | |
| 34 try: | |
| 35 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) | |
| 36 returncode = proc.wait() | |
| 37 # get stderr, allowing for case where it's very large | |
| 38 stderr = '' | |
| 39 buffsize = 1048576 | |
| 40 try: | |
| 41 while True: | |
| 42 stderr += proc.stderr.read( buffsize ) | |
| 43 if not stderr or len( stderr ) % buffsize != 0: | |
| 44 break | |
| 45 except OverflowError: | |
| 46 pass | |
| 47 if returncode != 0: | |
| 48 raise Exception, stderr | |
| 49 except Exception, e: | |
| 50 stop_err( 'Error running sed ' + str( e ) ) | |
| 51 | |
| 52 cmdline = 'iprscan -cli -nocrc -i temp.fa -o temp.iprscan -goterms -seqtype p -altjobs -format %s -appl hmmpfam > /dev/null' % (format) | |
| 53 #print >> sys.stderr, cmdline # so will appear as blurb for file | |
| 54 try: | |
| 55 proc = subprocess.Popen( args=cmdline, shell=True, stderr=subprocess.PIPE ) | |
| 56 returncode = proc.wait() | |
| 57 # get stderr, allowing for case where it's very large | |
| 58 stderr = '' | |
| 59 buffsize = 1048576 | |
| 60 try: | |
| 61 while True: | |
| 62 stderr += proc.stderr.read( buffsize ) | |
| 63 if not stderr or len( stderr ) % buffsize != 0: | |
| 64 break | |
| 65 except OverflowError: | |
| 66 pass | |
| 67 if returncode != 0: | |
| 68 raise Exception, stderr | |
| 69 except Exception, e: | |
| 70 stop_err( 'Error running iprscan ' + str( e ) ) | |
| 71 | |
| 72 out = open(output,'w') | |
| 73 #outpe_path = os.path.join(working_dir,'') | |
| 74 for line in open('temp.iprscan'): | |
| 75 out.write( "%s" % (line) ) | |
| 76 out.close() | |
| 77 | |
| 78 if __name__ == "__main__": __main__() |
