comparison jbrowse2.py @ 10:c60b17456297 draft

planemo upload commit 740eeca506257070c95f4e9f1a75911c31db5a04
author fubar
date Sat, 20 Jan 2024 07:13:26 +0000
parents a26c41e304c3
children f5ce31c2f47d
comparison
equal deleted inserted replaced
9:a26c41e304c3 10:c60b17456297
1145 1145
1146 # We need to know the track type from the config.json generated just before 1146 # We need to know the track type from the config.json generated just before
1147 track_types = {} 1147 track_types = {}
1148 with open(self.config_json_file, "r") as config_file: 1148 with open(self.config_json_file, "r") as config_file:
1149 config_json = json.load(config_file) 1149 config_json = json.load(config_file)
1150 if self.config_json:
1151 config_json.update(self.config_json)
1150 1152
1151 for track_conf in self.tracksToAdd: 1153 for track_conf in self.tracksToAdd:
1152 track_types[track_conf["trackId"]] = track_conf["type"] 1154 track_types[track_conf["trackId"]] = track_conf["type"]
1153 tId = track_conf["trackId"] 1155 tId = track_conf["trackId"]
1154 if tId in data["visibility"]["default_on"]: 1156 if tId in data["visibility"]["default_on"]:
1193 "assemblyName": self.genome_name, 1195 "assemblyName": self.genome_name,
1194 } 1196 }
1195 ] 1197 ]
1196 1198
1197 session_name = data.get("session_name", "New session") 1199 session_name = data.get("session_name", "New session")
1198 1200 for key, value in mapped_chars.items():
1201 session_name = session_name.replace(value, key)
1199 # Merge with possibly existing defaultSession (if upgrading a jbrowse instance) 1202 # Merge with possibly existing defaultSession (if upgrading a jbrowse instance)
1200 session_json = {} 1203 session_json = {}
1201 if "defaultSession" in config_json: 1204 if "defaultSession" in config_json:
1202 session_json = config_json["defaultSession"] 1205 session_json = config_json["defaultSession"]
1203 1206
1207 session_json["views"] = [] 1210 session_json["views"] = []
1208 1211
1209 session_json["views"].append(view_json) 1212 session_json["views"].append(view_json)
1210 1213
1211 config_json["defaultSession"] = session_json 1214 config_json["defaultSession"] = session_json
1215 self.config_json.update(config_json)
1212 1216
1213 with open(self.config_json_file, "w") as config_file: 1217 with open(self.config_json_file, "w") as config_file:
1214 json.dump(config_json, config_file, indent=2) 1218 json.dump(self.config_json, config_file, indent=2)
1215 1219
1216 def add_general_configuration(self, data): 1220 def add_general_configuration(self, data):
1217 """ 1221 """
1218 Add some general configuration to the config.json file 1222 Add some general configuration to the config.json file
1219 """ 1223 """
1220 1224
1221 config_path = self.config_json_file 1225 config_path = self.config_json_file
1222 config_json = {}
1223 if os.path.exists(config_path): 1226 if os.path.exists(config_path):
1224 with open(config_path, "r") as config_file: 1227 with open(config_path, "r") as config_file:
1225 config_json = json.load(config_file) 1228 config_json = json.load(config_file)
1226 1229 else:
1230 config_json = {}
1231 if self.config_json:
1232 config_json.update(self.config_json)
1227 config_data = {} 1233 config_data = {}
1228 1234
1229 config_data["disableAnalytics"] = data.get("analytics", "false") == "true" 1235 config_data["disableAnalytics"] = data.get("analytics", "false") == "true"
1230 1236
1231 config_data["theme"] = { 1237 config_data["theme"] = {
1238 "typography": {"fontSize": int(data.get("font_size", 10))}, 1244 "typography": {"fontSize": int(data.get("font_size", 10))},
1239 } 1245 }
1240 if not config_json.get("configuration", None): 1246 if not config_json.get("configuration", None):
1241 config_json["configuration"] = {} 1247 config_json["configuration"] = {}
1242 config_json["configuration"].update(config_data) 1248 config_json["configuration"].update(config_data)
1243 1249 self.config_json.update(config_json)
1244 with open(config_path, "w") as config_file: 1250 with open(config_path, "w") as config_file:
1245 json.dump(config_json, config_file, indent=2) 1251 json.dump(self.config_json, config_file, indent=2)
1246 1252
1247 def clone_jbrowse(self): 1253 def clone_jbrowse(self):
1248 """Clone a JBrowse directory into a destination directory.""" 1254 """Clone a JBrowse directory into a destination directory."""
1249 # dest = os.path.realpath(self.outdir) 1255 # dest = os.path.realpath(self.outdir)
1250 dest = self.outdir 1256 dest = self.outdir
1422 except TypeError: 1428 except TypeError:
1423 track_conf["style"] = {} 1429 track_conf["style"] = {}
1424 pass 1430 pass
1425 track_conf["conf"] = etree_to_dict(track.find("options")) 1431 track_conf["conf"] = etree_to_dict(track.find("options"))
1426 jc.add_general_configuration(general_data) 1432 jc.add_general_configuration(general_data)
1427 x = open(args.xml, "r").read()
1428 jc.config_json["tracks"] = jc.tracksToAdd 1433 jc.config_json["tracks"] = jc.tracksToAdd
1429 jc.write_config() 1434 jc.write_config()
1430 jc.add_default_session(default_session_data) 1435 jc.add_default_session(default_session_data)
1431 1436
1432 # jc.text_index() not sure what broke here. 1437 # jc.text_index() not sure what broke here.