comparison autogenJB2.py @ 19:bde6b1d09f7d draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 1290bf486bc55c02fecd0327de10a28655a18e81-dirty
author fubar
date Tue, 30 Jan 2024 06:05:03 +0000
parents
children
comparison
equal deleted inserted replaced
18:2e6c48910819 19:bde6b1d09f7d
1 import argparse
2 import os
3
4 from jbrowse2 import jbrowseConnector as jbC
5
6
7
8
9 if __name__ == "__main__":
10 parser = argparse.ArgumentParser(description="", epilog="")
11 parser.add_argument("--yaml", help="Track Configuration")
12 parser.add_argument("--outdir", help="Output directory", default="out")
13 parser.add_argument("--version", "-V", action="version", version="%(prog)s 0.0.1")
14 args = parser.parse_args()
15 if os.path.exists(args.outdir):
16 root = args.outdir
17 dirList = os.scandir(root)
18 subdirs = [f.path for f in dirList if f.is_dir()]
19 genome_paths = [f.path for f in dirList if f.name.startswith('genome') and f.is_file()]
20 if len(genome_paths) > 0:
21 genome_fnames = [os.path.basename(x).split('_')[2:] for x in genome_paths] # expect genome_1_genomename.fasta etc
22 jc = jbC(
23 outdir=args.outdir,
24 genomes=[
25 {
26 "path": x,
27 "meta": {"name" : genome_fnames[i], },
28 }
29 for i,x in enumerate(genome_paths)
30 ],
31 )
32 jc.process_genomes()
33 # .add_default_view() replace from https://github.com/abretaud/tools-iuc/blob/jbrowse2/tools/jbrowse2/jbrowse2.py
34 default_session_data = {
35 "visibility": {
36 "default_on": [],
37 "default_off": [],
38 },
39 "style": {},
40 "style_labels": {},
41 }
42
43 track_paths = [x for x in genome_paths if not x.startswith('genome') and x.is_file()]
44 for i, track in enumerate(track_paths):
45 track_conf = {}
46 track_conf['format']= os.path.basename(track).split('_')[0]
47 track_conf["name"] = os.path.basename(track).split('_')[2:] # expect genome_1_genomename.fasta etc
48 fext = os.path.splitext(os.path.basename(track)).replace('.','')
49 track_conf["label"] = "%s_%i" % (os.path.basename(track), i)
50 track_conf["trackfiles"] = []
51 keys = jc.process_annotations(track_conf)
52
53 if keys:
54 for key in keys:
55 default_session_data["visibility"][
56 track.attrib.get("visibility", "default_off")
57 ].append(key)
58 if track_conf.get("style", None):
59 default_session_data["style"][key] = track_conf[
60 "style"
61 ] # TODO do we need this anymore?
62 if track_conf.get("style_lables", None):
63 default_session_data["style_labels"][key] = track_conf.get(
64 "style_labels", None
65 )
66 # default_session_data["defaultLocation"] = root.find(
67 # "metadata/general/defaultLocation"
68 # ).text
69 # default_session_data["session_name"] = root.find(
70 # "metadata/general/session_name"
71 # ).text
72 # general_data = {
73 # "analytics": root.find("metadata/general/analytics").text,
74 # "primary_color": root.find("metadata/general/primary_color").text,
75 # "secondary_color": root.find("metadata/general/secondary_color").text,
76 # "tertiary_color": root.find("metadata/general/tertiary_color").text,
77 # "quaternary_color": root.find("metadata/general/quaternary_color").text,
78 # "font_size": root.find("metadata/general/font_size").text,
79 # }
80 # jc.add_general_configuration(general_data)
81 trackconf = jc.config_json.get("tracks", None)
82 if trackconf:
83 jc.config_json["tracks"].update(jc.tracksToAdd)
84 else:
85 jc.config_json["tracks"] = jc.tracksToAdd
86 jc.write_config()
87 jc.add_default_session(default_session_data)
88 # jc.text_index() not sure what broke here.