<jupyter_start><jupyter_text>Beta-2 adrenergic receptor - part 3 (rule aggregation)  Import libraries<jupyter_code>import pandas as pd<jupyter_output><empty_output><jupyter_text>Read in the datasets<jupyter_code>df = pd.read_csv('beta2_agonists_stripped.csv')
df_pairs = pd.read_csv('beta2_agonists_pairs.csv')<jupyter_output><empty_output><jupyter_text>Filter pairs with MCS > 70% and radius 3<jupyter_code>df_pairs = df_pairs[(df_pairs.percentmcs > 0.7) & (df_pairs.radius == 3)]<jupyter_output><empty_output><jupyter_text>Determine which measurements can be included in delta property calculation<jupyter_code>df['pchembl_exact'] = df.apply(lambda x: x.pchembl_value if x.standard_relation == "=" and x.pchembl_value else None, axis=1)<jupyter_output><empty_output><jupyter_text>Combine twice with confirmed molecular pairs<jupyter_code>df_merge = df_pairs.merge(df, left_on='smiles1', right_on='stripped_smiles')
df_merge = df_merge.merge(df, left_on=['smiles2', 'target_pref_name', 'standard_type'], right_on=['stripped_smiles', 'target_pref_name', 'standard_type'])
df_merge['pchembl_exact_delta'] = df_merge['pchembl_exact_y'] - df_merge['pchembl_exact_x'] 
df_merge.sample(3).transpose()<jupyter_output><empty_output><jupyter_text>Aggregate data by the two fragments<jupyter_code>indexcols = ['fragment1', 'fragment2', 'radius', 'target_pref_name', 'standard_type'] #, 'assay_chembl_id', 'standard_units']
df_agg_data = pd.pivot_table(df_merge, values='pchembl_exact_delta', index=indexcols, aggfunc=['count','mean'])
df_agg_data.columns = ['_'.join(col).strip() for col in df_agg_data.columns.values]<jupyter_output><empty_output><jupyter_text>Retain single SMIRKS per transformation (effectively at random)<jupyter_code>df_agg_smirks = pd.pivot_table(df_merge, values='smirks', index=indexcols, aggfunc='first')
df_agg = df_agg_data.join(df_agg_smirks).reset_index()<jupyter_output><empty_output><jupyter_text>Write to file<jupyter_code>df_agg.to_csv('beta2_agonists_transformations.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13130818226359628, 'fraction_numerical': 0.008329250367466928, 'mean_word_length': 11.842767295597485, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '279585', 'license': 'Apache-2.0', 'n_tokens_mistral': 780, 'n_tokens_neox': 757, 'n_words': 107, 'path': 'notebooks/beta2_agonists_part3.ipynb', 'repo_name': 'warner121/wizepair2', 'size': '2041'}