comparison preppereads.py @ 0:4d237a31970b default tip

Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
author konradpaszkiewicz
date Tue, 07 Jun 2011 17:42:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4d237a31970b
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 = 'preppereads.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 input1 = sys.argv[2]
29 input2 = sys.argv[3]
30 outpe = sys.argv[4]
31 outsingletons = sys.argv[5]
32 cmdline = '/users/galaxy/galaxyscripts/prepare_pe_reads_for_velvet.sh %s %s %s %s %s %s > /dev/null' % (input1, '1.fastq', input2, '2.fastq', 'single.fq', 'pe.fq')
33 #print >> sys.stderr, cmdline # so will appear as blurb for file
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 preppereads.sh ' + str( e ) )
51
52 out = open(outpe,'w')
53 #outpe_path = os.path.join(working_dir,'')
54 for line in open('pe.fq'):
55 out.write( "%s" % (line) )
56 out.close()
57
58 out = open(outsingletons,'w')
59 #singletons_path = os.path.join(working_dir,'')
60 for line in open('single.fq'):
61 out.write( "%s" % (line) )
62 out.close()
63
64 if __name__ == "__main__": __main__()