Skip to content

Commit

Permalink
Small changes to stderr and debug file
Browse files Browse the repository at this point in the history
  • Loading branch information
rrwick committed Jul 21, 2021
1 parent 4d285d2 commit e9e963c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
5 changes: 2 additions & 3 deletions polypolish/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def starting_message(args):
'it to repair errors in repeat regions that other alignment-based polishers '
'cannot fix.')

log(f'Polypolish version: v{__version__}')
log(f'Polypolish version: {__version__}')
log()
log('Input assembly:')
log(f' {args.assembly}')
Expand Down Expand Up @@ -122,9 +122,8 @@ def load_assembly(assembly_filename):
count = len(assembly_seqs)
if count == 0:
sys.exit(f'Error: no sequences in {assembly_filename}')
log(f'{count} sequence{"" if count == 1 else "s"} in {assembly_filename}:')
for name, seq in assembly_seqs:
log(f' {name} ({len(seq):,} bp)')
log(f'{name} ({len(seq):,} bp)')
log()
return assembly_seqs

Expand Down
13 changes: 6 additions & 7 deletions polypolish/polish_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ def polish_target_sequence(seq_name, target_seq, alignments, debug_file, min_dep
log(f'Polishing {seq_name} ({len(target_seq):,} bp):')

changed_positions = set()
log(' Building read pileup:')
pileup, depths_by_pos = get_pileup(alignments, seq_name, target_seq)
mean_depth = statistics.mean(depths_by_pos.values())
log(f' mean read depth: {mean_depth:.1f}x')
log(f' mean read depth: {mean_depth:.1f}x')
uncovered = sum(1 if d == 0.0 else 0 for d in depths_by_pos.values())
coverage = 100.0 * (len(target_seq) - uncovered) / len(target_seq)
have = 'has' if uncovered == 1 else 'have'
log(f' {uncovered:,} bp {have} a depth of zero ({coverage:.4f}% coverage)')
log(f' {uncovered:,} bp {have} a depth of zero ({coverage:.4f}% coverage)')

log(' Repairing assembly sequence:')
new_bases = []
for i in range(len(target_seq)):
read_base_counts = pileup[i]
Expand Down Expand Up @@ -89,8 +87,8 @@ def polish_target_sequence(seq_name, target_seq, alignments, debug_file, min_dep
estimated_accuracy = 100.0 - changed_percent

positions = 'position' if changed_count == 1 else 'positions'
log(f' {changed_count:,} {positions} changed ({changed_percent:.4f}% of total positions)')
log(f' estimated pre-polishing sequence accuracy: {estimated_accuracy:.4f}%')
log(f' {changed_count:,} {positions} changed ({changed_percent:.4f}% of total positions)')
log(f' estimated pre-polishing sequence accuracy: {estimated_accuracy:.4f}%')
log()

new_name = f'{seq_name}_polypolish'
Expand All @@ -115,7 +113,8 @@ def write_debug_header(debug_file):

def write_debug_line(debug_file, seq_name, i, ref_base, depth, target_count, read_base_counts,
new_base, status):
pileup_str = ','.join([f'{b}x{c}' for b, c in read_base_counts.items()])
pileup_pieces = sorted([f'{b}x{c}' for b, c in read_base_counts.items()])
pileup_str = ','.join(pileup_pieces)
debug_str = f'{seq_name}\t{i}\t{ref_base}\t{depth:.1f}\t{target_count}\t{pileup_str}\t' \
f'{status}\t{new_base}\n'
debug_file.write(debug_str)
Expand Down
2 changes: 1 addition & 1 deletion polypolish/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
If not, see <http://www.gnu.org/licenses/>.
"""

__version__ = '0.3.1'
__version__ = '0.3.2'

0 comments on commit e9e963c

Please sign in to comment.