Mercurial > repos > konradpaszkiewicz > preppereadsforveletfasta
annotate 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 |
rev | line source |
---|---|
0
4d237a31970b
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 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
2 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
3 """ |
4d237a31970b
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. |
4d237a31970b
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 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
6 """ |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
7 import pkg_resources; |
4d237a31970b
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 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
9 import shlex, subprocess |
4d237a31970b
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 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
11 from stat import * |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
12 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
13 |
4d237a31970b
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__ ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
15 |
4d237a31970b
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 ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
17 |
4d237a31970b
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 ): |
4d237a31970b
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 ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
20 sys.exit() |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
21 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
22 def __main__(): |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
23 #Parse Command Line |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
24 s = 'preppereads.py: argv = %s\n' % (sys.argv) |
4d237a31970b
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 |
4d237a31970b
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) |
4d237a31970b
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] |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
28 input1 = sys.argv[2] |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
29 input2 = sys.argv[3] |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
30 outpe = sys.argv[4] |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
31 outsingletons = sys.argv[5] |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
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') |
4d237a31970b
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 # so will appear as blurb for file |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
34 try: |
4d237a31970b
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 ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
36 returncode = proc.wait() |
4d237a31970b
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 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
38 stderr = '' |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
39 buffsize = 1048576 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
40 try: |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
41 while True: |
4d237a31970b
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 ) |
4d237a31970b
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: |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
44 break |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
45 except OverflowError: |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
46 pass |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
47 if returncode != 0: |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
48 raise Exception, stderr |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
49 except Exception, e: |
4d237a31970b
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 preppereads.sh ' + str( e ) ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
51 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
52 out = open(outpe,'w') |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
53 #outpe_path = os.path.join(working_dir,'') |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
54 for line in open('pe.fq'): |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
55 out.write( "%s" % (line) ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
56 out.close() |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
57 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
58 out = open(outsingletons,'w') |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
59 #singletons_path = os.path.join(working_dir,'') |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
60 for line in open('single.fq'): |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
61 out.write( "%s" % (line) ) |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
62 out.close() |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
63 |
4d237a31970b
Migrated tool version 1.0.0 from old tool shed archive to new tool shed repository
konradpaszkiewicz
parents:
diff
changeset
|
64 if __name__ == "__main__": __main__() |