| import os |
| import sys |
| import torch |
| import PATH |
| import utils |
| import numpy as np |
| import pandas as pd |
| import seaborn as sns |
| from matplotlib import pyplot as plt |
|
|
| from sklearn.preprocessing import StandardScaler |
|
|
|
|
| |
|
|
| |
| Ex_data_dir = utils.data_dir |
| csv_path_ls = [os.path.join(Ex_data_dir,csv) for csv in ['GSM3130435_egfp_unmod_1.csv','GSM3130443_designed_library.csv','GSM4084997_varying_length_25to100.csv']] |
| for path in csv_path_ls: |
| assert os.path.exists(path), f"The file {path} is not properly downloaded" |
|
|
| df_dict = { |
| csv_path.split("_")[-1].replace(".csv","") : pd.read_csv(csv_path,low_memory=False) for csv_path in csv_path_ls |
| } |
| |
| df_dict['library'].rename({'total':'total_reads'},axis=1,inplace=True) |
| df_dict['25to100']['r13'] = np.zeros((df_dict['25to100'].shape[0],)) |
|
|
|
|
|
|
| |
| df = df_dict['1'] |
| df.sort_values('total_reads', inplace=True, ascending=False) |
| df.reset_index(inplace=True, drop=True) |
|
|
|
|
| |
| |
| test_df = df.iloc[:20000] |
| train_val_df = df.iloc[20000:280000] |
|
|
|
|
|
|
| |
| df = df_dict['library'] |
| |
| human_lib = df[(df['library'] == 'human_utrs') | (df['library'] == 'snv')] |
| human_lib = human_lib.sort_values('total_reads', ascending=False).reset_index(drop=True) |
|
|
| |
| sub = human_lib.iloc[:25000] |
| remaining = human_lib.iloc[25000:] |
|
|
|
|
| |
| df1 = df_dict['25to100'] |
| |
| df = df1[df1['set']=='random'] |
|
|
| |
| df=df[df['total_reads']>=10] |
|
|
| df['utr100'] = 75*'N' +df['utr'] |
| df['utr100'] = df['utr100'].str[-100:] |
| df.sort_values('total_reads', inplace=True, ascending=False) |
| df.reset_index(inplace=True, drop=True) |
|
|
| |
| human = df1[df1['set']=='human'] |
| |
| human=human[human['total_reads']>=10] |
| human['utr100'] = 75*'N' +human['utr'] |
| human['utr100'] = human['utr100'].str[-100:] |
| human.sort_values('total_reads', inplace=True, ascending=False) |
| human.reset_index(inplace=True, drop=True) |
|
|
| e_test = pd.DataFrame(columns=df.columns) |
| for i in range(25,101): |
| tmp = df[df['len']==i] |
| tmp.sort_values('total_reads', inplace=True, ascending=False) |
| tmp.reset_index(inplace=True, drop=True) |
| e_test = e_test.append(tmp.iloc[:100]) |
|
|
| subhuman = pd.DataFrame(columns=human.columns) |
| for i in range(25,101): |
| tmp = human[human['len']==i] |
| tmp.sort_values('total_reads', inplace=True, ascending=False) |
| tmp.reset_index(inplace=True, drop=True) |
| subhuman = subhuman.append(tmp.iloc[:100]) |
|
|
| e_train = pd.concat([df, e_test, e_test]).drop_duplicates(keep=False) |
|
|
| vleng_test = pd.concat([e_test,subhuman]) |
| bins = np.arange(24, 105, 20) |
| labels = [ '25-44' , '45-64', '65-84', '85-100'] |
| vleng_test['rng'] = pd.cut(vleng_test['len'], bins=bins) |
|
|
| |
| e_test.to_csv(os.path.join(Ex_data_dir,"MPA_V_test.csv"),index=False) |
| e_train.to_csv(os.path.join(Ex_data_dir,"MPA_V_train_val.csv"),index=False) |
|
|
| sub.to_csv(os.path.join(Ex_data_dir,"MPA_H_test.csv"),index=False) |
| remaining.to_csv(os.path.join(Ex_data_dir,"MPA_H_train_val.csv"),index=False) |
|
|
| |
| remaining.sample(frac=0.1).to_csv(os.path.join(Ex_data_dir,"SubMPA_H_train_val.csv"),index=False) |
| sub.to_csv(os.path.join(Ex_data_dir,"SubMPA_H_test.csv"),index=False) |
|
|
| test_df.to_csv(os.path.join(Ex_data_dir,"MPA_U_test.csv"),index=False) |
| train_val_df.to_csv(os.path.join(Ex_data_dir,"MPA_U_train_val.csv"),index=False) |
|
|
|
|
|
|
| print("The preprocssing for MPA tasks is Finished !!") |
| print(f"The files are saved to {utils.data_dir}") |