Dear David,
when you do many operations in Amira or Avizo for a bug the landmarkAscii file
is converted in a 2setlandmarkAscii file, in fact a second empty matrix will be
added…
I report two functions to convert a landmarkAscii file or a folder containing
the amira/avizo Landmark files in an array k*3*n, where k=number of landmarks
and n=number of specimens.
My functions read only the matrix between the @1 and @2.
Let me know if it works or not…
Best,
Antonio
#' read.amira.set
#'
#' This function convert a file landmark set of Amira in a array
#' @param name.file character: path of landamrkascii file
#' @param nland numeric: number of landmark sampled in Amira, if is set on
"auto" will be automatically recognized the landmark number
#' @return array.set numeric: an array with landmark coordinates (kxdxn)
#' @author Antonio Profico
#' @export
#'
read.amira.set=function(name.file,nland){
A <- readLines(name.file, n = 100)
end <- which(A == "@1")
end_2 <- which(A == "@2")
if(length(end_2!=0)){
print(paste("file named",name.file, "contains a second matrix of 000"))
B_junk=read.table(name.file,skip=end,nrows=(end_2-end-2))
if(nland!="auto"){
if (dim(B_junk)[1] != nland){
print(paste("nland is different from dim(matrix)[1]:
",paste("nland=",nland,",",sep=""),
paste("dim(matrix)[1]=", dim(B_junk)[1],sep="")))
B=matrix(NA,ncol=3,nrow=nland)}
if(dim(B_junk)[1]==nland){
B=B_junk
}}
if(nland=="auto"){
B=read.table(name.file,skip=end,nrows=(end_2-end-2))
}}
if(length(end_2)==0){
B_junk=read.table(name.file,skip=end)
if(nland!="auto"){
if (dim(B_junk)[1] != nland){
print(paste("nland is different from dim(matrix)[1]:
",paste("nland=",nland,",",sep=""),
paste("dim(matrix)[1]=", dim(B_junk)[1],sep="")))
B=matrix(NA,ncol=3,nrow=nland)}
if(dim(B_junk)[1]==nland){
B=B_junk
}}
if(nland=="auto"){
B=B_junk}}
array.set=array(as.matrix(B),dim=c(dim(B)[1],3,1))
dimnames(array.set)[[3]]=list(name.file)
return(array.set)}
#' read.amira.dir
#'
#' This function read and store in array the coordinated allocated in a folder
in separate files (format
#' @param path.dir character: path of the folder
#' @param nland numeric: number of landmark sampled in Amira
#' @return array.set numeric: a kxdxn array with landmark coordinates
#' @author Antonio Profico
#' @export
read.amira.dir=function(path.dir,nland){
names=list.files(path.dir)
if(nland=="auto"){
dims=c()
for(i in 1:length(names)){
dims[i]=dim(read.amira.set(paste(path.dir,"/",names[i],sep=""),"auto"))[1]}
array.amira=array(NA,dim=c(as.numeric(names(sort(-table(dims)))[1]),3,length(names)))}
else{array.amira=array(NA,dim=c(nland,3,length(names)))}
for(i in 1:length(names)){
array.amira[,,i]=read.amira.set(paste(path.dir,"/",names[i],sep=""),nland)
}
if(length(names)==1){
dimnames(array.amira)[[3]]=list(names)}
if(length(names)!=1){
dimnames(array.amira)[[3]]=names}
return(array.amira)
}
__
Antonio Profico
PhD student
Department of Environmental Biology – Dipartimento di Biologia Ambientale
SAPIENZA Università di Roma
Lab. 06 4991 2690
Mob. 3293440766
Da: David Katz
Data invio: mercoledì 20 gennaio 2016 06:49
A: Emma Sherratt
Cc: MORPHMET
I won't get back to my office, and the hard drive where the files are stored,
for about a week. I'll send something along then.
Thanks, Emma.
David
On Wed, Jan 20, 2016 at 12:08 AM, Emma Sherratt wrote:
Hi David,
Not sure what the file actually looks like since you’ve not included a sample
here. However I suggest taking a look at the readland functions in geomorph R
package to see how we tackle the different types. If you want, send it through
to us and we can take a look. If there’s a lot of people using AVIZO for
digitising, we can include a function in geomorph.
Regarding a read function writing? Nope, never heard of that.
Em
~~~
Emma Sherratt, PhD.
Lecturer in Zoology,
Zoology Division, School of Environmental and Rural Science,
Room L112 Bldg C02,
University of New England,
Armidale, NSW, Australia, 2351
Tel: +61 2 6773 5041
email: emma.sherr...@une.edu.au
Twitter: @DrEmSherratt
Caecilians are legless amphibians...
__
(\ .-. .-. /_")
\\_//^\\_//^\\_//
`"` `"` `"`
learn more about them here: www.emmasherratt.com/caecilians
On 20 January 2016 at 14:50:38, David Katz (dck...@ucdavis.edu) wrote:
Hi everyone,
I've collected 3D landmarks on a series of cranial surface models in Avizo.
Avizo's landmark editor outputs .landmarkAscii files, which I would like to
read into R. The way I've done the reading has the following very unexpected
effect: sometimes, it writes additional data to my .landmarkAscii files. I'd
like to understand why, but am mostly interested in finding a solution.
To read in the landmark files for a specimen...
# Below, avz.file is