Mercurial > repos > iuc > jbrowse
comparison jbrowse.py @ 40:17359b808b01 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 2f072c4183a0d1221fb9d81909aeeafb2dbda892"
author | iuc |
---|---|
date | Fri, 21 Aug 2020 04:42:41 -0400 |
parents | 9de82b4963e6 |
children | 8774b28235bb |
comparison
equal
deleted
inserted
replaced
39:fd5dbf0f732e | 40:17359b808b01 |
---|---|
321 ) | 321 ) |
322 metadata['tool_tool'] = '<a target="_blank" href="{galaxy}/datasets/{encoded_id}/show_params">{tool_id}</a>'.format( | 322 metadata['tool_tool'] = '<a target="_blank" href="{galaxy}/datasets/{encoded_id}/show_params">{tool_id}</a>'.format( |
323 galaxy=GALAXY_INFRASTRUCTURE_URL, | 323 galaxy=GALAXY_INFRASTRUCTURE_URL, |
324 encoded_id=metadata['dataset_id'], | 324 encoded_id=metadata['dataset_id'], |
325 tool_id=metadata['tool_tool_id'], | 325 tool_id=metadata['tool_tool_id'], |
326 tool_version=metadata['tool_tool_version'], | 326 # tool_version=metadata['tool_tool_version'], |
327 ) | 327 ) |
328 return metadata | 328 return metadata |
329 | 329 |
330 | 330 |
331 class JbrowseConnector(object): | 331 class JbrowseConnector(object): |
332 | 332 |
333 def __init__(self, jbrowse, outdir, genomes, standalone=False, gencode=1): | 333 def __init__(self, jbrowse, outdir, genomes, standalone=None, gencode=1): |
334 self.cs = ColorScaling() | 334 self.cs = ColorScaling() |
335 self.jbrowse = jbrowse | 335 self.jbrowse = jbrowse |
336 self.outdir = outdir | 336 self.outdir = outdir |
337 self.genome_paths = genomes | 337 self.genome_paths = genomes |
338 self.standalone = standalone | 338 self.standalone = standalone |
339 self.gencode = gencode | 339 self.gencode = gencode |
340 self.tracksToIndex = [] | 340 self.tracksToIndex = [] |
341 | 341 |
342 if standalone: | 342 if standalone == "complete": |
343 self.clone_jbrowse(self.jbrowse, self.outdir) | 343 self.clone_jbrowse(self.jbrowse, self.outdir) |
344 elif standalone == "minimal": | |
345 self.clone_jbrowse(self.jbrowse, self.outdir, minimal=True) | |
344 else: | 346 else: |
345 try: | 347 try: |
346 os.makedirs(self.outdir) | 348 os.makedirs(self.outdir) |
347 except OSError: | 349 except OSError: |
348 # Ignore if the folder exists | 350 # Ignore if the folder exists |
389 log.error('cd %s && %s', self.outdir, command) | 391 log.error('cd %s && %s', self.outdir, command) |
390 log.error(output) | 392 log.error(output) |
391 log.error(err) | 393 log.error(err) |
392 raise RuntimeError("Command failed with exit code %s" % (retcode)) | 394 raise RuntimeError("Command failed with exit code %s" % (retcode)) |
393 | 395 |
396 def subprocess_check_output(self, command): | |
397 log.debug('cd %s && %s', self.outdir, ' '.join(command)) | |
398 return subprocess.check_output(command, cwd=self.outdir) | |
399 | |
394 def _jbrowse_bin(self, command): | 400 def _jbrowse_bin(self, command): |
395 return os.path.realpath(os.path.join(self.jbrowse, 'bin', command)) | 401 return os.path.realpath(os.path.join(self.jbrowse, 'bin', command)) |
396 | 402 |
397 def process_genomes(self): | 403 def process_genomes(self): |
398 for genome_node in self.genome_paths: | 404 for genome_node in self.genome_paths: |
499 if blastOpts.get('index', 'false') == 'true': | 505 if blastOpts.get('index', 'false') == 'true': |
500 self.tracksToIndex.append("%s" % trackData['label']) | 506 self.tracksToIndex.append("%s" % trackData['label']) |
501 | 507 |
502 def add_bigwig(self, data, trackData, wiggleOpts, **kwargs): | 508 def add_bigwig(self, data, trackData, wiggleOpts, **kwargs): |
503 dest = os.path.join('data', 'raw', trackData['label'] + '.bw') | 509 dest = os.path.join('data', 'raw', trackData['label'] + '.bw') |
504 cmd = ['ln', '-s', data, dest] | 510 cmd = ['cp', data, dest] |
505 self.subprocess_check_call(cmd) | 511 self.subprocess_check_call(cmd) |
506 | 512 |
507 url = os.path.join('raw', trackData['label'] + '.bw') | 513 url = os.path.join('raw', trackData['label'] + '.bw') |
508 trackData.update({ | 514 trackData.update({ |
509 "urlTemplate": url, | 515 "urlTemplate": url, |
1067 } | 1073 } |
1068 }) | 1074 }) |
1069 with open(os.path.join(self.outdir, 'data', 'trackList2.json'), 'w') as handle: | 1075 with open(os.path.join(self.outdir, 'data', 'trackList2.json'), 'w') as handle: |
1070 json.dump(trackListJson, handle) | 1076 json.dump(trackListJson, handle) |
1071 | 1077 |
1072 def clone_jbrowse(self, jbrowse_dir, destination): | 1078 def clone_jbrowse(self, jbrowse_dir, destination, minimal=False): |
1073 """Clone a JBrowse directory into a destination directory. | 1079 """Clone a JBrowse directory into a destination directory. |
1074 """ | 1080 """ |
1075 # JBrowse seems to have included some bad symlinks, cp ignores bad symlinks | 1081 if minimal: |
1076 # unlike copytree | 1082 # Should be the absolute minimum required for JBrowse to function. |
1077 cmd = ['cp', '-r', os.path.join(jbrowse_dir, '.'), destination] | 1083 interesting = [ |
1078 log.debug(' '.join(cmd)) | 1084 'dist', 'img', 'index.html', 'jbrowse.conf', 'jbrowse_conf.json', 'webpack.config.js' |
1079 subprocess.check_call(cmd) | 1085 ] |
1086 for i in interesting: | |
1087 cmd = ['cp', '-r', os.path.join(jbrowse_dir, i), destination] | |
1088 self.subprocess_check_call(cmd) | |
1089 else: | |
1090 # JBrowse seems to have included some bad symlinks, cp ignores bad symlinks | |
1091 # unlike copytree | |
1092 cmd = ['cp', '-r', os.path.join(jbrowse_dir, '.'), destination] | |
1093 self.subprocess_check_call(cmd) | |
1094 | |
1080 cmd = ['mkdir', '-p', os.path.join(destination, 'data', 'raw')] | 1095 cmd = ['mkdir', '-p', os.path.join(destination, 'data', 'raw')] |
1081 log.debug(' '.join(cmd)) | 1096 self.subprocess_check_call(cmd) |
1082 subprocess.check_call(cmd) | |
1083 | 1097 |
1084 # http://unix.stackexchange.com/a/38691/22785 | 1098 # http://unix.stackexchange.com/a/38691/22785 |
1085 # JBrowse releases come with some broken symlinks | 1099 # JBrowse releases come with some broken symlinks |
1086 cmd = ['find', destination, '-type', 'l', '-xtype', 'l'] | 1100 cmd = ['find', destination, '-type', 'l', '-xtype', 'l'] |
1087 log.debug(' '.join(cmd)) | 1101 symlinks = self.subprocess_check_output(cmd) |
1088 symlinks = subprocess.check_output(cmd) | 1102 |
1089 for i in symlinks: | 1103 for i in symlinks: |
1090 try: | 1104 try: |
1091 os.unlink(i) | 1105 os.unlink(i) |
1092 except OSError: | 1106 except OSError: |
1093 pass | 1107 pass |
1097 parser = argparse.ArgumentParser(description="", epilog="") | 1111 parser = argparse.ArgumentParser(description="", epilog="") |
1098 parser.add_argument('xml', type=argparse.FileType('r'), help='Track Configuration') | 1112 parser.add_argument('xml', type=argparse.FileType('r'), help='Track Configuration') |
1099 | 1113 |
1100 parser.add_argument('--jbrowse', help='Folder containing a jbrowse release') | 1114 parser.add_argument('--jbrowse', help='Folder containing a jbrowse release') |
1101 parser.add_argument('--outdir', help='Output directory', default='out') | 1115 parser.add_argument('--outdir', help='Output directory', default='out') |
1102 parser.add_argument('--standalone', help='Standalone mode includes a copy of JBrowse', action='store_true') | 1116 parser.add_argument('--standalone', choices=['complete', 'minimal', 'data'], help='Standalone mode includes a copy of JBrowse') |
1103 parser.add_argument('--version', '-V', action='version', version="%(prog)s 0.8.0") | 1117 parser.add_argument('--version', '-V', action='version', version="%(prog)s 0.8.0") |
1104 args = parser.parse_args() | 1118 args = parser.parse_args() |
1105 | 1119 |
1106 tree = ET.parse(args.xml.name) | 1120 tree = ET.parse(args.xml.name) |
1107 root = tree.getroot() | 1121 root = tree.getroot() |