read.malpaca.estimates: Read MALPACA estimates

View source: R/read.malpaca.estimates.R

read.malpaca.estimatesR Documentation

Read MALPACA estimates

Description

This function returns store MALPACA median estimates and corresponding manual landmarks in 3D arrays. It also returns a 4D array that contains all landmark estimates of individual templates

Usage

read.malpaca.estimates(MALPACA_outputDir, templates_Dir)

Arguments

MALPACA_outputDir

The output directory of MALPACA

template_number

The number of templates

Value

A list that contains median estimates, manual landmarks and estimates of individual templates
The returned value contains:

  • $MALPACA_medians = a 3d array for the median estimates of MALPACA

  • $allEstimates = A 4d array for all estimates of each template. The 1st dimension is the landmark number. The 2nd dimension specifies x, y, z coordinates. The 3rd dimension is the template number. The 4th dimension is the sample size.

Examples

#The example below shows how this function reads MALPACA output.
#The output estimates are then submitted to the 'extract.outliers' for removing outlier estimates.
#Finally, 'get.medians'is used to calculate a new set of median estimates based on the result of 'extract.outliers'
#Please see the help file of 'extract.outliers' and 'get.medians' in SlicerMorphR for more detail.

#Clone the Github repository that contains the sample ape MALPACA output and template landmark files using the url 'https://github.com/SlicerMorph/Mouse_Models.git'
#The ape MALPACA output is in the 'ape_MALPACA' folder. See 'https://github.com/SlicerMorph/Mouse_Models' for details

# Users can also download and unzip the file in the Github repository using the following R code:
save.dir='C:/tmp'  #enter your directory to download the MALPACA data sample
setwd(save.dir)
zip_url <- "https://github.com/SlicerMorph/Mouse_Models/archive/refs/heads/main.zip"
download.file(url = zip_url, destfile = "Mouse_Models.zip")
unzip(zipfile = "Mouse_Models.zip")

MAL_outDir_git<- paste(save.dir, 'Mouse_Models-main/ape_malpaca', sep="/")
#If cloned the repository, MAL_outDir_git <- 'your_directory_for_the_Cloned_folder/ape_malpaca'

templates_path_git<- paste(save.dir, 'Mouse_Models-main/ape_malpaca/templates_LMs', sep='/')
#If cloned the repository, templates_path_git <- 'your_directory_for_the_Cloned_folder/ape_malpaca/templates_LMs'

#Read MALPACA median estimates and estimates by individual templates
LMs <- read.malpaca.estimates(MALPACA_outputDir = MAL_outDir_git, templates_Dir = templates_path_git)

allEst <- LMs$allEstimates #Store all individual estimates in a 4D array
#For the ape data
allEst[1:2, , 1, 3] #The LM1 and LM2 estimated by template 1 for target specimen 3
          [,1]    [,2]    [,3]
[1,] -15.37080 428.172 159.411
[2,]  -1.88649 365.697 180.744

MAL_medians <- LMs$MALPACA_medians #Store all median estimates in a 3D array
MAL_medians[1:2, , 3] #The median estimates for LM 1 and LM3 of the target specimen 3
          [,1]     [,2]     [,3]
[1,] -7.218665 417.9610 158.4400
[2,] -1.850612 366.3141 180.6046


#########Run 'extract.outliers'
outPath <- the_output_path_for_boxplots_that_mark_outlier_estimates
outliers <- extract.outliers(allEstimates = allEst, MALPACA_medians = MAL_medians, outputPath = outPath)

outliers$estimates_no_out[18:23, , 2, 7]
#Show LM18 to LM23 estimated by template 2 for the 7th target specimen.
#Note the coordinates of LM21 are marked as NA because it is an outlier
            x        y        z
18   3.123262 441.5676 226.7014
19   1.254022 417.1126 206.4035
20  -2.445040 385.6000 193.9190
21         NA       NA       NA
22 -17.194445 457.1618 238.1673
23  28.504499 455.5570 234.8030

outliers$outlier_info[[7]]
#Print out the outlier LMs generated by each template for the 7th target specimen. "NULL" means no outlier generated.
$`USNM084655-Cranium_merged_1`
NULL

$`USNM142185-Cranium`
[1] 21 39

$`USNM153830-Cranium`
[1] 21

$`USNM176236-Cranium_merged_1`
NULL

$USNM590953_CRANIUM
[1] 19 36 38
$USNM599167_CRANIUM
[1] 19 25 36 37


#######Run 'get.medians'
medians <- get.medians(AllLMs = outliers$estimates_no_out, outlier.NA = TRUE)
#Because therer are NAs in outliers$estimates_no_out, assign "TRUE" to "outlier.NA"
medians[1:2, , 3]
[,1]     [,2]     [,3]
[1,] -7.218665 416.3260 158.4400
[2,] -1.850612 366.3141 180.6046

chz31/SlicerMorphR documentation built on Feb. 10, 2023, 11:56 p.m.