Re: Results tablw manipulation
Posted by Crowell Elizabeth on Jul 19, 2010; 12:52pm
URL: http://imagej.273.s1.nabble.com/Results-tablw-manipulation-tp3687576p3687578.html
Okay, let's go for it.
The script is attached. You might want to place it on the Desktop for now.
This script is run from the Unix command prompt.
So, to run it, open up the Terminal window and type the following
information in order, separated by spaces:
The filepath to the script (such as ~/Desktop/modify.tcl)
The filepath to the files you want to process (such as ~/Desktop/test).
The number of the column you want to save in a new file.
Your final command should look something like this:
~/Desktop/modify.tcl ~/Desktop/test 2
Press enter and you should see printed a list of the files that were
processed. (That is the big advantage - you can process as many files
as you like all at once.)
The new files will be created in the same directory as the old ones,
with c2 added on to the end of the name (or c1 if you extracted the
first column, or c3 for the third column, etc).
If you got a "Permission denied" message, don't panick! You probably
just have to make the script executable. Check that the script is
executable by typing in the Terminal window: ls -l "filepath to the script"
The message printed out on the screen should be -rwxr--r-- or something
similar, but the x has to be present, indicating that the script is
executable. If there is no x, type chmod u+x "filepath to the script."
You can edit the script in ImageJ if you need to (such as for changing
the default filepath for the location of the files). Of course you can
make an alias to modify.tcl in your .profile file to avoid typing the
filepath the next time.
Please let me know if it works for you!
Elizabeth
> Andrew James Bell a écrit :
>> Dear Elizabeth,
>>
>> It couldn't hurt to take a look.
>>
>> Andrew
>>
>
>
--
Elizabeth CROWELL
----------------------------------------------------------------------
Membrane Traffic and Cell Division Research Group
Institut Pasteur
28 rue du Dr Roux
75015 PARIS, France
Tel : 01.44.38.94.07
Fax : 01.45.68.89.54
----------------------------------------------------------------------
#!/usr/bin/tclsh
proc MakeListOfFiles {path} {
set theFiles [exec ls $path]
set aList [split $theFiles]
set aListLength [llength $aList]
set newList {}
if {$aListLength==0} {
puts "WARNING: this folder is empty"
# puts is equivalent to print
}
foreach fileName $aList {
set fullName ${path}\/${fileName}
if {[file isfile $fullName]} {
lappend newList $fullName
}
}
return $newList
}
proc ModifyFiles {fileName colNumber headerOption} {
set modifiedFullFileName ${fileName}c${colNumber}
puts "Opening $fileName"
set inId [open $fileName r]
set outId [open $modifiedFullFileName w]
set iline 0
while {[gets $inId fileLine] > 0} {
incr iline
# skip header
if {$iline==1} {
if {$headerOption == -1} {
if {[string match {*[0123456789]*} $fileLine]==0} {
set linesToSkip 1
} else {
set linesToSkip 0
}
} else {
set linesToSkip $headerOption
}
}
if {$iline > $linesToSkip} {
set columnList [split $fileLine]
# select the column of interest
set iRealCol 0
set ncol [llength $columnList]
set i 0
set found 0
set readError 0
while {$found==0 && $readError==0} {
if {[lindex $columnList $i]!={}} {
incr iRealCol
}
if {$iRealCol==$colNumber} {
set found 1
} else {
incr i
if {$i>($ncol-1)} {
set readError 1
}
}
}
if {$readError==0} {
puts $outId [lindex $columnList $i]
}
}
}
close $inId
close $outId
}
# *********************** MAIN ***********************
# Sets the default filepath of the files to be processed
set path /Users/liz/Documents/Work/Process/Modify
# Sets the default column to extract from the files
set colNumber 2
set headerOption -1
if {$argc > 0} {
set argList [split $argv]
set path [lindex $argList 0]
if {$argc > 1} {
set colNumber [lindex $argList 1]
}
if {$argc > 2} {
set headerOption [lindex $argList 2]
}
}
if {[file exists $path]} {
set aList [MakeListOfFiles $path]
foreach fullName $aList {
ModifyFiles $fullName $colNumber $headerOption
}
} else {
puts "ERROR: $path is not a valid path"
}