acorg / Racmacs

Racmacs R package for performing antigenic cartography
https://acorg.github.io/Racmacs/
GNU Affero General Public License v3.0
20 stars 9 forks source link

What's different between function agCoords() and agBaseCoords()? #154

Closed judyssister closed 1 year ago

judyssister commented 1 year ago

Dear authors,

I am confused about the results from:

  1. agCoords(acmap_obj, optimization_number = 1000)
  2. acmap_obj$optimizations[[1000]]$ag_base_coords
  3. agBaseCoords(acmap_obj, optimization_number = 1000)

The results from 2 and 3 are the same, but the output of 1 is different. What's the relationship between function agCoords and agBaseCoords?

Cheers, Jing

drserajames commented 1 year ago

I don't know why there are both (perhaps @shwilks can say? It might be something to do eliminating rounding errors), but they should give the same map just with different rotation or reflection. You can check this by calculating the distances between the points and plotting them for the two sets of coordinates e.g.

plot( dist(agCoords(acmap_obj, optimization_number = 1000)), dist(agBaseCoords(acmap_obj, optimization_number = 1000)))

I only ever use agCoords.

Hope this helps and you're getting on okay with Racmacs.

shwilks commented 1 year ago

Hi Jing,

Yes Sarah is correct it is to do with rounding errors after transformation of the map, like rotation. Basically, optimization is performed on the map to give the coordinates found in e.g. agBaseCoords(), but when you call agCoords() it additionally applies any transformations stored in mapTransformation(). This means that base coordinates remain unchanged when you align different maps etc. and don't suffer continuous rounding error distortions.

As you have found you can access the same information from the map object through accessing its list structure directly e.g. your acmap_obj$optimizations[[1000]]$ag_base_coords but this is not recommended since the underlying data structure of the map might change at some point in the future.

I hope that helps,

Sam

judyssister commented 1 year ago

Thanks, Sarah. Thanks, Sam. Your response helps a lot :)