scripts/split_datasets.py
def save_each_part_in_seperate_file(original_filename, original_data, leading_line, smiles_folds, smiles_test,
                                    smiles_index, saving_path, data_name):
    """
    For each subset find lines that belong to it and save them to the corresponding file.
    :param original_filename: str: path to the original dataset
    :param original_data: data returned by load_original_file
    :param leading_line: str or None: firstline returned by load_original_file
    :param smiles_folds: returned by define_split_on_smiles
    :param smiles_test: returned by define_split_on_smiles
    :param smiles_index: int: which entry is SMILES
    :param saving_path: where should the data be stored
    :param data_name: under what label should the data be stored
    :return: None
    """
    with open(original_filename, 'r') as f:
        lines = f.readlines()

    if leading_line is not None:
        leading_line = lines[0]
        lines = lines[1:]

    # test set
    with open(os.path.join(saving_path, data_name + "-test.csv"), 'w') as f:
        if leading_line is not None:
            f.write(leading_line)

        for line, row in zip(lines, original_data):
            try:
                mol = Chem.MolFromSmiles(row[smiles_index], sanitize=False)
                Chem.SanitizeMol(mol)
                this_smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
                if this_smiles in smiles_test:
                    f.write(line)
            except Exception as e:
                pass

    # folds
    for idx, current_smiles in enumerate(smiles_folds):
        with open(os.path.join(saving_path, f"{data_name}-fold{idx+1}.csv"), 'w') as f:
            if leading_line is not None:
                f.write(leading_line)

            for line, row in zip(lines, original_data):
                try:
                    mol = Chem.MolFromSmiles(row[smiles_index], sanitize=False)
                    Chem.SanitizeMol(mol)
                    this_smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
                    if this_smiles in current_smiles:
                        f.write(line)
                except Exception as e:
                    pass

    For each subset find lines that belong to it and save them to the corresponding file.
    :param original_filename: str: path to the original dataset
    :param original_data: data returned by load_original_file
    :param leading_line: str or None: firstline returned by load_original_file
    :param smiles_folds: returned by define_split_on_smiles
    :param smiles_test: returned by define_split_on_smiles
    :param smiles_index: int: which entry is SMILES
    :param saving_path: where should the data be stored
    :param data_name: under what label should the data be stored
    :return: None
    
For each subset find lines that belong to it and save them to the corresponding file.
For each subset find lines that belong to it and save them to the corresponding file .
def save_each_part_in_seperate_file(original_filename, original_data, leading_line, smiles_folds, smiles_test,
                                    smiles_index, saving_path, data_name):
    with open(original_filename, 'r') as f:
        lines = f.readlines()
    if leading_line is not None:
        leading_line = lines[0]
        lines = lines[1:]
    with open(os.path.join(saving_path, data_name + "-test.csv"), 'w') as f:
        if leading_line is not None:
            f.write(leading_line)
        for line, row in zip(lines, original_data):
            try:
                mol = Chem.MolFromSmiles(row[smiles_index], sanitize=False)
                Chem.SanitizeMol(mol)
                this_smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
                if this_smiles in smiles_test:
                    f.write(line)
            except Exception as e:
                pass
    for idx, current_smiles in enumerate(smiles_folds):
        with open(os.path.join(saving_path, f"{data_name}-fold{idx+1}.csv"), 'w') as f:
            if leading_line is not None:
                f.write(leading_line)
            for line, row in zip(lines, original_data):
                try:
                    mol = Chem.MolFromSmiles(row[smiles_index], sanitize=False)
                    Chem.SanitizeMol(mol)
                    this_smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
                    if this_smiles in current_smiles:
                        f.write(line)
                except Exception as e:
                    pass
def save_each_part_in_seperate_file ( original_filename , original_data , leading_line , smiles_folds , smiles_test , smiles_index , saving_path , data_name ) : with open ( original_filename , 'r' ) as f : lines = f . readlines ( ) if leading_line is not None : leading_line = lines [ 0 ] lines = lines [ 1 : ] with open ( os . path . join ( saving_path , data_name + "-test.csv" ) , 'w' ) as f : if leading_line is not None : f . write ( leading_line ) for line , row in zip ( lines , original_data ) : try : mol = Chem . MolFromSmiles ( row [ smiles_index ] , sanitize = False ) Chem . SanitizeMol ( mol ) this_smiles = Chem . MolToSmiles ( mol , isomericSmiles = True ) if this_smiles in smiles_test : f . write ( line ) except Exception as e : pass for idx , current_smiles in enumerate ( smiles_folds ) : with open ( os . path . join ( saving_path , f"{data_name}-fold{idx+1}.csv" ) , 'w' ) as f : if leading_line is not None : f . write ( leading_line ) for line , row in zip ( lines , original_data ) : try : mol = Chem . MolFromSmiles ( row [ smiles_index ] , sanitize = False ) Chem . SanitizeMol ( mol ) this_smiles = Chem . MolToSmiles ( mol , isomericSmiles = True ) if this_smiles in current_smiles : f . write ( line ) except Exception as e : pass
For each subset find lines that belong to it and save them to the corresponding file.
For each subset find lines that belong to it and save them to the corresponding file .
"""
    For each subset find lines that belong to it and save them to the corresponding file.
    :param original_filename: str: path to the original dataset
    :param original_data: data returned by load_original_file
    :param leading_line: str or None: firstline returned by load_original_file
    :param smiles_folds: returned by define_split_on_smiles
    :param smiles_test: returned by define_split_on_smiles
    :param smiles_index: int: which entry is SMILES
    :param saving_path: where should the data be stored
    :param data_name: under what label should the data be stored
    :return: None
    """ # test set # folds
None
original_filename
path to the original dataset
path to the original dataset
original_data
data returned by load_original_file
data returned by load_original_file
leading_line
str or None: firstline returned by load_original_file
str or None : firstline returned by load_original_file
smiles_folds
returned by define_split_on_smiles
returned by define_split_on_smiles
smiles_test
returned by define_split_on_smiles
returned by define_split_on_smiles
smiles_index
which entry is SMILES
which entry is SMILES
saving_path
None
data_name
under what label should the data be stored
under what label should the data be stored