Alignment API
This section documents the components responsible for structural alignment in FlatProt, primarily focused on finding the best match in a reference database and retrieving the associated transformation matrix.
Alignment Concept
The alignment process in FlatProt serves to orient an input protein structure according to a standardized reference frame, typically based on its structural superfamily.
- Structural Search: It uses an external tool, Foldseek, to search a pre-compiled database of reference structures (e.g., CATH domains) for the best structural match to the input protein.
- Result Filtering: The Foldseek results are filtered based on metrics like alignment probability (
--min-probability
) or by specifying a direct target ID (--target-db-id
). - Matrix Retrieval: Once a suitable match is identified (represented by a
target_id
from Foldseek), FlatProt queries its internal HDF5 database (AlignmentDatabase
) using thistarget_id
. This database stores pre-calculated 4x4 transformation matrices that map the reference structure (the target) to a standardized orientation for its superfamily. - Output: The primary output is the retrieved transformation matrix (
TransformationMatrix
), which can then be used by theproject
command to render the input structure in the standardized orientation. Alignment metadata (scores, matched IDs) can also be saved.
Top-Level Alignment Functions
These functions provide the main entry points for performing alignment using a database.
AlignmentDBEntry
dataclass
Stores alignment data with its rotation matrix.
Source code in src/flatprot/alignment/db.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
AlignmentDatabase
Handles alignment database using HDF5 storage with memory-mapped arrays.
Source code in src/flatprot/alignment/db.py
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
add_entry(entry)
Adds a new entry to the database.
Source code in src/flatprot/alignment/db.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
close()
Closes the database file.
Source code in src/flatprot/alignment/db.py
55 56 57 58 59 |
|
contains_entry_id(entry_id)
Checks if an entry_id exists in the database. O(1) lookup.
Source code in src/flatprot/alignment/db.py
81 82 83 84 85 |
|
contains_structure_name(structure_name)
Checks if a structure_name exists in the database. O(1) lookup.
Source code in src/flatprot/alignment/db.py
87 88 89 |
|
get_by_entry_id(entry_id, default=None)
Returns alignment entry for given entry_id or default if not found. O(1) lookup.
Source code in src/flatprot/alignment/db.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
get_by_structure_name(structure_name, default=None)
Returns alignment entry for given structure_name or default if not found. O(1) lookup.
Source code in src/flatprot/alignment/db.py
109 110 111 112 113 114 115 116 |
|
open()
Opens the database file in read/write mode.
Source code in src/flatprot/alignment/db.py
50 51 52 53 |
|
update(entry)
Updates an existing entry in the database.
Source code in src/flatprot/alignment/db.py
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 |
|
AlignmentError
Bases: FlatProtError
Base class for alignment-related errors.
Source code in src/flatprot/alignment/errors.py
8 9 10 11 |
|
AlignmentResult
Bases: NamedTuple
Results from a structural family alignment.
Source code in src/flatprot/alignment/foldseek.py
15 16 17 18 19 20 21 22 |
|
DatabaseEntryNotFoundError
Bases: AlignmentError
Raised when a database entry is not found.
Source code in src/flatprot/alignment/errors.py
20 21 22 23 |
|
FoldseekAligner
Handles structural family alignments using FoldSeek.
Source code in src/flatprot/alignment/foldseek.py
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 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 |
|
align_structure(structure_path, min_probability=0.5, fixed_alignment_id=None, tmp_dir=None)
Aligns structure to family database and returns best match.
Source code in src/flatprot/alignment/foldseek.py
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 |
|
align_structures_batch(structure_paths, min_probability=0.5, fixed_alignment_id=None, tmp_dir=None)
Batch align multiple structures to family database for better performance.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/flatprot/alignment/foldseek.py
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 |
|
NoSignificantAlignmentError
Bases: AlignmentError
Raised when no significant alignment is found.
Source code in src/flatprot/alignment/errors.py
14 15 16 17 |
|
align_structure_database(structure_file, foldseek_db_path, foldseek_command='foldseek', min_probability=0.5, target_db_id=None)
Calculate the alignment result for structural alignment using FoldSeek.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/alignment/utils.py
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 |
|
get_aligned_rotation_database(alignment, db, id_transform=_foldseek_id_to_db_id)
Combines alignment rotation with database rotation.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/alignment/utils.py
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 |
|
options: members: - align_structure_database - get_aligned_rotation_database show_root_heading: true show_root_toc_entry: false
Foldseek Interaction
Classes and functions related to running Foldseek and parsing its results.
AlignmentResult
Bases: NamedTuple
Results from a structural family alignment.
Source code in src/flatprot/alignment/foldseek.py
15 16 17 18 19 20 21 22 |
|
FoldseekAligner
Handles structural family alignments using FoldSeek.
Source code in src/flatprot/alignment/foldseek.py
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 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 |
|
align_structure(structure_path, min_probability=0.5, fixed_alignment_id=None, tmp_dir=None)
Aligns structure to family database and returns best match.
Source code in src/flatprot/alignment/foldseek.py
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 |
|
align_structures_batch(structure_paths, min_probability=0.5, fixed_alignment_id=None, tmp_dir=None)
Batch align multiple structures to family database for better performance.
Parameters: |
|
---|
Returns: |
|
---|
Source code in src/flatprot/alignment/foldseek.py
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 |
|
options: show_root_heading: true show_root_toc_entry: false
Alignment Database
Class for interacting with the HDF5 alignment database containing pre-calculated matrices and the associated data entry structure.
AlignmentDBEntry
dataclass
Stores alignment data with its rotation matrix.
Source code in src/flatprot/alignment/db.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
AlignmentDatabase
Handles alignment database using HDF5 storage with memory-mapped arrays.
Source code in src/flatprot/alignment/db.py
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
add_entry(entry)
Adds a new entry to the database.
Source code in src/flatprot/alignment/db.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
close()
Closes the database file.
Source code in src/flatprot/alignment/db.py
55 56 57 58 59 |
|
contains_entry_id(entry_id)
Checks if an entry_id exists in the database. O(1) lookup.
Source code in src/flatprot/alignment/db.py
81 82 83 84 85 |
|
contains_structure_name(structure_name)
Checks if a structure_name exists in the database. O(1) lookup.
Source code in src/flatprot/alignment/db.py
87 88 89 |
|
get_by_entry_id(entry_id, default=None)
Returns alignment entry for given entry_id or default if not found. O(1) lookup.
Source code in src/flatprot/alignment/db.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
get_by_structure_name(structure_name, default=None)
Returns alignment entry for given structure_name or default if not found. O(1) lookup.
Source code in src/flatprot/alignment/db.py
109 110 111 112 113 114 115 116 |
|
open()
Opens the database file in read/write mode.
Source code in src/flatprot/alignment/db.py
50 51 52 53 |
|
update(entry)
Updates an existing entry in the database.
Source code in src/flatprot/alignment/db.py
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 |
|
options: show_root_heading: true show_root_toc_entry: false
Alignment Utilities
Utility functions used within the alignment module.
align_structure_database(structure_file, foldseek_db_path, foldseek_command='foldseek', min_probability=0.5, target_db_id=None)
Calculate the alignment result for structural alignment using FoldSeek.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/alignment/utils.py
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 |
|
get_aligned_rotation_database(alignment, db, id_transform=_foldseek_id_to_db_id)
Combines alignment rotation with database rotation.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
Source code in src/flatprot/alignment/utils.py
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 |
|
options: show_root_heading: true show_root_toc_entry: false
Alignment Errors
Exceptions specific to the alignment process.
AlignmentError
Bases: FlatProtError
Base class for alignment-related errors.
Source code in src/flatprot/alignment/errors.py
8 9 10 11 |
|
DatabaseEntryNotFoundError
Bases: AlignmentError
Raised when a database entry is not found.
Source code in src/flatprot/alignment/errors.py
20 21 22 23 |
|
NoSignificantAlignmentError
Bases: AlignmentError
Raised when no significant alignment is found.
Source code in src/flatprot/alignment/errors.py
14 15 16 17 |
|
options: show_root_heading: true show_root_toc_entry: false