Input/Output API
This section documents the components responsible for handling file input and output in FlatProt, including parsing structure files and configuration files (styles, annotations).
IO Concept
The IO module acts as the interface between FlatProt's internal data structures and external files. Its primary responsibilities are:
- Structure Parsing: Reading 3D coordinates, sequence information, and potentially secondary structure assignments from standard formats like PDB and mmCIF. This often involves leveraging libraries like Gemmi (e.g., via
GemmiStructureParser
). - Configuration Parsing: Reading and validating configuration files written in TOML format, specifically for custom styles (
StyleParser
) and annotations (AnnotationParser
). These parsers translate the TOML definitions into structured Pydantic models used by the Scene and Rendering systems. - Validation: Performing basic checks on input files (e.g., existence, basic format validation) before attempting full parsing.
- Error Handling: Defining specific exception types related to file reading, parsing, and validation errors.
Structure Parser
Handles reading and parsing protein structure files (PDB, mmCIF).
Bases: StructureParser
Source code in src/flatprot/io/structure_gemmi_adapter.py
16 17 18 19 20 21 22 23 24 25 26 27 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
parse_structure(structure_file, secondary_structure_file=None)
Main entry point for structure parsing
Source code in src/flatprot/io/structure_gemmi_adapter.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
save_structure(structure, output_file, separate_chains=False)
Save structure using gemmi
Source code in src/flatprot/io/structure_gemmi_adapter.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
options: show_root_heading: true members_order: source
Style Parser
Parses TOML files defining custom styles for structure elements.
Parser for TOML style files focusing on structure elements and connections.
Source code in src/flatprot/io/styles.py
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 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 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 |
|
__init__(file_path)
Initialize the style parser.
Parameters: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/styles.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
get_element_styles()
Parse and return the element styles defined in the TOML file.
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/styles.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
get_raw_data()
Return the raw, unprocessed style data loaded from the TOML file.
Returns: |
|
---|
Source code in src/flatprot/io/styles.py
152 153 154 155 156 157 158 |
|
parse()
Parses the known sections from the TOML file into Pydantic style objects.
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/styles.py
77 78 79 80 81 82 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 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
options: show_root_heading: true members_order: source
Annotation Parser
Parses TOML files defining annotations (points, lines, areas) and their inline styles.
Parses annotation files in TOML format with optional inline styles.
Creates fully initialized PointAnnotation, LineAnnotation, or AreaAnnotation
objects from the flatprot.scene.annotations
module.
Source code in src/flatprot/io/annotations.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 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 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 260 261 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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
__init__(file_path)
Initialize the parser with the path to the annotation file.
Parameters: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/annotations.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
parse()
Parse the annotation file and create annotation objects.
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/annotations.py
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 260 261 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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
options: show_root_heading: true members_order: source
File Validation
Utility functions for validating input files.
Validate that the file exists and is a valid PDB or CIF format.
Parameters: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/structure.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 |
|
options: show_root_heading: true
Validate that optional files exist if specified.
Parameters: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/io/__init__.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
options: show_root_heading: true
IO Errors
Exceptions specific to file input, output, parsing, and validation.
Error classes for the FlatProt IO module.
AnnotationError
Bases: IOError
Base class for annotation-related errors.
Source code in src/flatprot/io/errors.py
90 91 92 93 94 |
|
AnnotationFileError
Bases: AnnotationError
Exception raised when there's an issue with an annotation file.
Source code in src/flatprot/io/errors.py
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 |
|
AnnotationFileNotFoundError
Bases: AnnotationError
Exception raised when an annotation file is not found.
Source code in src/flatprot/io/errors.py
97 98 99 100 101 102 |
|
FileError
Bases: IOError
Base class for file-related errors.
Source code in src/flatprot/io/errors.py
22 23 24 25 26 |
|
FileNotFoundError
Bases: FileError
Exception raised when a required file is not found.
Source code in src/flatprot/io/errors.py
29 30 31 32 33 34 35 36 |
|
IOError
Bases: FlatProtError
Base class for all IO-related errors in FlatProt.
Source code in src/flatprot/io/errors.py
15 16 17 18 19 |
|
InvalidColorError
Bases: StyleError
Exception raised when an invalid color is specified.
Source code in src/flatprot/io/errors.py
236 237 238 239 240 241 242 243 244 245 246 |
|
InvalidFieldTypeError
Bases: AnnotationError
Exception raised when a field has an invalid type.
Source code in src/flatprot/io/errors.py
121 122 123 124 125 126 127 128 129 130 131 132 |
|
InvalidFileFormatError
Bases: FileError
Exception raised when a file has an invalid format.
Source code in src/flatprot/io/errors.py
39 40 41 42 43 44 45 46 |
|
InvalidMatrixDimensionsError
Bases: MatrixError
Error raised when a matrix has invalid dimensions.
Source code in src/flatprot/io/errors.py
265 266 267 268 |
|
InvalidMatrixError
Bases: MatrixError
Exception raised when a matrix file has an invalid format.
Source code in src/flatprot/io/errors.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
InvalidMatrixFormatError
Bases: MatrixError
Error raised when a matrix file has an invalid format.
Source code in src/flatprot/io/errors.py
271 272 273 274 |
|
InvalidReferenceError
Bases: AnnotationError
Exception raised when an annotation references a nonexistent chain or residue.
Source code in src/flatprot/io/errors.py
135 136 137 138 139 140 141 142 143 144 145 146 |
|
InvalidStructureError
Bases: StructureError
Exception raised when a structure file has an invalid format.
Source code in src/flatprot/io/errors.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
InvalidTomlError
Bases: StyleParsingError
Error for malformed TOML files.
Source code in src/flatprot/io/errors.py
198 199 200 201 |
|
MalformedAnnotationError
Bases: AnnotationError
Exception raised when an annotation file has an invalid format.
Source code in src/flatprot/io/errors.py
105 106 107 108 109 110 |
|
MatrixError
Bases: IOError
Base class for matrix-related errors.
Source code in src/flatprot/io/errors.py
250 251 252 253 254 |
|
MatrixFileError
Bases: MatrixError
Error raised when a matrix file can't be read.
Source code in src/flatprot/io/errors.py
277 278 279 280 |
|
MatrixFileNotFoundError
Bases: MatrixError
Exception raised when a matrix file is not found.
Source code in src/flatprot/io/errors.py
257 258 259 260 261 262 |
|
MissingRequiredFieldError
Bases: AnnotationError
Exception raised when a required field is missing from an annotation.
Source code in src/flatprot/io/errors.py
113 114 115 116 117 118 |
|
OutputError
Bases: IOError
Base class for output-related errors.
Source code in src/flatprot/io/errors.py
301 302 303 304 305 |
|
OutputFileError
Bases: OutputError
Exception raised when there's an issue with an output file.
Source code in src/flatprot/io/errors.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
StructureError
Bases: IOError
Base class for structure-related errors.
Source code in src/flatprot/io/errors.py
50 51 52 53 54 |
|
StructureFileNotFoundError
Bases: StructureError
Exception raised when a structure file is not found.
Source code in src/flatprot/io/errors.py
57 58 59 60 61 62 63 |
|
StyleError
Bases: IOError
Base class for style-related errors.
Source code in src/flatprot/io/errors.py
177 178 179 180 181 |
|
StyleFileError
Bases: StyleError
Exception raised when there's an issue with a style file.
Source code in src/flatprot/io/errors.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
StyleFileNotFoundError
Bases: StyleError
Exception raised when a style file is not found.
Source code in src/flatprot/io/errors.py
184 185 186 187 188 189 |
|
StyleParsingError
Bases: StyleError
Base error for style parsing issues.
Source code in src/flatprot/io/errors.py
192 193 194 195 |
|
StyleValidationError
Bases: StyleParsingError
Error for invalid style field types or values.
Source code in src/flatprot/io/errors.py
204 205 206 207 |
|
options: show_root_heading: true