Post
The inner attributes have been altered according to the content of the files
SuccinctMultipleAlignment
Examples:
>>> msa = SuccinctMultipleAlignment("tests/align1.fa", ratio_other_vector=.25)
>>> len(msa)
16
>>> msa.get_nb_sequences()
5
>>> msa.get_consensus()
'CGTATCAGCNTACGAT'
>>> msa.get_sequence(0)
'AGTATCAGCATA-GAT'
>>> msa.get_sequence(4)
'CGTTTCAGCATA-GAT'
>>> msa.get_kept_nucleotides(0)
'AC'
>>> msa.get_kept_nucleotides(1)
'G'
>>> msa.get_kept_nucleotides(12)
'-C-'
>>> msa.get_column(0).nt_pos() == {'A': [(0,1)], 'C': [(2, 4)]}
True
>>> msa.get_column(1).nt_pos() == {'G': [(0,4)]}
True
>>> msa.get_column(12).nt_pos() == {'-': [(0,0), (4, 4)], 'C': [(1,3)]}
True
>>> msa.get_column(12).nt_frequency() == {'-': .4, 'C': .6}
True
>>> msa.get_column(9).get_nb_changes()
5
>>> len(msa.get_column(3))
5
>>> msa.get_column(5) == msa[5]
True
>>> msa.get_column(1).get_vector_type()
<class 'pysdsl.pysdsl.SDVector'>
>>> msa.get_column(0).get_vector_type()
<class 'pysdsl.pysdsl.RamanRamanRaoVector63'>
>>> import tempfile
>>> import os
>>> f = tempfile.NamedTemporaryFile(delete=False)
>>> msa.store_to_file(f.name)
>>> del msa
>>> msa = SuccinctMultipleAlignment.load(f.name)
>>> os.unlink(f.name)
>>> len(msa)
16
>>> msa.get_nb_sequences()
5
>>> msa.get_consensus()
'CGTATCAGCNTACGAT'
>>> msa.get_sequence(0)
'AGTATCAGCATA-GAT'
>>> msa.get_sequence(4)
'CGTTTCAGCATA-GAT'
>>> msa.get_kept_nucleotides(0)
'AC'
>>> msa.get_kept_nucleotides(1)
'G'
>>> msa.get_kept_nucleotides(12)
'-C-'
>>> msa.get_column(0).nt_pos() == {'A': [(0,1)], 'C': [(2, 4)]}
True
>>> msa.get_column(1).nt_pos() == {'G': [(0,4)]}
True
>>> msa.get_column(12).nt_pos() == {'-': [(0,0), (4, 4)], 'C': [(1,3)]}
True
>>> msa.get_column(12).nt_frequency() == {'-': .4, 'C': .6}
True
>>> msa.get_column(9).get_nb_changes()
5
>>> len(msa.get_column(3))
5
>>> msa.get_column(5) == msa[5]
True
>>> msa.get_column(1).get_vector_type()
<class 'pysdsl.pysdsl.SDVector'>
>>> msa.get_column(0).get_vector_type()
<class 'pysdsl.pysdsl.RamanRamanRaoVector63'>
succinct_multiple_alignment.py
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 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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
__fetch_alignment_size(fasta_file, compressed=False)
staticmethod
Read the FASTA file and store the size and the number of sequences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fasta_file |
str
|
A FASTA file containing multiple sequences aligned. |
required |
compressed |
bool
|
Whether the input is compressed or not. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
tuple of int
|
|
succinct_multiple_alignment.py
__fetch_column(fasta_file, position, nb_column, compressed=False)
Read the FASTA file and store 'nb_column' columns as SuccinctColumn objects in a list. To do that, it reads 'nb_column' nucleotides in each sequence, starting at the position 'position' in the file 'fasta_file'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fasta_file |
st
|
A FASTA file containing multiple sequences aligned. |
required |
position |
int
|
The position in the sequence where the search starts. |
required |
nb_column |
int
|
The number of columns to build in a single run. |
required |
compressed |
bool
|
Whether the input is compressed or not. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
list of SuccinctColumn
|
A list of SuccinctColumns objects of size 'nb_column' corresponding to columns of the multialignment starting at the position 'position'. |
succinct_multiple_alignment.py
__init__(fasta_file, nb_columns=1000, vector=pysdsl.SDVector, compressed=False, other_vector_type='pysdsl.RamanRamanRaoVector63', ratio_other_vector=0.1)
Build the succinct multiple alignment as a list of SuccinctColumn.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fasta_file |
str
|
A FASTA file containing multiple sequences aligned. |
required |
vector |
str
|
Selection of the class representing the bit vector. |
SDVector
|
succinct_multiple_alignment.py
column_size_in_bytes(index)
Return the size in bytes of the SuccinctColumn objects at the index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The column considered. |
required |
Returns:
Type | Description |
---|---|
int
|
The size in bytes of the selected SuccinctColumn objects. |
succinct_multiple_alignment.py
find_columns_with_excessive_space(threshold_ratio=2)
Identifies columns that occupy significantly more space than the average column size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
threshold_ratio |
float
|
The threshold ratio used to determine whether a column occupies significantly more space than the average column size. Default value is 2, meaning a column is considered to occupy significantly more space if its size is at least twice the average size. |
2
|
Returns:
Type | Description |
---|---|
list[int]
|
A list of indices of columns that occupy significantly more space than the average column size. |
succinct_multiple_alignment.py
get_column(index)
Returns the column at index index
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of the column (starts at 0). |
required |
Returns:
Type | Description |
---|---|
SuccinctColumn
|
The column at the requested index. |
succinct_multiple_alignment.py
get_consensus(ratio_min=0.5)
Computes and returns a consensus sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio_min |
int
|
The minimal ratio of the nucleotide in majority to add it to the consensus (N otherwise). |
0.5
|
\(\Omega(n)\), \(O(n\times s)\), with \(s\) the number of sequences and \(n\) the number of columns. On average, \(\Theta(n\times b)\), with \(b\) the average number of changes in nucleotides in a given column.
Returns:
Type | Description |
---|---|
str
|
A consensus sequence. |
succinct_multiple_alignment.py
get_info()
Return general informations such as the alignment length (length of the sequences) and the alignment size (number of sequences).
Returns:
Type | Description |
---|---|
int
|
The alignment length (length of the sequences). |
int
|
The alignment size (number of sequences). |
succinct_multiple_alignment.py
get_kept_nucleotides(index)
Returns the nucleotides - used to deduce the column's sequence from the bit vector - of the 'index'-th column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The column considered. |
required |
Returns:
Type | Description |
---|---|
str
|
The nucleotides kept in the SuccinctColumn object corresponding to the 'index'-th column in the multiple alignment. |
succinct_multiple_alignment.py
get_nb_sequences()
get_nt(seq_index, position)
Return the nucleotide in the position specified in the sequence of index "seq_index".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_index |
int
|
The index of the sequence to search in. |
required |
position |
int
|
The position to look at in the sequence. |
required |
Returns:
Type | Description |
---|---|
str
|
The nucleotide in the position specified in the sequence of index "seq_index". |
succinct_multiple_alignment.py
get_sequence(seq_index)
Return the sequence of index "seq_index".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq_index |
int
|
The index of the sequence to search in. |
required |
Returns:
Type | Description |
---|---|
str
|
The sequence of index "seq_index". |
succinct_multiple_alignment.py
get_vector(index)
Returns the SDVector object of a SuccinctColumn object corresponding to the 'index'-th column in the multiple alignment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
The column considered. |
required |
Returns:
Type | Description |
---|---|
SDVector
|
The SDVector object corresponding to the compacted representation of the bit vector of the column specified. |
succinct_multiple_alignment.py
load(input_file)
staticmethod
Load a previously saved multiple alignment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_file |
str
|
The filename to load |
required |
Returns:
Type | Description |
---|---|
SuccinctMultipleAlignment
|
The loaded SuccinctMultipleAlignment |
succinct_multiple_alignment.py
load_from_file(filename)
Create a SuccinctMultipleAlignment from the files produced by the store_to_file() function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
The filename from which to recreate the saved SuccinctMultipleAlignment. |
required |
Returns:
Type | Description |
---|---|
list
|
All the Succinct_columns |
int
|
The number of sequences. |
int
|
The length of the sequences (which is supposed to be the same for every sequence). |
succinct_multiple_alignment.py
size_in_bytes()
Return the size in bytes of the entire succinct multiple alignment (sum of the size in bytes of all the SuccinctColumn objects).
Returns:
Type | Description |
---|---|
int
|
The size in bytes of the entire succinct multiple alignment. |
succinct_multiple_alignment.py
size_to_csv(file_name='size.csv', sort_by_size=True)
Save the size in bytes of each SuccinctColumn object in a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
The name of the CSV file to save the sizes. Default is "size.csv". |
'size.csv'
|
sort_by_size |
bool
|
If True, the sizes will be sorted in ascending order. Default is True. |
True
|
succinct_multiple_alignment.py
store_to_file(output_file)
Store all the Succinct_column in the SuccinctMultipleAlignment, in a compressed directory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_file |
str
|
The path or the directory where the save will be created. |
required |
succinct_multiple_alignment.py
vector_type(nb_changes, total_length, ratio, bv_type)
Returns the vector type to use depending on the number of changes in the bit vector (ie. the number of 1) and the total length
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nb_changes |
int
|
The number of 1s in the bit vector |
required |
total_length |
int
|
The length of the bit vector |
required |
Returns:
Type | Description |
---|---|
type
|
A type corresponding to a bit vector type (e.g., pysdsl.SDVector). |
succinct_multiple_alignment.py
SuccinctColumn
succinct_column.py
9 10 11 12 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 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 |
|
__init__(bitvector=None, nt_kept=None, vector=None)
Build a SDVector or a BitVector and a sequence of nucleotides (corresponding to the "1" in the bit sequence) from all the nucleotides in a column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bitvector |
BitVector
|
A bit vector corresponding to a simplified version of multiple alignment. |
None
|
nt_kept |
str
|
Nucleotides corresponding to the '1' in the bit vector. |
None
|
vector |
type
|
Selection of the class representing the bit vector. |
None
|
succinct_column.py
__init_rank()
get_kept_nucleotides()
Returns the nucleotides used to deduce the column's sequence from the bit vector.
Returns:
Type | Description |
---|---|
str
|
The nucleotides kept. |
get_nb_changes()
Returns the number of changes in the vector
Returns:
Type | Description |
---|---|
int
|
The number of positions with a 1 in the bit vector |
get_nt(position)
Returns the nucleotide at the position specified in the column (the p-th sequence in the alignment).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position |
int
|
The position of the nucleotide in the column. |
required |
Returns:
Type | Description |
---|---|
str
|
The target nucleotide. |
succinct_column.py
get_pos_of_ones()
Return the positions of the ones in the bit vector
Returns:
Type | Description |
---|---|
set
|
The set of the positions where the value in the bit vector is 1 |
succinct_column.py
get_vector()
Returns the SDVector object corresponding to the compacted representation of the bit vector.
Returns:
Type | Description |
---|---|
vector
|
The object (whose type corresponds to self.get_vector_type()) corresponding to the compacted representation of the bit vector. |
succinct_column.py
get_vector_type()
Returns the type of the vector returned by self.get_vector().
Returns:
Type | Description |
---|---|
type
|
The type of the bit vector |
load(path, nt_file, vector_type)
staticmethod
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Path to the file storing the bitvector of the SuccinctColumn. |
required |
nt_file |
str or Reader
|
The file in which nucleotides will be written. |
required |
vector_type |
type
|
The type of the vector. |
required |
Returns:
Type | Description |
---|---|
SuccinctColumn
|
A column loaded from the file |
succinct_column.py
load_from_file(bv_file, nt_file, vector_type)
Create a Succinct_column from the files produced by the store_to_file() function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bv_file |
str
|
The path to the file that will store the bitvector. |
required |
nt_file |
str or Reader
|
The file in which nucleotides will be read. |
required |
vector_type |
type
|
The type of vector to load. |
required |
The inner attributes have been altered according to the content of the files
succinct_column.py
nt_counts()
Returns the counts of each nucleotide in the column.
Returns:
Type | Description |
---|---|
dict
|
the counts of each nucleotide/symbol existing in the column |
succinct_column.py
nt_frequency()
Returns the percentage of each nucleotide in the column.
Returns:
Type | Description |
---|---|
dict
|
the percentage of each nucleotide/symbol existing in the column |
succinct_column.py
nt_pos()
Get the start and end positions of each run of nucleotides
Returns:
Type | Description |
---|---|
dict
|
keys are existing nucleotides and values are a list of tuples with start and end positions (inclusive) |
succinct_column.py
size_in_bytes()
Return the size in bytes of the pysdsl vector representing the column of nucleotides.
Returns:
Type | Description |
---|---|
int
|
The size in bytes of the pysdsl vector representing the column of nucleotides |
succinct_column.py
store_to_file(bv_file, nt_file)
Store the SDVector and the nucleotides in two files. Do not use if the bit vector is represented by a pysdsl.BitVector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bv_file |
str
|
The path to the file that will store the bitvector. |
required |
nt_file |
str or Writer
|
The file in which nucleotides will be written. |
required |
succinct_column.py