comparison autogenJB2.py @ 30:8f02a84ee278 draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 48bc917d34af182e9158915862c8a35723660919
author fubar
date Wed, 21 Feb 2024 02:57:30 +0000
parents
children 15da358c3108
comparison
equal deleted inserted replaced
29:f728cf0df71d 30:8f02a84ee278
1 import argparse
2 import re
3 import sys
4
5 from jbrowse2 import jbrowseConnector as jbC
6
7
8 def makeDefaultLocation(jc, defLoc=None):
9
10 refName = None
11 drdict = {
12 "reversed": False,
13 "assemblyName": jc.genome_name,
14 "start": 0,
15 "end": 100000,
16 }
17
18 if defLoc:
19 loc_match = re.search(r"^([^:]+):([\d,]*)\.*([\d,]*)$", defLoc)
20 # allow commas like 100,000 but ignore as integer
21 if loc_match:
22 refName = loc_match.group(1)
23 drdict["refName"] = refName
24 if loc_match.group(2) > "":
25 drdict["start"] = int(loc_match.group(2).replace(",", ""))
26 if loc_match.group(3) > "":
27 drdict["end"] = int(loc_match.group(3).replace(",", ""))
28 else:
29 jc.logging.info(
30 "@@@ regexp could not match contig:start..end in the supplied location %s - please fix"
31 % defLoc
32 )
33 else:
34 drdict["refName"] = jc.genome_firstcontig
35 if drdict.get("refName", None):
36 jc.logging.info("@@@ defaultlocation %s for default session" % drdict)
37 return drdict
38 else:
39 jc.logging.info("@@@ no contig name found for default session - please add one!")
40 return None
41
42
43 if __name__ == "__main__":
44 parser = argparse.ArgumentParser(description="", epilog="")
45 parser.add_argument("--sessname", help="Session name", default="AutoJBrowse")
46 parser.add_argument(
47 "--collection",
48 help="Collection of 'filepath, filename, filext' for JBrowse2",
49 default=[],
50 action="extend",
51 )
52 parser.add_argument("--version", "-V", action="version", version="%(prog)s 0.0.1")
53 args = parser.parse_args()
54 sessName = args.sessname
55 flistList = [x.split(",") for x in args.collection]
56 if flistList:
57 listgenomes = [f for f in flistList if f[0].startswith("REFERENCE_")]
58 if len(listgenomes) > 0:
59 genome_paths = [
60 x[1] for x in listgenomes
61 ] # expect genome_1_genomename.fasta etc
62 genome_names = [x[0].split("REFERENCE_")[1] for x in listgenomes]
63 jc = jbC(
64 outdir=args.outdir,
65 genomes=[
66 {
67 "path": x,
68 "meta": {
69 "name": genome_names[i],
70 },
71 }
72 for i, x in enumerate(genome_paths)
73 ],
74 )
75 jc.process_genomes()
76 default_session_data = {
77 "visibility": {
78 "default_on": [],
79 "default_off": [],
80 },
81 "style": {},
82 "style_labels": {},
83 }
84 defLoc = makeDefaultLocation(jc)
85 listtracks = [f for f in flistList if not f[0].startswith("REFERENCE_")]
86 # foo.paf must have a foo_paf.fasta or fasta.gz to match
87 tnames = [x[0] for x in listtracks]
88 texts = [x[2] for x in listtracks]
89 for i, track in enumerate(listtracks):
90 if track[2] == "paf":
91 refname = track[0] + "_paf.fasta"
92 refdat = [x[1] for x in listtracks if x[0] == refname]
93 if not refdat:
94 jc.logging.warn(
95 "!! No reference file %s corresponding to paf file %s found. Not building - there must be a corresponding fasta for each paf"
96 % (refname, tnames[i])
97 )
98 sys.exit(3)
99 else:
100 track_conf = {
101 "conf": {
102 "options": {
103 "paf": {"genome": refdat, "genome_label": track[0]}
104 }
105 }
106 }
107 else:
108 track_conf = {}
109 track_conf["format"] = track[2]
110 track_conf["name"] = track[0]
111 track_conf["label"] = track[0]
112 track_conf["trackfiles"] = []
113 keys = jc.process_annotations(track_conf)
114
115 if keys:
116 for key in keys:
117 default_session_data["visibility"][
118 track.attrib.get("visibility", "default_off")
119 ].append(key)
120 # if track_conf.get("style", None):
121 # default_session_data["style"][key] = track_conf[
122 # "style"
123 # ] # TODO do we need this anymore?
124 # if track_conf.get("style_lables", None):
125 # default_session_data["style_labels"][key] = track_conf.get(
126 # "style_labels", None
127 # )
128 # general_data = {
129 # "analytics": root.find("metadata/general/analytics").text,
130 # "primary_color": root.find("metadata/general/primary_color").text,
131 # "secondary_color": root.find("metadata/general/secondary_color").text,
132 # "tertiary_color": root.find("metadata/general/tertiary_color").text,
133 # "quaternary_color": root.find("metadata/general/quaternary_color").text,
134 # "font_size": root.find("metadata/general/font_size").text,
135 # }
136 # jc.add_general_configuration(general_data)
137 trackconf = jc.config_json.get("tracks", None)
138 if trackconf:
139 jc.config_json["tracks"].update(jc.tracksToAdd)
140 else:
141 jc.config_json["tracks"] = jc.tracksToAdd
142 jc.write_config()
143 defaultData = {"defaultLocation": defLoc, "session_name": sessName}
144 jc.add_default_session(defaultData)
145 # jc.text_index() not sure what broke here.
146 else:
147 sys.stderr.write("!! empty collection supplied - nothing to process")