0b6529d0ca040778605cb0e1537813bbce276493 angie Thu Aug 17 20:18:32 2023 -0700 Fix format string, check __name__ before calling main so this can be used as a module. diff --git src/hg/utils/otto/sarscov2phylo/branchSpecificMask.py src/hg/utils/otto/sarscov2phylo/branchSpecificMask.py index 26a6766..e16418e 100755 --- src/hg/utils/otto/sarscov2phylo/branchSpecificMask.py +++ src/hg/utils/otto/sarscov2phylo/branchSpecificMask.py @@ -97,31 +97,31 @@ # In most cases we want the last node in the path [-1] nodeIx = -1 # ... but if the last word starts with the sample name (with private mutations) # then we do not want to mask just that sample, so backtrack to [-2] if nodes[-1].startswith(name): nodeIx = nodeIx - 1 # ... and the spec might say to backtrack even more (e.g. parent or grandparent): nodeIx = nodeIx - getBacktrack(spec, name) nodeMuts = nodes[nodeIx] # Strip to just the node ID, discard mutations node = nodeMuts.split(':')[0] repNodes[name] = node; # Make sure we found all of them for rep in repNodes: if repNodes[rep] == '': - die("sample-paths file {samplePaths.name} does not have name {rep}") + die(f"sample-paths file {samplePaths.name} does not have name {rep}") os.unlink(samplePaths.name) return repNodes def makeMaskFile(spec, repNodes, maskFileName): """Create a file to use as input for matUtils mask --mask-mutations, generated from spec with node IDs from repNodes.""" with open(maskFileName, 'w') as maskFile: for branch in spec: branchSpec = spec[branch] rep = branchSpec['representative'] nodeId = repNodes[rep] ranges = branchSpec.get('ranges') if ranges: for r in ranges: for pos in range(r[0], r[1]+1): @@ -131,16 +131,17 @@ for pos in sites: maskFile.write(f'N{pos}N\t{nodeId}\n') reversions = branchSpec.get('reversions') if reversions: for rev in reversions: maskFile.write(f'{rev}\t{nodeId}\n') def main(): args = getArgs() spec = getSpec(args.yamlIn) repNodes = getRepresentativeNodes(args.pbIn, spec) maskFileName = args.pbIn + '.branchSpecificMask.tsv' makeMaskFile(spec, repNodes, maskFileName) run(['matUtils', 'mask', '-i', args.pbIn, '--mask-mutations', maskFileName, '-o', args.pbOut]) +if __name__ == '__main__': main()