Help improve this workflow!
This workflow has been published but could be further improved with some additional meta data:- Keyword(s) in categories input, output, operation
You can help improve this workflow by suggesting the addition or removal of keywords, suggest changes and report issues, or request to become a maintainer of the Workflow .
Prediction of complementary regions between RNA-RNA contacts derived from RIC-seq data. Developed by Sergei Margasyuk (smargasyuk@gmail.com) and Dmitri Pervouchine (pervouchine@gmail.com).
Description
This package contains a pipeline for
Code Snippets
7 8 9 10 11 | shell: """ cat {input} |\ awk -v 'OFS=\t' '($10>{params.min_support})&&($22>{params.min_support})' |\ awk -v 'OFS=\t' '{{print $1,$15,$2,$13,$6,$17,$7,$8,$9,$10,$19,$20,$21,$22,$11,$12,$25}}' > {output} """ |
23 24 25 26 27 28 29 30 31 32 33 | shell: """ paste <(cut -f1-6 {input.pairs}) {input.pairs} |\ awk -v 'OFS=\t' '($3-$2<={params.max_radius}) && ($3-$2>={params.min_radius})' |\ sort-bed - |\ bedops -n 1 - <(sort-bed {input.rmsk}) |\ cut -f4- |\ awk -v 'OFS=\t' '($3-$2<={params.max_radius}) && ($3-$2>={params.min_radius})' |\ sort-bed - |\ bedops -n 1 - <(sort-bed {input.rmsk}) |\ cut -f 4- > {output} """ |
43 44 45 46 47 48 49 50 51 | shell: """ cat {input.pairs} |\ awk -v 'OFS=\t' '{{print $1,$2,$3,$17,".",$15}}' |\ bedtools getfasta -s -bed stdin -fi {input.genome_fasta} > {output.seq_L} cat {input.pairs} |\ awk -v 'OFS=\t' '{{print $4,$5,$6,$17,".",$15}}' |\ bedtools getfasta -s -bed stdin -fi {input.genome_fasta} > {output.seq_R} """ |
62 63 64 65 66 67 | shell: """ paste <(grep -v '>' {input.seq_L}) <(grep -v '>' {input.seq_R}) |\ grep -v "^$" |\ python workflow/scripts/PrePH/src/fold2.py -e {params.max_energy} -a 8 -u False -j{threads} \ > {output} """ |
77 78 79 80 81 82 83 | shell: """ paste {input.pairs} {input.preph} <(grep -v '>' {input.seq_L}) <(grep -v '>' {input.seq_R}) |\ awk -v 'OFS=\t' '{{gsub(/[\(\)]/, "", $22)}}1' |\ awk -v 'OFS=\t' 'NF==24' |\ awk -v 'OFS=\t' '{{print $1,$2,$6,$17,$10+$14,$15,$2,$6,"0,0,0",2,$3-$2","$6-$5,0","$5-$2,$0}}'|\ sort-bed - > {output} """ |
90 91 92 93 | run: t0 = pd.read_table(str(input), header=None) t3 = postprocess_preph_table(t0) t3.to_csv(str(output.tsv), index=None, sep='\t') |
9 10 11 12 13 14 15 | shell: """ mkdir -p $(dirname {output.starch}) gtfToGenePred {input} {output.gp1} -geneNameAsName2 -ignoreGroupsWithoutExons -genePredExt awk '{{print $12"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11"\t"$12"\t"$13"\t"$14"\t"$15"\t"}}' {output.gp1} > {output.gp2} genePredToBed {output.gp2} {output.bed1} sort-bed {output.bed1} | starch - > {output.starch} """ |
23 24 25 26 27 28 | shell: """ mkdir -p $(dirname {output}) unpigz -c {input} |\ awk -v 'OFS=\t' '{{print $0,"{wildcards.project}","{wildcards.sample}","{wildcards.t}"}}' |\ pigz - > {output} """ |
34 35 36 | shell: """ unpigz -c {input} | pigz - > {output} """ |
44 45 46 47 48 49 50 | shell: """ unpigz -c {input} |\ awk -v 'OFS=\t' '$1==$5' |\ awk -v 'OFS=\t' '{{if ($2>$6){{s1=$2;s2=$3;s3=$4;$2=$6;$3=$7;$4=$8;$6=s1;$7=s2;$8=s3}};print}}' |\ awk -v 'OFS=\t' '$6-$2>{params.min_spread}' |\ pigz > {output} """ |
59 60 61 62 63 64 65 66 67 | shell: """ unpigz -c {input} |\ cut -f1,2,3,5,6,7,11 |\ sort --buffer-size={resources.mem_mb}M --parallel={threads} |\ uniq -c |\ sed -E 's/^ *//; s/ /\t/' |\ awk -v 'OFS=\t' '{{print $2,$3,$4,$5,$6,$7,$8,$1}}' |\ pigz > {output} """ |
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | shell: """ unpigz -c {input} |\ awk -v 'OFS=\t' '{{print $0,$0}}' |\ sort-bed --tmpdir {resources.tmpdir} --max-mem {resources.mem_mb}M - |\ bedtools cluster -d {params.clustering_distance} -i stdin |\ cut -f 4- |\ sort-bed --tmpdir {resources.tmpdir} --max-mem {resources.mem_mb}M - |\ bedtools cluster -d {params.clustering_distance} -i stdin |\ cut -f 6- |\ awk -v 'OFS=\t' '{{print $0,"id_"NR}}' |\ sort --parallel={threads} --buffer-size={resources.mem_mb}M -k9,9 -k10,10 |\ datamash groupby 9,10 first 1 min 2 max 3 first 4 min 5 max 6 unique 7 countunique 7 countunique 11 sum 8 |\ cut -f 3- |\ pigz > {output} """ |
100 101 102 103 104 105 | shell: """ unpigz -c {input} |\ awk -v 'OFS=\t' '{{print $1,$2,$6,".", ".", "+",$0}}' |\ sort-bed --tmpdir {resources.tmpdir} --max-mem {resources.mem_mb}M - |\ starch - > {output} """ |
114 115 116 117 118 119 120 | shell: """ mkdir -p $(dirname {output}) bedmap --chrom {wildcards.chrom} --fraction-ref 1 --echo --echo-map --delim "\t" --multidelim "\t" --skip-unmapped {input.contacts} {input.annotation} |\ awk -v "OFS=\t" '{{$17=$22;$18=$20; print $0}}' | cut -f7-18 |\ awk -v "OFS=\t" '{{print $0,"id_"NR}}' |\ pigz > {output} """ |
126 127 128 129 130 131 | shell: """ mkdir -p $(dirname {output}) unpigz -c {input} |\ awk -v 'OFS=\t' '{{print $1,$2,$3,$13}}' |\ sort-bed - > {output} """ |
137 138 139 140 141 142 | shell: """ mkdir -p $(dirname {output}) unpigz -c {input} |\ awk -v 'OFS=\t' '{{print $4,$5,$6,$13}}' |\ sort-bed - > {output} """ |
151 152 153 154 155 | shell: """ mkdir -p $(dirname {output}) cat {input} |\ awk -v 'OFS=\t' '{{$2=$3+{params.min_radius};$3=$3+{params.max_radius};print $0}}' | sort-bed - > {output} """ |
164 165 166 167 168 | shell: """ mkdir -p $(dirname {output}) cat {input} |\ awk -v 'OFS=\t' '{{$3=$2-{params.min_radius};$2=$2-{params.max_radius};print $0}}' | sort-bed - > {output} """ |
179 180 181 182 183 184 185 186 187 | shell: """ mkdir -p $(dirname {output}) intersectBed -wa -wb -sorted \ -a {input.handles} \ -b {input.windows} |\ awk -v 'OFS=\t' '{{print "{wildcards.chrom}_"$4"_"$8,$4,$8}}' |\ sort --parallel={threads} --buffer-size={resources.mem_mb}M -T $TEMPDIR |\ pigz - > {output} """ |
195 196 197 198 | shell: """ mkdir -p $(dirname {output}) comm -12 <(unpigz -c {input.left}) <(unpigz -c {input.right}) | awk -v 'OFS=\t' '$2!=$3' > {output} """ |
208 209 210 211 212 | shell: """ mkdir -p $(dirname {output}) join -1 2 -2 13 -t$'\t' <(sort -k2,2 {input.pairs}) <(unpigz -c {input.contacts} | sort -k13,13) > {output.l} join -1 3 -2 13 -t$'\t' <(sort -k3,3 {output.l}) <(unpigz -c {input.contacts} | sort -k13,13) | cut -f 4- > {output.r} """ |
218 219 220 | shell: """ awk -v 'OFS=\t' '{{print $0,"id_"NR}}' {input} > {output} """ |
8 9 10 11 12 | run: for f1, f2 in zip(input["pipeline_out"], input["ref_out"]): if not filecmp.cmp(f1, f2, shallow = False): print(f"Files {f1} and {f2} are different") raise ValueError |
3 4 5 6 7 8 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 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 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | from numpy import ( argmin, unravel_index, full, empty, load, set_printoptions, argwhere, argsort, ) from math import ceil import binascii, itertools, sys, getopt, os from functools import partial from sys import getsizeof import sys from multiprocessing import Pool import argparse inf = float("inf") os.chdir(os.path.dirname(os.path.abspath(__file__))) # Dictionary for nts (used in 1x1, 2x1, 2x2 loops in last 2 dims) Dic_nt = {"@": 0, "A": 1, "C": 2, "G": 3, "T": 4} # Dictionary of basepairs (used in 1x1, 2x1, 2x2 loops in first 2 dims) Dic_bp = {"CG": 0, "GC": 1, "GT": 2, "TG": 3, "AT": 4, "TA": 5} stacking_matrix = load("../lib//stacking_matrix.npy") bulge_list = load("../lib/bulge_list.npy") intl11_matrix = load("../lib/intl11_matrix.npy") intl12_matrix = load("../lib/intl12_matrix.npy") intl22_matrix = load("../lib/intl22_matrix.npy") # Adding for long bulges TerminalAU = 50 def Seq_to_bin(seq): # Uses bitwise shift to make bin from sequence Dict = {"A": 0b0, "T": 0b10, "G": 0b11, "C": 0b1} s = 0 for char in seq: try: s = s << 2 | Dict[char] except KeyError: s = False return s def Index_seq(seq, k): # Uses bitwise shift to divide bin into kmers seq_bin = Seq_to_bin(seq) if seq_bin is False: return False else: seq_indxd_tmp = [] mask = 2 ** (k * 2) - 1 for i in range(len(seq) - (k - 1)): seq_indxd_tmp.append(mask & seq_bin) seq_bin >>= 2 return seq_indxd_tmp def Initiate_with_kmers( seq, seq_compl, seq_indxd_tmp, seq_compl_indxd_tmp, kmers_stacking_matrix, k ): min_energy = end_pos_i = end_pos_j = start_pos_i = start_pos_j = 0 # seq_indxd_tmp = Index_seq(seq, k=k) # seq_compl_indxd_tmp = Index_seq(seq_compl[::-1], k=k) if (seq_indxd_tmp == False) | (seq_compl_indxd_tmp == False): return ( False, False, False, False, False, False, False, False, False, False, False, False, False, ) else: seq_length = len(seq) seq = seq + "$" * (k + 2) # (horizontally) _ seq_compl = "$" * (k + 2) + seq_compl # (vertically) | seq_compl_length = len(seq_compl) D = full((len(seq_compl), len(seq)), inf) # distance matrix zero_coords = empty((), dtype=object) zero_coords[()] = (0, 0) B = full( (len(seq_compl), len(seq)), zero_coords, dtype=object ) # backtracker matrix S = empty( [len(seq_compl), len(seq)], dtype="S" + str(len(seq) + len(seq_compl)) ) # dot bracket structure matrix for I, kmer_i in enumerate(seq_compl_indxd_tmp): i = seq_compl_length - I - k for J, kmer_j in enumerate(seq_indxd_tmp): j = seq_length - J - 1 D[i][j] = kmers_stacking_matrix[kmer_j, kmer_i] if D[i][j] != inf: B[i][j] = (i + k - 1, j - k + 1) S[i][j] = "(" * k + ")" * k if D[i][j] < min_energy: min_energy = D[i][j] end_pos_i = i end_pos_j = j start_pos_i = i + k - 1 start_pos_j = j - k + 1 return ( D, B, S, min_energy, end_pos_i, end_pos_j, start_pos_i, start_pos_j, seq_indxd_tmp, seq_compl_indxd_tmp, seq_length, seq_compl_length, seq, seq_compl, ) def End_coords(argmin_, i, j, old_end_pos_i, old_end_pos_j, k=3): Dict_end_coords = { 1: (-1, +1), 2: (-k, +1 + k), 3: (-1 - k, k), 4: (-k, +2 + k), 5: (-2 - k, k), 6: (-1 - k, +1 + k), 7: (-1 - k, +2 + k), 8: (-2 - k, +1 + k), 9: (-2 - k, +2 + k), } if argmin_ == 0: return (old_end_pos_i, old_end_pos_j) else: add_i, add_j = Dict_end_coords[argmin_] return (i + add_i, j + add_j) def Start_coords(argmin_, backtrack, old_start_pos_i, old_start_pos_j): if argmin_ == 0: return (old_start_pos_i, old_start_pos_j) else: return (backtrack[0], backtrack[1]) def Backtrack(argmin_, old_coords, new_coords): if argmin_ == 0: return (0, 0) elif argmin_ == 1: return old_coords else: return new_coords def Check_ranges_overlap(x1, x2, y1, y2): return (x1 < y2) & (y1 < x2) # segment1[start[i,j],end[i,j]], segment2 - part of the square [start[i,j],end[i,j]] def Check_segments_intersection(segment1, segment2, slope): a1 = float(-segment1[0][0] + segment1[1][0]) / (segment1[0][1] - segment1[1][1]) b1 = -segment1[0][0] - a1 * segment1[0][1] if slope == "v": # check vertical if segment1[0][1] <= segment2[0][1] & segment2[1][1] <= segment1[1][1]: intersection_i = -(a1 * segment2[0][1] + b1) if (intersection_i > min(segment1[0][0], segment2[0][0])) | ( intersection_i < max(segment1[1][0], segment2[1][0]) ): return False # intersection is out of bound return (int(intersection_i), segment2[0][1]) else: return False # check horizontal elif segment1[0][0] >= segment2[0][0] & segment2[1][0] >= segment1[1][0]: intersection_j = (-segment2[0][0] - b1) / a1 if (intersection_j < max(segment1[0][1], segment2[0][1])) | ( intersection_j > min(segment1[1][1], segment2[1][1]) ): return False # intersection is out of bound return (segment2[0][0], int(intersection_j)) else: return False def FindMinEnLocAlkmer( seq, seq_compl, seq_indxd, seq_compl_indxd, k, energy_threshold, handle_length_threshold, need_suboptimal, kmers_stacking_matrix, ): if (seq_indxd == False) | (seq_compl_indxd == False): return 0 else: seq_indxd_tmp = seq_indxd[:] seq_compl_indxd_tmp = seq_compl_indxd[:] ( D, B, S, min_energy, end_pos_i, end_pos_j, start_pos_i, start_pos_j, seq_indxd_tmp, seq_compl_indxd_tmp, seq_length, seq_compl_length, seq, seq_compl, ) = Initiate_with_kmers( seq, seq_compl, seq_indxd_tmp, seq_compl_indxd_tmp, kmers_stacking_matrix, k ) only_optimal = True if (min_energy != 0) & (seq != False): only_optimal = False alignments = [] seq_indxd_tmp.extend([kmers_stacking_matrix.shape[0] - 1] * (k + 2)) seq_compl_indxd_tmp.extend([kmers_stacking_matrix.shape[0] - 1] * (k + 2)) # go through matrices and fill them in for i in range(len(seq_compl) - k, k + 2, -1): I = seq_compl_length - k - i for j in range(k - 1, len(seq) - k - 3): J = seq_length - j - 1 if D[i][j] != inf and D[i][j] != 0: # found kmer stacking S_head = S[i][j][: S[i][j].find(")")] S_tail = S[i][j][S[i][j].find(")") :] # stem new_en = ( D[i][j] + stacking_matrix[ Dic_bp.get(seq_compl[i - 1] + seq[j + 1], 6) ][Dic_bp.get(seq[j] + seq_compl[i], 6)] ) argmin_ = argmin([0, D[i - 1][j + 1], new_en]) B[i - 1][j + 1] = Backtrack(argmin_, B[i - 1][j + 1], B[i][j]) D[i - 1][j + 1] = [0, D[i - 1][j + 1], new_en][argmin_] S[i - 1][j + 1] = [ "*", S[i - 1][j + 1], S_head + "()" + S_tail, ][argmin_] # bulge01 (seq has 1 more nt) new_en = ( D[i][j] + bulge_list[1] + stacking_matrix[ Dic_bp.get(seq_compl[i - 1] + seq[j + 2], 6) ][Dic_bp.get(seq[j] + seq_compl[i], 6)] + kmers_stacking_matrix[ seq_indxd_tmp[J - 1 - k], seq_compl_indxd_tmp[I + k] ] ) argmin_ = argmin([0, D[i - k][j + 1 + k], new_en]) B[i - k][j + 1 + k] = Backtrack( argmin_, B[i - k][j + 1 + k], B[i][j] ) D[i - k][j + 1 + k] = [0, D[i - k][j + 1 + k], new_en][argmin_] S[i - k][j + 1 + k] = [ "*", S[i - k][j + 1 + k], S_head + "." + "(" * k + ")" * k + S_tail, ][argmin_] # bulge10 (seq_compl has 1 more nt) new_en = ( D[i][j] + bulge_list[1] + stacking_matrix[ Dic_bp.get(seq_compl[i - 2] + seq[j + 1], 6) ][Dic_bp.get(seq[j] + seq_compl[i], 6)] + kmers_stacking_matrix[ seq_indxd_tmp[J - k], seq_compl_indxd_tmp[I + 1 + k] ] ) argmin_ = argmin([0, D[i - 1 - k][j + k], new_en]) B[i - 1 - k][j + k] = Backtrack( argmin_, B[i - 1 - k][j + k], B[i][j] ) D[i - 1 - k][j + k] = [0, D[i - 1 - k][j + k], new_en][argmin_] S[i - 1 - k][j + k] = [ "*", S[i - 1 - k][j + k], S_head + "(" * k + ")" * k + "." + S_tail, ][argmin_] # bulge 02 new_en = ( D[i][j] + bulge_list[2] + ( TerminalAU if Dic_bp.get(seq_compl[i - 1] + seq[j + 3], 6) > 1 or Dic_bp.get(seq[j] + seq_compl[i], 6) > 1 else 0 ) + kmers_stacking_matrix[ seq_indxd_tmp[J - 2 - k], seq_compl_indxd_tmp[I + k] ] ) argmin_ = argmin([0, D[i - k][j + 2 + k], new_en]) B[i - k][j + 2 + k] = Backtrack( argmin_, B[i - k][j + 2 + k], B[i][j] ) D[i - k][j + 2 + k] = [0, D[i - k][j + 2 + k], new_en][argmin_] S[i - k][j + 2 + k] = [ "*", S[i - k][j + 2 + k], S_head + ".." + "(" * k + ")" * k + S_tail, ][argmin_] # bulge 20 new_en = ( D[i][j] + bulge_list[2] + ( TerminalAU if Dic_bp.get(seq_compl[i - 3] + seq[j + 1], 6) > 1 or Dic_bp.get(seq[j] + seq_compl[i], 6) > 1 else 0 ) + kmers_stacking_matrix[ seq_indxd_tmp[J - k], seq_compl_indxd_tmp[I + 2 + k] ] ) argmin_ = argmin([0, D[i - 2 - k][j + k], new_en]) B[i - 2 - k][j + k] = Backtrack( argmin_, B[i - 2 - k][j + k], B[i][j] ) D[i - 2 - k][j + k] = [0, D[i - 2 - k][j + k], new_en][argmin_] S[i - 2 - k][j + k] = [ "*", S[i - 2 - k][j + k], S_head + "(" * k + ")" * k + ".." + S_tail, ][argmin_] # loop11 new_en = ( D[i][j] + intl11_matrix[ Dic_bp.get(seq_compl[i - 2] + seq[j + 2], 7) ][Dic_bp.get(seq[j] + seq_compl[i], 7)][ Dic_nt.get(seq_compl[i - 1], 5) ][ Dic_nt.get(seq[j + 1], 5) ] + kmers_stacking_matrix[ seq_indxd_tmp[J - 1 - k], seq_compl_indxd_tmp[I + 1 + k] ] ) argmin_ = argmin([0, D[i - 1 - k][j + 1 + k], new_en]) B[i - 1 - k][j + 1 + k] = Backtrack( argmin_, B[i - 1 - k][j + 1 + k], B[i][j] ) D[i - 1 - k][j + 1 + k] = [0, D[i - 1 - k][j + 1 + k], new_en][ argmin_ ] S[i - 1 - k][j + 1 + k] = [ "*", S[i - 1 - k][j + 1 + k], S_head + "." + "(" * k + ")" * k + "." + S_tail, ][argmin_] # loop12 new_en = ( D[i][j] + intl12_matrix[ Dic_bp.get(seq_compl[i - 2] + seq[j + 3], 7) ][Dic_bp.get(seq[j] + seq_compl[i], 7)][ Dic_nt.get(seq_compl[i - 1], 5) ][ Dic_nt.get(seq[j + 1], 5) ][ Dic_nt.get(seq[j + 2], 5) ] + kmers_stacking_matrix[ seq_indxd_tmp[J - 2 - k], seq_compl_indxd_tmp[I + 1 + k] ] ) argmin_ = argmin([0, D[i - 1 - k][j + 2 + k], new_en]) B[i - 1 - k][j + 2 + k] = Backtrack( argmin_, B[i - 1 - k][j + 2 + k], B[i][j] ) D[i - 1 - k][j + 2 + k] = [0, D[i - 1 - k][j + 2 + k], new_en][ argmin_ ] S[i - 1 - k][j + 2 + k] = [ "*", S[i - 1 - k][j + 2 + k], S_head + ".." + "(" * k + ")" * k + "." + S_tail, ][argmin_] # loop21 new_en = ( D[i][j] + intl12_matrix[Dic_bp.get(seq[j] + seq_compl[i], 7)][ Dic_bp.get(seq_compl[i - 3] + seq[j + 2], 7) ][Dic_nt.get(seq[j + 1], 5)][ Dic_nt.get(seq_compl[i - 2], 5) ][ Dic_nt.get(seq_compl[i - 1], 5) ] + kmers_stacking_matrix[ seq_indxd_tmp[J - 1 - k], seq_compl_indxd_tmp[I + 2 + k] ] ) argmin_ = argmin([0, D[i - 2 - k][j + 1 + k], new_en]) B[i - 2 - k][j + 1 + k] = Backtrack( argmin_, B[i - 2 - k][j + 1 + k], B[i][j] ) D[i - 2 - k][j + 1 + k] = [0, D[i - 2 - k][j + 1 + k], new_en][ argmin_ ] S[i - 2 - k][j + 1 + k] = [ "*", S[i - 2 - k][j + 1 + k], S_head + "." + "(" * k + ")" * k + ".." + S_tail, ][argmin_] # loop22 new_en = ( D[i][j] + intl22_matrix[ Dic_bp.get(seq_compl[i - 3] + seq[j + 3], 7) ][Dic_bp.get(seq[j] + seq_compl[i], 7)][ Dic_nt.get(seq_compl[i - 2], 5) ][ Dic_nt.get(seq_compl[i - 1], 5) ][ Dic_nt.get(seq[j + 1], 5) ][ Dic_nt.get(seq[j + 2], 5) ] + kmers_stacking_matrix[ seq_indxd_tmp[J - 2 - k], seq_compl_indxd_tmp[I + 2 + k] ] ) argmin_ = argmin([0, D[i - 2 - k][j + 2 + k], new_en]) B[i - 2 - k][j + 2 + k] = Backtrack( argmin_, B[i - 2 - k][j + 2 + k], B[i][j] ) D[i - 2 - k][j + 2 + k] = [0, D[i - 2 - k][j + 2 + k], new_en][ argmin_ ] S[i - 2 - k][j + 2 + k] = [ "*", S[i - 2 - k][j + 2 + k], S_head + ".." + "(" * k + ")" * k + ".." + S_tail, ][argmin_] # check if found min Energy argmin_ = argmin( [ min_energy, D[i - 1][j + 1], D[i - k][j + 1 + k], D[i - 1 - k][j + k], D[i - k][j + 2 + k], D[i - 2 - k][j + k], D[i - 1 - k][j + 1 + k], D[i - 1 - k][j + 2 + k], D[i - 2 - k][j + 1 + k], D[i - 2 - k][j + 2 + k], ] ) end_pos_i, end_pos_j = End_coords( argmin_, i, j, end_pos_i, end_pos_j, k=k ) start_pos_i, start_pos_j = Start_coords( argmin_, B[i][j], start_pos_i, start_pos_j ) min_energy = [ min_energy, D[i - 1][j + 1], D[i - k][j + 1 + k], D[i - 1 - k][j + k], D[i - k][j + 2 + k], D[i - 2 - k][j + k], D[i - 1 - k][j + 1 + k], D[i - 1 - k][j + 2 + k], D[i - 2 - k][j + 1 + k], D[i - 2 - k][j + 2 + k], ][argmin_] # save optimal structure if ( (min_energy / 100.0 <= energy_threshold) & (end_pos_j - start_pos_j + 1 >= handle_length_threshold) & (start_pos_i - end_pos_i + 1 >= handle_length_threshold) ): alignments.append( ( min_energy / 100, start_pos_j, end_pos_j, end_pos_i - k - 2, start_pos_i - k - 2, seq[start_pos_j : end_pos_j + 1], seq_compl[end_pos_i : start_pos_i + 1], S[end_pos_i, end_pos_j], ) ) if (only_optimal == False) & (need_suboptimal == True): min_energy_potential = 0 while True: # LOOK FOR SUBOPTIMAL STRUCTURES ## put zeros in square from start to end of the best alignment len_zero_i = start_pos_i - end_pos_i + 1 len_zero_j = end_pos_j - start_pos_j + 1 zero_matrix_D = full((len_zero_i, len_zero_j), 0) D[ end_pos_i : start_pos_i + 1, start_pos_j : end_pos_j + 1 ] = zero_matrix_D ## find next suboptimal structure argmin_ = D.argmin() end_pos_i_potential, end_pos_j_potential = unravel_index( argmin_, D.shape ) start_pos_i_potential, start_pos_j_potential = Start_coords( 1, B[end_pos_i_potential][end_pos_j_potential], 0, 0 ) min_energy_potential = D[end_pos_i_potential][ end_pos_j_potential ] ## check it's energy is higher than threshold if min_energy_potential / 100.0 > energy_threshold: break ## check it doesn't overlap any previous alignments overlap = False for alignment in alignments: start_pos_j = alignment[1] end_pos_j = alignment[2] + k + 2 end_pos_i = alignment[3] start_pos_i = alignment[4] + k + 2 if Check_ranges_overlap( start_pos_j, end_pos_j, start_pos_j_potential, end_pos_j_potential, ) & Check_ranges_overlap( end_pos_i_potential, start_pos_i_potential, end_pos_i, start_pos_i, ): overlap = True break ## if it overlaps, delete it from D matrix if overlap: D[end_pos_i_potential][end_pos_j_potential] = 0 ## if it doesn't overlap, save the suboptimal structure else: min_energy = min_energy_potential start_pos_i = start_pos_i_potential end_pos_i = end_pos_i_potential start_pos_j = start_pos_j_potential end_pos_j = end_pos_j_potential if ( end_pos_j - start_pos_j + 1 >= handle_length_threshold ) & ( start_pos_i - end_pos_i + 1 >= handle_length_threshold ): # check the al is long enough alignments.append( ( min_energy / 100, start_pos_j, end_pos_j, end_pos_i - k - 2, start_pos_i - k - 2, seq[start_pos_j : end_pos_j + 1], seq_compl[end_pos_i : start_pos_i + 1], S[end_pos_i, end_pos_j], ) ) return alignments else: return 0 else: return 0 def process_pair( seq, seq_compl, k, energy_threshold, handle_length_threshold, need_suboptimal, kmers_stacking_matrix, ): seq_indxd = Index_seq(seq, k) seq_compl_indxd = Index_seq(seq_compl, k) res = FindMinEnLocAlkmer( seq, seq_compl, seq_indxd, seq_compl_indxd, k, energy_threshold, handle_length_threshold, need_suboptimal, kmers_stacking_matrix, ) return res def process_pair_full(args): res = process_pair(*args) if res != 0: res = [str(el) for el in res[0]] res_fmt = "\t".join( [ res[7], res[1] + "," + res[2], ":", res[3] + "," + res[4], "(" + res[0] + ")", ] ) return res_fmt else: return "" def main(argv): parser = argparse.ArgumentParser(description="Process some integers.") parser.add_argument("-k", "--k", dest="k", type=int, default=5, help="kmer_length") parser.add_argument( "-a", "--handle_len_min", dest="handle_length_threshold", type=int, default=10, help="handle_len_min", ) parser.add_argument( "-e", "--energy_max", dest="energy_threshold", type=float, default=-15, help="energy_max, kcal/mol", ) parser.add_argument( "-u", "--need_subopt", dest="need_suboptimal", type=bool, default=True, help="need_subopt", ) parser.add_argument( "-d", "--gt_threshold", dest="GT_threshold", type=int, default=2, help="gt_threshold", ) parser.add_argument( "-j", dest="nproc", type=int, default=4, help="number of processes", ) args = parser.parse_args() kmers_stacking_matrix = load( "../data/" + str(args.k) + str(args.GT_threshold) + "mers_stacking_energy_binary.npy" ) pool = Pool(args.nproc) pairs = [line.strip().split("\t") for line in sys.stdin if line.strip()] content = [ ( pair[0], pair[1], args.k, args.energy_threshold, args.handle_length_threshold, args.need_suboptimal, kmers_stacking_matrix, ) for pair in pairs ] for r in pool.map(process_pair_full, content): print(r) if __name__ == "__main__": main(sys.argv[1:]) |
Support
Do you know this workflow well? If so, you can
request seller status , and start supporting this workflow.
Created: 1yr ago
Updated: 1yr ago
Maitainers:
public
URL:
https://github.com/smargasyuk/PHRIC
Name:
phric
Version:
1
Downloaded:
0
Copyright:
Public Domain
License:
None
- Future updates
Related Workflows

ENCODE pipeline for histone marks developed for the psychENCODE project
psychip pipeline is an improved version of the ENCODE pipeline for histone marks developed for the psychENCODE project.
The o...

Near-real time tracking of SARS-CoV-2 in Connecticut
Repository containing scripts to perform near-real time tracking of SARS-CoV-2 in Connecticut using genomic data. This pipeli...

snakemake workflow to run cellranger on a given bucket using gke.
A Snakemake workflow for running cellranger on a given bucket using Google Kubernetes Engine. The usage of this workflow ...

ATLAS - Three commands to start analyzing your metagenome data
Metagenome-atlas is a easy-to-use metagenomic pipeline based on snakemake. It handles all steps from QC, Assembly, Binning, t...
raw sequence reads
Genome assembly
Annotation track
checkm2
gunc
prodigal
snakemake-wrapper-utils
MEGAHIT
Atlas
BBMap
Biopython
BioRuby
Bwa-mem2
cd-hit
CheckM
DAS
Diamond
eggNOG-mapper v2
MetaBAT 2
Minimap2
MMseqs
MultiQC
Pandas
Picard
pyfastx
SAMtools
SemiBin
Snakemake
SPAdes
SqueezeMeta
TADpole
VAMB
CONCOCT
ete3
gtdbtk
h5py
networkx
numpy
plotly
psutil
utils
metagenomics

RNA-seq workflow using STAR and DESeq2
This workflow performs a differential gene expression analysis with STAR and Deseq2. The usage of this workflow is described ...

This Snakemake pipeline implements the GATK best-practices workflow
This Snakemake pipeline implements the GATK best-practices workflow for calling small germline variants. The usage of thi...