Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 133:cec274db51c0 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit 7d28252954cae9f8db5f8a85d8f29cb2865b504b-dirty
author | fubar |
---|---|
date | Fri, 18 Oct 2024 11:57:55 +0000 |
parents | 1efcc387bef4 |
children | ed3a21033188 |
comparison
equal
deleted
inserted
replaced
132:1efcc387bef4 | 133:cec274db51c0 |
---|---|
444 if logCommands: | 444 if logCommands: |
445 log.debug(command) | 445 log.debug(command) |
446 p = subprocess.Popen( | 446 p = subprocess.Popen( |
447 command, | 447 command, |
448 cwd=self.outdir, | 448 cwd=self.outdir, |
449 shell=True, | 449 shell=False, |
450 stdin=subprocess.PIPE, | 450 stdin=subprocess.PIPE, |
451 stdout=subprocess.PIPE, | 451 stdout=subprocess.PIPE, |
452 stderr=subprocess.PIPE, | 452 stderr=subprocess.PIPE, |
453 ) | 453 ) |
454 output, err = p.communicate() | 454 output, err = p.communicate() |
552 contig = fl.decode("utf8").strip() | 552 contig = fl.decode("utf8").strip() |
553 # Merlin 172788 8 60 61 | 553 # Merlin 172788 8 60 61 |
554 else: | 554 else: |
555 faname = gname + ".fa.gz" | 555 faname = gname + ".fa.gz" |
556 fadest = os.path.realpath(os.path.join(self.outdir, faname)) | 556 fadest = os.path.realpath(os.path.join(self.outdir, faname)) |
557 cmd = "bgzip -i -c %s -I %s.gzi > %s && samtools faidx %s" % ( | 557 cmd = ["bgzip", "-i", "-c", fapath, "-I", fadest + ".gzi"] |
558 fapath, | 558 with open(fadest, "wb") as fout: |
559 fadest, | 559 self.subprocess_check_call(cmd, output=fout) |
560 fadest, | 560 cmd = ["samtools", "faidx", fadest] |
561 fadest, | 561 self.subprocess_check_call(cmd) |
562 ) | |
563 self.subprocess_popen(cmd) | |
564 contig = open(fadest + ".fai", "r").readline().strip() | 562 contig = open(fadest + ".fai", "r").readline().strip() |
565 adapter = { | 563 adapter = { |
566 "type": "BgzipFastaAdapter", | 564 "type": "BgzipFastaAdapter", |
567 "fastaLocation": { | 565 "fastaLocation": { |
568 "uri": faname, | 566 "uri": faname, |
955 if useuri: | 953 if useuri: |
956 url = data | 954 url = data |
957 else: | 955 else: |
958 url = tId | 956 url = tId |
959 dest = os.path.join(self.outdir, url) | 957 dest = os.path.join(self.outdir, url) |
960 cmd = "bgzip -c %s > %s" % (data, dest) | 958 cmd = ["bgzip", "-c", data] |
961 self.subprocess_popen(cmd) | 959 with open(dest, "wb") as fout: |
960 subprocess.run(cmd, stdout=fout) | |
962 cmd = ["tabix", "-f", "-p", "vcf", dest] | 961 cmd = ["tabix", "-f", "-p", "vcf", dest] |
963 self.subprocess_check_call(cmd) | 962 self.subprocess_check_call(cmd) |
964 trackDict = { | 963 trackDict = { |
965 "type": "VariantTrack", | 964 "type": "VariantTrack", |
966 "trackId": tId, | 965 "trackId": tId, |
999 self.trackIdlist.append(tId) | 998 self.trackIdlist.append(tId) |
1000 | 999 |
1001 def _sort_gff(self, data, dest): | 1000 def _sort_gff(self, data, dest): |
1002 # Only index if not already done | 1001 # Only index if not already done |
1003 if not os.path.exists(dest): | 1002 if not os.path.exists(dest): |
1004 cmd = "jbrowse sort-gff '%s' | bgzip -c > '%s'" % ( | 1003 e = os.environ |
1005 data, | 1004 e['SHELL'] = '/bin/sh' |
1006 dest, | 1005 cmd = ['/bin/sh', '-c', "jbrowse sort-gff %s | bgzip -c > %s" % (data, dest)] |
1007 ) | 1006 subprocess.run(cmd, env=e) |
1008 self.subprocess_popen(cmd) | |
1009 self.subprocess_check_call(["tabix", "-f", "-p", "gff", dest]) | 1007 self.subprocess_check_call(["tabix", "-f", "-p", "gff", dest]) |
1010 | 1008 |
1011 def _sort_bed(self, data, dest): | 1009 def _sort_bed(self, data, dest): |
1012 # Only index if not already done | 1010 # Only index if not already done |
1013 if not os.path.exists(dest): | 1011 if not os.path.exists(dest): |
1014 cmd = "sort -k1,1 -k2,2n '%s' | bgzip -c > '%s'" % (data, dest) | 1012 cmd = ["sort", "-k1,1", "-k2,2n", data] |
1015 self.subprocess_popen(cmd) | 1013 ps = subprocess.run(cmd, check=True, capture_output=True) |
1014 cmd = ["bgzip", "-c"] | |
1015 with open(dest, "wb") as fout: | |
1016 subprocess.run(cmd, input=ps.stdout, stdout=fout) | |
1016 cmd = ["tabix", "-f", "-p", "bed", dest] | 1017 cmd = ["tabix", "-f", "-p", "bed", dest] |
1017 self.subprocess_check_call(cmd) | 1018 self.subprocess_check_call(cmd) |
1018 | 1019 |
1019 def add_gff(self, data, trackData): | 1020 def add_gff(self, data, trackData): |
1020 tId = trackData["label"] | 1021 tId = trackData["label"] |
1128 ] | 1129 ] |
1129 self.tracksToAdd[trackData["assemblyNames"]].append(copy.copy(trackDict)) | 1130 self.tracksToAdd[trackData["assemblyNames"]].append(copy.copy(trackDict)) |
1130 self.trackIdlist.append(tId) | 1131 self.trackIdlist.append(tId) |
1131 | 1132 |
1132 def add_paf(self, data, trackData, pafOpts, **kwargs): | 1133 def add_paf(self, data, trackData, pafOpts, **kwargs): |
1133 canPIF = False | 1134 canPIF = True |
1134 tname = trackData["name"] | 1135 tname = trackData["name"] |
1135 tId = trackData["label"] | 1136 tId = trackData["label"] |
1136 url = tId | 1137 url = tId |
1137 usePIF = False # much faster if indexed remotely or locally but broken in biocontainer. | 1138 usePIF = False # much faster if indexed remotely or locally but broken in biocontainer. |
1138 useuri = data.startswith("http://") or data.startswith("https://") | 1139 useuri = data.startswith("http://") or data.startswith("https://") |
1139 if not useuri: | 1140 if not useuri: |
1140 if canPIF: | 1141 if canPIF: |
1141 fakeName = '%s.paf' % tId | 1142 fakeName = "%s.paf" % tId |
1142 url = "%s.pif.gz" % tId | 1143 url = "%s.pif.gz" % tId |
1143 cmd = ["cp", data, fakeName] | 1144 cmd = ["cp", data, fakeName] |
1144 self.subprocess_check_call(cmd) | 1145 self.subprocess_check_call(cmd) |
1145 cmd = ["jbrowse", "make-pif", fakeName] # jbrowse pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also | 1146 cmd = [ |
1147 "jbrowse", | |
1148 "make-pif", | |
1149 fakeName, | |
1150 ] # jbrowse pif input.paf --out output.pif.gz # specify output file, creates output.pif.gz.tbi also | |
1146 self.subprocess_check_call(cmd) | 1151 self.subprocess_check_call(cmd) |
1147 usePIF = True | 1152 usePIF = True |
1148 else: | 1153 else: |
1149 dest = os.path.join(self.outdir, url) | 1154 dest = os.path.join(self.outdir, url) |
1150 self.symlink_or_copy(os.path.realpath(data), dest) | 1155 self.symlink_or_copy(os.path.realpath(data), dest) |