NDPLZGraph Class
NDPLZGraph
Bases: LZGraphBase
This class implements the logic and infrastructure of the "Nucleotide Double Positional" version of the LZGraph The nodes of this graph are LZ sub-patterns with added reading frame start position and the start position in the sequence, formally: {lz_subpattern}{reading frame start}_{start position in sequence}, This class best fits analysis and inference of nucleotide sequences.
...
Args:
walk_probability(walk,verbose=True): returns the PGEN of the given walk (list of sub-patterns)
is_dag(): the function checks whether the graph is a Directed acyclic graph
walk_genes(walk,dropna=True): give a walk on the graph (a list of nodes) the function will return a table representing the possible genes and their probabilities at each edge of the walk.
path_gene_table(cdr3_sample,threshold=None): the function will return two tables of all possible v and j genes that colud be used to generate the sequence given by "cdr3_sample"
path_gene_table_plot(threshold=None,figsize=None): the function plots two heatmap, one for V genes and one for J genes, and represents the probability at each edge to select that gene, the color at each cell is equal to the probability of selecting the gene, a black cell means that the graph didn't see that gene used with that sub-pattern.
the data used to create the charts can be derived by using the "path_gene_table" method.
gene_variation(cdr3): given a sequence, this will derive a charts that shows the number of V and J genes observed per node (LZ- subpattern).
gene_variation_plot(cdr3): Plots the data derived at the "gene_variation" method as two bar charts overlayed, one for V gene count and one for J gene count.
random_walk(steps): given a number of steps (sub-patterns) returns a random walk on the graph between a random inital state to a random terminal state in the given number of steps
gene_random_walk(seq_len, initial_state): given a target sequence length and an initial state, the function will select a random V and a random J genes from the observed gene frequency in the graph's "Training data" and generate a walk on the graph from the initial state to a terminal state while making sure at each step that both the selected V and J genes were seen used by that specific sub-pattern.
unsupervised_random_walk(): a random initial state and a random terminal state are selected and a random unsupervised walk is carried out until the randomly selected terminal state is reached.
eigenvector_centrality(): return the eigen vector centrality value for each node (this function is used as the feature extractor for the LZGraph)
sequence_variation_curve(cdr3_sample): given a cdr3 sequence, the function will calculate the value of the variation curve and return 2 arrays, 1 of the sub-patterns and 1 for the number of out neighbours for each sub-pattern
graph_summary(): the function will return a pandas DataFrame containing the graphs Chromatic Number,Number of Isolates,Max In Deg,Max Out Deg,Number of Edges
Attributes:
nodes:
returns the nodes of the graph
edges:
return the edges of the graph
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
|
__init__(data, verbose=True, calculate_trainset_pgen=False)
:param data: a padnas dataframe with 1 mandatory column "cdr3_rearrangement" which is all the cdr3 neuclitode sequences , optinaly genes can be added to graph for gene inference via adding a "V" and "J" column :param verbose: :param dictionary:
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
clean_node(base)
staticmethod
given a sub-pattern that has reading frame and position added to it, cleans it and returns only the nucleotides from the string
Parameters:
base (str): a node from the NDPLZGraph
Returns:
str : only the nucleotides of the node
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
encode_sequence(cdr3)
staticmethod
given a sequence of nucleotides this function will encode it into the following format: {lz_subpattern}{reading frame start}_{start position in sequence} matching the requirement of the NDPLZGraph.
Parameters:
cdr3 (str): a string to encode into the NDPLZGraph format
Returns:
list : a list of unique sub-patterns in the NDPLZGraph format
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
gene_random_walk(seq_len, initial_state=None, vj_init='marginal')
given a target sequence length and an initial state, the function will select a random V and a random J genes from the observed gene frequency in the graph's "Training data" and generate a walk on the graph from the initial state to a terminal state while making sure at each step that both the selected V and J genes were seen used by that specific sub-pattern.
if seq_len is equal to "unsupervised" than a random seq len will be returned
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
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 |
|
gene_variation(cdr3)
Plots the data derived at the "gene_variation" method as two bar charts overlayed, one for V gene count and one for J gene count. :param cdr3: :return:
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
path_gene_table(cdr3_sample, threshold=None)
the function will return two tables of all possible v and j genes that colud be used to generate the sequence given by "cdr3_sample" :param cdr3_sample: a cdr3 sequence :param threshold: drop genes that are missing from threshold % of the sequence :return:
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
sequence_variation_curve(cdr3_sample)
given a sequence this function will return 2 list, the first is the lz-subpattern path through the graph and the second list is the number of possible choices that can be made at each sub-pattern :param cdr3_sample: :return:
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
unsupervised_random_walk()
a random initial state and a random terminal state are selected and a random unsupervised walk is carried out until the randomly selected terminal state is reached.
Parameters:
None
Returns:
(list,str) : a list of LZ sub-patterns representing the random walk and a string
matching the walk only translated back into a sequence.
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
walk_genes(walk, dropna=True)
give a walk on the graph (a list of nodes) the function will return a table representing the possible genes and their probabilities at each edge of the walk. :param walk: :param dropna: :return:
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
walk_probability(walk, verbose=True)
given a walk (a sequence converted into LZ sub-pattern) return the probability of generation (PGEN) of the walk.
you can use "lempel_ziv_decomposition" from this libraries decomposition module in order to convert a sequence into LZ sub-patterns
Parameters:
walk (list): a list of LZ - sub-patterns
Returns:
float : the probability of generating such a walk (PGEN)
Source code in src\LZGraphs\Graphs\NucleotideDoublePositional.py
derive_lz_reading_frame_position(cdr3)
given a string this function will return the LZ sub-patterns, the reading frame position of each sub-pattern and the start position in the sequence of each sub-patterns in the form of 3 lists.
Parameters:
cdr3 (str): a string from which to derive sub-patterns
Returns:
(list,list,list) : (lz_subpatterns,reading_frame_position,position_in_sequence)