annotate data_manager/data_manager_snpEff_download.py @ 6:a329eda0cdff draft default tip

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