Beispiel #1
0
def get_max_reads_length(reads_file, log, num_checked):
    file_type = SeqIO.get_read_file_type(reads_file)
    if not file_type:
        error('Incorrect extension of reads file: ' + reads_file, log)

    max_reads_length = max([len(rec) for rec in itertools.islice(SeqIO.parse(SeqIO.Open(reads_file, "r"), file_type), num_checked)])
    log.info(reads_file + ': max reads length: ' + str(max_reads_length))
    return max_reads_length
Beispiel #2
0
def check_file_not_empty(input_filename, message="", log=None):
    filename = abspath(expanduser(input_filename))
    file_type = get_read_file_type(input_filename, log)
    if (file_type == 'bam'):
        return

    try:
        reads_iterator = SeqIO.parse(SeqIO.Open(filename, "r"), file_type)
        if next(reads_iterator, None) is None:
            error("file is empty: %s (%s)" % (filename, message), log=log)
    except Exception as inst:
        error(inst.args[0].format(FILE=filename) + "\n\n" +
              traceback.format_exc().format(FILE=filename),
              log=log)
def get_max_reads_length(reads_file, log, num_checked):
    if reads_file in options_storage.dict_of_prefixes:
        ext = options_storage.dict_of_prefixes[reads_file]
        file_type = SeqIO.get_read_file_type(ext)
    else:
        file_type = SeqIO.get_read_file_type(reads_file)

    if not file_type:
        error("incorrect extension of reads file: %s" % reads_file, log)

    max_reads_length = max([
        len(rec) for rec in itertools.islice(
            SeqIO.parse(SeqIO.Open(reads_file, "r"), file_type), num_checked)
    ])
    log.info("%s: max reads length: %s" % (reads_file, str(max_reads_length)))
    return max_reads_length
Beispiel #4
0
def get_max_reads_length(reads_file, log, num_checked):
    file_type = get_read_file_type(reads_file, log)
    max_reads_length = 0
    try:
        max_reads_length = max([
            len(rec) for rec in itertools.islice(
                SeqIO.parse(SeqIO.Open(reads_file, "r"), file_type),
                num_checked)
        ])
    except Exception as inst:
        error(inst.args[0].format(FILE=reads_file) + "\n\n" +
              traceback.format_exc().format(FILE=reads_file),
              log=log)
    else:
        log.info("%s: max reads length: %s" %
                 (reads_file, str(max_reads_length)))
    return max_reads_length