Skip to content

Commit

Permalink
Pass ID range components around as strings
Browse files Browse the repository at this point in the history
This may fix #824.
  • Loading branch information
adamnovak authored Aug 27, 2020
1 parent 074b650 commit 6f926db
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/toil_vg/vg_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ def run_id_range(job, context, graph_id, graph_name, chrom):
"""
Compute a node id range for a graph (which should be an entire contig/chromosome with
contiguous id space -- see vg ids) using vg stats
Returns a tuple of 3 strings: chromosome name, first base number, last base number.
"""
work_dir = job.fileStore.getLocalTempDir()

Expand All @@ -869,9 +871,9 @@ def run_id_range(job, context, graph_id, graph_name, chrom):
#run vg stats
#expect result of form node-id-range <tab> first:last
command = ['vg', 'stats', '--node-id-range', os.path.basename(graph_filename)]
stats_out = context.runner.call(job, command, work_dir=work_dir, check_output = True).strip().split()
assert stats_out[0].decode('ascii') == 'node-id-range'
first, last = stats_out[1].split(b':')
stats_out = context.runner.call(job, command, work_dir=work_dir, check_output = True).decode('utf-8').strip().split()
assert stats_out[0] == 'node-id-range'
first, last = stats_out[1].split(':')

return chrom, first, last

Expand All @@ -883,9 +885,9 @@ def run_merge_id_ranges(job, context, id_ranges, index_name):
# Where do we put the id ranges tsv?
id_range_filename = os.path.join(work_dir, '{}_id_ranges.tsv'.format(index_name))

with open(id_range_filename, 'wb') as f:
with open(id_range_filename, 'w') as f:
for id_range in id_ranges:
f.write('{}\t{}\t{}\n'.format(*id_range).encode())
f.write('{}\t{}\t{}\n'.format(*id_range))

# Checkpoint index to output store
return context.write_output_file(job, id_range_filename)
Expand Down

0 comments on commit 6f926db

Please sign in to comment.