sub setting TPS Files in R

245 views
Skip to first unread message

Cybil Cavalieri

unread,
Jul 27, 2018, 2:09:55 PM7/27/18
to geomorph R package

Dear Everyone,

 

I want to subset a tps file, by asking for specific individuals. I want to make a new tps file of only females.

This seems like something many people would do regularly.  

 

I can call specific individuals using

 

Data[,,"CMNMA_L_52555"] #Show me this individual

 

But when I try to write them as a new TPS file using

#write TPS file

writeland.tps(TPS_ArticFox_Females, "4ArticFox_Females_Made_in_R.TPS",  scale= T, specID = TRUE )

 

The new file does not contain the original scale, Image, or ID from original file.

#### New

LM=25

28.994352 39.788445

40.576335 46.800666

42.309693 41.915748

42.230904 36.558096

40.733913 32.461068

44.830941 39.315711

71.067678 38.842977

75.085917 54.915933

72.958614 24.582168

88.322469 38.60661

89.504304 60.982686

88.24368 15.915378

110.147022 67.837329

109.910655 7.327377

138.983796 37.739931

89.346726 47.824923

89.189148 29.545875

132.129153 44.988519

131.892786 31.200444

116.686509 53.891676

115.977408 22.06092

59.87964 49.715859

60.194796 28.36404

127.559391 57.831126

128.189703 18.751782

SCALE=TRUE

ID=UAM-V-12650

#####

## original

LM=25

54.00000 492.00000

199.00000 569.00000

211.00000 519.00000

221.00000 466.00000

190.00000 420.00000

247.00000 493.00000

506.00000 486.00000

541.00000 662.00000

531.00000 312.00000

688.00000 483.00000

653.00000 721.00000

653.00000 248.00000

933.00000 814.00000

917.00000 144.00000

1210.00000 473.00000

702.00000 585.00000

748.00000 365.00000

1137.00000 557.00000

1131.00000 399.00000

977.00000 649.00000

971.00000 317.00000

376.00000 608.00000

353.00000 377.00000

1060.00000 673.00000

1058.00000 264.00000

IMAGE=UAM-V-12122.JPG

ID=0

SCALE=0.098058

 

How do you properly subset tps files in R?


Full code below.


Thank you for any and all help


Nikki Cavalieri


#############


###Libraries
library(geomorph)

#############################
## Step 1: Read in TPS file##
#############################

#Read in TPS
#This is a three-dimensional array, the first dimension being the rows (landmarks), the next being the columns (the x- and y-coordinates) and the third being the individual (Tamias umbrinus). ImageID
Data_All<-readland.tps(file="data.TPS", specID="imageID")
Data_All

Data_All[, , "UAM-V-12297"]

typeof(Data)
class(Data)
str(Data)
dimnames(Data)
Data[,,"USNM_L_592332"]# Show me this guy
Data[,,1]#show me the first guy
Data[,,"CMNMA_L_52555"]#Show me this guy

#Read in Assocated Data
AsData_All<-read.csv("AsData.csv",header = T)
head(AsData_All)
colnames(AsData_All)

#pull Females  from AsData
AsData_Female<-subset(AsData_All,sex_code==1)

#make CSV file
#write.csv(AsData_Female, "TestAsData.csv")


#New TPS of only females

Female_TPS_List<-AsData_Female$Image_ID
Female_TPS_List

class(Female_TPS_List)

#Make it a character string
Female_TPS_List<-as.character(Female_TPS_List)
Female_TPS_List

#strip list of .jpg, .JPG and extra '

library(stringr)
#example
#a <- "a#g abcdefgtdkfef_jpg>pple"
#str_replace(a, "#g.*jpg>", "")
# [1] "apple"


#Strip upper Case JPG
Female_TPS_List_NoJPG<-str_replace(Female_TPS_List,".JPG", "")
Female_TPS_List_NoJPG

# And now Strip Lower Case JPG
Female_TPS_List_Nojpg<-str_replace(Female_TPS_List_NoJPG,".jpg", "")
Female_TPS_List_Nojpg

#and now strip '
Female_TPS_List_NoQuotes<-str_replace(Female_TPS_List_Nojpg,"'", "")
Female_TPS_List_NoQuotes

#and now strip '
Female_TPS_List_NoQuotes2<-str_replace(Female_TPS_List_NoQuotes,"'", "")
Female_TPS_List_NoQuotes2

#Make TPS file of only females

TPS_ArticFox_Females<-Data_All[,,Female_TPS_List_NoQuotes2]
TPS_ArticFox_Females

#How many are in TPS file
ImagesInTPS<-(TPS_ArticFox_Females[1,1,])
NumberInTPS<-length(ImagesInTPS)# 35
NumberInTPS

#write TPS file

writeland.tps(TPS_ArticFox_Females, "4ArticFox_Females_Made_in_R.TPS",  scale= T, specID = TRUE )

#Problems !
# no scale  just says TRUE
#IMAGE= Wrong not jpg so wont connect to photos
#ID= is photo name with no jpg


#writing it as a table does not work
write.table(TPS_ArticFox_Females, file = "TestTPS.txt", sep = "\t",
            row.names = FALSE)


Adams, Dean [EEOBS]

unread,
Jul 27, 2018, 4:02:38 PM7/27/18
to geomorph-...@googlegroups.com

Cybil,

 

Please read the help files for the functions more carefully.

 

First, for readland.tps:

 

Landmark coordinates are multiplied by their scale factor if this is provided for all specimens.” 

 

This means as they are read in the scale is taken into account in the coordinates.

 

Second, for writeland.tps

 

scale    An optional vector containing the length of the scale for each specimen

 

This is not a T/F option, but a vector of numbers. However, in your case it is completely unnecessary as the scale was already incorporated in the landmark data when read into geomorph.

 

Dean

 

Dr. Dean C. Adams

Director of Graduate Education, EEB Program

Professor

Department of Ecology, Evolution, and Organismal Biology

Iowa State University

www.public.iastate.edu/~dcadams/

phone: 515-294-3834

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/8cf22e5a-0ebf-48fb-b01d-4325fd4d62e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cybil Cavalieri

unread,
Jul 27, 2018, 9:33:02 PM7/27/18
to geomorph R package

Dear Dean,

 

Thank you for providing clarification.  I will read more carefully in the future.

 

Thank you

Nikki


Reply all
Reply to author
Forward
0 new messages