Mercurial > repos > fubar > jbrowse2
comparison jbrowse2.py @ 92:3c4db8203fad draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse2 commit f2fba2e6b169256dc9adfa141e3bd59665f08f78
author | fubar |
---|---|
date | Sun, 21 Apr 2024 04:42:29 +0000 |
parents | 408781c080fc |
children | 4c517a0041a8 |
comparison
equal
deleted
inserted
replaced
91:6246925692cb | 92:3c4db8203fad |
---|---|
862 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict) | 862 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict) |
863 self.trackIdlist.append(tId) | 863 self.trackIdlist.append(tId) |
864 | 864 |
865 def add_bam(self, data, trackData, bam_indexes=None, **kwargs): | 865 def add_bam(self, data, trackData, bam_indexes=None, **kwargs): |
866 tId = trackData["label"] | 866 tId = trackData["label"] |
867 realFName = trackData["key"] | 867 realFName = trackData["path"] |
868 useuri = trackData["useuri"].lower() == "yes" | 868 useuri = trackData["useuri"].lower() == "yes" |
869 categ = trackData["category"] | 869 categ = trackData["category"] |
870 if useuri: | 870 if useuri: |
871 url = data | 871 url = data |
872 else: | 872 else: |
873 fname = tId | 873 fname = tId |
874 dest = "%s/%s" % (self.outdir, fname) | 874 dest = "%s/%s" % (self.outdir, fname) |
875 self.subprocess_check_call(["cp", data, dest]) | |
875 url = fname | 876 url = fname |
876 bindex = fname + ".bai" | 877 bindex = fname + ".bai" |
877 self.subprocess_check_call(["cp", data, dest]) | 878 bi = bam_indexes.split(",") |
878 bi = bam_indexes.split() | |
879 bam_index = [ | 879 bam_index = [ |
880 x.split(",")[1].strip() | 880 x.split(":")[1].strip() |
881 for x in bi | 881 for x in bi |
882 if "," in x and x.split(",")[0].strip() == realFName | 882 if ":" in x and x.split(":")[0].strip() == realFName |
883 ] | 883 ] |
884 if len(bam_index) > 0: | 884 logging.debug( |
885 bam_index = bam_index[0] | 885 "===realFName=%s got %s as bam_indexes %s as bi, %s for bam_index" |
886 % (realFName, bam_indexes, bi, bam_index) | |
887 ) | |
888 if len(bam_index) > 0 and os.path.exists(os.path.realpath(bam_index[0])): | |
889 self.subprocess_check_call(["cp", bam_index[0], bindex]) | |
886 else: | 890 else: |
887 bam_index = None | 891 cmd = ["samtools", "index", "-b", "-o", bindex, data] |
888 logging.debug( | 892 self.subprocess_check_call(cmd) |
889 "===realFName=%s got %s as bi, %s for bam_index" | |
890 % (realFName, bi, bam_index) | |
891 ) | |
892 if bam_index is not None and os.path.exists(bam_index): | |
893 if not os.path.exists(bindex): | |
894 # bai most probably made by galaxy and stored in galaxy dirs, need to copy it to dest | |
895 self.subprocess_check_call(["cp", bam_index, bindex]) | |
896 else: | |
897 # Can happen in exotic condition | |
898 # e.g. if bam imported as symlink with datatype=unsorted.bam, then datatype changed to bam | |
899 # => no index generated by galaxy, but there might be one next to the symlink target | |
900 # this trick allows to skip the bam sorting made by galaxy if already done outside | |
901 if os.path.exists(os.path.realpath(data) + ".bai"): | |
902 self.symlink_or_copy(os.path.realpath(data) + ".bai", bindex) | |
903 else: | |
904 log.warn("Could not find a bam index (.bai file) for %s", data) | |
905 trackDict = { | 893 trackDict = { |
906 "type": "AlignmentsTrack", | 894 "type": "AlignmentsTrack", |
907 "trackId": tId, | 895 "trackId": tId, |
908 "name": trackData["name"], | 896 "name": trackData["name"], |
909 "category": [ | 897 "category": [ |
931 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict) | 919 self.tracksToAdd[trackData["assemblyNames"]].append(trackDict) |
932 self.trackIdlist.append(tId) | 920 self.trackIdlist.append(tId) |
933 | 921 |
934 def add_cram(self, data, trackData, cram_indexes=None, **kwargs): | 922 def add_cram(self, data, trackData, cram_indexes=None, **kwargs): |
935 tId = trackData["label"] | 923 tId = trackData["label"] |
936 realFName = trackData["key"] | 924 realFName = trackData["path"] |
937 categ = trackData["category"] | 925 categ = trackData["category"] |
938 useuri = trackData["useuri"].lower() == "yes" | 926 useuri = trackData["useuri"].lower() == "yes" |
939 gsa = self.assmeta.get(trackData["assemblyNames"], None) | 927 gsa = self.assmeta.get(trackData["assemblyNames"], None) |
940 if gsa: | 928 if gsa: |
941 genseqad = gsa[0]["genome_sequence_adapter"] | 929 genseqad = gsa[0]["genome_sequence_adapter"] |
947 else: | 935 else: |
948 fname = tId | 936 fname = tId |
949 dest = os.path.join(self.outdir, fname) | 937 dest = os.path.join(self.outdir, fname) |
950 url = fname | 938 url = fname |
951 self.subprocess_check_call(["cp", data, dest]) | 939 self.subprocess_check_call(["cp", data, dest]) |
952 ci = cram_indexes.split() | 940 ci = cram_indexes.split(",") |
953 cram_index = [ | 941 cram_index = [ |
954 x.split(",")[1].strip() | 942 x.split(":")[1].strip() |
955 for x in ci | 943 for x in ci |
956 if "," in x and x.split(",")[0] == realFName | 944 if ":" in x and x.split(":")[0].strip() == realFName |
957 ] | 945 ] |
958 if len(cram_index) > 0: | |
959 cram_index = cram_index[0] | |
960 else: | |
961 cram_index = None | |
962 logging.debug( | 946 logging.debug( |
963 "=== for %s got %s as cram_indexes, %s for cram_index" | 947 "===realFName=%s got %s as cram_indexes %s as ci, %s for cram_index" |
964 % (realFName, cram_indexes, cram_index) | 948 % (realFName, cram_indexes, ci, cram_index) |
965 ) | 949 ) |
966 if cram_index and os.path.exists(cram_index): | 950 if len(cram_index) > 0 and os.path.exists(cram_index[0]): |
967 if not os.path.exists(dest + ".crai"): | 951 if not os.path.exists(dest + ".crai"): |
968 # most probably made by galaxy and stored in galaxy dirs, need to copy it to dest | 952 # most probably made by galaxy and stored in galaxy dirs, need to copy it to dest |
969 self.subprocess_check_call( | 953 self.subprocess_check_call( |
970 ["cp", os.path.realpath(cram_index), dest + ".crai"] | 954 ["cp", os.path.realpath(cram_index[0]), dest + ".crai"] |
971 ) | 955 ) |
972 else: | 956 else: |
973 cpath = os.path.realpath(dest) + ".crai" | 957 cpath = os.path.realpath(dest) + ".crai" |
974 cmd = ["samtools", "index", "-c", "-o", cpath, os.path.realpath(dest)] | 958 cmd = ["samtools", "index", "-c", "-o", cpath, os.path.realpath(dest)] |
975 self.subprocess_check_call(cmd) | 959 self.subprocess_check_call(cmd) |