Skip to content

Commit

Permalink
Starting work on Unicycler-scrub
Browse files Browse the repository at this point in the history
  • Loading branch information
rrwick committed May 2, 2017
1 parent e2ab9ed commit e952229
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
112 changes: 112 additions & 0 deletions unicycler/unicycler_scrub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env python3
"""
Copyright 2017 Ryan Wick ([email protected])
https://github.com/rrwick/Unicycler
This module contains the main script for the Unicycler assembly polisher. It is executed when a
user runs `unicycler_polish` (after installation) or `unicycler_polish-runner.py`.
It uses Pilon, Arrow, Racon and Freebayes (as appropriate for the input reads) to repeatedly polish
the assembly. The assembly quality is quantified using ALE and polishing will continue until no
more improvements are possible.
This file is part of Unicycler. Unicycler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version. Unicycler is distributed in
the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. You should have received a copy of the GNU General Public License along with Unicycler. If
not, see <http://www.gnu.org/licenses/>.
"""


import argparse
import os
import sys
from .misc import MyHelpFormatter, bold, quit_with_error
from . import log


def main():
full_command = ' '.join(('"' + x + '"' if ' ' in x else x) for x in sys.argv)
args = get_arguments()
print_intro_message(args, full_command)



def get_arguments():
parser = argparse.ArgumentParser(description='Unicycler-scrub - read trimming, chimera '
'detection and misassembly detection',
formatter_class=MyHelpFormatter)

parser.add_argument('-i', '--in', type=str, required=True,
help='These are the reads or assembly to be scrubbed (can be FASTA or '
'FASTQ format')
parser.add_argument('-o', '--out', type=str, required=True,
help='The scrubbed reads or assembly will be saved to this file (will '
'have the same format as the --in file format)')
parser.add_argument('-r', '--reads', type=str, required=True,
help='These are the reads used to scrub --input (can be FASTA or FASTQ '
'format, can be the same file as --input)')
parser.add_argument('-t', '--trim', type=int, default=50,
help='The aggressiveness with which the input will be trimmed (0 to 100, '
'where 0 is no trimming and 100 is very aggressive trimming)')
parser.add_argument('-s', '--split', type=int, default=50,
help='The aggressiveness with which the input will be split (0 to 100, '
'where 0 is no splitting and 100 is very aggressive splitting)')
args = parser.parse_args()

if args.trim < 0 or args.trim > 100:
quit_with_error('--trim must be between 0 and 100 (inclusive)')
if args.split < 0 or args.split > 100:
quit_with_error('--split must be between 0 and 100 (inclusive)')

return args


def print_intro_message(args, full_command):
log.log_section_header('Starting Unicycler-scrub', single_newline=True)

log.log_explanation('Unicycler-scrub uses local alignments (from minimap) to trim and/or '
'split an input sequence. Long reads can be used to scrub themselves (by '
'supplying the same reads to --in and --out) to trim the reads and split '
'chimeric reads. Long reads can also be used to check an assembly by '
'searching for misassembly points (by supplying the assembly to --in and '
'the long reads to --out).',
extra_empty_lines_after=0)
log.log_explanation('For more information, please see https://github.com/rrwick/Unicycler')

log.log('Command: ' + bold(full_command))
log.log('')

trim_level_str = '%3d' % args.trim
if args.trim == 0.0:
trim_level_str += ' (no trimming)'
elif args.trim < 20.0:
trim_level_str += ' (very conservative trimming)'
elif args.trim < 40.0:
trim_level_str += ' (conservative trimming)'
elif args.trim < 60.0:
trim_level_str += ' (moderate trimming)'
elif args.trim < 80.0:
trim_level_str += ' (aggressive trimming)'
else:
trim_level_str += ' (very aggressive trimming)'

split_level_str = '%3d' % args.split
if args.split == 0.0:
split_level_str += ' (no splitting)'
elif args.split < 20.0:
split_level_str += ' (very conservative splitting)'
elif args.split < 40.0:
split_level_str += ' (conservative splitting)'
elif args.split < 60.0:
split_level_str += ' (moderate splitting)'
elif args.split < 80.0:
split_level_str += ' (aggressive splitting)'
else:
split_level_str += ' (very aggressive splitting)'

log.log('Trim level: ' + trim_level_str)
log.log('Split level: ' + split_level_str)
log.log('')
21 changes: 21 additions & 0 deletions unicycler_scrub-runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""
Copyright 2017 Ryan Wick ([email protected])
https://github.com/rrwick/Unicycler
This file is a convenience wrapper for running Unicycler-scrub directly from the source tree. By
executing `unicycler_scrub-runner.py`, users can run unicycler_scrub without installing Unicycler.
This file is part of Unicycler. Unicycler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version. Unicycler is distributed in
the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. You should have received a copy of the GNU General Public License along with Unicycler. If
not, see <http://www.gnu.org/licenses/>.
"""

from unicycler.unicycler_scrub import main

if __name__ == '__main__':
main()

0 comments on commit e952229

Please sign in to comment.