Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 53:bdfa6a7c4543 draft
planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit 44df75b3714aa9e02983e0b67ef43fc0eee4a8d4-dirty
author | fubar |
---|---|
date | Thu, 07 Mar 2024 09:23:06 +0000 |
parents | f350467f9433 |
children | d6b0feb22584 |
comparison
equal
deleted
inserted
replaced
52:ae12977c0e5e | 53:bdfa6a7c4543 |
---|---|
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
11 import struct | 11 import struct |
12 import subprocess | 12 import subprocess |
13 import sys | |
13 import tempfile | 14 import tempfile |
14 import urllib.request | 15 import urllib.request |
15 import xml.etree.ElementTree as ET | 16 import xml.etree.ElementTree as ET |
16 from collections import defaultdict | 17 from collections import defaultdict |
17 | 18 |
465 self.genome_names.append(genome_name) | 466 self.genome_names.append(genome_name) |
466 if self.genome_name is None: | 467 if self.genome_name is None: |
467 self.genome_name = ( | 468 self.genome_name = ( |
468 genome_name # first one for all tracks - other than paf | 469 genome_name # first one for all tracks - other than paf |
469 ) | 470 ) |
471 self.genome_sequence_adapter = assem["sequence"]["adapter"] | |
470 self.genome_firstcontig = None | 472 self.genome_firstcontig = None |
471 if not useuri: | 473 if not useuri: |
472 # https://lazarus.name/jbrowse/fish/bigwig_0_coverage_bedgraph_cov_count_count_bw.bigwig | 474 # https://lazarus.name/jbrowse/fish/bigwig_0_coverage_bedgraph_cov_count_count_bw.bigwig |
473 # https://lazarus.name/jbrowse/fish/klBraLanc5.haps_combined.decontam.20230620.fasta.fa.gz | 475 # https://lazarus.name/jbrowse/fish/klBraLanc5.haps_combined.decontam.20230620.fasta.fa.gz |
474 fl = open(fapath, "r").readline() | 476 fl = open(fapath, "r").readline() |
527 }, | 529 }, |
528 "gziLocation": { | 530 "gziLocation": { |
529 "uri": faname + ".gzi", | 531 "uri": faname + ".gzi", |
530 }, | 532 }, |
531 } | 533 } |
532 self.genome_sequence_adapter = adapter | 534 |
533 trackDict = { | 535 trackDict = { |
534 "name": gname, | 536 "name": gname, |
535 "sequence": { | 537 "sequence": { |
536 "type": "ReferenceSequenceTrack", | 538 "type": "ReferenceSequenceTrack", |
537 "trackId": gname, | 539 "trackId": gname, |
872 if useuri: | 874 if useuri: |
873 url = data | 875 url = data |
874 else: | 876 else: |
875 fname = "%s.cram" % trackData["label"] | 877 fname = "%s.cram" % trackData["label"] |
876 dest = "%s/%s" % (self.outdir, fname) | 878 dest = "%s/%s" % (self.outdir, fname) |
877 bindex = fname + '.bai' | 879 bindex = fname + '.crai' |
878 url = fname | 880 url = fname |
879 self.subprocess_check_call(["cp", data, dest]) | 881 self.subprocess_check_call(["cp", data, dest]) |
880 | |
881 if bindex is not None and os.path.exists(bindex): | 882 if bindex is not None and os.path.exists(bindex): |
882 if not os.path.exists(dest+'.crai'): | 883 if not os.path.exists(dest+'.crai'): |
883 # most probably made by galaxy and stored in galaxy dirs, need to copy it to dest | 884 # most probably made by galaxy and stored in galaxy dirs, need to copy it to dest |
884 self.subprocess_check_call( | 885 self.subprocess_check_call( |
885 ["cp", os.path.realpath(cram_index), dest + ".crai"] | 886 ["cp", os.path.realpath(cram_index), dest + ".crai"] |
886 ) | 887 ) |
887 else: | 888 else: |
888 # Can happen in exotic condition | 889 cpath = os.path.realpath(dest) + '.crai' |
889 # e.g. if bam imported as symlink with datatype=unsorted.bam, then datatype changed to bam | 890 cmd = ["samtools", "index", "-c", "-o", cpath, os.path.realpath(dest)] |
890 # => no index generated by galaxy, but there might be one next to the symlink target | 891 logging.debug('executing cmd %s' % ' '.join(cmd)) |
891 # this trick allows to skip the bam sorting made by galaxy if already done outside | 892 self.subprocess_check_call(cmd) |
892 if os.path.exists(os.path.realpath(data) + ".crai"): | |
893 self.symlink_or_copy( | |
894 os.path.realpath(data) + ".crai", dest + ".crai" | |
895 ) | |
896 else: | |
897 log.warn("Could not find a cram index (.crai file) for %s", data) | |
898 trackDict = { | 893 trackDict = { |
899 "type": "AlignmentsTrack", | 894 "type": "AlignmentsTrack", |
900 "trackId": tId, | 895 "trackId": tId, |
901 "name": trackData["name"], | 896 "name": trackData["name"], |
902 "assemblyNames": [self.genome_name], | 897 "assemblyNames": [self.genome_name], |
1278 | 1273 |
1279 refName = None | 1274 refName = None |
1280 drdict = { | 1275 drdict = { |
1281 "reversed": False, | 1276 "reversed": False, |
1282 "assemblyName": self.genome_name, | 1277 "assemblyName": self.genome_name, |
1283 "start": 0, | 1278 "start": 2000, |
1284 "end": 100000, | 1279 "end": 0, |
1285 "refName": "x", | 1280 "refName": "x", |
1286 } | 1281 } |
1287 | 1282 |
1288 if data.get("defaultLocation", ""): | 1283 if data.get("defaultLocation", ""): |
1289 ddl = data["defaultLocation"] | 1284 ddl = data["defaultLocation"] |