def _check_input_bam_valid(args, log=None): #pylint: disable=unused-argument try: bamfile = samtools.alignment_file(args.input_bam, 'rb') bamfile.close() except ValueError: raise utils.UsageError(("Specified input [{}] not a valid BAM. Review " "inputs and try again.").format(args.input_bam))
def _check_input_bam_indexed(args, log=None): #pylint: disable=unused-argument bamfile = samtools.alignment_file(args.input_bam, 'rb') try: bamfile.fetch() except ValueError: raise utils.UsageError(("Specified input [{}] is not indexed. Review " "inputs and try again.").format(args.input_bam)) finally: bamfile.close()
def _check_input_bam_not_empty(args, log=None): #pylint: disable=unused-argument bamfile = samtools.alignment_file(args.input_bam, 'rb') try: next(bamfile.fetch()) except StopIteration: msg = "Specified input [{}] is empty" raise utils.UsageError(msg.format(args.input_bam)) finally: bamfile.close()
def error(self, message): '''Suppress default exit behavior''' raise utils.UsageError(message)
def _check_input_bam_exists(args, log=None): #pylint: disable=unused-argument if not os.path.exists(args.input_bam): raise utils.UsageError(("Specified input [{}] does not exist. Review " "inputs and try again.").format(args.input_bam))
def _log_force_or_raise(args, log, msg): if args.force: log.warning(msg + ' (**forcing**)') else: raise utils.UsageError(msg + ' Are you sure? (--force to proceed)')