annotate asist_dynamic.py @ 0:c1a77856070c draft

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