text_html_output_1.png
from multiprocess import Pool

import numpy as np

import numpy as np

import os

import os

import pandas as pd

import pandas as pd

import warnings

import pandas as pd
import numpy as np
import plotly.express as px
from plotly.subplots import make_subplots
import gc
from tqdm import tqdm
import pickle
import os
import warnings
warnings.filterwarnings('ignore')
train_clinical_data = pd.read_csv('../input/amp-parkinsons-disease-progression-prediction/train_clinical_data.csv')
train_peptides = pd.read_csv('../input/amp-parkinsons-disease-progression-prediction/train_peptides.csv')
train_proteins = pd.read_csv('../input/amp-parkinsons-disease-progression-prediction/train_proteins.csv')
supplemental_clinical_data = pd.read_csv('../input/amp-parkinsons-disease-progression-prediction/supplemental_clinical_data.csv')

peptideIndexLabels = ['visit_id', 'patient_id', 'UniProt']
train_peptides.set_index(peptideIndexLabels, drop=True)
peptideData = train_peptides.merge(train_proteins, on=['visit_id', 'visit_month', 'patient_id', 'UniProt'], how='inner').drop_duplicates()

peptides_per_patient = peptideData.groupby('patient_id')['Peptide'].nunique()

import numpy as np
import pandas as pd
from tqdm import tqdm
from multiprocess import Pool
import os
import tensorflow as tf
peptideData['Peptide oxidation score'] = 0
peptideData['Protein oxidation score'] = 0
peptideData['Peptide carbamidomethylation score'] = 0
peptideData['Protein carbamidomethylation score'] = 0
def preprocessPeptides(args):
    (patientID, proteinID), currentPeptides = args
    peptideCount = len(currentPeptides)
    if peptideCount == 0:
        return currentPeptides
    def deserializeUniMod(peptide, scoreAndRemove=['UniMod_35', 'UniMod_4']):
        oxidationScore, carbamidomethylationScore = (0, 0)
        for string in scoreAndRemove:
            while string in peptide:
                peptide = peptide.replace(f'({string})', '', 1)
                if string == 'UniMod_35':
                    oxidationScore += np.log(len(peptide))
                elif string == 'UniMod_4':
                    carbamidomethylationScore += np.log(len(peptide))
        return pd.Series([peptide, oxidationScore, carbamidomethylationScore])
    currentPeptides[['Peptide', 'Peptide oxidation score', 'Peptide carbamidomethylation score']] = currentPeptides['Peptide'].apply(deserializeUniMod)
    normalized_carbamidomethylation_score = currentPeptides['Peptide carbamidomethylation score'].sum() / peptideCount
    normalized_oxidation_score = currentPeptides['Peptide oxidation score'].sum() / peptideCount
    currentPeptides['Protein oxidation score'] = normalized_oxidation_score
    currentPeptides['Protein carbamidomethylation score'] = normalized_carbamidomethylation_score
    return currentPeptides
grouped_peptides = peptideData.groupby(['patient_id', 'UniProt'])
with Pool(os.cpu_count()) as pool:
    preprocessed_peptides = pool.map(preprocessPeptides, [(group, data) for group, data in grouped_peptides])
peptideData = pd.concat(preprocessed_peptides).reset_index(drop=True)

len([(row[0], row[0]) for row in peptideData.groupby(['Peptide'])])