Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Hi all. I seem to have restricted the lines of data printed when attempting to add comments (currently I have scripted: if commentcell.onset >= regioncell.onset and commentcell.offset <= regioncell.offset "). Comments are nested to the region cell but not every region cell is associated with a comment (hence why, right now, only lines with comments are printed). How can I print all data while also printing the comments correctly? Can I somehow break the nested loop or can this be solved by a simple conditional statement (when commentcell.onset = 0...). I've included my script below. Any suggestions would be helpful! Thanks!!

# Loop thru all of the id cells
for idcell in id.cells
    # Loop thru all of the trial cells
      for trialcell in trial.cells
            # Test to make sure the trial cell is inside of the id cell
            if idcell.onset <= trialcell.onset and idcell.offset >= trialcell.offset
                # If the trial cell is inside the ID cell, then loop thru all of the region cells
                for regioncell in region.cells
                    # Make sure this region cell is inside of the trial cell
                    if regioncell.onset >= trialcell.onset and regioncell.offset <= trialcell.offset
                        for commentcell in comment.cells
                            if commentcell.onset >= regioncell.onset and commentcell.offset <= regioncell.offset 
                        # Finally, print everything
                            output_file.write(idcell.sub + "\t" + idcell.age + "\t" + idcell.gender + "\t" + 
                                trialcell.onset.to_s + "\t" + trialcell.offset.to_s + "\t" +
                                trialcell.trialnum + "\t" + trialcell.distance+ "\t" + 
                                regioncell.ordinal.to_s + "\t" + regioncell.onset.to_s + "\t" + regioncell.offset.to_s + "\t" +
                                regioncell.fix + "\t" + commentcell.com + "\t" + "\r\n")
                            end
                        end
                    end
                end
            end
      end
end

asked 21 Jun '12, 14:00

cwallin's gravatar image

cwallin
1111
accept rate: 0%


We run into this problem too. Basically, it won't print a line because you don't have a comment there.

Solution #1 is not ideal, but you could write a script that just inserts blank comment cells for every trial that doesn't have a comment cell. That way, you'll get a blank printed in the same column that you would have your comment.

I think there might be a solution #2, but I have tried it yet. You could try breaking up the print statement so that it prints everything except the comment, then checks for comment cells, then prints them if they're there. It would basically be rearranging your script like this:

# Print everything except for comment
     output_file.write(idcell.sub + "\t" + idcell.age + "\t" + idcell.gender + "\t" + 
       trialcell.onset.to_s + "\t" + trialcell.offset.to_s + "\t" +
       trialcell.trialnum + "\t" + trialcell.distance+ "\t" + 
       regioncell.ordinal.to_s + "\t" + regioncell.onset.to_s + "\t" + regioncell.offset.to_s + "\t" +
       regioncell.fix) 
#Then loop through comments and print comments if they're there
     for commentcell in comment.cells 
        if commentcell.onset >= regioncell.onset and commentcell.offset <= regioncell.offset
            output_file.write("\t" + commentcell.com)
        end
     end
#Then print the newline regardless of whether there are comments
     output_file.write("\r\n")

I haven't tried this yet, so let me know if it works!

permanent link

answered 21 Jun '12, 23:28

JohnFranchak's gravatar image

JohnFranchak ♦
3964410
accept rate: 17%

Yes, Solution #2 works! Thank you so much for your help!

permanent link

answered 22 Jun '12, 06:04

cwallin's gravatar image

cwallin
1111
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×46
×2
×1

question asked: 21 Jun '12, 14:00

question was seen: 3,279 times

last updated: 22 Jun '12, 06:04

powered by OSQA