comparison autogenJB2.py @ 57:94264fe60478 draft

planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 4b5df41484f6bdf316edaf95b53c92d328ec1674-dirty
author fubar
date Thu, 21 Mar 2024 08:01:42 +0000
parents bdfa6a7c4543
children 81d535970196
comparison
equal deleted inserted replaced
56:c0097a584a8a 57:94264fe60478
59 if len(listgenomes) > 0: 59 if len(listgenomes) > 0:
60 genome_paths = [x[0] for x in listgenomes] 60 genome_paths = [x[0] for x in listgenomes]
61 genome_names = [x[2] for x in listgenomes] 61 genome_names = [x[2] for x in listgenomes]
62 guseuri = [] 62 guseuri = []
63 for x in genome_paths: 63 for x in genome_paths:
64 if x.startswith('http://') or x.startswith('https://'): 64 if x.startswith("http://") or x.startswith("https://"):
65 guseuri.append('yes') 65 guseuri.append("yes")
66 else: 66 else:
67 guseuri.append('no') 67 guseuri.append("no")
68 jc = jbC( 68 jc = jbC(
69 outdir=args.outdir, 69 outdir=args.outdir,
70 jbrowse2path=args.jbrowse2path, 70 jbrowse2path=args.jbrowse2path,
71 genomes=[ 71 genomes=[
72 { 72 {
73 "path": x, 73 "path": x,
74 "label": genome_names[i], 74 "label": genome_names[i],
75 "useuri": guseuri[i], 75 "useuri": guseuri[i],
76 "meta": {"name": genome_names[i], 76 "meta": {
77 "dataset_dname": genome_names[i] 77 "name": genome_names[i],
78 } 78 "dataset_dname": genome_names[i],
79 },
79 } 80 }
80 for i, x in enumerate(genome_paths) 81 for i, x in enumerate(genome_paths)
81 ], 82 ],
82 ) 83 )
83 84
97 for i, track in enumerate(listtracks): 98 for i, track in enumerate(listtracks):
98 track_conf = {"trackfiles": [], "category": "autogenerated"} 99 track_conf = {"trackfiles": [], "category": "autogenerated"}
99 tpath, trext, trackname = track[:3] 100 tpath, trext, trackname = track[:3]
100 track_conf["dataset_id"] = trackname 101 track_conf["dataset_id"] = trackname
101 useuri = "no" 102 useuri = "no"
102 if tpath.startswith('http://') or tpath.startswith('https://'): 103 if tpath.startswith("http://") or tpath.startswith("https://"):
103 useuri = "yes" 104 useuri = "yes"
104 if trext == "paf": 105 if trext == "paf":
105 refname = trackname + "_paf.fasta" 106 refname = trackname + "_paf.fasta"
106 refdat = [x[2] for x in listtracks if x[2] == refname] 107 refdat = [x[2] for x in listtracks if x[2] == refname]
107 if not refdat: 108 if not refdat:
109 "!! No reference file %s corresponding to paf file %s found. Not building - there must be a corresponding fasta for each paf" 110 "!! No reference file %s corresponding to paf file %s found. Not building - there must be a corresponding fasta for each paf"
110 % (refname, trackname) 111 % (refname, trackname)
111 ) 112 )
112 sys.exit(3) 113 sys.exit(3)
113 else: 114 else:
114 track_conf.update({ 115 track_conf.update(
115 "conf": { 116 {
116 "options": { 117 "conf": {
117 "paf": {"genome": refdat, "genome_label": trackname} 118 "options": {
119 "paf": {
120 "genome": refdat,
121 "genome_label": trackname,
122 }
123 }
118 } 124 }
119 } 125 }
120 }) 126 )
121 elif trext == "bam": 127 elif trext == "bam":
122 ipath = track[3] 128 ipath = track[3]
123 if not os.path.exists(ipath): 129 if not os.path.exists(ipath):
124 ipath = os.path.realpath(os.path.join(jc.outdir, trackname + '.bai')) 130 ipath = os.path.realpath(
125 cmd = ["samtools", "index", "-b", "-o", ipath, os.path.realpath(track[0])] 131 os.path.join(jc.outdir, trackname + ".bai")
126 sys.stdout.write('#### calling %s' % ' '.join(cmd)) 132 )
133 cmd = [
134 "samtools",
135 "index",
136 "-b",
137 "-o",
138 ipath,
139 os.path.realpath(track[0]),
140 ]
141 sys.stdout.write("#### calling %s" % " ".join(cmd))
127 jc.subprocess_check_call(cmd) 142 jc.subprocess_check_call(cmd)
128 track_conf.update({"conf": {"options": {"bam": {"bam_index": ipath}}}}) 143 track_conf.update(
144 {"conf": {"options": {"bam": {"bam_index": ipath}}}}
145 )
129 elif trext == "cram": 146 elif trext == "cram":
130 ipath = track[3] 147 ipath = track[3]
131 if not os.path.exists(ipath): 148 if not os.path.exists(ipath):
132 ipath = os.path.realpath(os.path.join('./', trackname + '.crai')) 149 ipath = os.path.realpath(
133 cmd = ["samtools", "index", "-c", "-o", ipath, os.path.realpath(track[0])] 150 os.path.join("./", trackname + ".crai")
151 )
152 cmd = [
153 "samtools",
154 "index",
155 "-c",
156 "-o",
157 ipath,
158 os.path.realpath(track[0]),
159 ]
134 jc.subprocess_check_call(cmd) 160 jc.subprocess_check_call(cmd)
135 track_conf.update({"conf": {"options": {"cram": {"cram_index": ipath}}}}) 161 track_conf.update(
162 {"conf": {"options": {"cram": {"cram_index": ipath}}}}
163 )
136 track_conf["path"] = tpath 164 track_conf["path"] = tpath
137 track_conf["format"] = trext 165 track_conf["format"] = trext
138 track_conf["name"] = trackname 166 track_conf["name"] = trackname
139 track_conf["label"] = trackname 167 track_conf["label"] = trackname
140 track_conf["trackfiles"].append((tpath, trext, useuri, trackname, {})) 168 track_conf["trackfiles"].append((tpath, trext, useuri, trackname, {}))