-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmapreads.py
29 lines (22 loc) · 1008 Bytes
/
mapreads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import tempfile, os, shutil
import subprocess
def get_temp_filename(filename, tempdir=None):
if tempdir is None:
tempdir = tempfile.mkdtemp(prefix='mapreads_')
return tempdir, os.path.join(tempdir, filename)
def bowtie_map_reads(indexpath, readfile, params=[], outputfile=None):
if outputfile is None:
_, outputfile = get_temp_filename('out.map')
cmd = 'bowtie %s %s %s %s' % (" ".join(params), indexpath, readfile,
outputfile)
args = ['bowtie'] + params + [indexpath, readfile, outputfile]
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(out, err) = p.communicate()
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, cmd)
return outputfile, out, err
if __name__ == '__main__':
outfile, out, err = bowtie_map_reads('random', 'genome-reads.fa', params=['-f'])
print err
print 'output in:', outfile