d2a7668073c78b3ed86ee6e23beebd6dac702640 mspeir Thu Oct 1 15:30:45 2026 -0700 Fix expMatrixToBarchartBed, which has aborted on every run since the python3 port, refs #37619 The port in 9ec8ecc35be left three things behind: - median() and the tpmCutoffs block use / where they index a list. Under python2 those were integer divisions; under python3 they are floats, so both the default median path and --useMean abort with a TypeError. - Every NamedTemporaryFile lost its bufsize=1, but two of them are read by name through os.system while python still holds the buffer. Small inputs came out as a header line with no data rows. Restored the original line-buffered behaviour with an explicit flush before each read. The six tests in tests/ would have caught this on the first run, but nothing reaches them: testAll in src/utils/makefile iterates ALL_APPS, and USER_APP_SCRIPTS is not part of it. They also invoked the bare program name, which PATH resolves to the installed copy rather than the one in the tree, so they were testing the shipped binary. They now run ../expMatrixToBarchartBed. The makefile wiring that makes them run at all comes with barChartReorder. Two columns of the expected output needed regenerating, neither of them because of this fix: - _lineLength is one smaller throughout. bedJoinTabOffset was rewritten in C in 46dc535d3f5 and measures the line without its trailing newline. This is harmless, since hgc reads _dataLen bytes and then chopByWhite's, and the comment in getSampleValsFromFile says so. Confirmed that every offset and length still lands on its own matrix row. - score moves by one 111-wide bucket on rows whose value sits exactly on one of the nine cutoffs. The value reaches an intermediate file through str() and comes back through float(). python2's str() kept 12 significant digits, so such a row compared as strictly less than its own cutoff and fell a bucket; python3 round trips exactly. It affects about six rows whatever the size of the dataset, since there are only nine cutoffs, and never by more than one bucket. Co-Authored-By: Claude Opus 5 (1M context) diff --git src/utils/expMatrixToBarchartBed/tests/makefile src/utils/expMatrixToBarchartBed/tests/makefile index 14051a6a2bf..9b31098804d 100644 --- src/utils/expMatrixToBarchartBed/tests/makefile +++ src/utils/expMatrixToBarchartBed/tests/makefile @@ -1,24 +1,26 @@ +# Run the copy in the tree rather than whatever is on PATH, which resolves to +# the installed production binary and so never tests these changes. test:: @printf "\ntest1: basic test\n" - expMatrixToBarchartBed test.meta test.matrix test.coords foo + ../expMatrixToBarchartBed test.meta test.matrix test.coords foo diff foo test.output @printf "\ntest2: test of --groupOrder\n" - expMatrixToBarchartBed test.meta test.matrix test.coords foo --groupOrder test.groupOrder --useMean + ../expMatrixToBarchartBed test.meta test.matrix test.coords foo --groupOrder test.groupOrder --useMean diff foo test.output2 rm foo @printf "\ntest3: test of extraFields in bed file and corresponding autoSql\n" - expMatrixToBarchartBed test.meta test.matrix extraFields.coords foo --autoSql test.as + ../expMatrixToBarchartBed test.meta test.matrix extraFields.coords foo --autoSql test.as diff foo extraFields.output rm foo @printf "\ntest4: test of all options\n" - expMatrixToBarchartBed test.meta test.matrix extraFields.coords foo --verbose --groupOrder test.groupOrder --useMean --autoSql test.as + ../expMatrixToBarchartBed test.meta test.matrix extraFields.coords foo --verbose --groupOrder test.groupOrder --useMean --autoSql test.as diff foo allOptions.output rm foo @printf "\ntest5: autoSql supplied but no actual extraFields\n" - expMatrixToBarchartBed test.meta test.matrix noExtraFields.coords foo --verbose --groupOrder test.groupOrder --useMean --autoSql ../../../hg/lib/barChartBed.as + ../expMatrixToBarchartBed test.meta test.matrix noExtraFields.coords foo --verbose --groupOrder test.groupOrder --useMean --autoSql ../../../hg/lib/barChartBed.as diff foo allOptions2.output rm foo @printf "\ntest6: mixed scientific notation and regular floats in matrix\n" - expMatrixToBarchartBed floats.meta floats.matrix floats.coords foo + ../expMatrixToBarchartBed floats.meta floats.matrix floats.coords foo diff foo floats.output rm foo