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 the filepath for the .landmarkAscii
# file for a single specimen.
# The code reads the .landmarkAscii file with read.csv.
# This is useful because the object created lays out
# the informational data that precedes the coordinate data
# predictably. This makes it easy to lop off the
# informational data.
  read.lms <- read.csv(avz.file, header=FALSE)[,1]

  # The last row of informational data will contain the
  # text "@1" and nothing else.
  lm.start <- which(read.lms=="@1")+1

  # Now it is possible to create an object with landmark
  # data only. R interprets each landmark (all three
  # coordinates together) as a factor. I convert the factor
  # vector to a character vector.
  lm.char <-
     as.character(droplevels(
         read.lms[(lm.start):length(read.lms)]))

  # Then I create an empty matrix for the landmark data
  lm.mat <- matrix(NA, nrow=length(lm.char), ncol=3)

  # Then fill lm.mat with the landmark data. As mentioned,
  # lm.char is a vector. Each element of that vector
  # contains the X, Y, and Z coordinate for a landmark.
  # The coordinates are separated by spaces
  # (or maybe tabs)
  for(i in 1:nrow(lm.mat))
     {lm.mat[i,] <-
         as.numeric(unlist(strsplit(ctlm.char[i], " ")))}

That's it. The code above will read in the data and make a landmark matrix.
Unfortunately, it sometimes also writes additional lines to the
.landmarkAscii file. The first added element is "@2." Thereafter, the
landmark file adds as many three-coordinate triplets as there are landmarks
in the original data file. The values of these triplets are 0,0,1 (or maybe
1,0,0).

This is really strange behavior. A read function shouldn't write.

My issue may be better suited to an R forum, but I am hoping someone here
has reliable code for reading Avizo landmarks into R.

Thanks in advance.

David


-- 
David Katz
University of California, Davis

-- 
MORPHMET may be accessed via its webpage at http://www.morphometrics.org
--- 
You received this message because you are subscribed to the Google Groups 
"MORPHMET" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to morphmet+unsubscr...@morphometrics.org.

Reply via email to