-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBAM_download2.py
executable file
·68 lines (49 loc) · 1.57 KB
/
BAM_download2.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os.path
import re
import sys
from subprocess import Popen
from subprocess import PIPE
from multiprocessing import Pool
delete_bams = False
def format_gtdownload(url):
cmd = ""
cmd += "ionice -c2 /pod/pstore/groups/brookslab/bin/GeneTorrent/GeneTorrent-3.8.7/cghub/bin/gtdownload -c "
gtrepo = re.search("(gtrepo\S+?.com)", url).group(1)
if gtrepo == "gtrepo-osdc-tcga.annailabs.com":
cmd += "/scratch/jakutagawa/RNA-seq/keys/AKUTAGAWA_bionimbus_pcawg_tcga_180209.pem "
else:
cmd += ""
# cmd += "-v "
cmd += "%s" % url
return cmd
def remove_bams(batch_file):
#print ("Removing bams from file %s" % batch_file
p = Popen("awk '{print $2}' %s | xargs -n 1 rm " % batch_file, shell=True)
p.wait()
p = Popen("awk '{print $2\".bai\"}' %s | xargs -n 1 rm " % batch_file, shell=True)
p.wait()
return
def run_md5(num,batch):
p = Popen("python do-md5.py %s" % (batch), shell=True)
p.wait()
return
def runCMD(cmd):
p = Popen(cmd, shell=True)
p.wait()
def run_commands(threads,cmd_list):
waitlist = []
uuid_list = []
jb_proc = None
batch = 1
p = Pool(threads)
for i, _ in enumerate(p.imap_unordered(runCMD, cmd_list), 1):
sys.stderr.write('Downloading bams...\rdone {0:%}'.format(i/len(cmd_list)))
sys.stderr.write('\n')
p.close()
urls = sys.argv[1]
infile = open(urls,'r')
download_commands = []
for line in infile:
uuid = ((line.rstrip()).split("/"))[-1]
download_commands.append(format_gtdownload(line.rstrip()))
run_commands(10,download_commands)