<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Check Survival curves for the different classes
Step1:  Comparison with MATLAB results
Step2:  The class ids obtained from MATLAB and from Theano are not the same, the formula below happens to convert them
Step3:  Number of samples with the same class
<ASSISTANT_TASK:>
Python Code:
import csv
id=[]
with open('../data/'+datafiles['mRNA']) as f:
    my_csv = csv.reader(f,delimiter='\t')
    id = my_csv.next()
stat={}
with open('../data/TCGA_Data/data_bcr_clinical_data_patient.csv') as f:
    reader = csv.reader(f, delimiter='\t')
    for row in reader:
        patient_id=row[1]
        stat[patient_id]=(row[15],row[16],row[17])
import re
time_list = []
event_list = []
group_list = []
print('The following case IDs were  not found in clinical data')
for index, key in enumerate(id[1:]):
    m = re.match('TCGA-\d+-\d+', key)
    patient_id = m.group(0)
    if patient_id in stat:
        patient_stat = stat[patient_id]
        add_group = True
        try:
            time_list.append(float(patient_stat[2]))
            event_list.append(1)
        except ValueError:
            try:
                time_list.append(float(patient_stat[1]))
                event_list.append(0)
            except ValueError:
                print('No data for %s' % patient_id)
                add_group = False
        if add_group:
            group_list.append(cl[index])
    else:
        print(patient_id)
from lifelines import KaplanMeierFitter
kmf = KaplanMeierFitter()
kmf.fit(time_list,event_observed=event_list)
kmf.plot()
T=np.array(time_list)
E=np.array(event_list)
ix = (np.array(group_list) == 1)
kmf.fit(T[ix], E[ix], label='group 1')
ax=kmf.plot()
for i in [4]:
    ix=(np.array(group_list)==i)
    kmf.fit(T[ix], E[ix], label='group %d' % i)
    kmf.plot(ax=ax)
T=np.array(time_list)
E=np.array(event_list)
ix = (np.array(group_list) == 0)
kmf.fit(T[ix], E[ix], label='group 0')
ax=kmf.plot()
for i in range(2,4):
    ix=(np.array(group_list)==i)
    kmf.fit(T[ix], E[ix], label='group %d' % i)
    kmf.plot(ax=ax)
Explanation: Check Survival curves for the different classes
End of explanation
with open('/Users/gluca/SoftwareProjects/Thesis/MDBN/MATLAB_classes.txt') as f:
    matlab_classes = f.readlines()
ML = []
for s in matlab_classes:
    ML.append(float(s))
ML = np.asarray(ML)
Explanation: Comparison with MATLAB results
End of explanation
new_cl = np.mod(ML+3,5)
new_cl
plt.hist(new_cl,bins=5)
Explanation: The class ids obtained from MATLAB and from Theano are not the same, the formula below happens to convert them
End of explanation
np.sum(new_cl == cl)
319./385.
Explanation: Number of samples with the same class
End of explanation
<END_TASK>