Authors: J. Coelho, S. Ammer

library(ggplot2)
library(Momocs) # package for outline and curve analysis
## This is Momocs 1.1.0
## 
## Attaching package: 'Momocs'
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:base':
## 
##     table
setwd("/Users/del/ACADEMY/WIP/HumerusProject/Photos_final/") # location of my data

rawLPF <- import_tps(tps.path = "LPF/LPF.TPS", curves = T) # read data Left, Posterior, Females
rawLPM <- import_tps(tps.path = "LPM/LPM.TPS", curves = T) # read data Left, Posterior, Males

Rebuild dataset

For some reason, I can’t use Momocs::Out() directly on my imported TPS. Tried many ways, always obtaining different errors. I thought this might be because the p of coordinates is not consistent. So I resample them. In my understanding coo_sample() works well for open curves, while I preferred coo_interpolate() for my closed outlines, since they had very inconsistent p.

# Rebuild datasets
# For females

for (i in seq_along(rawLPF$cur)){
    # open (curves)
    rawLPF$cur[[i]][[1]] <- coo_sample(rawLPF$cur[[i]][[1]], n = 16)
    # closed (outlines)
    rawLPF$cur[[i]][[2]] <- coo_interpolate(rawLPF$cur[[i]][[2]], n = 24)
    # keep the IDs
    names(rawLPF$cur)[[i]] <- names(rawLPF$cur)[[i]]
}

## For males

for (i in seq_along(rawLPM$cur)){
    # open (curves)
    rawLPM$cur[[i]][[1]] <- coo_sample(rawLPM$cur[[i]][[1]], n = 16)
    # closed (outlines)
    rawLPM$cur[[i]][[2]] <- coo_interpolate(rawLPM$cur[[i]][[2]], n = 24)
    # keep the IDs
    names(rawLPM$cur)[[i]] <- names(rawLPM$cur)[[i]]
}

Spliting data

I tried to work with my curves together but for some reason, I also got errors trying to Out() these. So first I will split my open curve (TE: Throclear Extension) from my closed outlines (OF: Olecranon Fossa), but combine my males and females datasets to see the differences among these groups.

TE.f <- list()
for (i in seq_along(rawLPF$cur)){
    TE.f[[i]] <- rawLPF$cur[[i]][[1]]
    names(TE.f)[[i]] <- names(rawLPF$cur)[[i]]
}

TE.m <- list()
for (i in seq_along(rawLPM$cur)){
    TE.m[[i]] <- rawLPM$cur[[i]][[1]]
    names(TE.m)[[i]] <- names(rawLPM$cur)[[i]]
}

Sex <- rep("Female", length(TE.f))
TE.f <- Out(TE.f, fac = as.data.frame(Sex))
Sex <- rep("Male", length(TE.m))
TE.m <- Out(TE.m, fac = as.data.frame(Sex))
TE <- combine(TE.f, TE.m)

###

OF.f <- list()
for (i in seq_along(rawLPF$cur)){
    OF.f[[i]] <- rawLPF$cur[[i]][[2]]
    names(OF.f)[[i]] <- names(rawLPF$cur)[[i]]
}

OF.m <- list()
for (i in seq_along(rawLPM$cur)){
    OF.m[[i]] <- rawLPM$cur[[i]][[2]]
    names(OF.m)[[i]] <- names(rawLPM$cur)[[i]]
}

Sex <- rep("Female", length(OF.f))
OF.f <- Out(OF.f, fac = as.data.frame(Sex))
Sex <- rep("Male", length(OF.m))
OF.m <- Out(OF.m, fac = as.data.frame(Sex))
OF <- combine(OF.f, OF.m)

Procrustes and Rotation

My pics were (anatomically) upside-down. So I use the very useful coo_rotate() by Pi radians (180º). I have done some landmarks-based analysis before were Procrustes was a mandatory step. I am not sure if it is with open curves and closed outlines, however I am also doing a superimposition step here.

TE.aligned <- TE %>% coo_rotate(.,theta = pi) %>% fgProcrustes() %>% Opn()
OF.aligned <- OF %>% coo_rotate(.,theta = pi) %>% fgProcrustes() %>% coo_close()

Throclear Extension

TE.aligned %>% stack(., title = "Trochlear Extension (H. sapiens)", fac = "Sex")