annotate data_manager/data_manager_snpEff_download.py @ 1:85a23e2dd92b draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
author iuc
date Tue, 07 Jun 2016 10:11:50 -0400
parents 9ac823a8b328
children 847b0f43c0e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
1 #!/usr/bin/env python
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
2 import gzip
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
3 import json
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
4 import optparse
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
5 import os
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
6 import re
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
7 import subprocess
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
8 import sys
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
9
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
10
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
11 def stop_err(msg):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
12 sys.stderr.write(msg)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
13 sys.exit(1)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
14
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
15
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
16 def fetch_databases(jar_path, genome_list=None):
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
17 snpDBs = dict()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
18 (snpEff_dir, snpEff_jar) = os.path.split(jar_path)
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
19 databases_path = 'databases.out'
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
20 databases_output = open(databases_path, 'w')
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
21 args = [ 'java', '-jar' ]
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
22 args.append( snpEff_jar )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
23 args.append( 'databases' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
24 # tmp_stderr = tempfile.NamedTemporaryFile( prefix = "tmp-data-manager-snpEff-stderr" )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
25 # databases_output = open(databases_path)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
26 # proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno(), stderr=tmp_stderr.fileno() )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
27 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stdout=databases_output.fileno() )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
28 return_code = proc.wait()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
29 if return_code:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
30 sys.exit( return_code )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
31 databases_output.close()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
32 try:
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
33 fh = open(databases_path, 'r')
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
34 for i, line in enumerate(fh):
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
35 fields = line.split('\t')
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
36 if len(fields) >= 2:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
37 genome_version = fields[0].strip()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
38 if genome_list and genome_version not in genome_list:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
39 continue
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
40 if genome_version.startswith("Genome") or genome_version.startswith("-"):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
41 continue
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
42 description = fields[1].strip()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
43 snpDBs[genome_version] = description
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
44 except Exception as e:
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
45 stop_err( 'Error parsing %s %s\n' % (databases_path, str( e )) )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
46 else:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
47 fh.close()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
48 return snpDBs
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
49
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
50
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
51 def getOrganismNames(jar_path, genomes, organisms):
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
52 genome_list = genomes.split(',')
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
53 organism_list = organisms.split(',') if organisms else []
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
54 if len(genome_list) != len(organism_list):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
55 descriptions = []
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
56 snpDBdict = fetch_databases(jar_path, genome_list=genome_list)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
57 for genome in snpDBdict:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
58 descriptions.append(snpDBdict[genome] if genome in snpDBdict else genome)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
59 return ','.join(descriptions)
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
60 return organisms
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
61
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
62
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
63 def getSnpeffVersion(jar_path):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
64 snpeff_version = 'SnpEff ?.?'
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
65 (snpEff_dir, snpEff_jar) = os.path.split(jar_path)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
66 stderr_path = 'snpeff.err'
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
67 stderr_fh = open(stderr_path, 'w')
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
68 args = [ 'java', '-jar' ]
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
69 args.append( snpEff_jar )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
70 args.append( '-h' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
71 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir, stderr=stderr_fh.fileno() )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
72 return_code = proc.wait()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
73 if return_code != 255:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
74 sys.exit( return_code )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
75 stderr_fh.close()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
76 fh = open(stderr_path, 'r')
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
77 for line in fh:
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
78 m = re.match('^[Ss]npEff version (SnpEff)\s*(\d+\.\d+).*$', line)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
79 if m:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
80 snpeff_version = m.groups()[0] + m.groups()[1]
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
81 break
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
82 fh.close()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
83 return snpeff_version
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
84
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
85
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
86 # Starting with SnpEff 4.1 the .bin files contain the SnpEff version:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
87 # Example - the first 3 line of GRCh37.75/snpEffectPredictor.bin (uncompressed):
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
88 #
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
89 # SnpEff 4.1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
90 # CHROMOSOME 2 1 0 179197 GL000219.1 false
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
91 # CHROMOSOME 3 1 0 81347269 HSCHR17_1 false
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
92 def getSnpeffVersionFromFile(path):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
93 snpeff_version = None
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
94 try:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
95 fh = gzip.open(path, 'rb')
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
96 buf = fh.read(100)
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
97 lines = buf.splitlines()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
98 m = re.match('^(SnpEff)\s+(\d+\.\d+).*$', lines[0].strip())
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
99 if m:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
100 snpeff_version = m.groups()[0] + m.groups()[1]
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
101 fh.close()
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
102 except Exception as e:
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
103 stop_err( 'Error parsing SnpEff version from: %s %s\n' % (path, str( e )) )
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
104 return snpeff_version
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
105
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
106
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
107 # Download human database 'hg19'
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
108 # java -jar snpEff.jar download -v hg19
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
109 #
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
110 # <command>java -jar \$SNPEFF_JAR_PATH/snpEff.jar download -c \$JAVA_JAR_PATH/snpEff.config $genomeVersion > $logfile </command>
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
111 #
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
112 # snpEffectPredictor.bin
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
113 # regulation_HeLa-S3.bin
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
114 # regulation_pattern = 'regulation_(.+).bin'
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
115 def download_database(data_manager_dict, target_directory, jar_path, config, genome_version, organism):
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
116 # get data_dir from config
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
117 # ---
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
118 # Databases are stored here
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
119 # E.g.: Information for 'hg19' is stored in data_dir/hg19/
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
120 #
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
121 # Note: Since version 2.1 you can use tilde ('~') as first character to refer to your home directory
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
122 # ---
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
123 # data_dir = ~/snpEff/data/
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
124 data_dir = target_directory
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
125 (snpEff_dir, snpEff_jar) = os.path.split(jar_path)
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
126 args = [ 'java', '-jar' ]
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
127 args.append( jar_path )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
128 args.append( 'download' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
129 args.append( '-c' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
130 args.append( config )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
131 args.append( '-dataDir' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
132 args.append( data_dir )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
133 args.append( '-v' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
134 args.append( genome_version )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
135 proc = subprocess.Popen( args=args, shell=False, cwd=snpEff_dir )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
136 return_code = proc.wait()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
137 if return_code:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
138 sys.exit( return_code )
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
139 # search data_dir/genome_version for files
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
140 regulation_pattern = 'regulation_(.+).bin'
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
141 # annotation files that are included in snpEff by a flag
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
142 annotations_dict = {'nextProt.bin': '-nextprot', 'motif.bin': '-motif'}
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
143 genome_path = os.path.join(data_dir, genome_version)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
144 snpeff_version = getSnpeffVersion(jar_path)
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
145 key = snpeff_version + '_' + genome_version
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
146 if os.path.isdir(genome_path):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
147 for root, dirs, files in os.walk(genome_path):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
148 for fname in files:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
149 if fname.startswith('snpEffectPredictor'):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
150 # if snpEffectPredictor.bin download succeeded
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
151 name = genome_version + (' : ' + organism if organism else '')
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
152 # version = getSnpeffVersionFromFile(os.path.join(root,fname))
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
153 data_table_entry = dict(key=key, version=snpeff_version, value=genome_version, name=name, path=data_dir)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
154 _add_data_table_entry( data_manager_dict, 'snpeffv_genomedb', data_table_entry )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
155 else:
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
156 m = re.match(regulation_pattern, fname)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
157 if m:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
158 name = m.groups()[0]
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
159 data_table_entry = dict(key=key, version=snpeff_version, genome=genome_version, value=name, name=name)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
160 _add_data_table_entry( data_manager_dict, 'snpeffv_regulationdb', data_table_entry )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
161 elif fname in annotations_dict:
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
162 value = annotations_dict[fname]
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
163 name = value.lstrip('-')
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
164 data_table_entry = dict(key=key, version=snpeff_version, genome=genome_version, value=value, name=name)
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
165 _add_data_table_entry( data_manager_dict, 'snpeffv_annotations', data_table_entry )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
166 return data_manager_dict
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
167
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
168
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
169 def _add_data_table_entry( data_manager_dict, data_table, data_table_entry ):
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
170 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
171 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get( data_table, [] )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
172 data_manager_dict['data_tables'][data_table].append( data_table_entry )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
173 return data_manager_dict
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
174
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
175
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
176 def main():
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
177 # Parse Command Line
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
178 parser = optparse.OptionParser()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
179 parser.add_option( '-j', '--jar_path', dest='jar_path', action='store', type="string", default=None, help='snpEff.jar path' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
180 parser.add_option( '-c', '--config', dest='config', action='store', type="string", default=None, help='snpEff.config path' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
181 parser.add_option( '-g', '--genome_version', dest='genome_version', action='store', type="string", default=None, help='genome_version' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
182 parser.add_option( '-o', '--organism', dest='organism', action='store', type="string", default=None, help='organism name' )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
183 (options, args) = parser.parse_args()
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
184
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
185 filename = args[0]
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
186
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
187 params = json.loads( open( filename ).read() )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
188 target_directory = params[ 'output_data' ][0]['extra_files_path']
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
189 os.mkdir( target_directory )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
190 data_manager_dict = {}
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
191
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
192 # Create SnpEff Reference Data
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
193 for genome_version, organism in zip(options.genome_version.split(','), getOrganismNames(options.jar_path, options.genome_version, options.organism).split(',')):
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
194 download_database( data_manager_dict, target_directory, options.jar_path, options.config, genome_version, organism )
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
195
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
196 # save info to json file
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
197 open( filename, 'wb' ).write( json.dumps( data_manager_dict ) )
0
9ac823a8b328 Uploaded
iuc
parents:
diff changeset
198
1
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
199 if __name__ == "__main__":
85a23e2dd92b planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/data_managers/data_manager_snpeff commit 88c982c5adcd32b11d98428fc554a4fdfcc19584
iuc
parents: 0
diff changeset
200 main()