<jupyter_start><jupyter_text>Example of using `cells_in_gel.batch` for Green (Phalloidin 488) Channel The Wrapping Function section shows the quickest way to achieve results using 20x tiff stacks with filenames labeled as:* Example filename: I61QTTA-CFbs_I61Q5ECM_1mMRGD_20x_002* Fibroblast Genotype (I61QTTA)* ECM Genotype and Concentration (I61QTTA, 5mg/mL)* RGD Concentration (1mM)* Gel number (1 z-stack acquired per 5uL gel, 3 gels per condition)The Maximum Intensity Projection, Segmentation and Region Properties, Extracting Average Values from Max Intesnity Projections, and  Graphing Groups sections all describe user tunable functions for more in depth approach of extracting data.   Imports<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import glob

from skimage.morphology import disk

from cells_in_gel import batch<jupyter_output><empty_output><jupyter_text>Load ImagesLoad your images from a filepath using `glob.glob('filenames.tif')` into a list of strings. The `*` can be used to capture all files with the remainder of specifications. For example, `*.tif` will capture all tif files in the directory.<jupyter_code># list of filenames
files = glob.glob('C3*.tif')<jupyter_output><empty_output><jupyter_text>Wrapping FunctionThe wrapping function, `batch.max_proj_wrap(files)`, takes the input filenames, and returns the segmented images with graphs of each comparison group. The grouping is based on comparing with or without RGD present, ECM type, and cell type.<jupyter_code>batch.max_proj_wrap(files)<jupyter_output><empty_output><jupyter_text>Further tunability can be achieved by following the remainder of this notebook as a step-by-step guide to using each function in batch.   Maximum Intensity Projections Maximum intensity projections can be obtained from each z stack and placed into a dictionary using the `batch.max_projection(files)` function.<jupyter_code>max_proj = batch.max_projection(files)<jupyter_output><empty_output><jupyter_text>Here is a plot showing the max intensity projection from the 19th filename in the list of `files`. By changing the number in `files[18]`, you can look through various max projections from the images.<jupyter_code>plt.imshow(max_proj[files[18]])
plt.axis('off')<jupyter_output><empty_output><jupyter_text>Segmentation and Region Properties Create the `selem` (shape) for separation of objects. A higher number will result in less separation between objects in max intensity projections.<jupyter_code>selem = disk(5)<jupyter_output><empty_output><jupyter_text>Using `cells_in_gel.batch.labels_regions(files)`, segment max projections, label objects, and extract region properties. The output `regions` will give a dictionary containing dataframes of properties for each max intensity projection.<jupyter_code>regions = batch.labels_regions(files, selem, min_size=350)<jupyter_output><empty_output><jupyter_text>Here is the head for the first max intensity projection dataframe in our list of `files`.<jupyter_code>regions[files[0]].head()<jupyter_output><empty_output><jupyter_text>Extracting Average Values from Max Intesnity Projections Create a list of `titles` that describe categories between each underscore in filenames. Create a list of average `properties` to extract from the max intensity projection regions dataframe.<jupyter_code>titles = ['celltype', 'ecmtype_conc', 'rgd_conc', 'mag', 'img_num']
properties = ['area', 'eccentricity', 'extent']<jupyter_output><empty_output><jupyter_text>Using `batch.image_summaries(files, properties, titles, regions)`, extract a summary dataframe that includes average and variance properties from each max intensity projection. See the `summary` head below.<jupyter_code>summary = batch.image_summaries(files, properties, titles, regions)
summary.head()<jupyter_output><empty_output><jupyter_text>Further analysis of grouping, etc. will be done using the `summary` dataframe. At this point, you can use `summary.to_csv('imagesummaries_green.csv', index=False)` for creating a CSV of this dataframe. Further analysis can be done in excel if preferred at this point.<jupyter_code>summary.to_csv('image_summaries.csv')<jupyter_output><empty_output><jupyter_text>Graphing GroupsGraphing of the `summary` dataframe requires further grouping of the data. The `batch.groups(summary)` function groups according to unique combinations of cell type, ECM type, and RGD concentration. This results in 20 groups that will be placed in the final dataframe shown below. The column titled index indicates the unique group combination of cell type, ecm type, and RGD type.<jupyter_code>final = batch.groups(summary)
final<jupyter_output><empty_output><jupyter_text>Properties and variance of these properties should now be defined for grouping the data into lists appropriate for graphing.<jupyter_code>properties = ['area', 'eccentricity', 'extent']
variance = ['area_var', 'eccentricity_var', 'extent_var']<jupyter_output><empty_output><jupyter_text>Lists of properties and groups can now be made for graphing. Here is what each group represents:* Group 1: I61QTTA cells with no RGD* Group 2: I61QTTA cells with RGD* Group 3: NTG cells with no RGD* Group 4: NTG cells with RGDWithin each group, contains a list of properties each entry corresponding to `properties` previously defined:* First entry: area* Second entry: eccentricity* Third entry: extent<jupyter_code>g1, g2, g3, g4 = batch.groupby_property(final, properties)<jupyter_output><empty_output><jupyter_text>A similar grouping can be done for the error bars of each group. Error bars area calculated as 2 * SEM (Standard Error of the Mean).<jupyter_code>yerr_g1, yerr_g2, yerr_g3, yerr_g4 = batch.group_sem(final, variance)<jupyter_output><empty_output><jupyter_text>Finally, a graph can be constructed using each of the groups we defined and their corresponding SEM.<jupyter_code>batch.graph(g1, g2, g3, g4, yerr_g1, yerr_g2, yerr_g3, yerr_g4)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07577785212445634, 'fraction_numerical': 0.010705921712947474, 'mean_word_length': 7.090663058186739, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '625721', 'license': 'MIT', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1720, 'n_words': 651, 'path': 'notebooks/Green_Channel_Example.ipynb', 'repo_name': 'jingexu/cells-in-gel', 'size': '5978'}