utils/genome_search_utils.py
def count_nucleotides_in_fasta(fasta_file):
    """
    Uses Infernal's esl-seqstat to get the number of nucleotides in a fasta a
    given fasta file

    param fasta_file (string): A string representing the path to a valid fasta
    file
    returns (int): The number of nucleotides in the given fasta file
    """

    # some sanity checks
    if os.path.exists(fasta_file):
        fasta_file_dir = os.path.split(fasta_file)[0]
        # decompress fasta file first
        if fasta_file.endswith(".gz"):
            filename = fasta_file.partition('.')[0]
            with gzip.open(fasta_file, 'r') as fasta_in, open(os.path.join(fasta_file_dir,
                                                                           filename+'.fa'), 'w') as fasta_out:
                shutil.copyfileobj(fasta_in, fasta_out)
            fasta_in.close()
            fasta_out.close()
            # delete compressed version
            os.remove(fasta_file)
            fasta_file = os.path.join(fasta_file_dir, filename+'.fa')

        # create a process channel and execute the command in cmd_args
        cmd_args = ["esl-seqstat", '--dna', "-c", fasta_file]
        channel = subprocess.Popen(cmd_args, stdout=subprocess.PIPE)

        # fetch esl-seqstat result
        proc_output = channel.communicate()

        # process the response
        esl_seqstat_out = proc_output[0].split('\n')

        # extract the total number of residues from the response
        total_residues = 0
        for item in esl_seqstat_out:
            if item.find("Total") != -1:
                item = item.split(' ')
                total_residues = item[len(item)-1]

    else:
        sys.exit("\nInvalid input. The file provided does not exist!!\n")

    # cast to int and return
    return int(total_residues)

    Uses Infernal's esl-seqstat to get the number of nucleotides in a fasta a
    given fasta file

    param fasta_file (string): A string representing the path to a valid fasta
    file
    returns (int): The number of nucleotides in the given fasta file
    
Uses Infernal's esl-seqstat to get the number of nucleotides in a fasta a
given fasta file

param fasta_file (string): A string representing the path to a valid fasta
file
returns (int): The number of nucleotides in the given fasta file
Uses Infernal ' s esl - seqstat to get the number of nucleotides in a fasta a given fasta file param fasta_file ( string ) : A string representing the path to a valid fasta file returns ( int ) : The number of nucleotides in the given fasta file
def count_nucleotides_in_fasta(fasta_file):
    if os.path.exists(fasta_file):
        fasta_file_dir = os.path.split(fasta_file)[0]
        if fasta_file.endswith(".gz"):
            filename = fasta_file.partition('.')[0]
            with gzip.open(fasta_file, 'r') as fasta_in, open(os.path.join(fasta_file_dir,
                                                                           filename+'.fa'), 'w') as fasta_out:
                shutil.copyfileobj(fasta_in, fasta_out)
            fasta_in.close()
            fasta_out.close()
            os.remove(fasta_file)
            fasta_file = os.path.join(fasta_file_dir, filename+'.fa')
        cmd_args = ["esl-seqstat", '--dna', "-c", fasta_file]
        channel = subprocess.Popen(cmd_args, stdout=subprocess.PIPE)
        proc_output = channel.communicate()
        esl_seqstat_out = proc_output[0].split('\n')
        total_residues = 0
        for item in esl_seqstat_out:
            if item.find("Total") != -1:
                item = item.split(' ')
                total_residues = item[len(item)-1]
    else:
        sys.exit("\nInvalid input. The file provided does not exist!!\n")
    return int(total_residues)
def count_nucleotides_in_fasta ( fasta_file ) : if os . path . exists ( fasta_file ) : fasta_file_dir = os . path . split ( fasta_file ) [ 0 ] if fasta_file . endswith ( ".gz" ) : filename = fasta_file . partition ( '.' ) [ 0 ] with gzip . open ( fasta_file , 'r' ) as fasta_in , open ( os . path . join ( fasta_file_dir , filename + '.fa' ) , 'w' ) as fasta_out : shutil . copyfileobj ( fasta_in , fasta_out ) fasta_in . close ( ) fasta_out . close ( ) os . remove ( fasta_file ) fasta_file = os . path . join ( fasta_file_dir , filename + '.fa' ) cmd_args = [ "esl-seqstat" , '--dna' , "-c" , fasta_file ] channel = subprocess . Popen ( cmd_args , stdout = subprocess . PIPE ) proc_output = channel . communicate ( ) esl_seqstat_out = proc_output [ 0 ] . split ( '\n' ) total_residues = 0 for item in esl_seqstat_out : if item . find ( "Total" ) != - 1 : item = item . split ( ' ' ) total_residues = item [ len ( item ) - 1 ] else : sys . exit ( "\nInvalid input. The file provided does not exist!!\n" ) return int ( total_residues )
Uses Infernal's esl-seqstat to get the number of nucleotides in a fasta a
given fasta file
Uses Infernal ' s esl - seqstat to get the number of nucleotides in a fasta a given fasta file
"""
    Uses Infernal's esl-seqstat to get the number of nucleotides in a fasta a
    given fasta file

    param fasta_file (string): A string representing the path to a valid fasta
    file
    returns (int): The number of nucleotides in the given fasta file
    """ # some sanity checks # decompress fasta file first # delete compressed version # create a process channel and execute the command in cmd_args # fetch esl-seqstat result # process the response # extract the total number of residues from the response # cast to int and return
fasta_file