annotate jbrowse.py @ 0:2c9e5136b416 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
author iuc
date Mon, 04 May 2015 17:21:38 -0400
parents
children 497c6bb3b717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
1 #!/usr/bin/env python
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
2 import os
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
3 import shutil
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
4 import argparse
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
5 import subprocess
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
6 import hashlib
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
7
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
8 TN_TABLE = {
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
9 'gff3': '--gff',
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
10 'gff': '--gff',
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
11 'bed': '--bed',
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
12 # 'genbank': '--gbk',
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
13 }
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
14
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
15
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
16 def process_genome(jbrowse_dir, genome):
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
17 subprocess.check_output(['perl', 'bin/prepare-refseqs.pl', '--fasta', genome], cwd=jbrowse_dir)
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
18
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
19
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
20 def process_annotations(jbrowse_dir, annot_file, annot_label, annot_format,
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
21 **kwargs):
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
22 key = hashlib.md5(annot_file).hexdigest()
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
23
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
24 cmd = ['perl', 'bin/flatfile-to-json.pl', TN_TABLE.get(annot_format, 'gff'),
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
25 annot_file, '--trackLabel', key, '--key', annot_label]
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
26 subprocess.check_output(cmd, cwd=jbrowse_dir)
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
27
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
28
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
29 if __name__ == '__main__':
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
30 parser = argparse.ArgumentParser(description="", epilog="")
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
31 parser.add_argument('genome', type=file, help='Input genome file')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
32
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
33 parser.add_argument('--gff3', type=file, nargs='*', help='GFF3/BED/GBK File')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
34 parser.add_argument('--gff3_format', choices=['gff3', 'gff', 'bed', 'gbk'], nargs='*', help='GFF3/BED/GBK Format')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
35 parser.add_argument('--gff3_label', type=str, nargs='*', help='GFF3/BED/GBK Label')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
36
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
37 parser.add_argument('--jbrowse', help='Folder containing a jbrowse release')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
38 parser.add_argument('--outdir', help='Output directory', default='out')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
39 args = parser.parse_args()
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
40
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
41 jbrowse_dir = os.path.join(args.outdir, 'JBrowse-1.11.6')
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
42 shutil.copytree(args.jbrowse, jbrowse_dir)
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
43
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
44 process_genome(jbrowse_dir, os.path.realpath(args.genome.name))
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
45
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
46 for gff3, gff3_format, gff3_label in zip(args.gff3, args.gff3_format, args.gff3_label):
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
47 gff3_path = os.path.realpath(gff3.name)
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
48 process_annotations(jbrowse_dir, gff3_path, gff3_label, gff3_format)
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
49
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
50 print """
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
51 <html>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
52 <body>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
53 <script type="text/javascript">
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
54 window.location=JBrowse-1.11.6/index.html
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
55 </script>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
56 <a href="JBrowse-1.11.6/index.html">Go to JBrowse</a>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
57 </body>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
58 </html>
2c9e5136b416 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 685773d3da40afdc4d14846d4935b3b0a100f56e
iuc
parents:
diff changeset
59 """