<commit_before>from Bio.SeqUtils.ProtParam import ProteinAnalysis
import ssbio.utils
import subprocess
import logging
log = logging.getLogger(__name__)


def sequence_properties(seq_str):
    """Utiize Biopython's ProteinAnalysis module to return general sequence properties of an amino acid string.

    Args:
        seq_str: String representation of a amino acid sequence

    Returns:
        dict: Dictionary of sequence properties. Some definitions include:
        instability_index: Any value above 40 means the protein is unstable (has a short half life).
        secondary_structure_fraction: Percentage of protein in helix, turn or sheet

    TODO:
        Finish definitions of dictionary

    """

    analysed_seq = ProteinAnalysis(seq_str)

    info_dict = {}
    info_dict['amino_acids_content'] = analysed_seq.count_amino_acids()
    info_dict['amino_acids_percent'] = analysed_seq.get_amino_acids_percent()
    info_dict['length'] = analysed_seq.length
    info_dict['monoisotopic'] = analysed_seq.monoisotopic
    info_dict['molecular_weight'] = analysed_seq.molecular_weight()
    info_dict['aromaticity'] = analysed_seq.aromaticity()
    info_dict['instability_index'] = analysed_seq.instability_index()
    info_dict['flexibility'] = analysed_seq.flexibility()
    info_dict['isoelectric_point'] = analysed_seq.isoelectric_point()
    info_dict['secondary_structure_fraction'] = analysed_seq.secondary_structure_fraction()

    return info_dict


def emboss_pepstats_on_fasta(infile, outfile='', outdir='', outext='.pepstats', force_rerun=False):
    """Run EMBOSS pepstats on a sequence string, or FASTA file.

    Args:
        infile: Path to FASTA file
        outfile: Name of output file without extension
        outdir: Path to output directory
        outext: Extension of results file, default is ".pepstats"
        force_rerun: Flag to rerun pepstats

    Returns:
        str: Path to output file.

    """

    # Create the output file name
    outfile = ssbio.utils.outfile_name_maker(inname=infile, outfile=outfile, outdir=outdir, outext=outext)

    # Run pepstats
    pepstats_args = '-sequence="{}" -outfile="{}"'.format(infile, outfile)
    ssbio.utils.command_runner(program='pepstats', args=pepstats_args, force_rerun=force_rerun, outfile=outfile)

    return outfile


def emboss_pepstats_on_str(instring, outfile, outdir='', outext='.pepstats', force_rerun=False):
    """Run EMBOSS pepstats on a sequence string, or FASTA file.

    Args:
        instring: Sequence string
        outfile: Name of output file without extension
        outdir: Path to output directory
        outext: Extension of results file, default is ".pepstats"
        force_rerun: Flag to rerun pepstats

    Returns:
        str: Path to output file.

    """
    # Create the output file name
    outfile = ssbio.utils.outfile_name_maker(inname='seq_str', outfile=outfile, outdir=outdir, outext=outext)

    # Run pepstats
    pepstats_args = '-sequence=asis::{} -outfile="{}"'.format(instring, outfile)
    ssbio.utils.command_runner(program='pepstats', args=pepstats_args, force_rerun=force_rerun, outfile=outfile)<commit_msg>Bug fix for force_rerun<commit_after>from Bio.SeqUtils.ProtParam import ProteinAnalysis
import ssbio.utils
import subprocess
import logging
log = logging.getLogger(__name__)


def sequence_properties(seq_str):
    """Utiize Biopython's ProteinAnalysis module to return general sequence properties of an amino acid string.

    Args:
        seq_str: String representation of a amino acid sequence

    Returns:
        dict: Dictionary of sequence properties. Some definitions include:
        instability_index: Any value above 40 means the protein is unstable (has a short half life).
        secondary_structure_fraction: Percentage of protein in helix, turn or sheet

    TODO:
        Finish definitions of dictionary

    """

    analysed_seq = ProteinAnalysis(seq_str)

    info_dict = {}
    info_dict['amino_acids_content'] = analysed_seq.count_amino_acids()
    info_dict['amino_acids_percent'] = analysed_seq.get_amino_acids_percent()
    info_dict['length'] = analysed_seq.length
    info_dict['monoisotopic'] = analysed_seq.monoisotopic
    info_dict['molecular_weight'] = analysed_seq.molecular_weight()
    info_dict['aromaticity'] = analysed_seq.aromaticity()
    info_dict['instability_index'] = analysed_seq.instability_index()
    info_dict['flexibility'] = analysed_seq.flexibility()
    info_dict['isoelectric_point'] = analysed_seq.isoelectric_point()
    info_dict['secondary_structure_fraction'] = analysed_seq.secondary_structure_fraction()

    return info_dict


def emboss_pepstats_on_fasta(infile, outfile='', outdir='', outext='.pepstats', force_rerun=False):
    """Run EMBOSS pepstats on a sequence string, or FASTA file.

    Args:
        infile: Path to FASTA file
        outfile: Name of output file without extension
        outdir: Path to output directory
        outext: Extension of results file, default is ".pepstats"
        force_rerun: Flag to rerun pepstats

    Returns:
        str: Path to output file.

    """

    # Create the output file name
    outfile = ssbio.utils.outfile_name_maker(inname=infile, outfile=outfile, outdir=outdir, outext=outext)

    # Run pepstats
    pepstats_args = '-sequence="{}" -outfile="{}"'.format(infile, outfile)
    ssbio.utils.command_runner(program='pepstats', args=pepstats_args, force_rerun_flag=force_rerun, outfile=outfile)

    return outfile


def emboss_pepstats_on_str(instring, outfile, outdir='', outext='.pepstats', force_rerun=False):
    """Run EMBOSS pepstats on a sequence string, or FASTA file.

    Args:
        instring: Sequence string
        outfile: Name of output file without extension
        outdir: Path to output directory
        outext: Extension of results file, default is ".pepstats"
        force_rerun: Flag to rerun pepstats

    Returns:
        str: Path to output file.

    """
    # Create the output file name
    outfile = ssbio.utils.outfile_name_maker(inname='seq_str', outfile=outfile, outdir=outdir, outext=outext)

    # Run pepstats
    pepstats_args = '-sequence=asis::{} -outfile="{}"'.format(instring, outfile)
    ssbio.utils.command_runner(program='pepstats', args=pepstats_args, force_rerun_flag=force_rerun, outfile=outfile)
{'fraction_non_alphanumeric': 0.09013282732447818, 'fraction_numerical': 0.0006325110689437065, 'mean_word_length': 4.117313915857605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '509632', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1879, 'n_words': 494}