|
15 | 15 | " <left>Particle Tracking</left>\n",
|
16 | 16 | " </h1>\n",
|
17 | 17 | " <p><left>============================================================================</left> </p>\n",
|
18 |
| - "<pre>Course: BIOM 421, Spring 2024\n", |
19 |
| - "Instructor: Brian Munsky\n", |
20 |
| - "Authors: Dr. Luis Aguilera, Dr. Zach Fox, Brian Munsky\n", |
21 |
| - "Contact Info: munsky@colostate.edu\n", |
| 18 | + "<pre>Course: UQ-Bio 2024\n", |
| 19 | + "Instructor: Luis Aguilera\n", |
| 20 | + "Authors: Luis Aguilera, Will Raymond, Brian Munsky\n", |
| 21 | + "Contact Info: luis.aguilera@colostate.edu\n", |
22 | 22 | "</pre>\n",
|
23 | 23 | " </div>\n",
|
24 | 24 | " </p>\n",
|
|
56 | 56 | "\n",
|
57 | 57 | "## List of objectives\n",
|
58 | 58 | "\n",
|
59 |
| - "1. Simulate 2D random walks.\n", |
60 |
| - "2. Implement a code to track single particles.\n", |
61 |
| - "3. Calculate mean square displacement and diffusion coefficients.\n", |
| 59 | + "1. **Simulate 2D random walks.**\n", |
| 60 | + "2. Implement a code to **track single particles**.\n", |
| 61 | + "3. Calculate **mean square displacement** and **diffusion coefficients**.\n", |
62 | 62 | "\n",
|
63 | 63 | "4. Use the scientific libraries needed to segment and track single molecules in live cells."
|
64 | 64 | ]
|
|
116 | 116 | },
|
117 | 117 | "outputs": [],
|
118 | 118 | "source": [
|
119 |
| - "#from biom421 import codes\n", |
120 |
| - "#students = codes.spring2024Students()\n", |
121 |
| - "students = ['name1', 'name'] #codes.spring2024Students()" |
| 119 | + "students = ['Daria', 'Wiktoria','Jinyi','Wei','Pilar','Camila','Jayden','Humberto',\n", |
| 120 | + "'Jakini','Varvara','Kanniese','Kristi','Eliud','Nam','Lakshay','Margaret',\n", |
| 121 | + "'Grace','Apurv','Yinfei','Samantha','Yingli','Rena','Emily','Pegah','Al-Bashir']" |
122 | 122 | ]
|
123 | 123 | },
|
124 | 124 | {
|
|
722 | 722 | "def movieFrame(i):\n",
|
723 | 723 | " ax.clear()\n",
|
724 | 724 | " ax.imshow(img_with_spots[i,:,:,0],cmap= 'gray')\n",
|
725 |
| - "\n", |
726 | 725 | " for iParticle in range(len(list_trajectories_short)):\n",
|
727 | 726 | " x_val = [x[1] for x in list_trajectories_short[iParticle][:i]]\n",
|
728 | 727 | " y_val = [x[0] for x in list_trajectories_short[iParticle][:i]]\n",
|
|
732 | 731 | " \n",
|
733 | 732 | " # Add a line to show the trajectory of the spot.\n",
|
734 | 733 | " ax.plot(x_val,y_val, linewidth = 2, alpha=0.75)\n",
|
735 |
| - "\n", |
736 | 734 | " return [fig]\n",
|
737 |
| - "\n", |
738 | 735 | "plt.close()\n",
|
739 | 736 | "anim = animation.FuncAnimation(fig, movieFrame, frames=img_with_spots.shape[0], interval=50, blit=True)\n",
|
740 | 737 | "\n",
|
|
1189 | 1186 | "ax[1].imshow(img_with_spots_noisy[selected_time_point,:,:,0], cmap=plt.cm.gray, alpha=0.5)\n",
|
1190 | 1187 | "for i in range(0,len(list_center_mass[selected_time_point])):\n",
|
1191 | 1188 | " ax[1].plot(list_center_mass[selected_time_point][i][0], list_center_mass[selected_time_point][i][1], color='r',marker='*')\n",
|
1192 |
| - "ax[1].set_title('Binary image with pixels above treshold')\n", |
| 1189 | + "ax[1].set_title('Binary image with pixels above threshold')\n", |
1193 | 1190 | "plt.show()"
|
1194 | 1191 | ]
|
1195 | 1192 | },
|
|
1618 | 1615 | "particle_size = 7 # according to the documentation must be an odd number 3,5,7,9 etc.\n",
|
1619 | 1616 | "minimal_intensity_for_selection = 0 # minimal intensity to detect a particle.\n",
|
1620 | 1617 | "\n",
|
1621 |
| - "# \"f\" is a pandas data freame that contains the information about the detected spots\n", |
| 1618 | + "# \"f\" is a pandas data frame that contains the information about the detected spots\n", |
1622 | 1619 | "f = tp.locate(video[10,:,:,0], particle_size, minmass=minimal_intensity_for_selection)\n",
|
1623 | 1620 | "\n",
|
1624 | 1621 | "plt.rcParams[\"figure.figsize\"] = (5,5)\n",
|
|
1670 | 1667 | "plt.rcParams[\"figure.figsize\"] = (10,10) # if movie is too big, change size to (7,7)\n",
|
1671 | 1668 | "def figure_viewer_tr(time,mass_text, drop_size):\n",
|
1672 | 1669 | " ch = 0\n",
|
1673 |
| - " f = tp.locate(video[time,:,:,ch],drop_size, minmass=mass_text,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n", |
| 1670 | + " f = tp.locate(video[time,:,:,ch],drop_size, minmass=mass_text,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n", |
1674 | 1671 | " tp.annotate(f,video[time,:,:,ch]); # tp.anotate is a trackpy function that displays the image with the detected spots\n",
|
1675 | 1672 | "\n",
|
1676 | 1673 | "values_size=[3,5,7,9] # Notice value must be an odd number.\n",
|
|
1720 | 1717 | "# Loop through each frame of the video, run TP to detect spots, and then create a single\n",
|
1721 | 1718 | "# data frame for all time points.\n",
|
1722 | 1719 | "ch = 0\n",
|
1723 |
| - "df_TrackPy = tp.locate(video[0,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n", |
| 1720 | + "df_TrackPy = tp.locate(video[0,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n", |
1724 | 1721 | "df_TrackPy['frame'] = 0\n",
|
1725 | 1722 | "\n",
|
1726 | 1723 | "for iFrame in range(1,video.shape[0]):\n",
|
1727 |
| - " f = tp.locate(video[iFrame,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data freame that contains the infomation about the detected spots\n", |
| 1724 | + " f = tp.locate(video[iFrame,:,:,ch],selected_size, minmass=selected_intensity,maxsize=7,percentile=60) # \"f\" is a pandas data frame that contains the infomation about the detected spots\n", |
1728 | 1725 | " f['frame'] = iFrame\n",
|
1729 | 1726 | " df_TrackPy = pd.concat([df_TrackPy,f])\n",
|
1730 | 1727 | "\n",
|
|
1749 | 1746 | "outputs": [],
|
1750 | 1747 | "source": [
|
1751 | 1748 | "# Create a function that extracts the y and x coordinates from the dataframe and\n",
|
1752 |
| - "# return an exteneded data frame that includes a boolean true if the spot is in \n", |
| 1749 | + "# return an extended data frame that includes a boolean true if the spot is in \n", |
1753 | 1750 | "# the mask and false otherwise.\n",
|
1754 | 1751 | "def spots_in_mask(f,mask):\n",
|
1755 | 1752 | " # extracting the contours in the image\n",
|
|
1981 | 1978 | "outputs": [],
|
1982 | 1979 | "source": [
|
1983 | 1980 | "# Make a movie of the original, but now add squares over the tracked particles.\n",
|
1984 |
| - "\n", |
1985 | 1981 | "# Plotting spots as a video\n",
|
1986 |
| - "\n", |
1987 | 1982 | "fig, ax = plt.subplots(figsize=(7,7))\n",
|
1988 |
| - "\n", |
1989 | 1983 | "def movieFrame(i):\n",
|
1990 | 1984 | " ax.clear()\n",
|
1991 | 1985 | " ax.imshow(video[i,:,:,0],cmap= 'gray')\n",
|
1992 |
| - "\n", |
1993 | 1986 | " for iParticle in range(0,dfp['particle'].nunique() ):\n",
|
1994 | 1987 | " x_val = dfp.loc[(dfp['particle']==iParticle) & (dfp['frame']<=i) ].x.values\n",
|
1995 | 1988 | " y_val = dfp.loc[(dfp['particle']==iParticle) & (dfp['frame']<=i) ].y.values\n",
|
|
1999 | 1992 | " \n",
|
2000 | 1993 | " # Add a line to show the trajectory of the spot.\n",
|
2001 | 1994 | " ax.plot(x_val,y_val, linewidth = 2, alpha=0.75)\n",
|
2002 |
| - "\n", |
2003 | 1995 | " return [fig]\n",
|
2004 |
| - "\n", |
2005 | 1996 | "plt.close()\n",
|
2006 | 1997 | "anim = animation.FuncAnimation(fig, movieFrame, frames=video.shape[0], interval=50, blit=True)\n",
|
2007 | 1998 | "from IPython.display import HTML\n",
|
|
2023 | 2014 | " ax[0].clear(); ax[1].clear()\n",
|
2024 | 2015 | " x_val = dfp.loc[(dfp['particle']==spot_number) & (dfp['frame']==i) ].x.values\n",
|
2025 | 2016 | " y_val = dfp.loc[(dfp['particle']==spot_number) & (dfp['frame']==i) ].y.values \n",
|
2026 |
| - " \n", |
2027 | 2017 | " ax[0].imshow(video[i,:,:,0],cmap= 'gray')\n",
|
2028 | 2018 | " ax[0].plot(x_val,y_val, 'o', linewidth = 1, markersize=8, color='y', alpha=0.25)\n",
|
2029 |
| - "\n", |
2030 | 2019 | " if len(x_val)>0: \n",
|
2031 | 2020 | " ylim = [int(x_val[0]-7), int(x_val[0]+8)]\n",
|
2032 | 2021 | " xlim = [int(y_val[0]-7), int(y_val[0]+8)]\n",
|
2033 | 2022 | " ax[1].imshow(video[i,xlim[0]:xlim[1],ylim[0]:ylim[1],1],cmap= 'Spectral_r')\n",
|
2034 | 2023 | " return [fig]\n",
|
2035 |
| - "\n", |
2036 | 2024 | " plt.close()\n",
|
2037 | 2025 | " anim = animation.FuncAnimation(fig, movieFrame, frames=video.shape[0], interval=50, blit=True)\n",
|
2038 | 2026 | " return anim\n",
|
2039 | 2027 | "\n",
|
2040 | 2028 | "anim = movieViewer(spot_number=3)\n",
|
2041 | 2029 | "HTML(anim.to_html5_video())\n",
|
2042 | 2030 | "\n",
|
2043 |
| - "\n", |
2044 | 2031 | "# interactive_plot = interactive(movieViewer,spot_number = widgets.IntSlider(min=0,max=dfp['particle'].nunique(),value=0,description='Particle Number'),continuous_update=False)\n",
|
2045 | 2032 | "# controls = HBox(interactive_plot.children[:-1], layout = Layout(flex_flow='row wrap'))\n",
|
2046 | 2033 | "# output = interactive_plot.children[-1]\n",
|
|
0 commit comments