<commit_before>import os.path as op
import pandas as pd
import shutil
import os
import logging
log = logging.getLogger(__name__)
import time
from ssbio.structure.pdbioext import PDBIOExt
from ssbio.structure.cleanpdb import CleanPDB
import ssbio.utils

def organize_itasser_models(raw_dir, copy_to_dir, rename_model_to=None, model_to_use='model1', force_rerun=False):
    """Reorganize the raw information from I-TASSER modeling.

    - Copies the model1.pdb file and COACH results (if they exist) to specified folder
    - Parses modeling information such as C-scores, template, etc
    - Also will parse binding site (COACH) information if it exists

    Returns:
        dict: summary of I-TASSER results for a sequence
    """

    hom_dict = {}
    # TODO: add force_rerun to more parts of this function
    # TODO: use ssbio.utils function

    # Best homology model is "model1.pdb"
    old_model_path = op.join(raw_dir, '{}.pdb'.format(model_to_use))

    if rename_model_to:
        new_filename = rename_model_to
    else:
        new_filename = model_to_use
    new_model_path = op.join(copy_to_dir, '{}.pdb'.format(new_filename))

    if op.exists(old_model_path):
        if ssbio.utils.force_rerun(flag=force_rerun, outfile=new_model_path):

            # Clean it
            custom_clean = CleanPDB()
            my_pdb = PDBIOExt(old_model_path)
            default_cleaned_pdb = my_pdb.write_pdb(custom_selection=custom_clean,
                                                   custom_name=new_filename,
                                                   out_dir=copy_to_dir)

        hom_dict['model_file'] = op.basename(new_model_path)
        hom_dict['model_date'] = time.strftime('%Y-%m-%d', time.gmtime(os.path.getmtime(old_model_path)))
    else:
        log.debug('{}: No homology model exists'.format(raw_dir))
        return hom_dict

    ### Other modeling results
    dest_itasser_dir = op.join(copy_to_dir, '{}_itasser'.format(new_filename))
    if not op.exists(dest_itasser_dir) and op.exists(old_model_path):
        os.mkdir(dest_itasser_dir)
<commit_msg>Clean PDBs when organizing ITASSER models<commit_after>import os.path as op
import pandas as pd
import shutil
import os
import logging
log = logging.getLogger(__name__)
import time
from ssbio.structure.pdbioext import PDBIOExt
from ssbio.structure.cleanpdb import CleanPDB
import ssbio.utils

def organize_itasser_models(raw_dir, copy_to_dir, rename_model_to=None, model_to_use='model1', force_rerun=False):
    """Reorganize the raw information from I-TASSER modeling.

    - Copies the model1.pdb file and COACH results (if they exist) to specified folder
    - Parses modeling information such as C-scores, template, etc
    - Also will parse binding site (COACH) information if it exists

    Returns:
        dict: summary of I-TASSER results for a sequence
    """

    hom_dict = {}
    # TODO: add force_rerun to more parts of this function
    # TODO: use ssbio.utils function

    # Best homology model is "model1.pdb"
    old_model_path = op.join(raw_dir, '{}.pdb'.format(model_to_use))

    if rename_model_to:
        new_filename = rename_model_to
    else:
        new_filename = model_to_use
    new_model_path = op.join(copy_to_dir, '{}.pdb'.format(new_filename))

    if op.exists(old_model_path):
        if ssbio.utils.force_rerun(flag=force_rerun, outfile=new_model_path):

            # Clean it
            custom_clean = CleanPDB()
            my_pdb = PDBIOExt(old_model_path)
            default_cleaned_pdb = my_pdb.write_pdb(custom_selection=custom_clean,
                                                   custom_name=new_filename,
                                                   out_dir=copy_to_dir,
                                                   out_suffix='')

        hom_dict['model_file'] = op.basename(new_model_path)
        hom_dict['model_date'] = time.strftime('%Y-%m-%d', time.gmtime(os.path.getmtime(old_model_path)))
    else:
        log.debug('{}: No homology model exists'.format(raw_dir))
        return hom_dict

    ### Other modeling results
    dest_itasser_dir = op.join(copy_to_dir, '{}_itasser'.format(new_filename))
    if not op.exists(dest_itasser_dir) and op.exists(old_model_path):
        os.mkdir(dest_itasser_dir)

{'fraction_non_alphanumeric': 0.08754681647940075, 'fraction_numerical': 0.0014044943820224719, 'mean_word_length': 2.863471971066908, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3371389', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1320, 'n_words': 312}