Difference between revisions of "Team:Montpellier/Tracking/Software"

 
(16 intermediate revisions by 3 users not shown)
Line 20: Line 20:
 
<section>
 
<section>
  
<h2>Introduction</h2>
+
<h2>Introduction</h2><hr/>
  
<p>To test the effect of our peptides and antibodies on sperm we needed a way to quantify the motility of spermatozoa. Ideally, we should see a decrease in sperm motility in presence of our molecules or our bacteria. In order to quantify the effect of spermicides on sperm motility, we developed a software to track spermatozoa trajectories on a frame by frame basis. The software then calculates the mean velocity of each spermatozoon enabling a quantitative analysis of sperm motility. Our tracking tool is based on the “Trackpy” package.</p>
+
<p>To test the effect of our peptides and antibodies we needed a way to quantify the motility of spermatozoa. Ideally, we should be able to see the decreasing of sperm motility when in contact with our molecules or our bacteria secreting those molecules.  
 +
For this, we developed a software that is able to track spermatozoa frame by frame. This software can give us the speed of each spermatozoon from a video and thus permits us a quantitative analysis of sperm motility. Our tracking tool is based on the “Trackpy” package that contains basic functions for tracking biological elements in sample.</p>
  
<p>Below we explain the general principles of our tracking software. At the bottom of this page we also provide a link to our python script, a step-by-step tutorial in python notebook format (.ipynb) in which you can test the analysis workflow with an example video (also provided), and a pdf of the same tutorial.
+
<p>All the functions that we are using are mentioned and described at the end of the page and the commented code is linked below. In this part, we are explaining the general principle and steps of our tracking software.</p>
</p>
+
  
<h2>General steps to analyze the sperm motility : </h2>  
+
<h2>General steps to analyze the sperm motility</h2><hr/>
<br>
+
  
<p>First of all the video is recorded by the camera and saved in TIFF format (figure 1).</p><br>
+
<p>First of all, the video is recorded by the camera and saved in TIFF format (Figure 1).</p><br>
  
 
<center><video width="50%" height="240" controls>  
 
<center><video width="50%" height="240" controls>  
<source src="https://static.igem.org/mediawiki/2018/0/01/T--Montpellier--Spermatozoa_without_nisin_montpellier.mp4" type="video/mp4">  
+
<source src="https://static.igem.org/mediawiki/2018/0/01/T--Montpellier--Spermatozoa_without_nisin_montpellier.mp4" type="video/mp4"></video></center>
</video><center>
+
<figcaption><span class="underline">Figure 1:</span> Video of spermatozoa.</figcaption>
<p class="legend">Figure 1: Video of spermatozoa </p>
+
<br>
+
  
<pThe first goal of the tracking is to identify all the spermatozoa. This identification needs to be well balanced between sensibility and specificity . Trackpy is able to distinguish the spermatozoa and assign to each of them a position (x,y) for each frame. This is shown in figure 2 where the identified spermatozoa are contoured with a red circle.  The choice of the parameters is given in the step-by-step description of the algorithm and in the tutorial. </p>
+
<p>The first goal of the tracking is to identify all the spermatozoa. This identification needs to be well balanced between sensibility and specificity . Trackpy is able to distinguish the spermatozoa and assign to each of them a position (x,y) for each frame. This is shown in figure 2 where the identified spermatozoa are contoured with a red circle.  The choice of the parameters is given in the step-by-step description of the algorithm and in the tutorial.</p>
 
<br>
 
<br>
  
Line 44: Line 41:
 
<source src="https://static.igem.org/mediawiki/2018/f/fc/T--Montpellier--Detection_of_the_spermatozoa.mp4" type="video/mp4">  
 
<source src="https://static.igem.org/mediawiki/2018/f/fc/T--Montpellier--Detection_of_the_spermatozoa.mp4" type="video/mp4">  
 
</video></center>
 
</video></center>
<p class="legend">Figure 2: Frame by frame identification of the spermatozoa thanks to the software </p>
+
<figcaption><span class="underline">Figure 2:</span> Frame by frame identification of the spermatozoa thanks to the software.</figcaption>
<br>
+
  
<p>Once all spermatozoa are detected, the software analyzes the position frame by frame and provides as an output the trajectory of each spermatozoa (figure 3). This is a tricky step in which the algorithm needs to link the objects identified in one frame to the following frame and hence get the position (x,y) of each red circle as a function of time. However, trackpy sometimes “loses” the spermatozoa from one frame to the other (and one spermatozoon could then generate two or more trajectories creating biases in the measurements), or two spermatozoa could come very close to each other during the length of the video (and their trajectories might mix up). We optimised the parameters of the method provided by the trackpy package in order to avoid these biases. Still, we manually checked all the videos analysed and corrected by hand the trajectories that were not accurate. To solve punctual errors we correctly linked misbehaving objects frame to frame. The final results can be observed in the video below. We successfully identify trajectories that allow us to extract information on the motility of the spermatozoa</p>
+
<p>Once all spermatozoa are detected, the software analyzes their positions frame by frame and provides as an output the trajectory of each spermatozoa (figure 3). This is a tricky step in which the algorithm needs to link the objects identified in one frame to the following frame and hence get the position (x,y) of each red circle as a function of time. However, trackpy sometimes “loses” the spermatozoa for some frames (and one spermatozoon could then generate two or more trajectories creating biases in the measurements), or two spermatozoa could come very close to each other during the length of the video (and their trajectories might mix up). We optimised the parameters of the method provided by the trackpy package in order to avoid these biases. Still, we manually checked all the videos analysed and corrected by hand the trajectories that were not accurate. To solve punctual errors, we correctly linked misbehaving objects frame to frame. The final results can be observed in the video below. We successfully identify trajectories that allow us to extract information on the motility of the spermatozoa.</p><br/>
 
+
<br>
+
  
 
<center><video width="50%" height="240" controls>  
 
<center><video width="50%" height="240" controls>  
<source src="https://static.igem.org/mediawiki/2018/7/70/T--Montpellier--Spermatozoa_with_trajectory_montpellier.mp4" type="video/mp4">  
+
<source src="https://static.igem.org/mediawiki/2018/7/70/T--Montpellier--Spermatozoa_with_trajectory_montpellier.mp4" type="video/mp4"></video></center>
</video></center>
+
<figcaption><span class="underline">Figure 3:</span> Trajectory of spermatozoa predicted by the software.</figcaption>
<p class="legend"> Figure 3: Trajectory of spermatozoa predicted by the software </p>
+
<br>
+
  
<p>The trajectories enable us to calculate the velocities of each spermatozoa. We first computed the instantaneous velocity of the spermatozoa along their trajectories, and then we smoothed the velocity with a linear filter (running average). We then calculated the mean velocity and the median velocity of each trajectory.  
+
<p>The trajectories enable us to calculate the velocities of each spermatozoa. We first computed the instantaneous velocity of the spermatozoa along their trajectories, and then we smoothed the velocity with a linear filter (running average). We then calculated the mean velocity and the median velocity of each trajectory.</p>
  
We then repeated the procedure for many videos in different conditions. More in particular, we tested the effect of different concentrations of nisin which is supposed to have a strong effect on the spermatozoa motility. We also measured the velocity of spermatozoa without nisin but after 1h 30 from.... We obtained  histograms representing the distribution of the velocity of spermatozoa for each condition(figure 4).
+
<p>We then repeated the procedure for many videos in different conditions. More in particular, we tested the effect of different concentrations of nisin which is supposed to have a strong effect on the motility of spermatozoa. We also measured the velocity of spermatozoa without nisin. <!--but after 1h30 from.... --></p>
  
Figure 4: Histograms of the velocities of the spermatozoa for different concentrations of nisin. N represent the number of spermatozoa successfully tracked for each case.</p>  
+
<p>We finally obtained  histograms representing the distribution of the velocity of spermatozoa for each condition (Figure 4).</p><br/>
  
<center><img src="https://static.igem.org/mediawiki/2018/c/c0/T--Montpellier--Histogram_nisin_mtp.png"></center>
+
<figure>
<p><caption>Figure 4 :Histogramm</caption></p>
+
<img class="image_figure" src="https://static.igem.org/mediawiki/2018/1/11/T--Montpellier--histogram_software_mtp.png">
 +
<figcaption><span class="underline">Figure 4:</span> Histograms of the velocities of the spermatozoa for different concentrations of nisin. N represent the number of spermatozoa successfully tracked for each case.</figcaption>
 +
</figure>
  
 +
<h2>The functions used in the script</h2><hr/>
  
<h2>The functions used in the script :</h2>  
+
<p>We start using the tp.locate function and put the good parameter that fit the circle to the object that has an average diameter:</p>
 +
<ol>
 +
  <li>We detect for each frame spermatozoa by using the tp.batch function and we link each frame with another and annotate the same particle at each frame.</li>
 +
  <li>We filter the data that we get by using tp.filter to keep only the spermatozoa that we detect only for 60FPs.</li>
 +
  <li>We make other filtration as the filter by intensity to keep only the spermatozoa that have an intensity high specific mass.</li>
 +
  <li>We add another filtration that it’s done manually in case the previous filtration doesn’t succeed to delete as the noise of background. Also, we combine the trajectory manually for the same spermatozoa.</li>
 +
  <li>We add to the script line of code to make a video with trajectory. To see the efficiency of the tracking.</li>
 +
  <li>We use the function tp.compute_drift to delete the drift case by the flux of the medium.</li>
 +
  <li>We add to the DataFrame other columns that transform from pixel x and y position, to Um and final we calculate the velocity. To have more flexibility to use the data for each Spermatozoa we transform the DataFrame to Nestedictionary that contain dictionary and each dictionary contain dx, dy, and velocity for spermatozoa.</li>
 +
  <li>We calculate the velocity by using the medium filter to make a uniform speed for each spermatozoa, we plot the velocity. And we calculate the medium velocity for each spermatozoa.</li>
 +
  <li>Finally, we plot the histogram with the percentage.</li>
 +
</ol>
  
<p>We start using the tp.locate function and put the good parameter that fit the circle to the object that has an average diameter. <br>
+
<h2>Explanation of the script line by line </h2><hr/>
We detect for each frame spermatozoa by using the <strong>tp.batch</strong> function and we link each frame with another and annotate the same particle at each frame. <br>
+
We filter the data that we get by using <strong>tp.filter</strong> to keep only the spermatozoa that we detect only for 60FPs.
+
We make other filtration as the filter by intensity to keep only the spermatozoa that have an intensity high specific mass.
+
We add another filtration that it’s done manually in case the previous filtration doesn’t succeed to delete as the noise of background. Also, we combine the trajectory manually for the same spermatozoa. <br>
+
We add to the script line of code to make a video with trajectory. To see the efficacity of the tracking. <br>
+
We use the function <strong>tp.compute_drift</strong> to delete the drift case by the flux of the medium. <br>
+
We add to the DataFrame other columns that transform from pixel x and y position, to Um and final we calculate the velocity.
+
To have more flexibility to use the data for each Spermatozoa we transform the DataFrame to Nestedictionary that contain dictionary and each dictionary contain dx, dy, and velocity for spermatozoa. <br>
+
+
  
<h2>Explanation of the script line by line </h2>
+
<p> Here you can find the script and its explanation line by line : <a href ="https://static.igem.org/mediawiki/2018/9/9a/T--Montpellier--Tutorial_for_Tracking_montpellier2.pdf" target="_blank" class="lien">tutorial</a>.</p>
<br>  
+
  
<p> Here you can find the script and its explanation line by line : <a href ="https://static.igem.org/mediawiki/2018/9/9a/T--Montpellier--Tutorial_for_Tracking_montpellier2.pdf" target="_blank" class="lien"> tutorial </a>.</p>
+
</section>
  
 +
</body>
  
</section>
 
 
</html>
 
</html>
  
 
{{Montpellier/Footer}}
 
{{Montpellier/Footer}}

Latest revision as of 13:34, 16 October 2018

Introduction


To test the effect of our peptides and antibodies we needed a way to quantify the motility of spermatozoa. Ideally, we should be able to see the decreasing of sperm motility when in contact with our molecules or our bacteria secreting those molecules. For this, we developed a software that is able to track spermatozoa frame by frame. This software can give us the speed of each spermatozoon from a video and thus permits us a quantitative analysis of sperm motility. Our tracking tool is based on the “Trackpy” package that contains basic functions for tracking biological elements in sample.

All the functions that we are using are mentioned and described at the end of the page and the commented code is linked below. In this part, we are explaining the general principle and steps of our tracking software.

General steps to analyze the sperm motility


First of all, the video is recorded by the camera and saved in TIFF format (Figure 1).


Figure 1: Video of spermatozoa.

The first goal of the tracking is to identify all the spermatozoa. This identification needs to be well balanced between sensibility and specificity . Trackpy is able to distinguish the spermatozoa and assign to each of them a position (x,y) for each frame. This is shown in figure 2 where the identified spermatozoa are contoured with a red circle. The choice of the parameters is given in the step-by-step description of the algorithm and in the tutorial.


Figure 2: Frame by frame identification of the spermatozoa thanks to the software.

Once all spermatozoa are detected, the software analyzes their positions frame by frame and provides as an output the trajectory of each spermatozoa (figure 3). This is a tricky step in which the algorithm needs to link the objects identified in one frame to the following frame and hence get the position (x,y) of each red circle as a function of time. However, trackpy sometimes “loses” the spermatozoa for some frames (and one spermatozoon could then generate two or more trajectories creating biases in the measurements), or two spermatozoa could come very close to each other during the length of the video (and their trajectories might mix up). We optimised the parameters of the method provided by the trackpy package in order to avoid these biases. Still, we manually checked all the videos analysed and corrected by hand the trajectories that were not accurate. To solve punctual errors, we correctly linked misbehaving objects frame to frame. The final results can be observed in the video below. We successfully identify trajectories that allow us to extract information on the motility of the spermatozoa.


Figure 3: Trajectory of spermatozoa predicted by the software.

The trajectories enable us to calculate the velocities of each spermatozoa. We first computed the instantaneous velocity of the spermatozoa along their trajectories, and then we smoothed the velocity with a linear filter (running average). We then calculated the mean velocity and the median velocity of each trajectory.

We then repeated the procedure for many videos in different conditions. More in particular, we tested the effect of different concentrations of nisin which is supposed to have a strong effect on the motility of spermatozoa. We also measured the velocity of spermatozoa without nisin.

We finally obtained histograms representing the distribution of the velocity of spermatozoa for each condition (Figure 4).


Figure 4: Histograms of the velocities of the spermatozoa for different concentrations of nisin. N represent the number of spermatozoa successfully tracked for each case.

The functions used in the script


We start using the tp.locate function and put the good parameter that fit the circle to the object that has an average diameter:

  1. We detect for each frame spermatozoa by using the tp.batch function and we link each frame with another and annotate the same particle at each frame.
  2. We filter the data that we get by using tp.filter to keep only the spermatozoa that we detect only for 60FPs.
  3. We make other filtration as the filter by intensity to keep only the spermatozoa that have an intensity high specific mass.
  4. We add another filtration that it’s done manually in case the previous filtration doesn’t succeed to delete as the noise of background. Also, we combine the trajectory manually for the same spermatozoa.
  5. We add to the script line of code to make a video with trajectory. To see the efficiency of the tracking.
  6. We use the function tp.compute_drift to delete the drift case by the flux of the medium.
  7. We add to the DataFrame other columns that transform from pixel x and y position, to Um and final we calculate the velocity. To have more flexibility to use the data for each Spermatozoa we transform the DataFrame to Nestedictionary that contain dictionary and each dictionary contain dx, dy, and velocity for spermatozoa.
  8. We calculate the velocity by using the medium filter to make a uniform speed for each spermatozoa, we plot the velocity. And we calculate the medium velocity for each spermatozoa.
  9. Finally, we plot the histogram with the percentage.

Explanation of the script line by line


Here you can find the script and its explanation line by line : tutorial.