775f8e290daefbb3312fd1d8962344690550c887 angie Mon Jun 8 16:20:24 2020 -0700 Extending and updating tree manipulation & SARS-CoV-2 lineage coloring 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 index 2cbb0f8..7d8cd20 100644 --- src/hg/utils/otto/nextstrainNcov/utils.py +++ src/hg/utils/otto/nextstrainNcov/utils.py @@ -1,25 +1,37 @@ # odds and ends import sys, logging def die(message): """good old perl die""" logging.error(message) sys.exit(1) +def listFromFile(fileName): + """Read in a file; return a list of its lines. Ignore blank lines.""" + lines = [] + with open(fileName, 'r') as inF: + line = inF.readline() + while (line): + line = line.rstrip() + if (len(line)): + lines.append(line) + line = inF.readline() + return lines + 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() + line = inF.readline() while (line): + line = line.rstrip() 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() + line = inF.readline() return mapper