示例#1
0
文件: run_midas.py 项目: zhaoc1/MIDAS
def check_species(args):
    # check file type
    if args['m1']:
        args['file_type'] = utility.auto_detect_file_type(args['m1'])
    # check database
    utility.check_database(args)
    # create output directories
    if not os.path.isdir('%s/species' % args['outdir']):
        os.makedirs('%s/species' % args['outdir'])
    # check word size
    if args['word_size'] < 12:
        sys.exit(
            "\nError: Invalid word size: %s. Must be greater than or equal to 12\n"
            % args['word_size'])
    # check mapping identity
    if args['mapid'] and (args['mapid'] < 0 or args['mapid'] > 100):
        sys.exit(
            "\nError: Invalid mapping identity: %s. Must be between 0 and 100\n"
            % args['mapid'])
    # check alignment coverage
    if args['aln_cov'] < 0 or args['aln_cov'] > 1:
        sys.exit(
            "\nError: Invalid alignment coverage: %s. Must be between 0 and 1\n"
            % args['aln_cov'])
    # check that m1 (and m2) exist
    for arg in ['m1', 'm2']:
        if args[arg] and not os.path.isfile(args[arg]):
            sys.exit("\nError: Input file does not exist: '%s'\n" % args[arg])
    # check that extention matches compression
    if args['m1']: utility.check_compression(args['m1'])
    if args['m2']: utility.check_compression(args['m2'])
示例#2
0
文件: run_midas.py 项目: zhaoc1/MIDAS
def check_snps(args):
    """ Check validity of command line arguments """
    # check file type
    if args['m1']:
        args['file_type'] = utility.auto_detect_file_type(args['m1'])
    # check database
    utility.check_database(args)
    # make sure selected species are valid
    check_selected_species(args)
    # create output directory
    if not os.path.isdir('%s/snps' % args['outdir']):
        os.makedirs('%s/snps' % args['outdir'])
    # pipeline options
    if not any([args['build_db'], args['align'], args['call']]):
        args['build_db'] = True
        args['align'] = True
        args['call'] = True
    # set default species selection
    if not any([args['species_id'], args['species_topn'], args['species_cov']
                ]):
        args['species_cov'] = 3.0
    # species selection options, but no no profile file
    profile = '%s/species/species_profile.txt' % args['outdir']
    if not os.path.isfile(profile):
        if (args['species_topn'] or args['species_cov']) and args['build_db']:
            sys.exit("\nError: Could not find species abundance profile: %s\n\
To specify species with --species_topn or --species_cov you must have run: run_midas.py species\n\
Alternatively, you can manually specify one or more species using --species_id\n"
                     % profile)
    # no database but --align specified
    if (args['align'] and not args['build_db'] and
            not os.path.isfile('%s/snps/temp/genomes.fa' % args['outdir'])):
        error = "\nError: You've specified --align, but no database has been built"
        error += "\nTry running with --build_db\n"
        sys.exit(error)
    # no bamfile but --call specified
    if (args['call'] and not args['align'] and
            not os.path.isfile('%s/snps/temp/genomes.bam' % args['outdir'])):
        error = "\nError: You've specified --pileup, but no alignments were found"
        error += "\nTry running with --align\n"
        sys.exit(error)
    # no genomes but --call specified
    if (args['call'] and not args['build_db'] and
            not os.path.isfile('%s/snps/temp/genomes.fa' % args['outdir'])):
        error = "\nError: You've specified --pileup, but the no genome database was found"
        error += "\nTry running with --build_db\n"
        sys.exit(error)
    # no reads
    if args['align'] and not args['m1']:
        sys.exit(
            "\nError: To align reads, you must specify path to input FASTA/FASTQ\n"
        )
    # check input file paths
    for arg in ['m1', 'm2']:
        if args[arg] and not os.path.isfile(args[arg]):
            sys.exit("\nError: Input file does not exist: '%s'\n" % args[arg])
    # check compression
    if args['m1']: utility.check_compression(args['m1'])
    if args['m2']: utility.check_compression(args['m2'])
    # input options
    if args['m2'] and not args['m1']:
        sys.exit(
            "\nError: Must specify -1 and -2 if aligning paired end reads\n")
    if args['m2'] and args['interleaved']:
        sys.exit("\nError: Cannot specify --interleaved together with -2\n")
    # sanity check input values
    if args['mapid'] < 1 or args['mapid'] > 100:
        sys.exit("\nError: MAPQ must be between 1 and 100\n")
    if args['mapq'] < 0 or args['mapq'] > 100:
        sys.exit("\nError: MAPQ must be between 0 and 100\n")
    if args['baseq'] < 0 or args['baseq'] > 100:
        sys.exit("\nError: BASEQ must be between 0 and 100\n")
    if args['aln_cov'] < 0 or args['aln_cov'] > 1:
        sys.exit("\nError: ALN_COV must be between 0 and 1\n")