Mercurial > repos > iuc > jbrowse
comparison jbrowse.py @ 10:1a6d882d340d draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit ac44b067ee08de23180e8b5030374cf362ac4524
author | iuc |
---|---|
date | Fri, 02 Dec 2016 17:58:54 -0500 |
parents | ad4b9d7eae6a |
children | 4cbceec1d6b4 |
comparison
equal
deleted
inserted
replaced
9:f422ba2e9aa5 | 10:1a6d882d340d |
---|---|
262 d = {t.tag: {} if t.attrib else None} | 262 d = {t.tag: {} if t.attrib else None} |
263 children = list(t) | 263 children = list(t) |
264 if children: | 264 if children: |
265 dd = defaultdict(list) | 265 dd = defaultdict(list) |
266 for dc in map(etree_to_dict, children): | 266 for dc in map(etree_to_dict, children): |
267 for k, v in dc.iteritems(): | 267 for k, v in dc.items(): |
268 dd[k].append(v) | 268 dd[k].append(v) |
269 d = {t.tag: {k: v[0] if len(v) == 1 else v for k, v in dd.iteritems()}} | 269 d = {t.tag: {k: v[0] if len(v) == 1 else v for k, v in dd.items()}} |
270 if t.attrib: | 270 if t.attrib: |
271 d[t.tag].update(('@' + k, v) for k, v in t.attrib.iteritems()) | 271 d[t.tag].update(('@' + k, v) for k, v in t.attrib.items()) |
272 if t.text: | 272 if t.text: |
273 text = t.text.strip() | 273 text = t.text.strip() |
274 if children or t.attrib: | 274 if children or t.attrib: |
275 if text: | 275 if text: |
276 d[t.tag]['#text'] = text | 276 d[t.tag]['#text'] = text |
368 os.path.join('data', 'trackList.json') | 368 os.path.join('data', 'trackList.json') |
369 ] | 369 ] |
370 self.subprocess_check_call(cmd) | 370 self.subprocess_check_call(cmd) |
371 | 371 |
372 def _add_track_json(self, json_data): | 372 def _add_track_json(self, json_data): |
373 if len(json_data.keys()) == 0: | 373 if len(json_data) == 0: |
374 return | 374 return |
375 | 375 |
376 tmp = tempfile.NamedTemporaryFile(delete=False) | 376 tmp = tempfile.NamedTemporaryFile(delete=False) |
377 tmp.write(json.dumps(json_data)) | 377 tmp.write(json.dumps(json_data)) |
378 tmp.close() | 378 tmp.close() |
497 cmd = [ | 497 cmd = [ |
498 'perl', self._jbrowse_bin('flatfile-to-json.pl'), | 498 'perl', self._jbrowse_bin('flatfile-to-json.pl'), |
499 self.TN_TABLE.get(format, 'gff'), | 499 self.TN_TABLE.get(format, 'gff'), |
500 data, | 500 data, |
501 '--trackLabel', trackData['label'], | 501 '--trackLabel', trackData['label'], |
502 # '--trackType', 'JBrowse/View/Track/CanvasFeatures', | |
503 '--key', trackData['key'] | 502 '--key', trackData['key'] |
504 ] | 503 ] |
505 | 504 |
506 config = copy.copy(trackData) | 505 config = copy.copy(trackData) |
507 clientConfig = trackData['style'] | 506 clientConfig = trackData['style'] |
512 cmd += ['--type', gffOpts['match']] | 511 cmd += ['--type', gffOpts['match']] |
513 | 512 |
514 cmd += ['--clientConfig', json.dumps(clientConfig), | 513 cmd += ['--clientConfig', json.dumps(clientConfig), |
515 ] | 514 ] |
516 | 515 |
516 trackType = 'JBrowse/View/Track/CanvasFeatures' | |
517 if 'trackType' in gffOpts: | 517 if 'trackType' in gffOpts: |
518 cmd += [ | 518 trackType = gffOpts['trackType'] |
519 '--trackType', gffOpts['trackType'] | 519 |
520 ] | 520 if trackType == 'JBrowse/View/Track/CanvasFeatures': |
521 else: | 521 if 'transcriptType' in gffOpts and gffOpts['transcriptType']: |
522 cmd += [ | 522 config['transcriptType'] = gffOpts['transcriptType'] |
523 '--trackType', 'JBrowse/View/Track/CanvasFeatures' | 523 if 'subParts' in gffOpts and gffOpts['subParts']: |
524 ] | 524 config['subParts'] = gffOpts['subParts'] |
525 if 'impliedUTRs' in gffOpts and gffOpts['impliedUTRs']: | |
526 config['impliedUTRs'] = gffOpts['impliedUTRs'] | |
527 | |
528 cmd += [ | |
529 '--trackType', gffOpts['trackType'] | |
530 ] | |
525 | 531 |
526 cmd.extend(['--config', json.dumps(config)]) | 532 cmd.extend(['--config', json.dumps(config)]) |
527 | 533 |
528 self.subprocess_check_call(cmd) | 534 self.subprocess_check_call(cmd) |
529 | 535 |
542 | 548 |
543 for i, (dataset_path, dataset_ext, track_human_label) in enumerate(track['trackfiles']): | 549 for i, (dataset_path, dataset_ext, track_human_label) in enumerate(track['trackfiles']): |
544 log.info('Processing %s / %s', track['category'], track_human_label) | 550 log.info('Processing %s / %s', track['category'], track_human_label) |
545 outputTrackConfig['key'] = track_human_label | 551 outputTrackConfig['key'] = track_human_label |
546 hashData = [dataset_path, track_human_label, track['category']] | 552 hashData = [dataset_path, track_human_label, track['category']] |
547 outputTrackConfig['label'] = hashlib.md5('|'.join(hashData)).hexdigest() + '_%s' % i | 553 outputTrackConfig['label'] = hashlib.md5('|'.join(hashData).encode('utf-8')).hexdigest() + '_%s' % i |
548 | 554 |
549 # Colour parsing is complex due to different track types having | 555 # Colour parsing is complex due to different track types having |
550 # different colour options. | 556 # different colour options. |
551 colourOptions = self.cs.parse_colours(track['conf']['options'], track['format'], gff3=dataset_path) | 557 colourOptions = self.cs.parse_colours(track['conf']['options'], track['format'], gff3=dataset_path) |
552 # This used to be done with a dict.update() call, however that wiped out any previous style settings... | 558 # This used to be done with a dict.update() call, however that wiped out any previous style settings... |
638 subprocess.check_call(cmd) | 644 subprocess.check_call(cmd) |
639 | 645 |
640 | 646 |
641 if __name__ == '__main__': | 647 if __name__ == '__main__': |
642 parser = argparse.ArgumentParser(description="", epilog="") | 648 parser = argparse.ArgumentParser(description="", epilog="") |
643 parser.add_argument('xml', type=file, help='Track Configuration') | 649 parser.add_argument('xml', type=argparse.FileType('r'), help='Track Configuration') |
644 | 650 |
645 parser.add_argument('--jbrowse', help='Folder containing a jbrowse release') | 651 parser.add_argument('--jbrowse', help='Folder containing a jbrowse release') |
646 parser.add_argument('--outdir', help='Output directory', default='out') | 652 parser.add_argument('--outdir', help='Output directory', default='out') |
647 parser.add_argument('--standalone', help='Standalone mode includes a copy of JBrowse', action='store_true') | 653 parser.add_argument('--standalone', help='Standalone mode includes a copy of JBrowse', action='store_true') |
648 args = parser.parse_args() | 654 args = parser.parse_args() |