Results tablw manipulation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Results tablw manipulation

AJBell
Hello,

Simple question with I hope a simple answer!

Is it possible to delete a column of a results table?

Regards,

Andrew Bell
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

Michael Schmid
Hi Andrew,

not a simple answer if you don't tell whether you talk about the user  
interface, a macro or a plugin.

Plugin: In ResultsTable.java
   /** Deletes the specified row. */
   public synchronized void deleteRow(int row)

Or, restricted to the system results table:
   /** Deletes 'row1' through 'row2' of the "Results" window. Arguments
   must be in the range 0-Analyzer.getCounter()-1. */
   IJ.deleteRows(int row1, int row2)

This should also work from a macro:
   call("ij.IJ.deleteRows", row1, row2);

User interface:
Right-click on the row, 'Clear'


Michael
________________________________________________________________

On 16 Jul 2010, at 12:50, AJBell wrote:

> Hello,
>
> Simple question with I hope a simple answer!
>
> Is it possible to delete a column of a results table?
>
> Regards,
>
> Andrew Bell
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

AJBell
In reply to this post by AJBell
Hi,

I'm interester is either via the user interface or in a macro.

Thank you for your reply, but I was asking about coloumns. As far as I am aware, these all deal with rows.

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

Michael Schmid
Hi Andrew,

oops, sorry, a person of my age one should be able to read an English  
text and find out the difference between 'rows' and 'columns'...

As far as I can see, the getColumnHeadings() method of ResultsTable  
is only accessible via Java (or JavaScript). Unless one knows the  
column headings in advance, one can't simply read the ResultsTable  
and create a new one from it.
The only way using a macro that I see would be writing the  
ResultsTable to a file, closing the table, and then reading the file;  
breaking it up into lines and cells, and populating a new  
ResultsTable with the values, omitting the unwanted columns.

Michael
________________________________________________________________

On 16 Jul 2010, at 13:28, Andrew James Bell wrote:

> Hi,
>
> I'm interester is either via the user interface or in a macro.
>
> Thank you for your reply, but I was asking about coloumns. As far  
> as I am aware, these all deal with rows.
>
> Andrew
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

Crowell Elizabeth
Hello Andrew and Michael,

I have a few scripts written in TCLTK that can extract columns from
files, and write them to new files.  This can also be done easily with
the Physics Analysis Workshop program (PAW).
Unfortunately, I'm just learning the TCLTK language, and the script was
written for me by someone else, so I wouldn't be able to customize it
for you myself.  But in its current form it just might do what you need!
Let me know if this is interesting for you, and I can send you the script.

Kind Regards,
Elizabeth



Michael Schmid a écrit :

> Hi Andrew,
>
> oops, sorry, a person of my age one should be able to read an English
> text and find out the difference between 'rows' and 'columns'...
>
> As far as I can see, the getColumnHeadings() method of ResultsTable is
> only accessible via Java (or JavaScript). Unless one knows the column
> headings in advance, one can't simply read the ResultsTable and create
> a new one from it.
> The only way using a macro that I see would be writing the
> ResultsTable to a file, closing the table, and then reading the file;
> breaking it up into lines and cells, and populating a new ResultsTable
> with the values, omitting the unwanted columns.
>
> Michael
> ________________________________________________________________
>
> On 16 Jul 2010, at 13:28, Andrew James Bell wrote:
>
>> Hi,
>>
>> I'm interester is either via the user interface or in a macro.
>>
>> Thank you for your reply, but I was asking about coloumns. As far as
>> I am aware, these all deal with rows.
>>
>> 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
----------------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

AJBell
In reply to this post by AJBell
Dear Elizabeth,

It couldn't hurt to take a look.

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: Results tablw manipulation

Crowell Elizabeth
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"
}