262ca5711bd80d3df1f85cd1a836063e52a7a4e0 max Mon Nov 23 04:43:33 2020 -0800 small fix to chromToUcsc for the special case of a mix of fixedStep + bed-Graph, no redmine diff --git src/utils/chromToUcsc/chromToUcsc src/utils/chromToUcsc/chromToUcsc index 636ed54..3760c0f 100755 --- src/utils/chromToUcsc/chromToUcsc +++ src/utils/chromToUcsc/chromToUcsc @@ -51,36 +51,39 @@ logging.basicConfig(level=logging.INFO) return args, options # ----------- main -------------- def splitLines(ifh): " yield (chromName, restOfLine) for all lines of ifh " sep = -1 #if (sys.version_info > (3, 0)): lineNo = 0 for line in ifh: if line.startswith("fixedStep") or line.startswith("variableStep"): row = line.split() yield lineNo, " ", row # *step lines are always space-separated else: if sep==-1: - if "\t" in line: - sep = "\t" - else: + # why test first for space? Because after fixedStep, the lines are just single numbers + if " " in line: sep = None # = split on any whitespace, consec. whitespc counts as one + else: + sep = "\t" # default is to split on tab row = line.rstrip("\n\t").split(sep) lineNo += 1 + if sep is None: + sep = " " yield lineNo, sep, row def parseAlias(fname): " parse tsv file with at least two columns, orig chrom name and new chrom name " toUcsc = {} if fname.startswith("http://") or fname.startswith("https://"): ifh = urlopen(fname) if fname.endswith(".gz"): data = gzip.GzipFile(fileobj=ifh).read().decode() ifh = data.splitlines() elif fname.endswith(".gz"): ifh = gzip.open(fname) else: ifh = open(fname)