mirror of https://github.com/msberends/AMR
commit
62304dc23f
34 changed files with 3459 additions and 0 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
.Rproj.user |
||||
.Rhistory |
||||
.RData |
||||
.Ruserdata |
||||
AMR.Rproj |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
Package: AMR |
||||
Version: 0.1.0 |
||||
Date: 2018-02-20 |
||||
Title: Antimicrobial Resistance (AMR) Analysis |
||||
Authors@R: c( |
||||
person( |
||||
given = c("Matthijs", "S."), |
||||
family = "Berends", |
||||
email = "m.s.berends@umcg.nl", |
||||
role = c("aut", "cre")), |
||||
person( |
||||
given = c("Christian", "F."), |
||||
family = "Luz", |
||||
email = "c.f.luz@umcg.nl", |
||||
role = c("aut", "ctb")), |
||||
person( |
||||
given = c("Erwin", "E.A."), |
||||
family = "Hassing", |
||||
email = "e.hassing@certe.nl", |
||||
role = "ctb")) |
||||
Description: Functions to simplify the analysis of Antimicrobial Resistance (AMR) |
||||
of microbial isolates, by using new S3 classes and applying EUCAST expert rules |
||||
on antibiograms. |
||||
Depends: R (>= 3.0) |
||||
Imports: dplyr (>= 0.7.0), reshape2 (>= 1.4.0), xml2, rvest |
||||
URL: https://github.com/msberends/AMR |
||||
BugReports: https://github.com/msberends/AMR/issues |
||||
License: GPL-2 | file LICENSE |
||||
Encoding: UTF-8 |
||||
LazyData: true |
||||
RoxygenNote: 6.0.1.9000 |
@ -0,0 +1,339 @@
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE |
||||
Version 2, June 1991 |
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/> |
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
Preamble |
||||
|
||||
The licenses for most software are designed to take away your |
||||
freedom to share and change it. By contrast, the GNU General Public |
||||
License is intended to guarantee your freedom to share and change free |
||||
software--to make sure the software is free for all its users. This |
||||
General Public License applies to most of the Free Software |
||||
Foundation's software and to any other program whose authors commit to |
||||
using it. (Some other Free Software Foundation software is covered by |
||||
the GNU Lesser General Public License instead.) You can apply it to |
||||
your programs, too. |
||||
|
||||
When we speak of free software, we are referring to freedom, not |
||||
price. Our General Public Licenses are designed to make sure that you |
||||
have the freedom to distribute copies of free software (and charge for |
||||
this service if you wish), that you receive source code or can get it |
||||
if you want it, that you can change the software or use pieces of it |
||||
in new free programs; and that you know you can do these things. |
||||
|
||||
To protect your rights, we need to make restrictions that forbid |
||||
anyone to deny you these rights or to ask you to surrender the rights. |
||||
These restrictions translate to certain responsibilities for you if you |
||||
distribute copies of the software, or if you modify it. |
||||
|
||||
For example, if you distribute copies of such a program, whether |
||||
gratis or for a fee, you must give the recipients all the rights that |
||||
you have. You must make sure that they, too, receive or can get the |
||||
source code. And you must show them these terms so they know their |
||||
rights. |
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and |
||||
(2) offer you this license which gives you legal permission to copy, |
||||
distribute and/or modify the software. |
||||
|
||||
Also, for each author's protection and ours, we want to make certain |
||||
that everyone understands that there is no warranty for this free |
||||
software. If the software is modified by someone else and passed on, we |
||||
want its recipients to know that what they have is not the original, so |
||||
that any problems introduced by others will not reflect on the original |
||||
authors' reputations. |
||||
|
||||
Finally, any free program is threatened constantly by software |
||||
patents. We wish to avoid the danger that redistributors of a free |
||||
program will individually obtain patent licenses, in effect making the |
||||
program proprietary. To prevent this, we have made it clear that any |
||||
patent must be licensed for everyone's free use or not licensed at all. |
||||
|
||||
The precise terms and conditions for copying, distribution and |
||||
modification follow. |
||||
|
||||
GNU GENERAL PUBLIC LICENSE |
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
||||
|
||||
0. This License applies to any program or other work which contains |
||||
a notice placed by the copyright holder saying it may be distributed |
||||
under the terms of this General Public License. The "Program", below, |
||||
refers to any such program or work, and a "work based on the Program" |
||||
means either the Program or any derivative work under copyright law: |
||||
that is to say, a work containing the Program or a portion of it, |
||||
either verbatim or with modifications and/or translated into another |
||||
language. (Hereinafter, translation is included without limitation in |
||||
the term "modification".) Each licensee is addressed as "you". |
||||
|
||||
Activities other than copying, distribution and modification are not |
||||
covered by this License; they are outside its scope. The act of |
||||
running the Program is not restricted, and the output from the Program |
||||
is covered only if its contents constitute a work based on the |
||||
Program (independent of having been made by running the Program). |
||||
Whether that is true depends on what the Program does. |
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's |
||||
source code as you receive it, in any medium, provided that you |
||||
conspicuously and appropriately publish on each copy an appropriate |
||||
copyright notice and disclaimer of warranty; keep intact all the |
||||
notices that refer to this License and to the absence of any warranty; |
||||
and give any other recipients of the Program a copy of this License |
||||
along with the Program. |
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and |
||||
you may at your option offer warranty protection in exchange for a fee. |
||||
|
||||
2. You may modify your copy or copies of the Program or any portion |
||||
of it, thus forming a work based on the Program, and copy and |
||||
distribute such modifications or work under the terms of Section 1 |
||||
above, provided that you also meet all of these conditions: |
||||
|
||||
a) You must cause the modified files to carry prominent notices |
||||
stating that you changed the files and the date of any change. |
||||
|
||||
b) You must cause any work that you distribute or publish, that in |
||||
whole or in part contains or is derived from the Program or any |
||||
part thereof, to be licensed as a whole at no charge to all third |
||||
parties under the terms of this License. |
||||
|
||||
c) If the modified program normally reads commands interactively |
||||
when run, you must cause it, when started running for such |
||||
interactive use in the most ordinary way, to print or display an |
||||
announcement including an appropriate copyright notice and a |
||||
notice that there is no warranty (or else, saying that you provide |
||||
a warranty) and that users may redistribute the program under |
||||
these conditions, and telling the user how to view a copy of this |
||||
License. (Exception: if the Program itself is interactive but |
||||
does not normally print such an announcement, your work based on |
||||
the Program is not required to print an announcement.) |
||||
|
||||
These requirements apply to the modified work as a whole. If |
||||
identifiable sections of that work are not derived from the Program, |
||||
and can be reasonably considered independent and separate works in |
||||
themselves, then this License, and its terms, do not apply to those |
||||
sections when you distribute them as separate works. But when you |
||||
distribute the same sections as part of a whole which is a work based |
||||
on the Program, the distribution of the whole must be on the terms of |
||||
this License, whose permissions for other licensees extend to the |
||||
entire whole, and thus to each and every part regardless of who wrote it. |
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest |
||||
your rights to work written entirely by you; rather, the intent is to |
||||
exercise the right to control the distribution of derivative or |
||||
collective works based on the Program. |
||||
|
||||
In addition, mere aggregation of another work not based on the Program |
||||
with the Program (or with a work based on the Program) on a volume of |
||||
a storage or distribution medium does not bring the other work under |
||||
the scope of this License. |
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, |
||||
under Section 2) in object code or executable form under the terms of |
||||
Sections 1 and 2 above provided that you also do one of the following: |
||||
|
||||
a) Accompany it with the complete corresponding machine-readable |
||||
source code, which must be distributed under the terms of Sections |
||||
1 and 2 above on a medium customarily used for software interchange; or, |
||||
|
||||
b) Accompany it with a written offer, valid for at least three |
||||
years, to give any third party, for a charge no more than your |
||||
cost of physically performing source distribution, a complete |
||||
machine-readable copy of the corresponding source code, to be |
||||
distributed under the terms of Sections 1 and 2 above on a medium |
||||
customarily used for software interchange; or, |
||||
|
||||
c) Accompany it with the information you received as to the offer |
||||
to distribute corresponding source code. (This alternative is |
||||
allowed only for noncommercial distribution and only if you |
||||
received the program in object code or executable form with such |
||||
an offer, in accord with Subsection b above.) |
||||
|
||||
The source code for a work means the preferred form of the work for |
||||
making modifications to it. For an executable work, complete source |
||||
code means all the source code for all modules it contains, plus any |
||||
associated interface definition files, plus the scripts used to |
||||
control compilation and installation of the executable. However, as a |
||||
special exception, the source code distributed need not include |
||||
anything that is normally distributed (in either source or binary |
||||
form) with the major components (compiler, kernel, and so on) of the |
||||
operating system on which the executable runs, unless that component |
||||
itself accompanies the executable. |
||||
|
||||
If distribution of executable or object code is made by offering |
||||
access to copy from a designated place, then offering equivalent |
||||
access to copy the source code from the same place counts as |
||||
distribution of the source code, even though third parties are not |
||||
compelled to copy the source along with the object code. |
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program |
||||
except as expressly provided under this License. Any attempt |
||||
otherwise to copy, modify, sublicense or distribute the Program is |
||||
void, and will automatically terminate your rights under this License. |
||||
However, parties who have received copies, or rights, from you under |
||||
this License will not have their licenses terminated so long as such |
||||
parties remain in full compliance. |
||||
|
||||
5. You are not required to accept this License, since you have not |
||||
signed it. However, nothing else grants you permission to modify or |
||||
distribute the Program or its derivative works. These actions are |
||||
prohibited by law if you do not accept this License. Therefore, by |
||||
modifying or distributing the Program (or any work based on the |
||||
Program), you indicate your acceptance of this License to do so, and |
||||
all its terms and conditions for copying, distributing or modifying |
||||
the Program or works based on it. |
||||
|
||||
6. Each time you redistribute the Program (or any work based on the |
||||
Program), the recipient automatically receives a license from the |
||||
original licensor to copy, distribute or modify the Program subject to |
||||
these terms and conditions. You may not impose any further |
||||
restrictions on the recipients' exercise of the rights granted herein. |
||||
You are not responsible for enforcing compliance by third parties to |
||||
this License. |
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent |
||||
infringement or for any other reason (not limited to patent issues), |
||||
conditions are imposed on you (whether by court order, agreement or |
||||
otherwise) that contradict the conditions of this License, they do not |
||||
excuse you from the conditions of this License. If you cannot |
||||
distribute so as to satisfy simultaneously your obligations under this |
||||
License and any other pertinent obligations, then as a consequence you |
||||
may not distribute the Program at all. For example, if a patent |
||||
license would not permit royalty-free redistribution of the Program by |
||||
all those who receive copies directly or indirectly through you, then |
||||
the only way you could satisfy both it and this License would be to |
||||
refrain entirely from distribution of the Program. |
||||
|
||||
If any portion of this section is held invalid or unenforceable under |
||||
any particular circumstance, the balance of the section is intended to |
||||
apply and the section as a whole is intended to apply in other |
||||
circumstances. |
||||
|
||||
It is not the purpose of this section to induce you to infringe any |
||||
patents or other property right claims or to contest validity of any |
||||
such claims; this section has the sole purpose of protecting the |
||||
integrity of the free software distribution system, which is |
||||
implemented by public license practices. Many people have made |
||||
generous contributions to the wide range of software distributed |
||||
through that system in reliance on consistent application of that |
||||
system; it is up to the author/donor to decide if he or she is willing |
||||
to distribute software through any other system and a licensee cannot |
||||
impose that choice. |
||||
|
||||
This section is intended to make thoroughly clear what is believed to |
||||
be a consequence of the rest of this License. |
||||
|
||||
8. If the distribution and/or use of the Program is restricted in |
||||
certain countries either by patents or by copyrighted interfaces, the |
||||
original copyright holder who places the Program under this License |
||||
may add an explicit geographical distribution limitation excluding |
||||
those countries, so that distribution is permitted only in or among |
||||
countries not thus excluded. In such case, this License incorporates |
||||
the limitation as if written in the body of this License. |
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions |
||||
of the General Public License from time to time. Such new versions will |
||||
be similar in spirit to the present version, but may differ in detail to |
||||
address new problems or concerns. |
||||
|
||||
Each version is given a distinguishing version number. If the Program |
||||
specifies a version number of this License which applies to it and "any |
||||
later version", you have the option of following the terms and conditions |
||||
either of that version or of any later version published by the Free |
||||
Software Foundation. If the Program does not specify a version number of |
||||
this License, you may choose any version ever published by the Free Software |
||||
Foundation. |
||||
|
||||
10. If you wish to incorporate parts of the Program into other free |
||||
programs whose distribution conditions are different, write to the author |
||||
to ask for permission. For software which is copyrighted by the Free |
||||
Software Foundation, write to the Free Software Foundation; we sometimes |
||||
make exceptions for this. Our decision will be guided by the two goals |
||||
of preserving the free status of all derivatives of our free software and |
||||
of promoting the sharing and reuse of software generally. |
||||
|
||||
NO WARRANTY |
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
||||
REPAIR OR CORRECTION. |
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
||||
POSSIBILITY OF SUCH DAMAGES. |
||||
|
||||
END OF TERMS AND CONDITIONS |
||||
|
||||
How to Apply These Terms to Your New Programs |
||||
|
||||
If you develop a new program, and you want it to be of the greatest |
||||
possible use to the public, the best way to achieve this is to make it |
||||
free software which everyone can redistribute and change under these terms. |
||||
|
||||
To do so, attach the following notices to the program. It is safest |
||||
to attach them to the start of each source file to most effectively |
||||
convey the exclusion of warranty; and each file should have at least |
||||
the "copyright" line and a pointer to where the full notice is found. |
||||
|
||||
{description} |
||||
Copyright (C) {year} {fullname} |
||||
|
||||
This program is free software; you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation; either version 2 of the License, or |
||||
(at your option) any later version. |
||||
|
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
GNU General Public License for more details. |
||||
|
||||
You should have received a copy of the GNU General Public License along |
||||
with this program; if not, write to the Free Software Foundation, Inc., |
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||||
|
||||
Also add information on how to contact you by electronic and paper mail. |
||||
|
||||
If the program is interactive, make it output a short notice like this |
||||
when it starts in an interactive mode: |
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author |
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
||||
This is free software, and you are welcome to redistribute it |
||||
under certain conditions; type `show c' for details. |
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate |
||||
parts of the General Public License. Of course, the commands you use may |
||||
be called something other than `show w' and `show c'; they could even be |
||||
mouse-clicks or menu items--whatever suits your program. |
||||
|
||||
You should also get your employer (if you work as a programmer) or your |
||||
school, if any, to sign a "copyright disclaimer" for the program, if |
||||
necessary. Here is a sample; alter the names: |
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker. |
||||
|
||||
{signature of Ty Coon}, 1 April 1989 |
||||
Ty Coon, President of Vice |
||||
|
||||
This General Public License does not permit incorporating your program into |
||||
proprietary programs. If your program is a subroutine library, you may |
||||
consider it more useful to permit linking proprietary applications with the |
||||
library. If this is what you want to do, use the GNU Lesser General |
||||
Public License instead of this License. |
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
# Generated by roxygen2: do not edit by hand |
||||
|
||||
S3method(as.double,mic) |
||||
S3method(as.integer,mic) |
||||
S3method(as.numeric,mic) |
||||
S3method(plot,mic) |
||||
S3method(plot,rsi) |
||||
S3method(print,mic) |
||||
S3method(print,rsi) |
||||
S3method(summary,mic) |
||||
S3method(summary,rsi) |
||||
export(EUCAST_rules) |
||||
export(anti_join_bactlist) |
||||
export(as.mic) |
||||
export(as.rsi) |
||||
export(atc_property) |
||||
export(full_join_bactlist) |
||||
export(inner_join_bactlist) |
||||
export(interpretive_reading) |
||||
export(is.mic) |
||||
export(is.rsi) |
||||
export(key_antibiotics) |
||||
export(key_antibiotics_equal) |
||||
export(left_join_bactlist) |
||||
export(mo_property) |
||||
export(right_join_bactlist) |
||||
export(rsi) |
||||
export(rsi_df) |
||||
export(rsi_predict) |
||||
export(semi_join_bactlist) |
||||
exportMethods(as.double.mic) |
||||
exportMethods(as.integer.mic) |
||||
exportMethods(as.numeric.mic) |
||||
exportMethods(plot.mic) |
||||
exportMethods(plot.rsi) |
||||
exportMethods(print.mic) |
||||
exportMethods(print.rsi) |
||||
exportMethods(summary.mic) |
||||
exportMethods(summary.rsi) |
||||
importFrom(dplyr,"%>%") |
||||
importFrom(dplyr,all_vars) |
||||
importFrom(dplyr,any_vars) |
||||
importFrom(dplyr,arrange) |
||||
importFrom(dplyr,arrange_at) |
||||
importFrom(dplyr,between) |
||||
importFrom(dplyr,filter) |
||||
importFrom(dplyr,filter_at) |
||||
importFrom(dplyr,group_by) |
||||
importFrom(dplyr,group_by_at) |
||||
importFrom(dplyr,if_else) |
||||
importFrom(dplyr,lag) |
||||
importFrom(dplyr,left_join) |
||||
importFrom(dplyr,mutate) |
||||
importFrom(dplyr,n_distinct) |
||||
importFrom(dplyr,progress_estimated) |
||||
importFrom(dplyr,pull) |
||||
importFrom(dplyr,row_number) |
||||
importFrom(dplyr,select) |
||||
importFrom(dplyr,summarise) |
||||
importFrom(dplyr,tibble) |
||||
importFrom(dplyr,vars) |
||||
importFrom(graphics,plot) |
||||
importFrom(graphics,text) |
||||
importFrom(reshape2,dcast) |
||||
importFrom(rvest,html_nodes) |
||||
importFrom(rvest,html_table) |
||||
importFrom(xml2,read_html) |
@ -0,0 +1,637 @@
@@ -0,0 +1,637 @@
|
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Analysis # |
||||
# # |
||||
# AUTHORS # |
||||
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # |
||||
# # |
||||
# LICENCE # |
||||
# This program is free software; you can redistribute it and/or modify # |
||||
# it under the terms of the GNU General Public License version 2.0, # |
||||
# as published by the Free Software Foundation. # |
||||
# # |
||||
# This program is distributed in the hope that it will be useful, # |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||||
# GNU General Public License for more details. # |
||||
# ==================================================================== # |
||||
|
||||
#' EUCAST expert rules |
||||
#' |
||||
#' Apply expert rules (like intrinsic resistance), as defined by the European Committee on Antimicrobial Susceptibility Testing (EUCAST, \url{http://eucast.org}), see \emph{Source}. |
||||
#' @param tbl table with antibiotic columns, like e.g. \code{amox} and \code{amcl} |
||||
#' @param col_bactcode column name of the bacteria ID in \code{tbl} - should also be present in \code{bactlist$bactid}, see \code{\link{bactlist}}. |
||||
#' @param info print progress |
||||
#' @param amcl,amik,amox,ampi,azit,aztr,cefa,cfra,cfep,cfot,cfox,cfta,cftr,cfur,chlo,cipr,clar,clin,clox,coli,czol,dapt,doxy,erta,eryt,fosf,fusi,gent,imip,kana,levo,linc,line,mero,mino,moxi,nali,neom,neti,nitr,novo,norf,oflo,peni,pita,poly,qida,rifa,roxi,siso,teic,tetr,tica,tige,tobr,trim,trsu,vanc column names of antibiotics. Use \code{NA} to skip a column, like \code{tica = NA}. Non-existing column will be skipped. |
||||
#' @param ... parameters that are passed on to \code{EUCAST_rules} |
||||
#' @name EUCAST |
||||
#' @rdname EUCAST |
||||
#' @export |
||||
#' @importFrom dplyr %>% left_join select |
||||
#' @source |
||||
#' EUCAST Expert Rules Version 2.0: \cr |
||||
#' Leclercq et al. \strong{EUCAST expert rules in antimicrobial susceptibility testing.} \emph{Clin Microbiol Infect.} 2013;19(2):141-60. \cr |
||||
#' \url{https://doi.org/10.1111/j.1469-0691.2011.03703.x} \cr |
||||
#' \cr |
||||
#' EUCAST Expert Rules Version 3.1: \cr |
||||
#' \url{http://www.eucast.org/expert_rules_and_intrinsic_resistance} |
||||
#' @examples |
||||
#' \dontrun{ |
||||
#' tbl <- interpretive_reading(tbl) |
||||
#' } |
||||
EUCAST_rules <- function(tbl, |
||||
col_bactcode = 'bacteriecode', |
||||
info = TRUE, |
||||
amcl = 'amcl', |
||||
amik = 'amik', |
||||
amox = 'amox', |
||||
ampi = 'ampi', |
||||
azit = 'azit', |
||||
aztr = 'aztr', |
||||
cefa = 'cefa', |
||||
cfra = 'cfra', |
||||
cfep = 'cfep', |
||||
cfot = 'cfot', |
||||
cfox = 'cfox', |
||||
cfta = 'cfta', |
||||
cftr = 'cftr', |
||||
cfur = 'cfur', |
||||
chlo = 'chlo', |
||||
cipr = 'cipr', |
||||
clar = 'clar', |
||||
clin = 'clin', |
||||
clox = 'clox', |
||||
coli = 'coli', |
||||
czol = 'czol', |
||||
dapt = 'dapt', |
||||
doxy = 'doxy', |
||||
erta = 'erta', |
||||
eryt = 'eryt', |
||||
fosf = 'fosf', |
||||
fusi = 'fusi', |
||||
gent = 'gent', |
||||
imip = 'imip', |
||||
kana = 'kana', |
||||
levo = 'levo', |
||||
linc = 'linc', |
||||
line = 'line', |
||||
mero = 'mero', |
||||
mino = 'mino', |
||||
moxi = 'moxi', |
||||
nali = 'nali', |
||||
neom = 'neom', |
||||
neti = 'neti', |
||||
nitr = 'nitr', |
||||
novo = 'novo', |
||||
norf = 'norf', |
||||
oflo = 'oflo', |
||||
peni = 'peni', |
||||
pita = 'pita', |
||||
poly = 'poly', |
||||
qida = 'qida', |
||||
rifa = 'rifa', |
||||
roxi = 'roxi', |
||||
siso = 'siso', |
||||
teic = 'teic', |
||||
tetr = 'tetr', |
||||
tica = 'tica', |
||||
tige = 'tige', |
||||
tobr = 'tobr', |
||||
trim = 'trim', |
||||
trsu = 'trsu', |
||||
vanc = 'vanc') { |
||||
|
||||
if (!col_bactcode %in% colnames(tbl)) { |
||||
stop('Column ', col_bactcode, ' not found.') |
||||
} |
||||
|
||||
# kolommen controleren |
||||
col.list <- c(amcl, amik, amox, ampi, azit, aztr, cefa, cfra, cfep, |
||||
cfot, cfox, cfta, cftr, cfur, cipr, clar, clin, clox, coli, czol, |
||||
dapt, doxy, erta, eryt, fusi, gent, imip, kana, levo, linc, line, |
||||
mero, mino, moxi, nali, neom, neti, nitr, novo, norf, oflo, peni, |
||||
pita, poly, qida, rifa, roxi, siso, teic, tetr, tica, tige, tobr, |
||||
trim, trsu, vanc) |
||||
col.list <- col.list[!is.na(col.list)] |
||||
if (!all(col.list %in% colnames(tbl))) { |
||||
if (info == TRUE) { |
||||
cat('\n') |
||||
} |
||||
if (info == TRUE) { |
||||
warning('These columns do not exist and will be ignored:\n', |
||||
col.list[!(col.list %in% colnames(tbl))] %>% toString(), |
||||
immediate. = TRUE, |
||||
call. = FALSE) |
||||
} |
||||
if (!amcl %in% colnames(tbl)) { amcl <- NA } |
||||
if (!amik %in% colnames(tbl)) { amik <- NA } |
||||
if (!amox %in% colnames(tbl)) { amox <- NA } |
||||
if (!ampi %in% colnames(tbl)) { ampi <- NA } |
||||
if (!azit %in% colnames(tbl)) { azit <- NA } |
||||
if (!aztr %in% colnames(tbl)) { aztr <- NA } |
||||
if (!cefa %in% colnames(tbl)) { cefa <- NA } |
||||
if (!cfra %in% colnames(tbl)) { cfra <- NA } |
||||
if (!cfep %in% colnames(tbl)) { cfep <- NA } |
||||
if (!cfot %in% colnames(tbl)) { cfot <- NA } |
||||
if (!cfox %in% colnames(tbl)) { cfox <- NA } |
||||
if (!cfta %in% colnames(tbl)) { cfta <- NA } |
||||
if (!cftr %in% colnames(tbl)) { cftr <- NA } |
||||
if (!cfur %in% colnames(tbl)) { cfur <- NA } |
||||
if (!chlo %in% colnames(tbl)) { chlo <- NA } |
||||
if (!cipr %in% colnames(tbl)) { cipr <- NA } |
||||
if (!clar %in% colnames(tbl)) { clar <- NA } |
||||
if (!clin %in% colnames(tbl)) { clin <- NA } |
||||
if (!clox %in% colnames(tbl)) { clox <- NA } |
||||
if (!coli %in% colnames(tbl)) { coli <- NA } |
||||
if (!czol %in% colnames(tbl)) { czol <- NA } |
||||
if (!dapt %in% colnames(tbl)) { dapt <- NA } |
||||
if (!doxy %in% colnames(tbl)) { doxy <- NA } |
||||
if (!erta %in% colnames(tbl)) { erta <- NA } |
||||
if (!eryt %in% colnames(tbl)) { eryt <- NA } |
||||
if (!fosf %in% colnames(tbl)) { fosf <- NA } |
||||
if (!fusi %in% colnames(tbl)) { fusi <- NA } |
||||
if (!gent %in% colnames(tbl)) { gent <- NA } |
||||
if (!imip %in% colnames(tbl)) { imip <- NA } |
||||
if (!kana %in% colnames(tbl)) { kana <- NA } |
||||
if (!levo %in% colnames(tbl)) { levo <- NA } |
||||
if (!linc %in% colnames(tbl)) { linc <- NA } |
||||
if (!line %in% colnames(tbl)) { line <- NA } |
||||
if (!mero %in% colnames(tbl)) { mero <- NA } |
||||
if (!mino %in% colnames(tbl)) { mino <- NA } |
||||
if (!moxi %in% colnames(tbl)) { moxi <- NA } |
||||
if (!nali %in% colnames(tbl)) { nali <- NA } |
||||
if (!neom %in% colnames(tbl)) { neom <- NA } |
||||
if (!neti %in% colnames(tbl)) { neti <- NA } |
||||
if (!nitr %in% colnames(tbl)) { nitr <- NA } |
||||
if (!novo %in% colnames(tbl)) { novo <- NA } |
||||
if (!norf %in% colnames(tbl)) { norf <- NA } |
||||
if (!oflo %in% colnames(tbl)) { oflo <- NA } |
||||
if (!peni %in% colnames(tbl)) { peni <- NA } |
||||
if (!pita %in% colnames(tbl)) { pita <- NA } |
||||
if (!poly %in% colnames(tbl)) { poly <- NA } |
||||
if (!qida %in% colnames(tbl)) { qida <- NA } |
||||
if (!rifa %in% colnames(tbl)) { rifa <- NA } |
||||
if (!roxi %in% colnames(tbl)) { roxi <- NA } |
||||
if (!siso %in% colnames(tbl)) { siso <- NA } |
||||
if (!teic %in% colnames(tbl)) { teic <- NA } |
||||
if (!tetr %in% colnames(tbl)) { tetr <- NA } |
||||
if (!tica %in% colnames(tbl)) { tica <- NA } |
||||
if (!tige %in% colnames(tbl)) { tige <- NA } |
||||
if (!tobr %in% colnames(tbl)) { tobr <- NA } |
||||
if (!trim %in% colnames(tbl)) { trim <- NA } |
||||
if (!trsu %in% colnames(tbl)) { trsu <- NA } |
||||
if (!vanc %in% colnames(tbl)) { vanc <- NA } |
||||
} |
||||
|
||||
total <- 0 |
||||
|
||||
# functie voor uitvoeren |
||||
edit_rsi <- function(to, rows, cols) { |
||||
#voortgang$tick()$print() |
||||
cols <- cols[!is.na(cols)] |
||||
if (length(rows) > 0 & length(cols) > 0) { |
||||
tbl[rows, cols] <<- to |
||||
total <<- total + (length(rows) * length(cols)) |
||||
} |
||||
} |
||||
|
||||
# bactlist aan vastknopen (bestaande kolommen krijgen extra suffix) |
||||
joinby <- colnames(AMR::bactlist)[1] |
||||
names(joinby) <- col_bactcode |
||||
tbl <- tbl %>% left_join(y = AMR::bactlist, by = joinby, suffix = c("_tempbactlist", "")) |
||||
|
||||
# antibioticagroepen |
||||
aminoglycosiden <- c(tobr, gent, kana, neom, neti, siso) |
||||
tetracyclines <- c(doxy, mino, tetr) # sinds EUCAST v3.1 is tige(cycline) apart |
||||
polymyxines <- c(poly, coli) |
||||
macroliden <- c(eryt, azit, roxi, clar) # sinds EUCAST v3.1 is clinda apart |
||||
glycopeptiden <- c(vanc, teic) |
||||
streptogramines <- qida # eigenlijk pristinamycine en quinupristine/dalfopristine |
||||
cefalosporines <- c(cfep, cfot, cfox, cfra, cfta, cftr, cfur, czol) |
||||
carbapenems <- c(erta, imip, mero) |
||||
aminopenicillines <- c(ampi, amox) |
||||
ureidopenicillines <- pita # eigenlijk ook azlo en mezlo |
||||
fluorochinolonen <- c(oflo, cipr, norf, levo, moxi) |
||||
|
||||
if (info == TRUE) { |
||||
cat('\nApplying EUCAST expert rules on', |
||||
tbl[!is.na(tbl$genus),] %>% nrow(), |
||||
'isolates according to "EUCAST Expert Rules Version 3.1"\n\n') |
||||
} |
||||
|
||||
# Table 1: Intrinsic resistance in Enterobacteriaceae ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 1: Intrinsic resistance in Enterobacteriaceae\n') |
||||
} |
||||
#voortgang <- progress_estimated(17) |
||||
# Intrisiek R voor groep |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$family == 'Enterobacteriaceae'), |
||||
cols = c(peni, glycopeptiden, fusi, macroliden, linc, streptogramines, rifa, dapt, line)) |
||||
# Citrobacter |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Citrobacter (koseri|amalonaticus|sedlakii|farmeri|rodentium)'), |
||||
cols = c(ampi, tica)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Citrobacter (freundii|braakii|murliniae|werkmanii|youngae)'), |
||||
cols = c(ampi, amcl, czol, cfox)) |
||||
# Enterobacter |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Enterobacter cloacae'), |
||||
cols = c(ampi, amcl, czol, cfox)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Enterobacter aerogenes'), |
||||
cols = c(ampi, amcl, czol, cfox)) |
||||
# Escherichia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Escherichia hermanni'), |
||||
cols = c(ampi, tica)) |
||||
# Hafnia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Hafnia alvei'), |
||||
cols = c(ampi, amcl, czol, cfox)) |
||||
# Klebsiella |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Klebsiella'), |
||||
cols = c(ampi, tica)) |
||||
# Morganella / Proteus |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Morganella morganii'), |
||||
cols = c(ampi, amcl, czol, tetracyclines, polymyxines, nitr)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Proteus mirabilis'), |
||||
cols = c(tetracyclines, tige, polymyxines, nitr)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Proteus penneri'), |
||||
cols = c(ampi, czol, cfur, tetracyclines, tige, polymyxines, nitr)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Proteus vulgaris'), |
||||
cols = c(ampi, czol, cfur, tetracyclines, tige, polymyxines, nitr)) |
||||
# Providencia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Providencia rettgeri'), |
||||
cols = c(ampi, amcl, czol, cfur, tetracyclines, tige, polymyxines, nitr)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Providencia stuartii'), |
||||
cols = c(ampi, amcl, czol, cfur, tetracyclines, tige, polymyxines, nitr)) |
||||
# Raoultella |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Raoultella'), |
||||
cols = c(ampi, tica)) |
||||
# Serratia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Serratia marcescens'), |
||||
cols = c(ampi, amcl, czol, cfox, cfur, tetracyclines[tetracyclines != 'mino'], polymyxines, nitr)) |
||||
# Yersinia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Yersinia enterocolitica'), |
||||
cols = c(ampi, amcl, tica, czol, cfox)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Yersinia pseudotuberculosis'), |
||||
cols = c(poly, coli)) |
||||
|
||||
|
||||
# Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 2: Intrinsic resistance in non-fermentative Gram-negative bacteria\n') |
||||
} |
||||
#voortgang <- progress_estimated(8) |
||||
# Intrisiek R voor groep |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus %in% c('Achromobacter', |
||||
'Acinetobacter', |
||||
'Alcaligenes', |
||||
'Bordatella', |
||||
'Burkholderia', |
||||
'Elizabethkingia', |
||||
'Flavobacterium', |
||||
'Ochrobactrum', |
||||
'Pseudomonas', |
||||
'Stenotrophomonas')), |
||||
cols = c(peni, cfox, cfur, glycopeptiden, fusi, macroliden, linc, streptogramines, rifa, dapt, line)) |
||||
# Acinetobacter |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Acinetobacter (baumannii|pittii|nosocomialis|calcoaceticus)'), |
||||
cols = c(ampi, amcl, czol, cfot, cftr, aztr, erta, trim, fosf, tetracyclines[tetracyclines != 'mino'])) |
||||
# Achromobacter |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Achromobacter (xylosoxydans|xylosoxidans)'), |
||||
cols = c(ampi, czol, cfot, cftr, erta)) |
||||
# Burkholderia |
||||
edit_rsi(to = 'R', |
||||
# onder 'Burkholderia cepacia complex' vallen deze species allemaal: PMID 16217180. |
||||
rows = which(tbl$fullname %like% '^Burkholderia (cepacia|multivorans|cenocepacia|stabilis|vietnamiensis|dolosa|ambifaria|anthina|pyrrocinia|ubonensis)'), |
||||
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, aztr, erta, cipr, chlo, aminoglycosiden, trim, fosf, polymyxines)) |
||||
# Elizabethkingia |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Elizabethkingia meningoseptic(a|um)'), |
||||
cols = c(ampi, amcl, tica, czol, cfot, cftr, cfta, cfep, aztr, erta, imip, mero, polymyxines)) |
||||
# Ochrobactrum |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Ochrobactrum anthropi'), |
||||
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, cfta, cfep, aztr, erta)) |
||||
# Pseudomonas |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Pseudomonas aeruginosa'), |
||||
cols = c(ampi, amcl, czol, cfot, cftr, erta, chlo, kana, neom, trim, trsu, tetracyclines, tige)) |
||||
# Stenotrophomonas |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Stenotrophomonas maltophilia'), |
||||
cols = c(ampi, amcl, tica, pita, czol, cfot, cftr, cfta, aztr, erta, imip, mero, aminoglycosiden, trim, fosf, tetr)) |
||||
|
||||
|
||||
# Table 3: Intrinsic resistance in other Gram-negative bacteria ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 3: Intrinsic resistance in other Gram-negative bacteria\n') |
||||
} |
||||
#voortgang <- progress_estimated(7) |
||||
# Intrisiek R voor groep |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus %in% c('Haemophilus', |
||||
'Moraxella', |
||||
'Neisseria', |
||||
'Campylobacter')), |
||||
cols = c(glycopeptiden, linc, dapt, line)) |
||||
# Haemophilus |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Haemophilus influenzae'), |
||||
cols = c(fusi, streptogramines)) |
||||
# Moraxella |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Moraxella catarrhalis'), |
||||
cols = trim) |
||||
# Neisseria |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Neisseria'), |
||||
cols = trim) |
||||
# Campylobacter |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Campylobacter fetus'), |
||||
cols = c(fusi, streptogramines, trim, nali)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Campylobacter (jejuni|coli)'), |
||||
cols = c(fusi, streptogramines, trim)) |
||||
|
||||
|
||||
# Table 4: Intrinsic resistance in Gram-positive bacteria ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 4: Intrinsic resistance in Gram-positive bacteria\n') |
||||
} |
||||
#voortgang <- progress_estimated(14) |
||||
# Intrisiek R voor groep |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$gramstain %like% 'Positi(e|)(v|f)'), |
||||
cols = c(aztr, polymyxines, nali)) |
||||
# Staphylococcus |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Staphylococcus saprophyticus'), |
||||
cols = c(fusi, cfta, fosf, novo)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Staphylococcus (cohnii|xylosus)'), |
||||
cols = c(cfta, novo)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Staphylococcus capitis'), |
||||
cols = c(cfta, fosf)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Staphylococcus (aureus|epidermidis|coagulase negatief|hominis|haemolyticus|intermedius|pseudointermedius)'), |
||||
cols = cfta) |
||||
# Streptococcus |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Streptococcus'), |
||||
cols = c(fusi, cfta, aminoglycosiden)) |
||||
# Enterococcus |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Enterococcus faecalis'), |
||||
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, clin, qida, trim, trsu)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Enterococcus (gallinarum|casseliflavus)'), |
||||
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, clin, qida, vanc, trim, trsu)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Enterococcus faecium'), |
||||
cols = c(fusi, cfta, cefalosporines[cefalosporines != cfta], aminoglycosiden, macroliden, trim, trsu)) |
||||
# Corynebacterium |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Corynebacterium'), |
||||
cols = fosf) |
||||
# Listeria |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Listeria monocytogenes'), |
||||
cols = c(cfta, cefalosporines[cefalosporines != cfta])) |
||||
# overig |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus %in% c('Leuconostoc', 'Pediococcus')), |
||||
cols = c(vanc, teic)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Lactobacillus'), |
||||
cols = c(vanc, teic)) |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Clostridium (ramosum|innocuum)'), |
||||
cols = vanc) |
||||
|
||||
# Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 8: Interpretive rules for B-lactam agents and Gram-positive cocci\n') |
||||
} |
||||
#voortgang <- progress_estimated(2) |
||||
# regel 8.3 |
||||
if (!is.na(peni)) { |
||||
edit_rsi(to = 'S', |
||||
rows = which(tbl$fullname %like% '^Streptococcus (pyogenes|agalactiae|dysgalactiae|groep A|groep B|groep C|groep G)' |
||||
& tbl[, peni] == 'S'), |
||||
cols = c(aminopenicillines, cefalosporines, carbapenems)) |
||||
} |
||||
# regel 8.6 |
||||
if (!is.na(ampi)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Enterococcus' |
||||
& tbl[, ampi] == 'R'), |
||||
cols = c(ureidopenicillines, carbapenems)) |
||||
} |
||||
|
||||
# Table 9: Interpretive rules for B-lactam agents and Gram-negative rods ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 9: Interpretive rules for B-lactam agents and Gram-negative rods\n') |
||||
} |
||||
#voortgang <- progress_estimated(1) |
||||
# regel 9.3 |
||||
if (!is.na(tica) & !is.na(pita)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$family == 'Enterobacteriaceae' |
||||
& tbl[, tica] == 'R' |
||||
& tbl[, pita] == 'S'), |
||||
cols = pita) |
||||
} |
||||
|
||||
# Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 10: Interpretive rules for B-lactam agents and other Gram-negative bacteria\n') |
||||
} |
||||
#voortgang <- progress_estimated(1) |
||||
# regel 10.2 |
||||
if (!is.na(ampi)) { |
||||
# hiervoor moeten we eerst weten of ze B-lactamase-positief zijn |
||||
# edit_rsi(to = 'R', |
||||
# rows = which(tbl$fullname %like% '^Haemophilus influenza' |
||||
# & tbl[, ampi] == 'R'), |
||||
# cols = c(ampi, amox, amcl, pita, cfur)) |
||||
} |
||||
|
||||
# Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 11: Interpretive rules for macrolides, lincosamides, and streptogramins\n') |
||||
} |
||||
# regel 11.1 |
||||
if (!is.na(eryt)) { |
||||
if (!is.na(azit)) { |
||||
tbl[, azit] <- tbl[, eryt] |
||||
} |
||||
if (!is.na(clar)) { |
||||
tbl[, clar] <- tbl[, eryt] |
||||
} |
||||
} |
||||
|
||||
# Table 12: Interpretive rules for aminoglycosides ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 12: Interpretive rules for aminoglycosides\n') |
||||
} |
||||
#voortgang <- progress_estimated(4) |
||||
# regel 12.2 |
||||
if (!is.na(tobr)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Staphylococcus' |
||||
& tbl[, tobr] == 'R'), |
||||
cols = c(kana, amik)) |
||||
} |
||||
# regel 12.3 |
||||
if (!is.na(gent)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Staphylococcus' |
||||
& tbl[, gent] == 'R'), |
||||
cols = aminoglycosiden) |
||||
} |
||||
# regel 12.8 |
||||
if (!is.na(gent) & !is.na(tobr)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$family == 'Enterobacteriaceae' |
||||
& tbl[, gent] == 'I' |
||||
& tbl[, tobr] == 'S'), |
||||
cols = gent) |
||||
} |
||||
# regel 12.9 |
||||
if (!is.na(gent) & !is.na(tobr)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$family == 'Enterobacteriaceae' |
||||
& tbl[, tobr] == 'I' |
||||
& tbl[, gent] == 'R'), |
||||
cols = tobr) |
||||
} |
||||
|
||||
|
||||
# Table 13: Interpretive rules for quinolones ---- |
||||
if (info == TRUE) { |
||||
cat('...Table 13: Interpretive rules for quinolones\n') |
||||
} |
||||
#voortgang <- progress_estimated(4) |
||||
# regel 13.2 |
||||
if (!is.na(moxi)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$genus == 'Staphylococcus' |
||||
& tbl[, moxi] == 'R'), |
||||
cols = fluorochinolonen) |
||||
} |
||||
# regel 13.4 |
||||
if (!is.na(moxi)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Streptococcus pneumoniae' |
||||
& tbl[, moxi] == 'R'), |
||||
cols = fluorochinolonen) |
||||
} |
||||
# regel 13.5 |
||||
if (!is.na(cipr)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$family == 'Enterobacteriaceae' |
||||
& tbl[, cipr] == 'R'), |
||||
cols = fluorochinolonen) |
||||
} |
||||
# regel 13.8 |
||||
if (!is.na(cipr)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl$fullname %like% '^Neisseria gonorrhoeae' |
||||
& tbl[, cipr] == 'R'), |
||||
cols = fluorochinolonen) |
||||
} |
||||
|
||||
|
||||
# Other ---- |
||||
if (info == TRUE) { |
||||
cat('...Other\n') |
||||
} |
||||
#voortgang <- progress_estimated(2) |
||||
if (!is.na(amcl)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl[, amcl] == 'R'), |
||||
cols = ampi) |
||||
} |
||||
if (!is.na(trsu)) { |
||||
edit_rsi(to = 'R', |
||||
rows = which(tbl[, trsu] == 'R'), |
||||
cols = trim) |
||||
} |
||||
if (!is.na(ampi) & !is.na(amox)) { |
||||
tbl[, amox] <- tbl[, ampi] |
||||
} |
||||
|
||||
# Toegevoegde kolommen weer verwijderen |
||||
bactlist.ncol <- ncol(AMR::bactlist) - 2 |
||||
tbl.ncol <- ncol(tbl) |
||||
tbl <- tbl %>% select(-c((tbl.ncol - bactlist.ncol):tbl.ncol)) |
||||
# en eventueel toegevoegde suffix aan bestaande kolommen weer verwijderen |
||||
colnames(tbl) <- gsub("_tempbactlist", "", colnames(tbl)) |
||||
|
||||
if (info == TRUE) { |
||||
cat('\nDone.\nExpert rules applied to', total, 'test results.\n') |
||||
} |
||||
|
||||
tbl |
||||
} |
||||
|
||||
#' @rdname EUCAST |
||||
#' @export |
||||
interpretive_reading <- function(...) { |
||||
EUCAST_rules(...) |
||||
} |
||||
|
||||
#' Poperties of a microorganism |
||||
#' |
||||
#' @param bactcode ID of a microorganisme, like \code{"STAAUR} and \code{"ESCCOL} |
||||
#' @param property One of the values \code{bactid}, \code{bactsys}, \code{family}, \code{genus}, \code{species}, \code{subspecies}, \code{fullname}, \code{type}, \code{gramstain}, \code{aerobic} |
||||
#' @export |
||||
#' @importFrom dplyr %>% filter select |
||||
#' @seealso \code{\link{bactlist}} |
||||
mo_property <- function(bactcode, property = 'fullname') { |
||||
|
||||
mocode <- as.character(bactcode) |
||||
|
||||
for (i in 1:length(mocode)) { |
||||
bug <- mocode[i] |
||||
|
||||
if (!is.na(bug)) { |
||||
result = tryCatch({ |
||||
mocode[i] <- |
||||
AMR::bactlist %>% |
||||
filter(bactid == bactcode) %>% |
||||
select(property) %>% |
||||
unlist() %>% |
||||
as.character() |
||||
}, error = function(error_condition) { |
||||
warning('Code ', bug, ' not found in bacteria list.') |
||||
}, finally = { |
||||
if (mocode[i] == bug & !property %in% c('bactid', 'bactsys')) { |
||||
mocode[i] <- NA |
||||
} |
||||
}) |
||||
} |
||||
|
||||
} |
||||
mocode |
||||
} |
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Analysis # |
||||
# # |
||||
# AUTHORS # |
||||
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # |
||||
# # |
||||
# LICENCE # |
||||
# This program is free software; you can redistribute it and/or modify # |
||||
# it under the terms of the GNU General Public License version 2.0, # |
||||
# as published by the Free Software Foundation. # |
||||
# # |
||||
# This program is distributed in the hope that it will be useful, # |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||||
# GNU General Public License for more details. # |
||||
# ==================================================================== # |
||||
|
||||
#' Properties of an ATC code |
||||
#' |
||||
#' Gets data from the WHO to determine properties of an ATC of e.g. an antibiotic. |
||||
#' @param atc_code a character or character vector with ATC code(s) of antibiotic(s) |
||||
#' @param property property of an ATC code. Valid values are \code{"ATC code"}, \code{"Name"}, \code{"DDD"}, \code{"U"} (\code{"unit"}), \code{"Adm.R"} en \code{"Note"}. |
||||
#' @param administration type of administration, see \emph{Details} |
||||
#' @param url url of website of the WHO. The sign \code{\%s} can be used as a placeholder for ATC codes. |
||||
#' @details |
||||
#' Abbreviations for the property \code{"Adm.R"} (parameter \code{administration}): |
||||
#' \itemize{ |
||||
#' \item{\code{"Implant"}}{ = Implant} |
||||
#' \item{\code{"Inhal"}}{ = Inhalation} |
||||
#' \item{\code{"Instill"}}{ = Instillation} |
||||
#' \item{\code{"N"}}{ = nasal} |
||||
#' \item{\code{"O"}}{ = oral} |
||||
#' \item{\code{"P"}}{ = parenteral} |
||||
#' \item{\code{"R"}}{ = rectal} |
||||
#' \item{\code{"SL"}}{ = sublingual/buccal} |
||||
#' \item{\code{"TD"}}{ = transdermal} |
||||
#' \item{\code{"V"}}{ = vaginal} |
||||
#' } |
||||
#' |
||||
#' Abbreviations for the property \code{"U"} (unit): |
||||
#' \itemize{ |
||||
#' \item{\code{"g"}}{ = gram} |
||||
#' \item{\code{"mg"}}{ = milligram} |
||||
#' \item{\code{"mcg"}}{ = microgram} |
||||
#' \item{\code{"U"}}{ = unit} |
||||
#' \item{\code{"TU"}}{ = thousand units} |
||||
#' \item{\code{"MU"}}{ = million units} |
||||
#' \item{\code{"mmol"}}{ = millimole} |
||||
#' \item{\code{"ml"}}{ = milliliter (e.g. eyedrops)} |
||||
#' } |
||||
#' @export |
||||
#' @importFrom dplyr %>% progress_estimated |
||||
#' @importFrom xml2 read_html |
||||
#' @importFrom rvest html_nodes html_table |
||||
#' @source \url{https://www.whocc.no/atc_ddd_alterations__cumulative/ddd_alterations/abbrevations/} |
||||
atc_property <- function(atc_code, |
||||
property, |
||||
administration = 'O', |
||||
url = 'https://www.whocc.no/atc_ddd_index/?code=%s&showdescription=no') { |
||||
|
||||
# property <- property %>% tolower() |
||||
# |
||||
if (property %like% 'unit') { |
||||
property <- 'U' |
||||
} |
||||
|
||||
# validation of properties |
||||
valid_properties.bak <- c("ATC code", "Name", "DDD", "U", "Adm.R", "Note") |
||||
valid_properties <- valid_properties.bak #%>% tolower() |
||||
if (!property %in% valid_properties) { |
||||
stop('Invalid `property`, use one of ', paste(valid_properties, collapse = ", "), '.') |
||||
} |
||||
|
||||
returnvalue <- rep(NA_character_, length(atc_code)) |
||||
if (property == 'DDD') { |
||||
returnvalue <- rep(NA_real_, length(atc_code)) |
||||
} |
||||
|
||||
progress <- progress_estimated(n = length(atc_code)) |
||||
|
||||
for (i in 1:length(atc_code)) { |
||||
|
||||
progress$tick()$print() |
||||
|
||||
atc_url <- sub('%s', atc_code[i], url, fixed = TRUE) |
||||
tbl <- xml2::read_html(atc_url) %>% |
||||
rvest::html_nodes('table') %>% |
||||
rvest::html_table(header = TRUE) |
||||
|
||||
if (length(tbl) == 0) { |
||||
warning('ATC not found: ', atc_code[i], '. Please check ', atc_url, '.', call. = FALSE) |
||||
returnvalue[i] <- NA |
||||
next |
||||
} |
||||
|
||||
tbl <- tbl[[1]] |
||||
|
||||
if (property == 'Name') { |
||||
returnvalue[i] <- tbl[1, 2] |
||||
} else { |
||||
|
||||
names(returnvalue)[i] <- tbl[1, 2] %>% as.character() |
||||
|
||||
if (!'Adm.R' %in% colnames(tbl) | is.na(tbl[1, 'Adm.R'])) { |
||||
returnvalue[i] <- NA |
||||
next |
||||
} else { |
||||
for (j in 1:nrow(tbl)) { |
||||
if (tbl[j, 'Adm.R'] == administration) { |
||||
returnvalue[i] <- tbl[j, property] |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
cat('\n') |
||||
returnvalue |
||||
|
||||
} |
@ -0,0 +1,356 @@
@@ -0,0 +1,356 @@
|
||||
# ==================================================================== # |
||||
# TITLE # |
||||
# Antimicrobial Resistance (AMR) Analysis # |
||||
# # |
||||
# AUTHORS # |
||||
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) # |
||||
# # |
||||
# LICENCE # |
||||
# This program is free software; you can redistribute it and/or modify # |
||||
# it under the terms of the GNU General Public License version 2.0, # |
||||
# as published by the Free Software Foundation. # |
||||
# # |
||||
# This program is distributed in the hope that it will be useful, # |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||||
# GNU General Public License for more details. # |
||||
# ==================================================================== # |
||||
|
||||
#' Class 'rsi' |
||||
#' |
||||
#' This transforms a vector to a new class \code{rsi}, which is an ordered factor with levels \code{S < I < R}. Invalid antimicrobial interpretations will be translated as \code{NA} with a warning. |
||||
#' @rdname as.rsi |
||||
#' @param x vector |
||||
#' @return New class \code{rsi} |
||||
#' @export |
||||
#' @importFrom dplyr %>% |
||||
#' @examples |
||||
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370))) |
||||
#' |
||||
#' rsi_data <- as.rsi(c(rep("S", 474), rep("I", 36), rep("R", 370), "A", "B", "C")) |
||||
as.rsi <- function(x) { |
||||
if (is.rsi(x)) { |
||||
x |
||||
} else { |
||||
|
||||
x <- x %>% unlist() |
||||
x.bak <- x |
||||
|
||||
na_before <- x[is.na(x) | x == ''] %>% length() |
||||
x <- gsub('[^RSI]+', '', x %>% toupper()) |
||||
# needed for UMCG in cases of "S;S" but also "S;I"; the latter will be NA: |
||||
x <- gsub('^S+$', 'S', x) |
||||
x <- gsub('^I+$', 'I', x) |
||||
x <- gsub('^R+$', 'R', x) |
||||
x[!x %in% c('S', 'I', 'R')] <- NA |
||||
na_after <- x[is.na(x) | x == ''] %>% length() |
||||
|
||||
if (na_before != na_after) { |
||||
list_missing <- x.bak[is.na(x) & !is.na(x.bak) & x.bak != ''] %>% |
||||
unique() %>% |
||||
sort() |
||||
list_missing <- paste0('"', list_missing , '"', collapse = ", ") |
||||
warning(na_after - na_before, ' results truncated (', |
||||
round(((na_after - na_before) / length(x)) / 100), |
||||
'%) that were invalid antimicrobial interpretations: ', |
||||
list_missing, call. = FALSE) |
||||
} |
||||
|
||||
x <- x %>% toupper() %>% factor(levels = c("S", "I", "R"), ordered = TRUE) |
||||
class(x) <- c('rsi', 'ordered', 'factor') |
||||
x |
||||
} |
||||
} |
||||
|
||||
#' @rdname as.rsi |
||||
#' @export |
||||
#' @importFrom dplyr %>% |
||||
is.rsi <- function(x) { |
||||
class(x) %>% identical(c('rsi', 'ordered', 'factor')) |
||||
} |
||||
|
||||
#' @exportMethod print.rsi |
||||
#' @export |
||||
#' @importFrom dplyr %>% |
||||
#' @noRd |
||||
print.rsi <- function(x, ...) { |
||||
n_total <- x %>% length() |
||||
x <- x[!is.na(x)] |
||||
n <- x %>% length() |
||||
S <- x[x == 'S'] %>% length() |
||||
I <- x[x == 'I'] %>% length() |
||||
R <- x[x == 'R'] %>% length() |
||||
IR <- x[x %in% c('I', 'R')] %>% length() |
||||
cat("Class 'rsi': ", n, " isolates\n", sep = '') |
||||
cat('\n') |
||||
cat('<NA>: ', n_total - n, '\n') |
||||
cat('Sum of S: ', S, '\n') |
||||
cat('Sum of IR: ', IR, '\n') |
||||
cat('- Sum of R:', R, '\n') |
||||
cat('- Sum of I:', I, '\n') |
||||
cat('\n') |
||||
print(c( |
||||
`%S` = round((S / n) * 100, 1), |
||||
`%IR` = round((IR / n) * 100, 1), |
||||
`%I` = round((I / n) * 100, 1), |
||||
`%R` = round((R / n) * 100, 1) |
||||
)) |
||||
} |
||||
|
||||
#' @exportMethod summary.rsi |
||||
#' @export |
||||
#' @importFrom dplyr %>% |
||||
#' @noRd |
||||
summary.rsi <- function(object, ...) { |
||||
x <- object |
||||
n_total <- x %>% length() |
||||
x <- x[!is.na(x)] |
||||
n <- x %>% length() |
||||
S <- x[x == 'S'] %>% length() |
||||
I <- x[x == 'I'] %>% length() |
||||
R <- x[x == 'R'] %>% length() |
||||
IR <- x[x %in% c('I', 'R')] %>% length() |
||||
lst <- c('rsi', n_total - n, S, IR, R, I) |
||||
names(lst) <- c("Mode", "<NA>", "Sum S", "Sum IR", "Sum R", "Sum I") |
||||
lst |
||||
} |
||||
|
||||
#' @exportMethod plot.rsi |
||||
#' @export |
||||
#' @importFrom dplyr %>% group_by summarise filter mutate if_else |
||||
#' @importFrom graphics plot text |
||||
#' @noRd |
||||
plot.rsi <- function(x, ...) { |
||||
x_name <- deparse(substitute(x)) |
||||
|
||||
data <- data.frame(x = x, |
||||
y = 1, |
||||
stringsAsFactors = TRUE) %>% |
||||
group_by(x) %>% |
||||
summarise(n = sum(y)) %>% |
||||
filter(!is.na(x)) %>% |
||||
mutate(s = round((n / sum(n)) * 100, 1)) |
||||
data$x <- factor(data$x, levels = c('S', 'I', 'R'), ordered = TRUE) |
||||
|
||||
ymax <- if_else(max(data$s) > 95, 105, 100) |
||||
|
||||
plot(x = data$x, |
||||
y = data$s, |
||||
lwd = 2, |
||||
col = c('green', 'orange', 'red'), |
||||
ylim = c(0, ymax), |
||||
ylab = 'Percentage', |
||||
xlab = 'Antimicrobial Interpretation', |
||||
main = paste('Susceptibilty Analysis of', x_name), |
||||
...) |
||||
text(x = data$x, |
||||
y = data$s + 5, |
||||
labels = paste0(data$s, '% (n = ', data$n, ')')) |
||||
} |
||||
|
||||
#' Class 'mic' |
||||
#' |
||||
#' This transforms a vector to a new class\code{mic}, which is an ordered factor valid MIC values as levels. Invalid MIC values will be translated as \code{NA} with a warning. |
||||
#' @rdname as.mic |
||||
#' @param x vector |
||||
#' @param na.rm a logical indicating whether missing values should be removed |
||||
#' @return New class \code{mic} |
||||
#' @export |
||||
#' @importFrom dplyr %>% |
||||
as.mic <- function(x, na.rm = FALSE) { |
||||
if (is.mic(x)) { |
||||
x |
||||
} else { |
||||
x <- x %>% unlist() |
||||
if (na.rm == TRUE) { |
||||
x <- x[!is.na(x)] |
||||
} |
||||
x.bak <- x |
||||
|
||||
# comma to dot |
||||
x <- gsub(',', '.', x, fixed = TRUE) |
||||
# starting dots must start with 0 |
||||
x <- gsub('^[.]', '0.', x) |
||||
# <=0.2560.512 should be 0.512 |
||||
x <- gsub('.*[.].*[.]', '0.', x) |
||||
# remove ending .0 |
||||
x <- gsub('[.]0$', '', x) |
||||
# remove all after last digit |
||||
x <- gsub('[^0-9]$', '', x) |
||||
# remove last zeroes |
||||
x <- gsub('[.]?0+$', '', x) |
||||
|
||||
lvls <- c("<0.002", "<=0.002", "0.002", ">=0.002", ">0.002", |
||||
"<0.003", "<=0.003", "0.003", ">=0.003", ">0.003", |
||||
"<0.004", "<=0.004", "0.004", ">=0.004", ">0.004", |
||||
"<0.006", "<=0.006", "0.006", ">=0.006", ">0.006", |
||||
"<0.008", "<=0.008", "0.008", ">=0.008", ">0.008", |
||||
"<0.012", "<=0.012", "0.012", ">=0.012", ">0.012", |
||||
"<0.016", "<=0.016", "0.016", ">=0.016", ">0.016", |
||||
"<0.023", "<=0.023", "0.023", ">=0.023", ">0.023", |
||||
"<0.03", "<=0.03", "0.03", ">=0.03", ">0.03", |
||||
"<0.032", "<=0.032", "0.032", ">=0.032", ">0.032", |
||||
"<0.047", "<=0.047", "0.047", ">=0.047", ">0.047", |
||||
"<0.05", "<=0.05", "0.05", ">=0.05", ">0.05", |
||||
"<0.06", "<=0.06", "0.06", ">=0.06", ">0.06", |
||||
"<0.0625", "<=0.0625", "0.0625", ">=0.0625", ">0.0625", |
||||
"<0.064", "<=0.064", "0.064", ">=0.064", ">0.064", |
||||
"<0.09", "<=0.09", " |