# Transform to microorganism ID — as.mo • AMR (for R)
Use this function to determine a valid microorganism ID (mo). Determination is done using Artificial Intelligence (AI) and the complete taxonomic kingdoms Bacteria, Fungi and Protozoa (see Source), so the input can be almost anything: a full name (like "Staphylococcus aureus"), an abbreviated name (like "S. aureus"), an abbreviation known in the field (like "MRSA"), or just a genus. You could also select a genus and species column, zie Examples.

# Transform to microorganism ID

`as.mo.Rd`

Use this function to determine a valid microorganism ID (`mo`). Determination is done using Artificial Intelligence (AI) and the complete taxonomic kingdoms Bacteria, Fungi and Protozoa (see Source), so the input can be almost anything: a full name (like `"Staphylococcus aureus"`), an abbreviated name (like `"S. aureus"`), an abbreviation known in the field (like `"MRSA"`), or just a genus. You could also `select` a genus and species column, zie Examples.

    as.mo(x, Becker = FALSE, Lancefield = FALSE, allow_uncertain = TRUE,
      reference_df = NULL)

    is.mo(x)

    guess_mo(x, Becker = FALSE, Lancefield = FALSE,
      allow_uncertain = TRUE, reference_df = NULL)

## Arguments

x | a character vector or a `data.frame` with one or two columns
Becker | a logical to indicate whether Staphylococci should be categorised into Coagulase Negative Staphylococci ("CoNS") and Coagulase Positive Staphylococci ("CoPS") instead of their own species, according to Karsten Becker et al. [1]. This excludes Staphylococcus aureus at default, use `Becker = "all"` to also categorise S. aureus as "CoPS".

Lancefield

a logical to indicate whether beta-haemolytic Streptococci should be categorised into Lancefield groups instead of their own species, according to Rebecca C. Lancefield [2]. These Streptococci will be categorised in their first group, e.g. Streptococcus dysgalactiae will be group C, although officially it was also categorised into groups G and L.

This excludes Enterococci at default (who are in group D), use `Lancefield = "all"` to also categorise all Enterococci as group D.

allow_uncertain | a logical to indicate whether the input should be checked for less possible results, see Details
reference_df | a `data.frame` to use for extra reference when translating `x` to a valid `mo`. The first column can be any microbial name, code or ID (used in your analysis or organisation), the second column must be a valid `mo` as found in the `microorganisms` data set.

## Value

Character (vector) with class `"mo"`. Unknown values will return `NA`.

## Details

A microbial ID from this package (class: `mo`) typically looks like these examples:

      Code              Full name
      ---------------   --------------------------------------
      B_KLBSL           Klebsiella
      B_KLBSL_PNE       Klebsiella pneumoniae
      B_KLBSL_PNE_RHI   Klebsiella pneumoniae rhinoscleromatis
      |   |    |   |
      |   |    |   |
      |   |    |    ----> subspecies, a 3-4 letter acronym
      |   |     ----> species, a 3-4 letter acronym
      |    ----> genus, a 5-7 letter acronym, mostly without vowels
       ----> taxonomic kingdom, either B (Bacteria), F (Fungi) or P (Protozoa)

Use the `mo_property` functions to get properties based on the returned code, see Examples.

This function uses Artificial Intelligence (AI) to help getting fast and logical results. It tries to find matches in this order:

- Taxonomic kingdom: it first searches in bacteria, then fungi, then protozoa

- Human pathogenic prevalence: it first searches in more prevalent microorganisms, then less prevalent ones

- Valid MO codes and full names: it first searches in already valid MO code and known genus/species combinations

- Breakdown of input values: from here it starts to breakdown input values to find possible matches

A couple of effects because of these rules:

- `"E. coli"` will return the ID of Escherichia coli and not Entamoeba coli, although the latter would alphabetically come first

- `"H. influenzae"` will return the ID of Haemophilus influenzae and not Haematobacter influenzae for the same reason

- Something like `"p aer"` will return the ID of Pseudomonas aeruginosa and not Pasteurella aerogenes

- Something like `"stau"` or `"S aur"` will return the ID of Staphylococcus aureus and not Staphylococcus auricularis

This means that looking up human pathogenic microorganisms takes less time than looking up human non-pathogenic microorganisms.

When using `allow_uncertain = TRUE` (which is the default setting), it will use additional rules if all previous AI rules failed to get valid results. Examples:

- `"Streptococcus group B (known as S. agalactiae)"`. The text between brackets will be removed and a warning will be thrown that the result Streptococcus group B (`B_STRPTC_GRB`) needs review.

- `"S. aureus - please mind: MRSA"`. The last word will be stripped, after which the function will try to find a match. If it does not, the second last word will be stripped, etc. Again, a warning will be thrown that the result Staphylococcus aureus (`B_STPHY_AUR`) needs review.

- `"D. spartina"`. This is the abbreviation of an old taxonomic name: Didymosphaeria spartinae (the last "e" was missing from the input). This fungus was renamed to Leptosphaeria obiones, so a warning will be thrown that this result (`F_LPTSP_OBI`) needs review.

`guess_mo` is an alias of `as.mo`.

## ITIS

This package contains the complete microbial taxonomic data (with all nine taxonomic ranks - from kingdom to subspecies) from the publicly available Integrated Taxonomic Information System (ITIS, https://www.itis.gov).

All (sub)species from the taxonomic kingdoms Bacteria, Fungi and Protozoa are included in this package, as well as all previously accepted names known to ITIS. Furthermore, the responsible authors and year of publication are available. This allows users to use authoritative taxonomic information for their data analysis on any microorganism, not only human pathogens. It also helps to quickly determine the Gram stain of bacteria, since all bacteria are classified into subkingdom Negibacteria or Posibacteria.

ITIS is a partnership of U.S., Canadian, and Mexican agencies and taxonomic specialists [3].

## Source

[1] Becker K et al. Coagulase-Negative Staphylococci. 2014. Clin Microbiol Rev. 27(4): 870–926. https://dx.doi.org/10.1128/CMR.00109-13

[2] Lancefield RC A serological differentiation of human and other groups of hemolytic streptococci. 1933. J Exp Med. 57(4): 571–95. https://dx.doi.org/10.1084/jem.57.4.571

[3] Integrated Taxonomic Information System (ITIS). Retrieved September 2018. http://www.itis.gov

## See also

`microorganisms` for the `data.frame` with ITIS content that is being used to determine ID's.
The `mo_property` functions (like `mo_genus`, `mo_gramstain`) to get properties based on the returned code.

## Examples

    # NOT RUN {
    # These examples all return "B_STPHY_AUR", the ID of S. aureus:
    as.mo("stau")
    as.mo("STAU")
    as.mo("staaur")
    as.mo("S. aureus")
    as.mo("S aureus")
    as.mo("Staphylococcus aureus")
    as.mo("Staphylococcus aureus (MRSA)")
    as.mo("MRSA") # Methicillin Resistant S. aureus
    as.mo("VISA") # Vancomycin Intermediate S. aureus
    as.mo("VRSA") # Vancomycin Resistant S. aureus
    as.mo(369)    # Search on TSN (Taxonomic Serial Number), a unique identifier
                  # for the Integrated Taxonomic Information System (ITIS)

    as.mo("Streptococcus group A")
    as.mo("GAS") # Group A Streptococci
    as.mo("GBS") # Group B Streptococci

    # guess_mo is an alias of as.mo and works the same
    guess_mo("S. epidermidis")                 # will remain species: B_STPHY_EPI
    guess_mo("S. epidermidis", Becker = TRUE)  # will not remain species: B_STPHY_CNS

    guess_mo("S. pyogenes")                    # will remain species: B_STRPTC_PYO
    guess_mo("S. pyogenes", Lancefield = TRUE) # will not remain species: B_STRPTC_GRA

    # Use mo_* functions to get a specific property based on `mo`
    Ecoli <- as.mo("E. coli")     # returns `B_ESCHR_COL`
    mo_genus(Ecoli)               # returns "Escherichia"
    mo_gramstain(Ecoli)           # returns "Gram negative"
    # but it uses as.mo internally too, so you could also just use:
    mo_genus("E. coli")           # returns "Escherichia"

    # }# NOT RUN {
    df$mo <- as.mo(df$microorganism_name)

    # the select function of tidyverse is also supported:
    library(dplyr)
    df$mo <- df %>%
      select(microorganism_name) %>%
      as.mo()

    # and can even contain 2 columns, which is convenient for genus/species combinations:
    df$mo <- df %>%
      select(genus, species) %>%
      as.mo()
    # although this works easier and does the same:
    df <- df %>%
      mutate(mo = as.mo(paste(genus, species)))
    # }