This tutorial shows how to run a demo of the two-choice discrimination task in the AD for zebrafish, which captures variable data during the experiment by using the LOGFIELD function.
The demo script below demonstrates how you can process variable results from a simple 2-choice assay. The demo script includes commands that produce real-time results that show:
- how many times the model organism triggers the initiator light
- how often the organism then goes on to trigger one of the other two lights.
- If the feeder is triggered, the results data also shows how often the fish subsequently visits the zone where the food is delivered.
INCLUDE ZSYS SET(AUTOREF_MODE,0) SET(AUTOREF_TIMEOUT,20) SET(DETECTOR_THRESHOLD,10) SET(SEARCH_DISTANCE,50) SET(SEARCH_STEP,7) SET(FILTER_RADIUS,15) DEFINE SQUARE 2 DEFINE SPRITE 5 DEFINE SPRITE_IMAGE 520 DEFINE FEED_TIME 5 DEFINE LIGHT_TIME DEFINE SCROLLTIME 4 DEFINE INTERTRIAL_TIME 5 DEFINE HABITUATION_TIME 10 DEFINE TRIALS 5
This first part of the script includes:
- Settings for a single fish to be tracked in the unit - SET commands
- The first three DEFINE commands enable the script to define both a square shape and a sprite to appear on the screen.
- The next five DEFINE commands specify time values (in seconds) that are used in the script.
- The word TRIALS is given a value of 5 to be used in the script below.
In this instance Action Main is quite long so is explained in two parts below.
ACTION MAIN SET(COUNTER1,COUNTER_ZERO) SET(COUNTER2,COUNTER_ZERO) SET(COUNTER3,COUNTER_ZERO) SET(COUNTER4,COUNTER_ZERO) SET(COUNTER5,COUNTER_ZERO) SETLIGHT(LIGHT2,SQUARE,1475,300,140) SETLIGHT(LIGHT4,SQUARE,1475,700,140) SETLIGHT(LIGHT6,SQUARE,325,500,140) SETLIGHT(LIGHT7,SQUARE,150,500,140) SETLIGHT(LIGHT8,SPRITE,0,500,0) SETLIGHT(LIGHT9,SPRITE,400,250,0) SETLIGHT(LIGHT10,SPRITE,400,750,0) SETLIGHT(LIGHT11,SPRITE,800,500,0) LOAD(SPRITE_IMAGE,"8:danio_small") LOAD(SPRITE_IMAGE,"9:danio_small") LOAD(SPRITE_IMAGE,"10:danio_small") LOAD(SPRITE_IMAGE,"11:danio_small") LOAD(DETECTORS,"operant5hole.bmp")
The first part of Action Main details:
- Five counters will be used in the script, each one is set to count from zero and can record how many times different elements of the script are actioned.
- Four square lights are are set at the same size (140 pixels) and positioned on the screen (their centre co-ordinates are the first two numbers) and named as LIGHT2, LIGHT4, LIGHT5, LIGHT 6, LIGHT7. For more details on how the screen co-ordinates work see illustration 'Screen co-ordinates on the Zantiks AD' found in the Functions section of the manual page, Zanscript syntax.
- Four sprites (bitmap images) are named as LIGHT8, LIGHT9, LIGHT10 and LIGHT11 and are positioned on the screen at the same size that they are saved in the Assets directory (0). Each of these sprite images are then loaded, in this case they will all be the same bitmap, 'danio_small' (which must be saved in the unit's Assets directory).
- Detector zones are loaded as detailed in the image saved as operant5hole.bmp in the Assets directory. For more details on assets see the Assets section on the manual page, Zanscripts and services.
LIGHTS(ALL,OFF) LOGCREATE("TEXT:") LOGRUN() LOGCREATE("RUNTIME|TEXT:|TEXT:|TEXT:TRIAL|TEXT:TIME_TRIAL_STARTS") LOGAPPEND("TEXT:INI_TRIGGERED|TEXT:TIME_INI_VISIT|TEXT:FEEDER_TRIGGERED") LOGAPPEND("TEXT:TIME_FEEDER_TRIGGERED|TEXT:AT_FEEDER|TEXT:TIME_AT_FEEDER") LOGAPPEND("TEXT:SHOAL_ACTIVATED|TEXT:TIME_SHOAL_ACTIVATED") LOGRUN() AUTOREFERENCE(0) WAIT(HABITUATION_TIME) INVOKE(TWO_CHOICE_DISCRIMINATION,TRIALS) LIGHTS(ALL,OFF) LOGCREATE("TEXT:") LOGRUN() LOGCREATE("TEXT:|TEXT:|TEXT:--SUMMARY--|TEXT:TOTAL_TRIALS|TEXT:") LOGAPPEND("TEXT:TOTAL_OF_INI_VISITS|TEXT:|TEXT:TOTAL_FEEDER_ACTIVATED") LOGAPPEND("TEXT:|TEXT:TOTAL_FEEDER_VISITS|TEXT:|TEXT:TOTAL_SHOAL_ACTIVATED") LOGRUN() LOGCREATE("TEXT:|TEXT:|TEXT:|COUNTER1|TEXT:|COUNTER2|TEXT:|COUNTER3") LOGAPPEND("TEXT:|COUNTER4|TEXT:|COUNTER5") LOGRUN() COMPLETE
In the second half of Action Main labels and values are detailed for the results to be recorded in a .csv file; and the whole experiment is also outlined in a middle section:
- After the lights are all turned off, the script specifies an empty line of data with LOGCREATE("TEXT: ") and then writes this empty line of data with the following line LOGRUN()
- The next five lines specify content for another line of data, as commanded by LOGCREATE (subsequent LOGAPPENDS enable this line of commands to exceed the character limit for a line of code):
- the first cell will output the actual time (RUNTIME) that the line is recorded.
- The following two cells are empty, hence the space after the colon in TEXT: |.
- Subsequent cells will fill with text as directed, eg "TRIAL" will be written in cell 4.
- LOGRUN() tells the unit to output the values as specified in the previous LOGCREATE (and LOGAPPEND) commands.
- The next four lines of code detail the whole experiment:
- First an auto reference image is taken which enables tracking.
- The unit waits for a period of time as defined above (HABITUATION_TIME).
- The ACTION TWO_CHOICE_DISCRIMINATION is invoked for the number of times as defined by TRIALS above.
- The next 9 lines of code detail three lines of data to output in a similar fashion as described above. However there is one new command:
- In the cells which are called COUNTER1, COUNTER2, COUNTER3, COUNTER4, COUNTER5 the final values for these counters will be outputted - as set in the ACTION scripts that are invoked earlier by the Action TWO_CHOICE_DISCRIMINATION
ACTION TWO_CHOICE_DISCRIMINATION SET(COUNTER1,COUNTER_INC) LIGHTS(LIGHT6,WHITE) LOGFIELD(1," ") LOGFIELD(2,COUNTER1) LOGFIELD(3,RUNTIME) DETECTOR(DETECTOR6,INITIATOR_TRIGGERED) WAIT(LIGHT_TIME) LIGHTS(LIGHT6,OFF) WAIT(INTERTRIAL_TIME) LOGFIELD(COMMIT) COMPLETE
This Action details:
- Counter 1 is set to start counting each trial.
- LIGHT 6 comes on white, this is also in the same position as the DETECTOR6
- The LOGFIELD commands prepare, in the memory, data for each cell in a new line; the first number in the brackets details the data to write that cell, please note, the LOGFIELD cell numbers start from the third cell in the line of data, so 1 is actually the third cell; 2 is actually the fourth cell, and so on.
- LOGFIELD(1," ") indicates that the third cell in the line of data will be empty (there is a space between the inverted commas.
- LOGFIELD(2,COUNTER1) tells the memory to remember the trial number
- LOGFIELD(3,RUNTIME) tells the memory to remember the runtime.
- If detector6 is triggered (i.e. the organism swims in the detector6 zone which is where LIGHT6 appears on the screen) the Action INITIATOR_TRIGGERED will happen.
- The unit waits the UNIT_TIME (as defined above) before LIGHT6 turns off.
- After the unit waits another period (as defined by INTERTRIAL_TIME) the unit writes the data specified by the previous LOGFIELD commands.
- This Action is then complete.
ACTION INITIATOR_TRIGGERED LIGHTS(LIGHT6,OFF) LOGFIELD(5,RUNTIME) LOGFIELD(4,"INITIATOR_TRIGGERED") SET(COUNTER2,COUNTER_INC) LIGHTS(LIGHT2,ON) LIGHTS(LIGHT4,ON) DETECTOR(DETECTOR2,FEEDER_ON) DETECTOR(DETECTOR4,SHOAL) WAIT(LIGHT_TIME) LIGHTS(ALL,OFF) COMPLETE
If the model organism moves over the detector zone as detailed earlier in Action Two-choice-discrimination, this Action takes place, in which:
- LIGHT6 turns off.
- The Runtime when this happens is committed to memory for the seventh cell in the line of data (as specified by the 5).
- The words "INITIATOR_TRIGGERED" will be committed to memory for the sixth cell in the line of data (as specified by the 4)
- COUNTER2 will start counting how many times this Action occurs.
- Two lights turn on - as defined earlier these are squares, positioned along the back of the screen.
- If the organism moves over LIGHT2, which is where DETECTOR2 is loaded, the Action FEEDER_ON will occur. Similarly if the fish swims over DETECTOR4, Action SHOAL occurs.
- If neither of the detectors is triggered the lights will stay on for the time defined earlier (LIGHT_TIME), before this Action is complete.
ACTION FEEDER_ON LIGHTS(ALL,OFF) LOGFIELD(7,RUNTIME) LOGFIELD(6,"FEEDER_TRIGGERED") SET(COUNTER3,COUNTER_INC) LIGHTS(LIGHT7,ON) FEEDER(1) DETECTOR(DETECTOR7,AT_FEEDER) WAIT(LIGHT_TIME) LIGHTS(LIGHT7,OFF) COMPLETE
This Action starts if DETECTOR2 is triggered during Action Initiator_triggered. The commands detail:
- Lights all turn off.
- The LOGFIELD commands tells the unit to remember:
- the Runtime in the ninth cell in the line of data;
- the words "FEEDER_TRIGGERED" in the eighth cell in the line of data.
- COUNTER3 counts the number of times that this Action occurs.
- LIGHT7 turns on, as defined above, this light is just below the feeder.
- DETECTOR7 turns on, and if the organism moves over this zone (which is in the same position as LIGHT7), the Action AT_FEEDER is triggered.
- If the DETECTOR7 is not triggered, LIGHT7 turns off after the specified time (LIGHT_TIME), and the action is then finished.
ACTION AT_FEEDER LIGHTS(ALL,OFF) LOGFIELD(9,RUNTIME) LOGFIELD(8,"FEEDER_VISIT") SET(COUNTER4,COUNTER_INC) WAIT(FEED_TIME) LIGHTS(ALL,OFF) COMPLETE
This Action starts if DETECTOR7 is triggered during Action Feeder_on. The commands detail:
- Lights all turn off.
- The LOGFIELD commands tells the unit to remember:
- the Runtime in the eleventh cell in the line of data;
- the words "FEEDER_VISIT" in the the tenth cell in the line of data.
- COUNTER4 counts the number of times that this Action occurs.
- The unit waits for the specified time (FEED_TIME) before all the lights turn off and the Action is complete.
ACTION SHOAL LIGHTS(ALL,OFF) LOGFIELD(11,RUNTIME) LOGFIELD(10,"SHOAL_ACTIVATED") SET(COUNTER5,COUNTER_INC) LIGHTS(LIGHT8,ON) PANLIGHT(LIGHT8,1800,500,SCROLLTIME) LIGHTS(LIGHT9,ON) PANLIGHT(LIGHT9,1800,250,SCROLLTIME) LIGHTS(LIGHT10,ON) PANLIGHT(LIGHT10,1800,750,SCROLLTIME) LIGHTS(LIGHT11,ON) PANLIGHT(LIGHT11,1800,500,SCROLLTIME) WAIT(LIGHT_TIME) LIGHTS(ALL,OFF) SETLIGHT(LIGHT8,SPRITE,0,500,0) SETLIGHT(LIGHT9,SPRITE,400,250,0) SETLIGHT(LIGHT10,SPRITE,400,750,0) SETLIGHT(LIGHT11,SPRITE,800,500,0) COMPLETE
If DETECTOR4 is triggered during Action Initiator_Triggered, then Action Shoal will start, during which:
- All the lights turn off.
- The LOGFIELD commands tells the unit to remember:
- the Runtime in the 13th cell in the line of data;
- the words "SHOAL_ACTIVATED" in the the 12th cell in the line of data.
- COUNTER5 counts the number of times this Action occurs
- Four lights turn on simultaneously (in this case the "danio-small" images as set in the Action Main) and each pans across the screen:
- LIGHT8 turns on in the position and size set in Action Main
- PANLIGHT(LIGHT8, 1800,500,SCROLLTIME) LIGHT8 then pans across the screen reaching its new position (with central coordinates 1800,500 which is just off the screen) during the specified time, SCROLLTIME (as defined earlier).
- LIGHT9, LIGHT10, LIGHT11 behave in a similar fashion to LIGHT8.
- The unit waits a pre-defined time (UNIT_TIME) which must be at least - usually longer than - the value of SCROLLTIME to give the images time to finish scrolling across the screen.
- The SETLIGHT commands for each of these four lights resets the positions after the action takes place - in the case the same position as they were in Action Main. In this way Action Shoal can be repeated in exactly the same way if DETECTOR4 is triggered during a subsequent trial.
Here you can download the two-choice assay demo script as a .zs file. Right click on the download link below and download / save the file as a zanscript file, i.e. in the same format: data_variables_demo.zs . You will also need to save the assets (used in the script) into the unit's Asset directory. Make sure that the name of the assets exactly matches the name you use in the script (upper and lower case).
Script download: data_variables_demo.zs
Asset download: operant5hole.bmp
Run the service
Build as a service - Once written, the zanscript is built (.zex file) and loaded on the Settings page in one of the 20 slots a service.
Run the demo service - The experiment can now be operated from the home page.
Results data file
The image below illustrates some of the results that were processed during the service and saved onto the unit as a .csv file in the Data files folder, following a trial with a fake fish. As you will see if you download the data file below during this trial the initiator was activated 5 times, the feeder activated three times and the feeder zone subsequently visited three times and the shoal was activated twice.
You may download the full results data file as a .csv file by clicking on the link here.