seq_region
ensembl.io.genomio.seq_region
¶
Sequence regions handling module.
StrPath = TypeVar('StrPath', str, os.PathLike)
module-attribute
¶
ArgumentParser
¶
Bases: ArgumentParser
Extends argparse.ArgumentParser
with additional methods and functionality.
The default behaviour of the help text will be to display the default values on every non-required
argument, i.e. optional arguments with required=False
.
Source code in ensembl/utils/argparse.py
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 293 294 295 296 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 |
|
formatter_class = argparse.ArgumentDefaultsHelpFormatter
instance-attribute
¶
add_argument(*args, **kwargs)
¶
Extends the parent function by excluding the default value in the help text when not provided.
Only applied to required arguments without a default value, i.e. positional arguments or optional
arguments with required=True
.
Source code in ensembl/utils/argparse.py
132 133 134 135 136 137 138 139 140 141 |
|
add_argument_dst_path(*args, exists_ok=True, **kwargs)
¶
Adds pathlib.Path
argument, checking if it is writable at parsing time.
If "metavar" is not defined it is added with "PATH" as value to improve help text readability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exists_ok
|
bool
|
Do not raise an error if the destination path already exists. |
True
|
Source code in ensembl/utils/argparse.py
153 154 155 156 157 158 159 160 161 162 163 164 |
|
add_argument_src_path(*args, **kwargs)
¶
Adds pathlib.Path
argument, checking if it exists and it is readable at parsing time.
If "metavar" is not defined, it is added with "PATH" as value to improve help text readability.
Source code in ensembl/utils/argparse.py
143 144 145 146 147 148 149 150 151 |
|
add_argument_url(*args, **kwargs)
¶
Adds sqlalchemy.engine.URL
argument.
If "metavar" is not defined it is added with "URI" as value to improve help text readability.
Source code in ensembl/utils/argparse.py
166 167 168 169 170 171 172 173 174 |
|
add_log_arguments(add_log_file=False)
¶
Adds the usual set of arguments required to set and initialise a logging system.
The current set includes a mutually exclusive group for the default logging level: --verbose
,
--debug
or --log LEVEL
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
add_log_file
|
bool
|
Add arguments to allow storing messages into a file, i.e. |
False
|
Source code in ensembl/utils/argparse.py
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 |
|
add_numeric_argument(*args, type=float, min_value=None, max_value=None, **kwargs)
¶
Adds a numeric argument with constrains on its type and its minimum or maximum value.
Note that the default value (if defined) is not checked unless the argument is an optional argument and no value is provided in the command line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type
|
Callable[[str], int | float]
|
Type to convert the argument value to when parsing. |
float
|
min_value
|
int | float | None
|
Minimum value constrain. If |
None
|
max_value
|
int | float | None
|
Maximum value constrain. If |
None
|
Source code in ensembl/utils/argparse.py
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 |
|
add_server_arguments(prefix='', include_database=False, help=None)
¶
Adds the usual set of arguments needed to connect to a server, i.e. --host
, --port
, --user
and --password
(optional).
Note that the parser will assume this is a MySQL server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prefix
|
str
|
Prefix to add the each argument, e.g. if prefix is |
''
|
include_database
|
bool
|
Include |
False
|
help
|
str | None
|
Description message to include for this set of arguments. |
None
|
Source code in ensembl/utils/argparse.py
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 |
|
parse_args(*args, **kwargs)
¶
Extends the parent function by adding a new URL argument for every server group added.
The type of this new argument will be sqlalchemy.engine.URL
. It also logs all the parsed
arguments for debugging purposes when logging arguments have been added.
Source code in ensembl/utils/argparse.py
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 |
|
SeqCollection
¶
Represent a collection of seq_regions metadata.
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
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 |
|
mock = mock
instance-attribute
¶
seqs = {}
instance-attribute
¶
add_mitochondrial_codon_table(taxon_id)
¶
Adds the mitochondrial codon table to each sequence region (when missing) based on the taxon ID.
If no mitochondrial genetic code can be found for the given taxon ID nothing will be changed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxon_id
|
int
|
The species taxon ID. |
required |
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
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 |
|
add_translation_table(location_codon=LOCATION_CODON)
¶
Adds the translation codon table to each sequence region (when missing) based on its location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
location_codon
|
Mapping[str, int]
|
Map of known codon tables for known locations. |
LOCATION_CODON
|
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
187 188 189 190 191 192 193 194 195 196 197 198 |
|
from_gbff(gbff_path)
¶
Store seq_regions extracted from a GBFF file.
If a seq_region with the same ID exists in the collection, it will be replaced.
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
48 49 50 51 52 53 54 55 56 57 58 59 |
|
from_report(report_path, is_refseq=False)
¶
Store seq_regions extracted from an INSDC assembly report file.
If a seq_region with the same id exists in the collection, it will be replaced.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
report_path
|
Path
|
Path to the sequence regions report file. |
required |
is_refseq
|
bool
|
True if the source of the report is RefSeq, false if INSDC. |
False
|
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
make_seq_region_from_report(seq_data, is_refseq, synonym_map=SYNONYM_MAP, molecule_location=MOLECULE_LOCATION)
staticmethod
¶
Returns a sequence region from the information provided.
An empty sequence region will be returned if no accession information is found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Dict from the report representing one line, where the key is the column name. |
required | |
is_refseq
|
bool
|
True if the source is RefSeq, false if INSDC. |
required |
synonym_map
|
Mapping[str, str]
|
Map of INSDC report column names to sequence region field names. |
SYNONYM_MAP
|
molecule_location
|
Mapping[str, str]
|
Map of sequence type to SO location. |
MOLECULE_LOCATION
|
Raises:
Type | Description |
---|---|
UnknownMetadata
|
If the sequence role or location is not recognised. |
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
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 |
|
make_seqregion_from_gbff(record_data)
staticmethod
¶
Returns a seq_region dict extracted from a GBFF record.
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
remove(to_exclude)
¶
Remove seq_regions based on a provided list of accessions.
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
179 180 181 182 183 184 185 |
|
to_list()
¶
Returns the sequences as a simple list of SeqRegionDict
objects.
Source code in src/python/ensembl/io/genomio/seq_region/collection.py
232 233 234 |
|
add_attribs(seq_region, seq_region_attrib)
¶
Map seq_regions attribs to a specific name and type defined below.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_region
|
dict
|
A seq_region dict to modify. |
required |
seq_region_attrib
|
dict
|
The attribs for this seq_region. |
required |
Source code in src/python/ensembl/io/genomio/seq_region/dump.py
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 |
|
fetch_coord_systems(session)
¶
Retrieve the coord_system metadata from the current core.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session for the current core database. |
required |
Yields:
Type | Description |
---|---|
CoordSystem
|
All default coord_systems in the core database. |
Source code in src/python/ensembl/io/genomio/seq_region/dump.py
44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_json(src_path, **kwargs)
¶
Generic data JSON loader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_path
|
StrPath
|
Path to the JSON file to load. |
required |
Source code in src/python/ensembl/io/genomio/utils/json_utils.py
26 27 28 29 30 31 32 33 34 |
|
get_karyotype(seq_region)
¶
Given a seq_region, extract the karyotype bands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_region
|
SeqRegion
|
The seq_region from which the karyotype bands are extracted. |
required |
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of all karyotype bands as a dict with values 'start', 'end', 'name' 'stain', 'structure'. |
Source code in src/python/ensembl/io/genomio/seq_region/dump.py
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 |
|
get_seq_regions(session, external_db_map)
¶
Returns all the sequence regions from the current core database.
Include synonyms, attribs and karyotypes. Only the top level sequences are exported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session from the current core database. |
required |
external_db_map
|
dict
|
Mapping of external_db names for the synonyms. |
required |
Source code in src/python/ensembl/io/genomio/seq_region/dump.py
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 |
|
get_synonyms(seq_region, external_db_map)
¶
Get all synonyms for a given seq_region. Use the mapping for synonym source names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_region
|
SeqRegion
|
Seq_region from which the synonyms are extracted. |
required |
external_db_map
|
dict[str, str]
|
To map the synonym source names. |
required |
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of all synonyms as a dict with 'name' and 'source' keys. |
Source code in src/python/ensembl/io/genomio/seq_region/dump.py
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 |
|
init_logging_with_args(args)
¶
Processes the Namespace object provided to call init_logging()
with the correct arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
Namespace
|
Namespace populated by an argument parser. |
required |
Source code in ensembl/utils/logging.py
98 99 100 101 102 103 104 105 106 107 |
|
main()
¶
Module's entry-point.
Source code in src/python/ensembl/io/genomio/seq_region/prepare.py
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 |
|
prepare_seq_region_metadata(genome_file, report_file, dst_file, *, gbff_file=None, to_exclude=None, mock_run=False)
¶
Prepares the sequence region metadata found in the INSDC/RefSeq report and GBFF files.
The sequence region information is loaded from both sources and combined. Elements are added/excluded as requested, and the final sequence region metadata is dumped in a JSON file that follows the schema defined in "src/python/ensembl/io/genomio/data/schemas/seq_region.json".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
genome_file
|
StrPath
|
Genome metadata JSON file path. |
required |
report_file
|
StrPath
|
INSDC/RefSeq sequences report file path to parse. |
required |
gbff_file
|
StrPath | None
|
INSDC/RefSeq GBFF file path to parse. |
None
|
dst_file
|
StrPath
|
JSON file output for the processed sequence regions JSON. |
required |
to_exclude
|
list[str] | None
|
Sequence region names to exclude. |
None
|
mock_run
|
bool
|
Do not call external taxonomy service. |
False
|
Source code in src/python/ensembl/io/genomio/seq_region/prepare.py
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 |
|
print_json(dst_path, data, **kwargs)
¶
Generic data JSON dumper to a file, with keys sorted and pretty-printed with indent 4 by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dst_path
|
StrPath
|
Path to the JSON file to create. |
required |
data
|
Any
|
Any data to store into the file. |
required |
Source code in src/python/ensembl/io/genomio/utils/json_utils.py
37 38 39 40 41 42 43 44 45 46 47 48 |
|