fasta
ensembl.io.genomio.fasta
¶
Fasta files processing module.
FastaParserError
¶
Bases: Exception
Error while parsing a FASTA file.
Source code in src/python/ensembl/io/genomio/fasta/process.py
35 36 |
|
check_chunk_size_and_tolerance(chunk_size, chunk_tolerance, error_f=_on_value_error)
¶
Check the chunk size and the tolerance are positive and chunk size is not too small
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_size
|
int
|
Chunk size to check |
required |
chunk_tolerance
|
int
|
Chunk tolerance to check |
required |
Dies
If checks failed dies with parser.error
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
chunk_fasta(input_fasta_file, chunk_size, chunk_size_tolerated, out_file_name, individual_file_prefix, *, agp_output_file=None, n_sequence_len=0, chunk_sfx='ens_chunk', append_offset_to_chunk_name=None)
¶
Open input_fasta_file
and split into a smaller chunks based on
stretches of "N"s and then based on chunk_size_tolerated and store either to
the out_file_name
if no individual_file_prefix
is provided or
store each individual chunk to a file starting with non-empty individual_file_prefix
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_fasta_file
|
str
|
Input FASTA |
required |
chunk_size
|
int
|
Size of the chunks to split into. |
required |
chunk_size_tolerated
|
int
|
If more flexibility allowed, use this as the maximum size of a chunk. |
required |
out_file_name
|
str
|
Output FASTA to store the chunks into if no |
required |
individual_file_prefix
|
Optional[Path]
|
A file path prefix including dirs and filenames part to use as a first part of the chunk file name. |
required |
agp_output_file
|
Optional[str]
|
Output AGP file to store the map for the chunking procedure if present and non-empty. |
None
|
n_sequence_len
|
int
|
Length of the stretch of |
0
|
chunk_sfx
|
str
|
A string to put between the original sequence name and the chunk suffix. |
'ens_chunk'
|
append_offset_to_chunk_name
|
Optional[bool]
|
Append 0-based offset in the form of |
None
|
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
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 |
|
chunk_fasta_stream(input_fasta, chunk_size, chunk_size_tolerated, output_fasta, individual_file_prefix, *, n_sequence_len=0, chunk_sfx='ens_chunk', append_offset_to_chunk_name=None, open_individual=_individual_file_opener)
¶
Split input TextIOWrapper stream with fasta into a smaller chunks based on
stretches of "N"s and then based on chunk_size_tolerated and store either to
the output_fasta stream (if valid) or to the files created by
invocation of the open_individual
callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_fasta
|
TextIOWrapper
|
Input FASTA as the TextIOWrapper stream. |
required |
chunk_size
|
int
|
Size of the chunks to split into. |
required |
chunk_size_tolerated
|
int
|
If more flexibility allowed, use this as the maximum size of a chunk. |
required |
output_fasta
|
Optional[TextIOWrapper] | nullcontext[Any]
|
Output FASTA TextIOWrapper stream to store the chunks into,
if none or False, |
required |
individual_file_prefix
|
Optional[Path]
|
A file path prefix including dirs and filenames part to use as a first part of the chunk file name. |
required |
n_sequence_len
|
int
|
Length of the stretch of |
0
|
chunk_sfx
|
str
|
A string to put between the original sequence name and the chunk suffix. |
'ens_chunk'
|
append_offset_to_chunk_name
|
Optional[bool]
|
A flag to append 0-based offset ( |
None
|
open_individual
|
Callable[[str], ContextManager[Any]]
|
A callable taking filename as an input to generate the output file for
individual contig if out_put FASTA is |
_individual_file_opener
|
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
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 |
|
get_peptides_to_exclude(genbank_path, seqr_to_exclude)
¶
Extract peptide IDs from a genbank file that are in a given list of seq regions
Source code in src/python/ensembl/io/genomio/fasta/process.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
get_tolerated_size(size, tolerance)
¶
Calculate max tolerated size of the chunk based on initial size and percent of allowed deviation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
Base chunk size |
required |
tolerance
|
int
|
Percent of allowed deviance as integer. |
required |
Returns:
Type | Description |
---|---|
int
|
Maximum tolerated chunk size. |
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
prep_fasta_data(fasta_infile, genbank_infile, fasta_outfile, peptide_mode=False)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fasta_file
|
Input FASTA file - DNA / Protein |
required | |
genbank_infile
|
Optional[PathLike]
|
Input GenBank GBFF file (Optional) |
required |
fasta_outfile
|
PathLike
|
Output FASTA sequence file. |
required |
peptide_mode
|
bool
|
Process proteins instead of DNA |
False
|
Source code in src/python/ensembl/io/genomio/fasta/process.py
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 |
|
prepare_out_dir_for_individuals(dir_name, file_part)
¶
Creates dir_name
(including upstream dirs) and returns its paths with the file_part
appended.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_name
|
Path
|
Directory to create. |
required |
file_part
|
str
|
File part to append. |
required |
Returns:
Type | Description |
---|---|
Optional[Path]
|
|
Throws
exception if not able to create directory.
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
split_seq_by_chunk_size(ends, chunk_size, tolerated_size=None)
¶
Split list of end coordinates, to form chunks not longer then chunk_size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ends
|
list[int]
|
List of one or more chunk(s) to split a sequence. |
required |
chunk_size
|
int
|
Size of chunks to split a sequence into. |
required |
tolerated_size
|
Optional[int]
|
Threshold to use instead of |
None
|
Returns:
Type | Description |
---|---|
list[int]
|
List with open coordinates of the chunks ends (or with only a single sequence length). |
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
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 |
|
split_seq_by_n(seq, split_pattern)
¶
Split a string into chunks at the positions where the
pattern is found. N
s (pattern) are appended to the chunk on the left.
The end point of each chunk will correspond to the end of the matching part.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq
|
str
|
Sequence to be split into chunks. |
required |
split_pattern
|
Optional[Pattern]
|
Pattern to search in the sequence. |
required |
Returns:
Type | Description |
---|---|
list[int]
|
List with open coordinates of the chunks ends (or with only a single sequence length). |
Source code in src/python/ensembl/io/genomio/fasta/chunk.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|