2e6ddaec223b5b760cbba134eee52d14a327fda3 angie Fri May 29 15:22:45 2020 -0700 Adding tree manipulation python scripts and modules that I've been working on for David et al. sorta refs #25278, #25382 diff --git src/hg/utils/otto/nextstrainNcov/utils.py src/hg/utils/otto/nextstrainNcov/utils.py new file mode 100644 index 0000000..2cbb0f8 --- /dev/null +++ src/hg/utils/otto/nextstrainNcov/utils.py @@ -0,0 +1,25 @@ +# odds and ends + +import sys, logging + +def die(message): + """good old perl die""" + logging.error(message) + sys.exit(1) + +def dictFromFile(fileName): + """Read in a tab-separated file with two columns; return a dict mapping first col to second. + Ignore blank lines.""" + mapper = {} + with open(fileName, 'r') as inF: + line = inF.readline().rstrip() + while (line): + if (len(line)): + cols = line.split('\t') + if (len(cols) < 2): + die("Expected at least two columns in file " + fileName + ", but got this:\n" + + line + "\n") + mapper[cols[0]] = cols[1] + line = inF.readline().rstrip() + inF.close() + return mapper