set.seed(100) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = rmarkdown::pandoc_available() )
In this vignette we're going to go through the process of making an antigenic map using Racmacs and viewing and saving the resulting map and images and interactive plots of the map.
The steps will be:
First of all we need to read in the titer data from a file, exactly how you do this depends on the format of your data but ultimately you need to end up with a matrix or dataframe of titers where rows represent antigens and columns represent sera.
If your titer data is in a simple format where you just have a single header for serum names and a single first column of antigen names you can try using the function read.titerTable()
, as in the example below.
For this example we will be reading the titer data from the first antigenic map of H3N2 antigenic evolution, published in 2004 and included with the Racmacs package.
# Load the Racmacs package library(Racmacs) # Set an option for the number of computer cores to run in parallel when optimizing maps # The default when running on CRAN is to use 2 options(RacOptimizer.num_cores = 1) # However you can also set the number of cores to the maximum number like this # options(RacOptimizer.num_cores = parallel::detectCores()) # Read in the titer table path_to_titer_file <- system.file("extdata/h3map2004_hitable.csv", package = "Racmacs") titer_table <- read.titerTable(path_to_titer_file)
The resulting titer table is a matrix of titers with column and row names:
print(titer_table[1:5,1:7])
Now we have the titers in the correct format we can use it create an antigenic map object or "acmap" object. For this we use the constructor function acmap()
, akin to how data.frame()
is used to make a data frame object or matrix()
for a matrix.
# Create the acmap object, specifying the titer table map <- acmap( titer_table = titer_table )
The resulting object, that we've given the name map
in this case, only has properties associated with the table. If the table had column names and row names, serum and antigen names are inferred from these. Alternatively, you can set these explicitly when creating the map with the ag_names
and sr_names
arguments.
Although we now have the acmap object there is no "map" yet as such, since we need to invoke the optimiser function to try and determine the antigenic map that best represents the patterns of reactivity seen in the titer table. To do this we call the function optimizeMap()
on the acmap object we've made, specifying the number of optimization runs and other parameters like the minimum column basis and number of dimensions.
In this case we're going to try and find the best 2-dimensional solution for the map data, using 500 optimization runs.
# Perform some optimization runs on the map object to try and determine a best map map <- optimizeMap( map = map, number_of_dimensions = 2, number_of_optimizations = 500, minimum_column_basis = "none" )
By default the resulting map optimizations are sorted by their stress, so that the optimization that resulted in the lowest map stress (i.e. usually thought of as the best solution), will be first and will be the default optimization run selected and therefore will be the one used when querying anything like antigen and serum coordinates, map stress etc. unless otherwise specified.
The lowest stress optimization run will also be the one used by default when viewing the map. To view the map, you can either do a simple plot of the map using the plot()
function
plot(map)
or you can view the map interactively using the view()
function
view(map)
make.acmap()
Note that there is also a small utility function provided to allow you to create the acmap object and run optimizations on it all in one step. In the example below we use it to create a 3d version of the antigenic map and then use view()
map to view the result (plot()
will not work with 3 dimensional maps).
# Make the acmap object and run optimizations map3d <- make.acmap( titer_table = titer_table, number_of_dimensions = 3, number_of_optimizations = 500, minimum_column_basis = "none" ) # View the result view(map3d)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.