scripts/support/genome_size_calculator.py
def calculate_genome_size(genome_source):
    """
    Calculate the size of a given sequence file (this should be a genome) and return the total
    number of nucleotides in the file, or if genome_fasta is a directory, return a dictionary
    of genome_ids: size pairs

    genome_source: A valid sequence file in fasta format or a directory of fasta files

    return: A dictionary or the an integer number which is the total number of nucleotides
    found in the sequence file that is provided as input
    """

    genome_files = []
    genome_sizes = {}

    if os.path.isdir(genome_source):
        genome_files = [x for x in os.listdir(genome_source)
                        if x.endswith('.fa') or x.endswith('.fasta')]

        for seq_file in genome_files:
            try:
                args = [gc.ESL_SEQSTAT, '--dna', os.path.join(genome_source, seq_file)]
                # response = subprocess.check_output(args, shell=True, stderr=subprocess.STDOUT)
                # calculate genome size using esl-seqstat and return Total
                response = subprocess.check_output(args)
                total_res_line = response.split('\n')[3]

            except subprocess.CalledProcessError as err:
                raise RuntimeError("command '{}' return with error (code {}): {}".format(err.cmd,
                                                                                         err.returncode,
                                                                                         err.output))

            # split the line and get total number of residues which must be the last element in the list
            # then strip any white characters and convert to integer
            total_res = int(total_res_line.split(' ')[-1].strip())
            genome_id = seq_file.partition('.')[0]
            genome_sizes[genome_id] = total_res

    else:

        try:
            # response = subprocess.check_output(args, shell=True, stderr=subprocess.STDOUT)
            # calculate genome size using esl-seqstat and return Total
            args = [gc.ESL_SEQSTAT, '--dna', genome_source]
            response = subprocess.check_output(args)
            total_res_line = response.split('\n')[3]

        except subprocess.CalledProcessError as err:
            raise RuntimeError("command '{}' return with error (code {}): {}".format(err.cmd,
                                                                                     err.returncode,
                                                                                     err.output))

        # split the line and get total number of residues which must be the last element in the list
        # then strip any white characters and convert to integer
        total_res = int(total_res_line.split(' ')[-1].strip())
        return total_res

    return genome_sizes

    Calculate the size of a given sequence file (this should be a genome) and return the total
    number of nucleotides in the file, or if genome_fasta is a directory, return a dictionary
    of genome_ids: size pairs

    genome_source: A valid sequence file in fasta format or a directory of fasta files

    return: A dictionary or the an integer number which is the total number of nucleotides
    found in the sequence file that is provided as input
    
Calculate the size of a given sequence file (this should be a genome) and return the total
number of nucleotides in the file, or if genome_fasta is a directory, return a dictionary
of genome_ids: size pairs

A valid sequence file in fasta format or a directory of fasta files

A dictionary or the an integer number which is the total number of nucleotides
found in the sequence file that is provided as input
Calculate the size of a given sequence file ( this should be a genome ) and return the total number of nucleotides in the file or if genome_fasta is a directory return a dictionary of genome_ids : size pairs A valid sequence file in fasta format or a directory of fasta files A dictionary or the an integer number which is the total number of nucleotides found in the sequence file that is provided as input
def calculate_genome_size(genome_source):
    genome_files = []
    genome_sizes = {}
    if os.path.isdir(genome_source):
        genome_files = [x for x in os.listdir(genome_source)
                        if x.endswith('.fa') or x.endswith('.fasta')]
        for seq_file in genome_files:
            try:
                args = [gc.ESL_SEQSTAT, '--dna', os.path.join(genome_source, seq_file)]
                response = subprocess.check_output(args)
                total_res_line = response.split('\n')[3]
            except subprocess.CalledProcessError as err:
                raise RuntimeError("command '{}' return with error (code {}): {}".format(err.cmd,
                                                                                         err.returncode,
                                                                                         err.output))
            total_res = int(total_res_line.split(' ')[-1].strip())
            genome_id = seq_file.partition('.')[0]
            genome_sizes[genome_id] = total_res
    else:
        try:
            args = [gc.ESL_SEQSTAT, '--dna', genome_source]
            response = subprocess.check_output(args)
            total_res_line = response.split('\n')[3]
        except subprocess.CalledProcessError as err:
            raise RuntimeError("command '{}' return with error (code {}): {}".format(err.cmd,
                                                                                     err.returncode,
                                                                                     err.output))
        total_res = int(total_res_line.split(' ')[-1].strip())
        return total_res
    return genome_sizes
def calculate_genome_size ( genome_source ) : genome_files = [ ] genome_sizes = { } if os . path . isdir ( genome_source ) : genome_files = [ x for x in os . listdir ( genome_source ) if x . endswith ( '.fa' ) or x . endswith ( '.fasta' ) ] for seq_file in genome_files : try : args = [ gc . ESL_SEQSTAT , '--dna' , os . path . join ( genome_source , seq_file ) ] response = subprocess . check_output ( args ) total_res_line = response . split ( '\n' ) [ 3 ] except subprocess . CalledProcessError as err : raise RuntimeError ( "command '{}' return with error (code {}): {}" . format ( err . cmd , err . returncode , err . output ) ) total_res = int ( total_res_line . split ( ' ' ) [ - 1 ] . strip ( ) ) genome_id = seq_file . partition ( '.' ) [ 0 ] genome_sizes [ genome_id ] = total_res else : try : args = [ gc . ESL_SEQSTAT , '--dna' , genome_source ] response = subprocess . check_output ( args ) total_res_line = response . split ( '\n' ) [ 3 ] except subprocess . CalledProcessError as err : raise RuntimeError ( "command '{}' return with error (code {}): {}" . format ( err . cmd , err . returncode , err . output ) ) total_res = int ( total_res_line . split ( ' ' ) [ - 1 ] . strip ( ) ) return total_res return genome_sizes
Calculate the size of a given sequence file (this should be a genome) and return the total
number of nucleotides in the file, or if genome_fasta is a directory, return a dictionary
of genome_ids: size pairs
Calculate the size of a given sequence file ( this should be a genome ) and return the total number of nucleotides in the file or if genome_fasta is a directory return a dictionary of genome_ids : size pairs
"""
    Calculate the size of a given sequence file (this should be a genome) and return the total
    number of nucleotides in the file, or if genome_fasta is a directory, return a dictionary
    of genome_ids: size pairs

    genome_source: A valid sequence file in fasta format or a directory of fasta files

    return: A dictionary or the an integer number which is the total number of nucleotides
    found in the sequence file that is provided as input
    """ # response = subprocess.check_output(args, shell=True, stderr=subprocess.STDOUT) # calculate genome size using esl-seqstat and return Total # split the line and get total number of residues which must be the last element in the list # then strip any white characters and convert to integer # response = subprocess.check_output(args, shell=True, stderr=subprocess.STDOUT) # calculate genome size using esl-seqstat and return Total # split the line and get total number of residues which must be the last element in the list # then strip any white characters and convert to integer
genome_source