Skip to content

Commit 8ed090c

Browse files
committed
Edit testing code to force columns setting
1 parent c437b87 commit 8ed090c

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

tests/test_umi_tools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ def test_script(test_name,
190190

191191
options = re.sub("\n", "", options)
192192

193+
# Set COLUMNS variable so that help messages are wrapped same as on
194+
# commandline
195+
exec_env = os.environ.copy()
196+
exec_env["COLUMNS"] = "80"
197+
193198
# use /bin/bash in order to enable "<( )" syntax in shells
194199
statement = ("/bin/bash -c "
195200
"'umi_tools %(options)s %(stdin)s > %(stdout)s'") % locals()
@@ -198,7 +203,8 @@ def test_script(test_name,
198203
shell=True,
199204
stdout=subprocess.PIPE,
200205
stderr=subprocess.PIPE,
201-
cwd=tmpdir)
206+
cwd=tmpdir,
207+
env=exec_env)
202208

203209
if DEBUG:
204210
print("tmpdir={}".format(tmpdir), end=" ")

umi_tools/Utilities.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -885,33 +885,33 @@ def Start(parser=None,
885885
choices=("sam", "bam", "cram"),
886886
default=None,
887887
help="File format of the input file. Format is usually" \
888-
"implied from the extension of the filename, but" \
889-
"maybe overridden with this option. Default=bam")
888+
" implied from the extension of the filename, but" \
889+
" maybe overridden with this option. Default=bam")
890890
group.add_option("--out-format", dest="out_format",
891891
type="choice",
892892
choices=("sam", "bam", "cram"),
893893
default=None,
894894
help="File format of the input file. Format is usually" \
895-
"implied from the extension of the filename, but" \
896-
"maybe overridden with this option. Default=bam")
895+
" implied from the extension of the filename, but" \
896+
" maybe overridden with this option. Default=bam")
897897
group.add_option("--input-options", dest="input_options", action="store",
898898
type="str",
899899
default=None,
900900
help="Format string provided to htslib for reading. Mostly" \
901-
"useful for CRAM formatted files. See samtools documentation")
901+
" useful for CRAM formatted files. See samtools documentation")
902902
group.add_option("--output-options", dest="output_options", action="store",
903903
type="str",
904904
default=None,
905905
help="Format string provided to htslib for writing. Mostly" \
906-
"useful for CRAM formatted files. See samtools documentation")
906+
" useful for CRAM formatted files. See samtools documentation")
907907
group.add_option("--reference-filename", dest="reference_filename",
908908
action="store",
909909
default=None,
910910
help="File path or URL to the genome reference to be used" \
911-
"when reading or writing CRAM files. By default, when reading" \
912-
"a CRAM file, the reference recorded in the input file will be" \
913-
"used unless this is specified. When writing, specifying a" \
914-
"reference location is required.")
911+
" when reading or writing CRAM files. By default, when reading" \
912+
" a CRAM file, the reference recorded in the input file will be" \
913+
" used unless this is specified. When writing, specifying a" \
914+
" reference location is required.")
915915
group.add_option("--mapping-quality", dest="mapping_quality",
916916
type="int",
917917
help="Minimum mapping quality for a read to be retained"
@@ -1466,8 +1466,8 @@ def debug(message):
14661466
def error(message):
14671467
'''log error message, see the :mod:`logging` module'''
14681468
logging.error(message)
1469-
raise ValueError("UMI-tools failed with an error. Check the log file")
1470-
1469+
sys.stderr.write("UMI-tools failed with an error. Check the log file\n")
1470+
sys.exit(1)
14711471

14721472
def critical(message):
14731473
'''log critical message, see the :mod:`logging` module'''
@@ -1746,6 +1746,12 @@ def sort_output(sorted_out_name,
17461746
params.extend(["--output-fmt-options", format_options])
17471747

17481748
params.append(infile)
1749-
debug(params)
1750-
pysam.sort(*params)
1749+
1750+
try:
1751+
pysam.sort(*params)
1752+
except pysam.SamtoolsError as e:
1753+
error("Sorting output file failed.\n\nSort command was:\n " +
1754+
" ".join(params) + "\n\n" +
1755+
f"Error was:\n {e.value}")
1756+
17511757
os.unlink(infile) # delete the tempfile

0 commit comments

Comments
 (0)