fileIO
csv_to_dataframe(filepath_or_buffer, comment='#', **kwargs)
Reads a .csv file or buffer into a pd.DataFrame object.
Comment lines are parsed where json dictionaries marked by tags are read.
The <pandas_kwargs>
marked json dict is used as kwargs for pd.read_csv.
The <metadata>
marked json dict is stored in the returned dataframe object as df.attrs['metadata']
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
Union[Path[str], str, StringIO]
|
File path of the .csv file or io.StringIO object. |
required |
comment |
str
|
Character indicating a comment line. |
'#'
|
**kwargs |
Any
|
Optional additional keyword arguments passed to pd.read_csv |
{}
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
The read dataframe. |
Source code in pyhdx/fileIO.py
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 |
|
csv_to_hdxm(filepath_or_buffer, comment='#', **kwargs)
Reads a pyhdx .csv file or buffer into a HDXMeasurement or HDXMeasurementSet object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
Union[Path[str], str, StringIO]
|
File path of the .csv file or io.StringIO object. |
required |
comment |
str
|
Character indicating a comment line. |
'#'
|
**kwargs |
Any
|
Optional additional keyword arguments passed to pd.read_csv |
{}
|
Returns:
Name | Type | Description |
---|---|---|
data_obj |
HDXMeasurement
|
The read HDXMeasurement or HDXMeasurementSet object. |
Source code in pyhdx/fileIO.py
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 |
|
dataframe_to_file(file_path, df, fmt='csv', include_metadata=True, include_version=False, **kwargs)
Save a pd.DataFrame to a file. Kwargs to read the resulting .csv object with pd.read_csv to get the original pd.DataFrame back are included in the comments. Optionally additional metadata or the version of PyHDX used can be included in the comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
PathLike
|
Path write to. |
required |
df |
DataFrame
|
The pd.DataFrame to write. |
required |
fmt |
str
|
Specify the formatting of the output. Options are |
'csv'
|
include_metadata |
Union[bool, dict]
|
If |
True
|
include_version |
bool
|
Set to |
False
|
**kwargs |
Any
|
Optional additional keyword arguments passed to df.to_csv. |
{}
|
Source code in pyhdx/fileIO.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
dataframe_to_stringio(df, sio=None, fmt='csv', include_metadata=True, include_version=True, **kwargs)
Save a pd.DataFrame to an io.StringIO object. Kwargs to read the resulting .csv object with pd.read_csv to get the original dataframe back are included in the comments. Optionally additional metadata or the version of PyHDX used can be included in the comments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
The pd.DataFrame to write. |
required |
sio |
Optional[StringIO]
|
Optional io.StringIO object to write to. If |
None
|
fmt |
str
|
Specify the formatting of the output. Options are |
'csv'
|
include_metadata |
Union[bool, dict]
|
If |
True
|
include_version |
bool
|
Set to |
True
|
**kwargs |
Any
|
Optional additional keyword arguments passed to df.to_csv. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
sio |
StringIO
|
Resulting io.StringIO object. |
Source code in pyhdx/fileIO.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
load_fitresult(fit_dir)
Load a fitresult.
The fit result must be in the format as generated by saving a fit result with save_fitresult
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fir_dir |
Fit result directory. |
required |
Returns:
Type | Description |
---|---|
Union[TorchFitResult, TorchFitResultSet]
|
Fit result object. |
Source code in pyhdx/fileIO.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
parse_header(filepath_or_buffer, comment='#')
Reads the header from a file and returns JSON metadata from header lines marked as comment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
Union[Path[str], str, StringIO, BytesIO]
|
File path of the .csv file or io.StringIO object. |
required |
comment |
str
|
Character indicating a comment line. |
'#'
|
Returns:
Type | Description |
---|---|
dict
|
Dictionary of read metadata. |
Source code in pyhdx/fileIO.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
read_dynamx(filepath_or_buffer, time_conversion=('min', 's'))
Reads DynamX .csv files and returns the resulting peptide table as a pandas DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath_or_buffer |
Union[Path[str], str, StringIO]
|
File path of the .csv file or io.StringIO object. |
required |
time_conversion |
Tuple[Literal['h', 'min', 's'], Literal['h', 'min', 's']]
|
How to convert the time unit of the field 'exposure'. Format is ( |
('min', 's')
|
Returns:
Type | Description |
---|---|
DataFrame
|
Peptide table as a pandas DataFrame. |
Source code in pyhdx/fileIO.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
save_fitresult(output_dir, fit_result, log_lines=None)
Save a fit result object to the specified directory with associated metadata
Output directory contents: dG.csv/.txt: Fit output result (dG, covariance, k_obs, pfact) losses.csv/.txt: Losses per epoch log.txt: Log file with additional metadata (number of epochs, final losses, pyhdx version, time/date)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir |
PathLike
|
Output directory to save fit result to. |
required |
fit_result |
TorchFitResult
|
fit result object to save. |
required |
log_lines |
Optional[list[str]]
|
Optional additional lines to write to log file. |
None
|
Source code in pyhdx/fileIO.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|