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, xname='Atlas_X', yname='Atlas_Y', zname='Atlas_Z')
#
Scans a directory for json files and concatenate them in a single DataFrame.
The json files must be generated with 'pipelineImportExport.groovy" or 'exportFibersAtlasCoordinates.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 |
xname
|
str
|
How to name x, y and z coordinates. Default is ABBA convention, eg. Atlas_X, Atlas_Y and Atlas_Z, resp. corresponding to AP, DV, ML. |
'Atlas_X'
|
yname
|
str
|
How to name x, y and z coordinates. Default is ABBA convention, eg. Atlas_X, Atlas_Y and Atlas_Z, resp. corresponding to AP, DV, ML. |
'Atlas_X'
|
zname
|
str
|
How to name x, y and z coordinates. Default is ABBA convention, eg. Atlas_X, Atlas_Y and Atlas_Z, resp. corresponding to AP, DV, ML. |
'Atlas_X'
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
All JSON files concatenated in a single DataFrame. |
Source code in cuisto/io.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
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 |