cuisto.io
io module, part of cuisto.
Contains loading and saving functions.
cat_csv_dir(directory, **kwargs)
#
Scans a directory for csv files and concatenate them into a single DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Path to the directory to scan. |
required |
**kwargs
|
passed to pandas.read_csv()
|
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
All CSV files concatenated in a single DataFrame. |
Source code in cuisto/io.py
cat_data_dir(directory, segtype, **kwargs)
#
Wraps either cat_csv_dir() or cat_json_dir() depending on segtype
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Path to the directory to scan. |
required |
segtype
|
str
|
"synaptophysin" or "fibers". |
required |
**kwargs
|
passed to cat_csv_dir() or cat_json_dir().
|
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
All files concatenated in a single DataFrame. |
Source code in cuisto/io.py
cat_json_dir(directory, hemisphere_names, atlas)
#
Scans a directory for json files and concatenate them in a single DataFrame.
The json files must be generated with 'workflow_import_export.groovy" from a QuPath project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Path to the directory to scan. |
required |
hemisphere_names
|
dict
|
Maps between hemisphere names in the json files ("Right" and "Left") to something else (eg. "Ipsi." and "Contra."). |
required |
atlas
|
BrainGlobeAtlas
|
Atlas to read regions from. |
required |
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
All JSON files concatenated in a single DataFrame. |
Source code in cuisto/io.py
check_empty_file(filename, threshold=1)
#
Checks if a file is empty.
Empty is defined as a file whose number of lines is lower than or equal to
threshold
(to allow for headers).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Full path to the file to check. |
required |
threshold
|
int
|
If number of lines is lower than or equal to this value, it is considered as empty. Default is 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
empty |
bool
|
True if the file is empty as defined above. |
Source code in cuisto/io.py
get_measurements_directory(wdir, animal, kind, segtype)
#
Get the directory with detections or annotations measurements for given animal ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wdir
|
str
|
Base working directory. |
required |
animal
|
str
|
Animal ID. |
required |
kind
|
str
|
"annotation" or "detection". |
required |
segtype
|
str
|
Type of segmentation, eg. "synaptophysin". |
required |
Returns:
Name | Type | Description |
---|---|---|
directory |
str
|
Path to detections or annotations directory. |
Source code in cuisto/io.py
load_dfs(filepath, fmt, identifiers=['df_regions', 'df_coordinates', 'df_distribution_ap', 'df_distribution_dv', 'df_distribution_ml'])
#
Load DataFrames from file.
If fmt
is "h5" ("xslx"), identifiers are interpreted as h5 group identifier (sheet
name, respectively).
If fmt
is "pickle", "csv" or "tsv", identifiers are appended to filename
.
Path to the file can't have a dot (".") in it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
Full path to the file(s), without extension. |
required |
fmt
|
(h5, csv, pickle, xlsx)
|
File(s) format. |
"h5"
|
identifiers
|
list of str
|
List of identifiers to load from files. Defaults to the ones saved in cuisto.process.process_animals(). |
['df_regions', 'df_coordinates', 'df_distribution_ap', 'df_distribution_dv', 'df_distribution_ml']
|
Returns:
Type | Description |
---|---|
All requested DataFrames.
|
|
Source code in cuisto/io.py
save_dfs(out_dir, filename, dfs)
#
Save DataFrames to file.
File format is inferred from file name extension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out_dir
|
str
|
Output directory. |
required |
filename
|
_type_
|
File name. |
required |
dfs
|
dict
|
DataFrames to save, as {identifier: df}. If HDF5 or xlsx, all df are saved in the same file, otherwise identifier is appended to the file name. |
required |