Mercurial > repos > modencode-dcc > bamedit
comparison bamedit.py @ 0:34450ff137d3 draft
Uploaded
author | modencode-dcc |
---|---|
date | Fri, 18 Jan 2013 10:53:14 -0500 |
parents | |
children | 1ceeba7b95a4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:34450ff137d3 |
---|---|
1 #purpose: python wrapper for bamedit tool | |
2 #author: Ziru Zhou | |
3 #date: October, 2012 | |
4 | |
5 import sys, subprocess, tempfile, shutil, glob, os, os.path, gzip | |
6 from galaxy import eggs | |
7 import pkg_resources | |
8 pkg_resources.require( "simplejson" ) | |
9 import simplejson | |
10 | |
11 CHUNK_SIZE = 1024 | |
12 | |
13 def main(): | |
14 options = simplejson.load( open( sys.argv[1] ) ) | |
15 | |
16 #experiment_name = '_'.join( options['bamout'] ) | |
17 | |
18 if(options['action'] == "merge"): | |
19 cmdline = "samtools merge %s %s %s" % ( options['bamout'], options['input1'], options['input2'] ) | |
20 if('input3' in options): | |
21 cmdline = "samtools merge %s %s %s %s" % ( options['bamout'], options['input1'], options['input2'], options['input3'] ) | |
22 elif (options['action'] == "split"): | |
23 cmdline = "bash /mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/bamedit/split.sh %s %s %s" % ( options['bamout'], options['bamout2'], options['input1'] ) | |
24 elif (options['action'] == "pileup"): | |
25 cmdline = "perl /mnt/galaxyTools/galaxy-central/tools/modENCODE_DCC_tools/bamedit/pileup.pl %s %s %s %s %s" % ( options['input1'], options['input2'], options['bamout'], options['bamname'], options['refname'] ) | |
26 elif (options['action'] == "filter"): | |
27 cmdline = "samtools view -q %s %s -bo %s" % ( options['quality'], options['input1'], options['bamout'] ) | |
28 | |
29 #create tempdir for output files and stderr reports | |
30 tmp_dir = tempfile.mkdtemp() | |
31 stderr_name = tempfile.NamedTemporaryFile().name | |
32 proc = subprocess.Popen( args=cmdline, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) ) | |
33 proc.wait() | |
34 | |
35 #Do not terminate if error code, allow dataset (e.g. log) creation and cleanup | |
36 if proc.returncode: | |
37 stderr_f = open( stderr_name ) | |
38 while True: | |
39 chunk = stderr_f.read( CHUNK_SIZE ) | |
40 if not chunk: | |
41 stderr_f.close() | |
42 break | |
43 sys.stderr.write( chunk ) | |
44 | |
45 if __name__ == "__main__": main() |