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