annotate asist_dynamic.py @ 9:4f36d48d6090 draft default tip

Uploaded xml
author rakesh4osdd
date Wed, 30 Jun 2021 07:42:51 +0000
parents 734777d3c253
children
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
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
12 # In[1]:
0
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
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
21 # In[176]:
0
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]
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
26 #input_file='test-data/asist_input.csv'
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
27 #output_file='test-data/asist_output.csv'
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
28
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
29
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
30 # In[177]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
31
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
32
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
33 # strain_profile to phenotype condition
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
34 def s_phen(sus,res,intm,na,pb_sus):
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
35 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
36 #print('Possible Susceptible')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
37 phen='Possible Susceptible'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
38 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
39 #print('Possible MDR')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
40 phen='Possible MDR'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
41 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
42 #print('Possible XDR')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
43 phen='Possible XDR'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
44 #special cases
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
45 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
46 #print('Possible XDR')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
47 phen='Possible XDR'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
48 #special cases
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
49 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
50 #print('Possible XDR')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
51 phen='Possible XDR'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
52 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
53 #print('Possible TDR')
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
54 phen='Possible TDR'
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
55 else:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
56 #print('Strain could not be classified')
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
57 phen='Strain could not be classified ('+ str(intm)+' | ' + str(na) +')'
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
58 return(phen)
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 #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
61
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
62
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
63 # In[178]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
64
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
65
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
66 # 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
67 #Aminoglycoside
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
68 cat1=['Amikacin','Tobramycin','Gentamycin','Netilmicin']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
69 #Beta-lactams- Carbapenems
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
70 cat2=['Imipenem','Meropenam','Doripenem']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
71 #Fluoroquinolone
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
72 cat3=['Ciprofloxacin','Levofloxacin']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
73 #Beta-lactam inhibitor
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
74 cat4=['Piperacillin/tazobactam','Ticarcillin/clavulanicacid']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
75 #Cephalosporin
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
76 cat5=['Cefotaxime','Ceftriaxone','Ceftazidime','Cefepime']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
77 #Sulfonamides
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
78 cat6=['Trimethoprim/sulfamethoxazole']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
79 #Penicillins/beta-lactamase
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
80 cat7=['Ampicillin/sulbactam']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
81 #Polymyxins
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
82 cat8=['Colistin','Polymyxinb']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
83 #Tetracycline
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
84 cat9=['Tetracycline','Doxicycline','Minocycline']
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
85
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
86 def s_profiler(pd_series):
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
87 #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
88 #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
89 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
90 # 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
91 for cat in cats:
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 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
94 #print(cats[cat])
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
95 #define res,sus,intm,na,pb_sus
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
96 res=0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
97 sus=0
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
98 intm=0
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
99 na=0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
100 pb_sus=0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
101 # 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
102 if 'Polymyxinb' in pd_series:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
103 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
104 if ctp == 'susceptible':
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
105 pb_sus=1
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
106 #print((ctp,p_sus))
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
107 # check all categories
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
108 for cat in cats:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
109 #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
110 #print(ctp)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
111 # Pandas series
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
112 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
113 #print(ct)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
114 # 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
115 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
116 #print(ct)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
117 k=Counter(ct)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
118 #j=Counter(ct)+Counter(j)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
119 #print(j)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
120 # category wise marking
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
121 if k['resistant']>=1:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
122 res=res+1
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
123 if k['susceptible']>=1:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
124 sus=sus+1
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
125 if k['intermediate']>=1:
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
126 intm=intm+1
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
127 if k['na']>=1:
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
128 na=na+1
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
129 #print(sus,res,intm,na,pb_sus)
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
130 #print(s_phen(sus,res,intm,na,pb_sus))
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
131 return(s_phen(sus,res,intm,na,pb_sus))
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
132
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
133
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
134 # In[179]:
0
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
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
137 #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
138 #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
139 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
140
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
141
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
142 # In[180]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
143
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 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
146 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
147
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
148
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
149 # In[181]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
150
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 # 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
153 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
154 #print(strain_profile.columns)
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
155 #strain_profile.head()
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
156 #strain_profile.columns
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
157
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
158
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
159 # In[182]:
0
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
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
162 # 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
163 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
164 #strain_profile.head()
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
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
167 # In[183]:
0
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['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
171
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
172
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
173 # In[184]:
0
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 #strain_profile.head()
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
177
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
178
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
179 # In[185]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
180
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 #rename headers for old name
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
183 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
184
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
185
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
186 # In[186]:
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
187
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
188
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
189 #strain_profile.columns
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
190
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
191
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
192 # In[187]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
193
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
194
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
195 #strain_profile
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
196
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
197
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
198 # In[188]:
0
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
199
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
200
c1a77856070c "planemo upload for repository https://github.com/rakesh4osdd/asist/tree/master commit f5b374bef15145c893ffdd3a7d2f2978d8052184-dirty"
rakesh4osdd
parents:
diff changeset
201 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
202
3
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
203
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
204 # In[189]:
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
205
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
206
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
207 # Open a file with access mode 'a'
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
208 with open(output_file, "a") as file_object:
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
209 # Append 'hello' at the end of file
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
210 file_object.write("Note: \n1. 'MDR': Multidrug-resistant, 'XDR': Extensively drug-resistant, 'TDR':totally drug resistant, NA': Data Not Available.\n2. 'Strain could not be classified' numbers follow the format as ('Number of antibiotics categories count as Intermediate' | 'Number of antibiotics categories count as NA')")
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
211
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
212
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
213 # In[ ]:
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
214
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
215
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
216
734777d3c253 Deleted selected files test
rakesh4osdd
parents: 0
diff changeset
217