annotate asist_dynamic.py @ 3:683299422575 draft

"planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
author rakesh4osdd
date Tue, 29 Jun 2021 05:20:41 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
1 #!/usr/bin/env python
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
2 # coding: utf-8
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
3
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
4 # In[1309]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
5
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
6
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
7 #ASIST program for phenotype based on Antibiotics profile
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
8 # create a profile based on selected antibiotics only
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
9 # rakesh4osdd@gmail.com, 14-June-2021
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
10
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
11
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
12 # In[1403]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
13
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
14
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
15 import pandas as pd
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
16 import sys
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
17 import os
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
18 from collections import Counter
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
19
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
20
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
21 # In[ ]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
22
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
23
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
24 input_file=sys.argv[1]
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
25 output_file=sys.argv[2]
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
26
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
27
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
28 # In[1362]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
29
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
30
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
31 # strain_profile to phenotype condition
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
32 def s_phen(sus,res,na,pb_sus):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
33 if (sus>0 and res==0 and na>=0):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
34 #print('Possible Susceptible')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
35 phen='Possible Susceptible'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
36 elif (sus>=0 and 3<=res<7 and na>=0 and pb_sus==0):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
37 #print('Possible MDR')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
38 phen='Possible MDR'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
39 elif (sus>=0 and 7<=res<9 and na>=0 and pb_sus==0):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
40 #print('Possible XDR')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
41 phen='Possible XDR'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
42 #special cases
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
43 elif (sus>=1 and res>0 and na>=0 and pb_sus==1):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
44 #print('Possible XDR')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
45 phen='Possible XDR'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
46 #special cases
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
47 elif (sus>0 and res==9 and na>=0):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
48 #print('Possible XDR')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
49 phen='Possible XDR'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
50 elif (sus==0 and res==9 and na>=0):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
51 #print('Possible TDR')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
52 phen='Possible TDR'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
53 else:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
54 #print('Strain could not be classified')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
55 phen='Strain could not be classified'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
56 return(phen)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
57
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
58 #print(s_phen(1,9,0,0))
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
59
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
60
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
61 # In[1363]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
62
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
63
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
64 # define Antibiotic groups as per antibiotic of CLSI breakpoints MIC
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
65 #Aminoglycoside
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
66 cat1=['Amikacin','Tobramycin','Gentamycin','Netilmicin']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
67 #Beta-lactams- Carbapenems
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
68 cat2=['Imipenem','Meropenam','Doripenem']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
69 #Fluoroquinolone
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
70 cat3=['Ciprofloxacin','Levofloxacin']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
71 #Beta-lactam inhibitor
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
72 cat4=['Piperacillin/tazobactam','Ticarcillin/clavulanicacid']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
73 #Cephalosporin
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
74 cat5=['Cefotaxime','Ceftriaxone','Ceftazidime','Cefepime']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
75 #Sulfonamides
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
76 cat6=['Trimethoprim/sulfamethoxazole']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
77 #Penicillins/beta-lactamase
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
78 cat7=['Ampicillin/sulbactam']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
79 #Polymyxins
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
80 cat8=['Colistin','Polymyxinb']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
81 #Tetracycline
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
82 cat9=['Tetracycline','Doxicycline','Minocycline']
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
83
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
84 def s_profiler(pd_series):
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
85 #print(type(pd_series),'\n', pd_series)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
86 #create a dictionary of dataframe series
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
87 cats={'s1':cat1,'s2':cat2,'s3':cat3,'s4':cat4,'s5':cat5,'s6':cat6,'s7':cat7,'s8':cat8,'s9':cat9}
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
88 # find the antibiotics name in input series
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
89 for cat in cats:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
90 #print(cats[cat])
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
91 cats[cat]=pd_series.filter(cats[cat])
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
92 #print(cats[cat])
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
93 #define res,sus,na,pb_sus
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
94 res=0
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
95 sus=0
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
96 na=0
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
97 pb_sus=0
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
98 # special case of 'Polymyxin b' for its value
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
99 if 'Polymyxinb' in pd_series:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
100 ctp=cats['s8']['Polymyxinb'].strip().lower()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
101 if ctp == 'susceptible':
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
102 pb_sus=1
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
103 #print((ctp,p_sus))
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
104 # check all categories
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
105 for cat in cats:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
106 #ctp=cats['s8'].iloc[i:i+1].stack().value_counts().to_dict()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
107 #print(ctp)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
108 # Pandas series
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
109 ct=cats[cat].value_counts().to_dict()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
110 #print(ct)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
111 # remove whitespace and convert to lowercase words
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
112 ct = {k.strip().lower(): v for k, v in ct.items()}
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
113 #print(ct)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
114 k=Counter(ct)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
115 #j=Counter(ct)+Counter(j)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
116 #print(j)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
117 # category wise marking
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
118 if k['resistant']>=1:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
119 res=res+1
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
120 if k['susceptible']>=1:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
121 sus=sus+1
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
122 if k['na']>=1:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
123 na=na+1
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
124 #print(s_phen(sus,res,na,pb_sus))
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
125 return(s_phen(sus,res,na,pb_sus))
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
126
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
127
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
128 # In[1397]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
129
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
130
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
131 #input_file='input2.csv_table.csv'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
132 #output_file=input_file+'_output.txt'
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
133 strain_profile=pd.read_csv(input_file, sep=',',na_filter=False,skipinitialspace = True)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
134
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
135
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
136 # In[1387]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
137
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
138
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
139 old_strain_name=strain_profile.columns[0]
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
140 new_strain_name=old_strain_name.capitalize().strip().replace(' ', '')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
141
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
142
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
143 # In[1388]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
144
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
145
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
146 # make header capitalization, remove leading,lagging, and multiple whitespace for comparision
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
147 strain_profile.columns=strain_profile.columns.str.capitalize().str.strip().str.replace('\s+', '', regex=True)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
148 #print(strain_profile.columns)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
149 #strain_profile.head()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
150 #strain_profile.columns
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
151
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
152
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
153 # In[1389]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
154
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
155
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
156 # add new column in dataframe on second position
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
157 strain_profile.insert(1, 'Strain phenotype','')
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
158 #strain_profile.head()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
159
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
160
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
161 # In[1390]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
162
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
163
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
164 strain_profile['Strain phenotype'] = strain_profile.apply(lambda x: (s_profiler(x)), axis=1)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
165
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
166
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
167 # In[1391]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
168
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
169
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
170 #strain_profile.head()
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
171
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
172
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
173 # In[1392]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
174
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
175
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
176 #rename headers for old name
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
177 strain_profile=strain_profile.rename(columns = {new_strain_name:old_strain_name, 'Ticarcillin/clavulanicacid':'Ticarcillin/ clavulanic acid','Piperacillin/tazobactam':'Piperacillin/ tazobactam','Trimethoprim/sulfamethoxazole': 'Trimethoprim/ sulfamethoxazole','Ampicillin/sulbactam':'Ampicillin/ sulbactam', 'Polymyxinb': 'Polymyxin B'} )
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
178
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
179
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
180 # In[1404]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
181
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
182
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
183 #strain_profile
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
184
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
185
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
186 # In[1394]:
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
187
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
188
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
189 strain_profile.to_csv(output_file,na_rep='NA',index=False)
683299422575 "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f085b88bf75f7b45ac3b0c4e1c39214c0ac0b67d"
rakesh4osdd
parents:
diff changeset
190