Data export

All data associated with the analysis of a TIF file or LOI, including metadata, results, and analysis parameters, are stored in the .json format. JSON (JavaScript Object Notation) is an open standard format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and array data types. JSON is language-independent and widely supported across various programming languages.

To read a JSON file in Python:

import json

# Load JSON data from a file
with open('data.json', 'r') as file:
    data = json.load(file)

# Access data
print(data)

SarcAsM further provides high-level functions to directly export data and summary statistics of one or multiple TIF files or LOIs as .xlsx or .csv file:

Structural data of single TIF file

For a single TIF file /Structure object, use Export.export_structure_data for export as .xlsx or .csv file. Features can be specified by list structure_keys, see list of structure features.

[ ]:
from sarcasm.export import Export

Export.export_structure_data('/path/to/xlsx/file.xlsx', sarc_obj)

Motion data of single LOI

For a single LOI /Motion object, use Export.export_motion_data for export as .xlsx or .csv file. Features can be specified by list motion_keys, see list of motion features.

[ ]:
from sarcasm.export import Export

Export.export_motion_data('/path/to/xlsx/file.xlsx', mot_obj)

Data of multiple TIF-files or LOIs

The MultiStructureAnalysis class is designed for multi-file comparison of structure. It allows users to iterate through a list of tif files, add metadata using regex functions, extract structure data, and store the data in one pandas DataFrame and export as .xlsx or .csv file. Details see API reference.

The MultiLOIAnalysis class, on the other hand, is used for multi-ROI comparison. It enables users to iterate through a list of tif files and ROI names, add metadata using regex functions, extract motion data, and store the data in a pandas DataFrame and export as .xlsx or .csv file. Details see API reference.

Below is an example how to use MultiStructureAnalysis (analogous for MultiLOIAnalysis).

[ ]:
import os

import glob
import re

from sarcasm import *


# select folder with tif files and create folder for results
files_folder = 'D:/2023_SarcAsM_drugs_chronic/'
result_folder = 'D:/2023_SarcAsM_drugs_chronic/results/'
os.makedirs(result_folder, exist_ok=True)

# find all tif files in folder
tif_files = glob.glob(files_folder + '*/*.tif')
print(f'{len(tif_files)} tif-files found')

# example regex function to extract date from filename (e.g. '20230502_wt_isoprenaline_10uM.tif')
date = lambda filename: re.search(r'(\d{4})(\d{2})(\d{2})', filename).group(0)

# initialize MultiStructureAnalysis object
multi_structure = MultiStructureAnalysis(list_files=tif_files, folder=result_folder, experiment='test_123', date=date)

# specify structure and metadata keys
structure_keys = ['z_length_mean', 'sarcomere_area_ratio']  # all keys see list of structure features
meta_keys = ['tif_name', 'file_id', 'date', 'experiment']  # more keys see print(Export.meta_keys_default)

# get structure data of tif-files
multi_structure.get_data(structure_keys=structure_keys, meta_keys=meta_keys)

The resulting pandas DataFrame can be exported to .xlsx or .csv:

[ ]:
multi_structure.export_data('/path/to/file.xlsx', format='.xlsx')