comparison repmatch_gff3_util.py @ 5:53cbf79396d7 draft

Uploaded
author greg
date Sat, 28 Nov 2015 14:54:22 -0500
parents 94e374d13037
children d10ae3aeebc8
comparison
equal deleted inserted replaced
4:1cea96c461a2 5:53cbf79396d7
19 pyplot.rc('ytick.major', size=10.00) 19 pyplot.rc('ytick.major', size=10.00)
20 pyplot.rc('lines', linewidth=4.00) 20 pyplot.rc('lines', linewidth=4.00)
21 pyplot.rc('axes', linewidth=3.00) 21 pyplot.rc('axes', linewidth=3.00)
22 pyplot.rc('font', family='Bitstream Vera Sans', size=32.0) 22 pyplot.rc('font', family='Bitstream Vera Sans', size=32.0)
23 23
24 PLOT_FORMATS = ['png', 'pdf', 'svg']
25 COLORS = 'krb' 24 COLORS = 'krb'
26 25
27 26
28 class Replicate(object): 27 class Replicate(object):
29 28
252 251
253 def gff_row(cname, start, end, score, source, type='.', strand='.', phase='.', attrs={}): 252 def gff_row(cname, start, end, score, source, type='.', strand='.', phase='.', attrs={}):
254 return (cname, source, type, start, end, score, strand, phase, gff_attrs(attrs)) 253 return (cname, source, type, start, end, score, strand, phase, gff_attrs(attrs))
255 254
256 255
257 def get_temporary_plot_path(plot_format): 256 def get_temporary_plot_path():
258 """ 257 """
259 Return the path to a temporary file with a valid image format 258 Return the path to a temporary file with a valid image format
260 file extension that can be used with bioformats. 259 file extension that can be used with bioformats.
261 """ 260 """
262 tmp_dir = tempfile.mkdtemp(prefix='tmp-repmatch-') 261 tmp_dir = tempfile.mkdtemp(prefix='tmp-repmatch-')
263 fd, name = tempfile.mkstemp(suffix='.%s' % plot_format, dir=tmp_dir) 262 fd, name = tempfile.mkstemp(suffix='.pdf', dir=tmp_dir)
264 os.close(fd) 263 os.close(fd)
265 return name 264 return name
266 265
267 266
268 def process_files(dataset_paths, galaxy_hids, method, distance, step, replicates, up_limit, low_limit, output_files, 267 def process_files(dataset_paths, galaxy_hids, method, distance, step, replicates, up_limit, low_limit, output_files,
269 plot_format, output_summary, output_orphan, output_detail, output_key, output_histogram): 268 output_summary, output_orphan, output_detail, output_key, output_histogram):
270 output_histogram_file = output_files in ["all"] and method in ["all"] 269 output_histogram_file = output_files in ["all"] and method in ["all"]
271 if len(dataset_paths) < 2: 270 if len(dataset_paths) < 2:
272 return 271 return
273 if method == 'all': 272 if method == 'all':
274 match_methods = METHODS.keys() 273 match_methods = METHODS.keys()
282 step, 281 step,
283 replicates, 282 replicates,
284 up_limit, 283 up_limit,
285 low_limit, 284 low_limit,
286 output_files, 285 output_files,
287 plot_format,
288 output_summary, 286 output_summary,
289 output_orphan, 287 output_orphan,
290 output_detail, 288 output_detail,
291 output_key, 289 output_key,
292 output_histogram) 290 output_histogram)
293 if output_histogram_file: 291 if output_histogram_file:
294 tmp_histogram_path = get_temporary_plot_path(plot_format) 292 tmp_histogram_path = get_temporary_plot_path()
295 frequency_histogram([stat['distribution'] for stat in [statistics]], 293 frequency_histogram([stat['distribution'] for stat in [statistics]],
296 tmp_histogram_path, 294 tmp_histogram_path,
297 METHODS.keys()) 295 METHODS.keys())
298 shutil.move(tmp_histogram_path, output_histogram) 296 shutil.move(tmp_histogram_path, output_histogram)
299 297
300 298
301 def perform_process(dataset_paths, galaxy_hids, method, distance, step, num_required, up_limit, low_limit, output_files, 299 def perform_process(dataset_paths, galaxy_hids, method, distance, step, num_required, up_limit, low_limit, output_files,
302 plot_format, output_summary, output_orphan, output_detail, output_key, output_histogram): 300 output_summary, output_orphan, output_detail, output_key, output_histogram):
303 output_detail_file = output_files in ["all"] and output_detail is not None 301 output_detail_file = output_files in ["all"] and output_detail is not None
304 output_key_file = output_files in ["all"] and output_key is not None 302 output_key_file = output_files in ["all"] and output_key is not None
305 output_orphan_file = output_files in ["all", "simple_orphan"] and output_orphan is not None 303 output_orphan_file = output_files in ["all", "simple_orphan"] and output_orphan is not None
306 output_histogram_file = output_files in ["all"] and output_histogram is not None 304 output_histogram_file = output_files in ["all"] and output_histogram is not None
307 replicates = [] 305 replicates = []
456 orphan.midpoint+1, 454 orphan.midpoint+1,
457 orphan.value, 455 orphan.value,
458 orphan.distance, 456 orphan.distance,
459 orphan.replicate.id)) 457 orphan.replicate.id))
460 if output_histogram_file: 458 if output_histogram_file:
461 tmp_histogram_path = get_temporary_plot_path(plot_format) 459 tmp_histogram_path = get_temporary_plot_path()
462 frequency_histogram([freq], tmp_histogram_path) 460 frequency_histogram([freq], tmp_histogram_path)
463 shutil.move(tmp_histogram_path, output_histogram) 461 shutil.move(tmp_histogram_path, output_histogram)
464 return {'distribution': freq} 462 return {'distribution': freq}