----- Forwarded message from
Ambrosio Torres Galvis
Date: Sun, 1
Jul 2012 20:48:31 -0500
From: Ambrosio Torres Galvis
Reply-To: Ambrosio Torres Galvis
Subject: reading nts file format in R
To:
[email protected]
Hi
Paolo,
In chapter 2 (Acquiring and Manipulating Morphometric Data) of the book "Morphometrics with R" by Julien Claude, there is a code to read nts files in R. I'm putting the piece of the chapter that explain the code to read nts.
"The *.NTS format is one of the more commonly used in geometric morphomet-
rics. Software performing morphometric analyses (Morpheus,6 the TPS family7 etc.)
can save or convert data in this format. The data are stored as a matrix with the rows
corresponding to the configurations and the columns to the coordinates of each land-
mark. The first line of the file contains four or five arguments. The first and fourth
are fixed, while the second and third respectively correspond to the number of speci-
mens and the number of landmarks multiplied by the number of dimensions (k × p).
The fifth and optional argument specifies the number of dimensions, and follows the
string “DIM=”. By correctly filling the arguments of the scan function, we open
this type of file quite easily. If the string or the character for comments is the dou-
ble quoting mark along the file, the conversion requires not more than two lines as
illustrated below.
The RATS.NTS dataset can be found in the data sets of the freely available software
tpsRegr.8 http://life.bio.sunysb.edu/morph/
>jo<-scan("/home/juju/morph/RATS.NTS",what="char",
+
quote="",sep="\n", comment.char="\"")
Obtain the number of dimensions k.
>jo1<-jo[1]
>l1<-unlist(strsplit(jo1, "="))
>l2<-unlist(strsplit(jo1, " "))
> if(length(l1)==1) {k<-2}
+ else {k<-as.numeric(l1[2])}
>k
[1] 2
Extract coordinates.
>jo2<-jo[-1]
>cat(jo2, file="jo2.txt")
>data<-matrix(scan("jo2.txt"), as.numeric(l2[2]),
+
as.numeric(l2[3]), byrow=T)
>unlink ("jo2.txt")
Delete the temporary file jo2.txt.
Notice the sep="\n" argument specified for the scan function; it indicates that
the separator corresponds to a new line."
In fact, this book is very good to many things in R...
Best...
--
Ambrosio Torres Galvis
Estudiante de Pregrado
Laboratorio de Sistemática & Biogeografìa
Escuela de Biología
Universidad Industrial de Santander
In chapter 2 (Acquiring and Manipulating Morphometric Data) of the book "Morphometrics with R" by Julien Claude, there is a code to read nts files in R. I'm putting the piece of the chapter that explain the code to read nts.
"The *.NTS format is one of the more commonly used in geometric morphomet-
rics. Software performing morphometric analyses (Morpheus,6 the TPS family7 etc.)
can save or convert data in this format. The data are stored as a matrix with the rows
corresponding to the configurations and the columns to the coordinates of each land-
mark. The first line of the file contains four or five arguments. The first and fourth
are fixed, while the second and third respectively correspond to the number of speci-
mens and the number of landmarks multiplied by the number of dimensions (k × p).
The fifth and optional argument specifies the number of dimensions, and follows the
string “DIM=”. By correctly filling the arguments of the scan function, we open
this type of file quite easily. If the string or the character for comments is the dou-
ble quoting mark along the file, the conversion requires not more than two lines as
illustrated below.
The RATS.NTS dataset can be found in the data sets of the freely available software
tpsRegr.8 http://life.bio.sunysb.edu/morph/
>jo<-scan("/home/juju/morph/RATS.NTS",what="char",
+
quote="",sep="\n", comment.char="\"")
Obtain the number of dimensions k.
>jo1<-jo[1]
>l1<-unlist(strsplit(jo1, "="))
>l2<-unlist(strsplit(jo1, " "))
> if(length(l1)==1) {k<-2}
+ else {k<-as.numeric(l1[2])}
>k
[1] 2
Extract coordinates.
>jo2<-jo[-1]
>cat(jo2, file="jo2.txt")
>data<-matrix(scan("jo2.txt"), as.numeric(l2[2]),
+
as.numeric(l2[3]), byrow=T)
>unlink ("jo2.txt")
Delete the temporary file jo2.txt.
Notice the sep="\n" argument specified for the scan function; it indicates that
the separator corresponds to a new line."
In fact, this book is very good to many things in R...
Best...
Ambrosio Torres Galvis
Estudiante de Pregrado
Laboratorio de Sistemática & Biogeografìa
Escuela de Biología
Universidad Industrial de Santander
----- End forwarded message -----
----- End forwarded message
-----
