Quick start

This example reuses the supplied three-channel masks, builds meshes, detects GFP-DnaN objects, and saves morphology and signal measurements. SVM curation and filtering of the resulting feature table are optional. The script first copies the dataset so that the original inputs and outputs remain available for comparison.

Run this in the BactoScoop environment, or in its Jupyter kernel:

"""Three-channel analysis with supplied masks and optional SVM curation."""
from datetime import datetime
import json
import os
from pathlib import Path
import shutil
import bactoscoop

examples = os.environ.get('BACTOSCOOP_EXAMPLES_DIR')
candidates = [Path(examples)] if examples else [candidate for base in (Path.cwd(), *Path.cwd().parents) for candidate in (base/'examples',base)]
source = next((base/'3_channel_example' for base in candidates if (base/'3_channel_example').is_dir()),None)
if source is None:
    raise FileNotFoundError('Download the release examples and run from that folder, or set BACTOSCOOP_EXAMPLES_DIR.')
destination = Path.home()/'bactoscoop_runs'/('3_channel_example_'+datetime.now().strftime('%Y%m%d_%H%M%S_%f'))
shutil.copytree(source,destination)
ic = bactoscoop.ImageCollection(str(destination),px=0.065)
ic.create_image_objects(phase_channel='C1')
ic.batch_process_mesh(phase_channel='C1',join_thresh=4,split_thresh=0.5,CD_width=False,smoothing=0.1,save_data=True)
# Optional: skip this step to extract features without an SVM model.
run_curation = True
if run_curation:
    ic.curate_dataset(str(destination/'DnaN_Timecourse.pkl'),control=False)
ic.batch_detect_objects(channels=['C3'],reset_channels=True,align=False,smoothing=0.1,log_sigma=3,kernel_width=3,min_overlap_ratio=0.001,max_external_ratio=0.3)
ic.load_channel_images(['C2'])
ic.add_channels(ic.image_objects,['C2'],load_data=False)
ic.batch_calculate_features([([None],'morphological'),(['C2','C3'],'profiling'),(['C3'],'objects')],all_data=False,reset=True,max_mesh_size=1000)
table = ic.merge_dataframes(discard_morphological_nan=True)
ic.dataframe_to_parquet()
ic.dataframe_to_pkl()

# Optional filtering after extraction; choose limits for your data.
apply_feature_filter = False
min_length_um, max_length_um = 1.0, 10.0
if apply_feature_filter:
    keep = table['cell_length'].between(min_length_um, max_length_um)
    filtered = table.loc[keep].copy()
    filtered.to_parquet(destination/'3_channel_example_filtered_features.parquet',index=False)
    print(f'Feature-table selection: {len(table)} to {len(filtered)} cells')

(destination/'processing_summary.json').write_text(json.dumps(ic.processing_summary(),indent=2),encoding='utf-8')
print(f'{len(table)} retained rows; outputs in {destination}')

Download the complete script. The default calibration matches the supplied walkthrough; replace it with your microscope’s µm/pixel calibration for your own images.

What to inspect

Inspect the mask outlines before trusting the reconstructed meshes. After optional SVM curation, compare the kept and rejected contours. Then inspect individual object detections and check whether the merged table contains the expected channels. See Plotting and visual quality control for the plotting functions.

Individual cell measurements can fail while the rest of the analysis completes. The resulting table can therefore contain missing measurements. See Processing summaries and logging for how to inspect these failures when needed.

This quick start intentionally uses the supplied SVM with its matching dataset. The same model need not classify cells correctly in a different experiment. Review Optional SVM curation before applying it to other images.

Expected files

The working copy contains new _meshdata.pkl, _curated_meshdata.pkl, _features.pkl, and _features.parquet files. The script also saves processing_summary.json so item-level and cell-level failures can be reviewed. Existing masks remain in the working copy’s masks/ folder.