run tracker web instructions - brandeis life scistep1$ makesureyourjavasettingsaresetto32...
Post on 13-Jul-2020
1 Views
Preview:
TRANSCRIPT
How to Track Flies.
Equipment you will need:
1. Mac computer – contact Robert Huber (lobsterman.bgsu.gmail.edu) for instructions on PC use.
2. USB extension cord 3. Webcam 4. Red lights 5. White lights 6. Light timer 7. Incubator or someplace with a controllable environment 8. Tubes or some enclosure for flies 9. Fly food 10. Parafilm 11. A pin or needle 12. Clip board or some hard surface 13. White office paper 14. Scotch tape
Software you will need:
1. xCode – Free from Apple. Found in the Developer section. 2. Matlab 3. QuickTime 4. Text Wrangler 5. ImageJ 6. Image editing software (Photoshop or something alike)
7. Tracker Application Package 8. Matlab script for accessing Tracker data and analysis 9. Matlab script for Sleep/Circadian/Deprivation analysis
*Some of the software is optional or can be switched for others. I have found that these are the most effective.*
STEP 1 – Tube setup
I’ll assume that initially, you’ll be setting up a sleep experiment using traditional methods and materials. Most long-‐term experiments are done with the flies in 65mm glass tubes with a reservoir of sucrose/agarose food at one end and a cap at the other.
Use parafilm to cover the end with the food, making sure not to go too high on the tube. Parafilm is essential because it will adhere to the glass if pressed hard. We don’t want to use plastic caps or yarn because of possible visual obstruction. Also, we want to minimize the ‘dark’ places in the visual field. We don’t want anything to compete contrast-‐wise with the fly.
STEP 2 – load the fly
Place one fly into each of the tubes by either using a mouth aspirator or CO2 anesthesia. Close the tubes with parafilm and use the pin to poke a single hole through the center of the film. Make sure that the parafilm only covers the end of the tube. It will look like this when you’re done.
STEP 3 – Position the tubes
I use an 8x11 sheet of white paper as a background for the tracker. Using strips of clear scotch tape, place the tubes in lanes on the paper. Have the tape sticky-‐side-‐up so that the tubes adhere without the tape getting in the way. Make sure to keep the tubes parallel to each other without touching.
STEP 4 – Position the camera
Attach the camera to a permanent mount of some kind. Make sure none of the mount is in frame. The camera should be high enough so that an entire 8x11 sheet of paper, with some boarder, is visible. Make sure the camera is level in the X and Y-‐axes and adjust the yaw so the camera is straight.
The Tracker uses QuickTime video drivers to capture individual frames. It can only do this via one camera. However, a signal splitter could be used to have multiple cameras feed into a single video input. The number of cameras in use will limit the size of each video image going into the Tracker. There will be less tracking ‘real estate’ for each camera.
STEP 5 – Position the paper
Put the paper onto a rigid background, like a clipboard, and place it in the incubator under the webcam.
STEP 5 – Lighting
There has to be some kind of light on all the time to allow the video camera to track the flies. But, the flies also have to be able to sleep. We use an LED array of red lights to give enough light for the camera, yet also allow for the flies to sleep when the white lights are turned off.
The white lights can’t be too overpowering compared to red light. The camera has to see roughly the same image with red and white light. I’ll go into this more later.
Position the board and lights so as to prevent ANY light reflections off of the tubes. Reflections can cause the tracker to lose the fly the same way an obstruction would block the view on the tube. Make the lighting as indirect as you can. Bounce it off of the walls and door to disperse the light.
An alternative to red light is Infrared. You will need a camera that can see that wavelength. Most webcams have a filter for infrared. You can easily remove the filter on some models.
When all is set, it should look something like this.
TRACKER SETUP
STEP 1
Make sure your java settings are set to 32-‐bit configuration in the Utilities folder. Java has issues with 64-‐bit and the current Quicktime architecture.
Open the file “ObjectTracker.xcodeproj”
Xcode will open. I use Xcode 3.2.6 to do all of this. There are more recent versions of Xcode available, but this one works very well for me. Xcode 4 changed some things in an annoying way.
Let me say explicitly that YOU DO NOT HAVE TO KNOW HOW TO CODE. Just be prepared to tweak some values that are already there.
STEP 2
The folder ‘src’ will have a file called ObjectTracker.java. Open this file if it isn’t already being displayed. It will look something like this:
This is the only file that you will have to edit.
Look through this file. You’ll notice text in different colors. Anything that is GREEN is blocked out from being read as code. This means that green text is either non-‐
functional or notes. You can make something blocked out by putting // at the beginning of the part you don’t want to be read. You can block many lines by using /* at the start and closing with */.
STEP 3 – This is the important bit!
Scroll down until you get to the pink words ‘public class’. This is the start of where you can alter how the Tracker works.
The BLUE numbers are what you change. You can change the values of these numbers to best suit your experiment. I’ve found that the current settings are most effective for me.
pixelThreshold tells how different from the background color the fly has to be in order to be detected.
objectSize tells how big an object can be to be tracked. The flies are small, make the number small so the tracker knows to look for small things.
darkObject = true means that the tracker will look for a dark colored object to track. If you make this false, it will look for a light colored object.
fps is Frames Per Second. This is the data capture rate. 1 fps is good for long-‐term experiments. 10 frames per second is good for short duration experiments. You could make it whatever you want. Many computers are not fast enough to record much more than 10fps. This can be limiting according to how many flies are being followed.
The tracker data will not drift over time. For example: If you start the tracker at 8:00:00 AM and have a fps setting of 1, the 7,200th data point will be recorded exactly at 10:00:00 AM. A file that is 86400 rows is absolutely 1 day.
secsToRun is how long you want the tracker to run for. If you want the tracker to run for an undetermined amount of time, make this -‐1. The tracker will run until you stop it. For example: If you want the tracker to run for 5 minutes, with an fps of 10, you will make secsToRun 300. You will end with 3000 data points, but for only 300 seconds.
That’s all you have to change here. You probably won’t be altering these numbers a whole lot.
STEP 4
Scroll down a bit further to the int nTrackingJobs. This is where you tell the tracker how many flies you have to track. Change the number accordingly for each experiment.
STEP 5
Scroll down further to where is says tJobs[0] = new TrackingJobSetting…..
Each fly has to be in it’s own unique tJob. This is where you tell the tracker where to look for the fly. If the fly were to ever leave that area defined in the tJob, the tracker would get confused and search for anything that it thought was the fly.
tJobs[0] is the number of the first track job. In Java, ‘0’ is actually ‘1’. So tJobs[1] is the second track job and so on.
Look further in that line of code and it will say ‘new Rectangle(10,0,200,163)’ followed by the parameters from up above. The numbers in parentheses are the dimensions of the track job. If you have a camera with 640 x 480 resolution, and want to take up the whole screen, you would use the coordinates (0,0,640,480).
The first number is the Start location in the X dimension. The second number is the Start location of the Y dimension. The third number is how many pixels to go in the X dimension. The fourth number is how many pixels to go in the Y dimension.
Suppose you want a track job that takes up the bottom right quadrant of the screen. You would use coordinates (320,240,320,240).
You can have as many unique track jobs as you want. Just be sure that the coordinates don’t ever overlap.
For each tJobs, you need to use a sequentially higher number. Don’t skip any numbers and make sure that your total number of tJobs equals the number you put in for “int nTrackingJobs =”.
For now, just make 1 track job of some arbitrary dimensions. We don’t know where the flies are yet, so we just need some place to start.
Delete or block out all unused tJobs.
Save the file. Just overwrite the old one. Don’t use Save As. Creating a new file will make things too complicated because of dependencies.
STEP 6
Press the green arrow button marked “Build and Run” at the top of the Xcode window. This will launch the Tracker script. Xcode 4 won’t run the script within the native environment. If you’re using Xcode 4, you’ll have to open the file within the folder. It’s annoying.
A prompt screen will open asking for you to create a “Save As:” file name. This file is where the coordinates will be saved during the experiment. Make sure to use a unique name for each experiment. You can also select where you want the file to be saved.
Click OK and a new screen will open.
Click on “Source” to select the correct camera.
Click on “Adjustments” to change Saturation/Brightness/Contrast/Sharpness of the camera. I use these settings: 0, 65, 18, 29 for my camera settings. Depending on the camera, you may also have hue. Essentially, you want a black and white image with decent contrast between the fly and the white paper background.
You may need to fiddle these values until you find an optimum. I do this with the white lights off and just the red light. It’s harder the see the flies in the red light, so it’s a better place to start.
Click OK.
Now you are in the actual Tracker run screen. On the left, you’ll see the live image that the camera sees. The right half of the screen is the location of the track jobs. Right now, you should only have 1 track job.
Press the “Reference” button one time. Now you can see in the right half of the screen where the track jobs are in relation to the live image. Go up to the top and click on “Tracking” and select “Save Reference to image”.
Save the image to the desktop. This will create a PICT file of the reference image.
Convert the image to a JPG. Much of the newest image software no longer supports PICT files. QuickTime saves as PICT, so that’s what we have to go with. After you convert it to JPG, open it in ImageJ.
ImageJ can tell you the exact coordinates for any pixel in the image. Use these coordinate numbers to record where you want your track jobs to start and end. Remember, the right side and bottom side of the track jobs are not the same as adding on to the left and top side values. For example, suppose you want a square shaped track job that is 50 x 50 pixels. If the track job starts at 10 in the X dimension and 30 in the Y dimension, the track job coordinates would not be (10,30,60,80). Rather, the coordinates for the track job would be (10,30,50,50). If you want a
second track job to start directly to the right of that track job, you would make the coordinates for the second track job (60,30,50,50).
Make sure you select coordinates that will cover the entire possible range for where you fly can be. I try to make them just big enough. You don’t need to waste space.
Once you have gotten all of the coordinates for your track jobs, put them into the ObjectTracker.java file. Add or subtract track jobs for however many flies you have. Don’t forget to change the number for “int nTrackingJobs =”.
Save and click “Build and Run” again. The Tracker has now been updated with your new coordinates. KEEP Xcode OPEN. It has a very useful function for watching the data as it’s being recorded.
Create the “Save As” file name and adjust the camera settings as before. You’ll see that the coordinates you put in Xcode now surround each of your flies. If your coordinates are off a bit, repeat the process until everything lines up.
Now that you have your track job boxes set, don’t move anything!
You’re now going to capture the Reference image that you’ll use for the experiment.
I’ve found that the Tracker works best when started in the red light. Therefore, the reference image should be saved in the red light too.
Save the Reference to a file on the desktop. Convert it to JPG first if you’re using the newest version of Photoshop. I use PhotoShop because of the Clone Stamp tool. Use this to airbrush out all of the flies.
This step saves you a lot of trouble. Without it, you would have had to load the tubes onto the board first without flies, get the coordinates of the tubes, save the reference, then load the flies, all while putting the tubes and board back into the EXACT same location. This is very hard to do. By airbrushing out the flies, you don’t have to change anything to the flies once their loaded. The Reference image will be exactly the same as the live image. Remember, the Tracker is looking for differences between Reference and Live image. The fly should be the ONLY thing that is different.
Once you have the flies airbrushed out, Save the image and covert it to a PICT. The Tracker reference image HAS to be a PICT. Load the new reference into the Tracker and you’re ready to go.
With the white lights still off, click on “Setup”. This will locate the position of each fly. They will show up on the right side of the screen as red circles within the track job bounding boxes. Actually, the biggest difference between Live and Reference will be identified. At this point, it will be the fly.
STEP 7 – Running the Tracker
With Xcode still running, open the “Console” window. Go to the “Run” dropdown menu and click “Console”. This will allow you to watch the data as it records live. When you’re ready to start collecting data, Click “Analyze” in the tracker window and the Tracker will start. If you notice a lot of -‐1 values being recorded, you may need to adjust your lighting. The red light may be too dark, so you might have to change the camera setting values or the light intensity.
If everything is running well, turn on the white lights. The data should continue to record without going into a bunch of -‐1 values. Try turning the lights on and off a couple of times to make sure it’s stable.
IF the track is bad, i.e. it’s full of -‐1 values or data points appear to be showing up randomly in space, it means that the difference between red and white light is too great and the Tracker can’t locate the fly. You will have to adjust the brightness of the lights or how the camera sees the lights. Ideally, the visible difference between red and white is very small. That is why we use a black and white video image. The hue difference between red and white should be as close as can be.
When you want to stop the Tracker, Press “Stop”. Or, if you have a predefined fps, the Tracker will stop itself when it gets to the end.
The text file that was created will have all of the data for the run. Either save it as a different name IMMEDIATELY or CLOSE THE TRACKER. This is to prevent you from accidently pressing “Analyze” again. If you press analyze a second time, without changing the file name, the tracker will overwrite the file and you would lose everything that had been previously written.
Add “.txt” to the end of the file to designate it as a text file.
The experiment is now complete.
STEP 8 – Analysis Preparation
I usually start the tracker several hours before I want my experiment to begin. That ensures me that my data is being recorded properly well before it has to. However, It also gives a bunch of useless data before the stuff that I’m actually interested in.
I stop the tracker at a VERY specific time. For example, if I have an experiment that I want to run for 24 hours, and the lights turn on at 9:00:00 AM, I will start the Tracker some hours before 9:00 AM, when the white lights are off. I will always stop the Tracker at exactly 9:00:00AM or at a time that I know exactly to the second.
I can now delete any data in excess of my 24 hours that is at the beginning (or end) of the file, leaving me with exactly the data window that I want.
I’ve found that TextWrangler works well for this because it can handle large text files and gives row numbers that I can jump to easily. Excel is not advised, as the data files can be very large.
When you’ve cropped the data file to the size you want, make sure there aren’t any -‐1 values in the first line of data. If there are, substitute the value for those columns with the values from the first row that has data.
The Matlab analyzer needs there to be a real number at the start for each fly. We make the assumption that the first line is always clean.
Save the edited text file as a date. For example, if my experiment ends on April 9th 2012, I would name the file 20120409. This naming format is important. The Matlab analyzers need it to be in this format.
Now you are free to do whatever you want with the data from the tracker.
We provide several very useful Matlab scripts for analyzing the data. You can use them if you want!
top related