Module: FlnStats
- Defined in:
- lib/full_lengther_next/classes/fln_stats.rb
Instance Method Summary collapse
- #annotation_stats(size_filter1, size_filter2) ⇒ Object
- #chimera_stats(size_filter1, size_filter2) ⇒ Object
- #html_code ⇒ Object
- #ncrna_stats(size_filter1, size_filter2) ⇒ Object
- #summary_stats ⇒ Object
- #testcode_stats(size_filter1, size_filter2) ⇒ Object
Instance Method Details
#annotation_stats(size_filter1, size_filter2) ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 363 def annotation_stats(size_filter1,size_filter2) seqs_number = 0 array_of_all_accs = [] array_of_complete_accs = [] error_1_num = 0 uni_500 = 0 uni_200 = 0 longest_one = 0 status_array = [] # total, status complete = [0,'Complete'] putative_complete = [0,'Putative Complete'] c_terminus = [0,'C-terminus'] putative_c_terminus = [0,'Putative C-terminus'] n_terminus = [0,'N-terminus'] putative_n_terminus = [0,'Putative N-terminus'] internal = [0,'Internal'] cod_seq = [0,'Misassembled'] #userdb, SwissProt, TrEMBL db_usage = [0,0,0] File.open('fln_results/dbannotated.txt').each do |line| line.chomp! (name,fasta_length,acc,db_name,status,kk1,kk2,kk3,kk4,kk5,msgs) = line.split("\t") if (line !~ /^Query_id\t/) && (!line.empty?) seqs_number += 1 if (fasta_length.to_i > longest_one) longest_one = fasta_length.to_i end array_of_all_accs.push acc if (db_name !~ /^sp_/) && (db_name !~ /^tr_/) db_usage[0] += 1 elsif (db_name =~ /^sp_/) db_usage[1] += 1 elsif (db_name =~ /^tr_/) db_usage[2] += 1 end # ------------------------------------------------------------------------- if (fasta_length.to_i >= size_filter1) uni_200 += 1 end if (fasta_length.to_i >= size_filter2) uni_500 += 1 end # ------------------------------------------------------------------------- if (msgs =~ /ERROR#1/) error_1_num += 1 end # ------------------------------------------------------------------------- if (status == 'Complete') complete[0] += 1 array_of_complete_accs.push acc elsif (status == 'Putative Complete') putative_complete[0] += 1 elsif (status == 'C-terminus') c_terminus[0] += 1 elsif (status == 'N-terminus') n_terminus[0] += 1 elsif (status == 'Putative C-terminus') putative_c_terminus[0] += 1 elsif (status == 'Putative N-terminus') putative_n_terminus[0] += 1 elsif (status == 'Internal') internal[0] += 1 elsif (status == 'Misassembled') cod_seq[0] += 1 end # ------------------------------------------------------------------------- end end status_array = [complete, putative_complete, c_terminus, putative_c_terminus, n_terminus, putative_n_terminus, internal, cod_seq] return [status_array, db_usage, seqs_number, error_1_num, array_of_all_accs.uniq.count, array_of_complete_accs.uniq.count, uni_500, uni_200, longest_one] end |
#chimera_stats(size_filter1, size_filter2) ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 551 def chimera_stats(size_filter1,size_filter2) uni_500 = 0 uni_200 = 0 ch_total = 0 longest_one = 0 db_usage = [0,0,0] if !File.exists?('fln_results/chimeric_sequences.txt') return [0, 0, 0, longest_one, db_usage] else File.open('fln_results/chimeric_sequences.txt').each do |line| line.chomp! if (!line.empty?) (name,fasta_length,acc,db_name,status) = line.split("\t") if (status == 'Putative chimera') if (fasta_length.to_i > longest_one) longest_one = fasta_length.to_i end # ------------------------------------------------------------------------- if (fasta_length.to_i >= size_filter1) uni_200 += 1 end if (fasta_length.to_i >= size_filter2) uni_500 += 1 end # ------------------------------------------------------------------------- if (db_name =~ /^sp_/) db_usage[1] += 1 elsif (db_name =~ /^tr_/) db_usage[2] += 1 else db_usage[0] += 1 end # ------------------------------------------------------------------------- ch_total += 1 end end end db_usage.each_with_index do |db,i| db_usage[i] = db/2 end return [(ch_total/2), (uni_500/2), (uni_200/2), longest_one, db_usage] end end |
#html_code ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 294 def html_code html_head = '<html> <head> <title>FLN Summary</title> </head> <body bgcolor="#FFFFFF"> <center> <h1 align="center"> Full-LengtherNEXT Summary </h1>' html_1 = ' <h2 align="center"> Status report </h2> <table border="2" cellspacing="0" cellpadding="2"> <tr> <th colspan="2">Status</th> <th>Unigenes</th> <th>%</th> </tr>' html_2= ' <h2 align="center"> Unigene report </h2> <table border="2" cellspacing="0" cellpadding="2"> <tr> <th></th> <th>Unigenes</th> <th>%</th> </tr>' html_3= ' <h2 align="center"> Database usage </h2> <table border="2" cellspacing="0" cellpadding="2"> <tr> <th></th> <th>Unigenes</th> <th>%</th> </tr>' html_4= ' <h2 align="center"> Report guiding assembly quality </h2> <table border="2" cellspacing="0" cellpadding="2"> <tr> <th></th> <th>Unigenes</th> <th>%</th> </tr>' html_5 = ' </body> </html>' return [html_head, html_1, html_2, html_3, html_4, html_5] end |
#ncrna_stats(size_filter1, size_filter2) ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 518 def ncrna_stats(size_filter1,size_filter2) uni_500 = 0 uni_200 = 0 nc_total = 0 longest_one = 0 File.open('fln_results/nc_rnas.txt').each do |line| line.chomp! (name,fasta_length,acc,db_name,status) = line.split("\t") if (status == 'Putative ncRNA') if (fasta_length.to_i > longest_one) longest_one = fasta_length.to_i end # ------------------------------------------------------------------------- if (fasta_length.to_i >= size_filter1) uni_200 += 1 end if (fasta_length.to_i >= size_filter2) uni_500 += 1 end # ------------------------------------------------------------------------- nc_total += 1 end end return [nc_total, uni_500, uni_200, longest_one] end |
#summary_stats ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 4 def summary_stats stats_file = File.open('fln_results/summary_stats.html', 'w') size_filter1 = 200 size_filter2 = 500 # recogemos los trozos de html fijos (html_head, html_st, html_uni, html_db, html_as, html_end) = html_code total_seqs = 0 status_suma = 0 #recogemos los datos que necesitamos de los ficheros de resultados (status_array, db_usage, seqs_number1, error_1_num, seq_uniq, complete_uniq, db_uni_500, db_uni_200, db_longest_one) = annotation_stats(size_filter1,size_filter2) (tcode_array, seqs_number2, tc_uni_500, tc_uni_200, tc_longest_one) = testcode_stats(size_filter1,size_filter2) (ncrna_total, nc_uni_500, nc_uni_200, nc_longest_one)=ncrna_stats(size_filter1,size_filter2) (chimera_total, ch_uni_500, ch_uni_200, ch_longest_one, ch_db_usage)=chimera_stats(size_filter1,size_filter2) seqs_number1 = (seqs_number1+chimera_total.to_i) total_seqs = (seqs_number1 + seqs_number2 + ncrna_total.to_i) uni_500 = (db_uni_500 + tc_uni_500 + nc_uni_500 + ch_uni_500) uni_200 = (db_uni_200 + tc_uni_200 + nc_uni_200 + ch_uni_200) longest_one = [db_longest_one, tc_longest_one, nc_longest_one, ch_longest_one].max db_usage[0] += ch_db_usage[0] db_usage[1] += ch_db_usage[1] db_usage[2] += ch_db_usage[2] stats_file.puts html_head if (total_seqs.to_i > 0) # imprimimos la tabla Status Report -------------------------------------------------------------------------------------------- stats_file.puts html_st status_array.each do |status| if (status[1] == 'Internal') || (status[1] == 'Misassembled') stats_file.puts ' <tr> <td colspan="2" align="left">'+status[1].to_s+'</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' elsif (status[1] =~ /^Putative/) stats_file.puts ' <tr> <td align="left">Putative</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' else stats_file.puts ' <tr> <td rowspan="2" align="left">'+status[1].to_s+'</td> <td align="left">Sure</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' end status_suma += status[0] end # adding chimeric seqs stats_file.puts ' <tr> <td colspan="2" align="left">Putative chimera</td> <td align="right">'+chimera_total.to_s+'</td> <td align="right">'+'%.2f' % (100*chimera_total.to_f/total_seqs.to_f).to_s+' %</td> </tr>' status_suma += chimera_total # añadimos los coding, P.coding tcode_array.each do |status| if (status[1] == 'Coding') stats_file.puts ' <tr> <td rowspan="2" align="left">'+status[1].to_s+'</td> <td align="left">Sure</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' elsif (status[1] == 'Putative Coding') stats_file.puts ' <tr> <td align="left">Putative</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' end status_suma += status[0] end # se ponen los ncRNA stats_file.puts ' <tr> <td colspan="2" align="left">Putative ncRNA</td> <td align="right">'+ncrna_total.to_s+'</td> <td align="right">'+'%.2f' % (100*ncrna_total.to_f/total_seqs.to_f).to_s+' %</td> </tr>' status_suma += ncrna_total # se ponen los unknown tcode_array.each do |status| if (status[1] =~ /Unknown/i) stats_file.puts ' <tr> <td colspan="2" align="left">'+status[1].to_s+'</td> <td align="right">'+status[0].to_s+'</td> <td align="right">'+'%.2f' % (100*status[0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' end end #se añade el total stats_file.puts ' <tr> <td colspan="2" align="left">Total</td> <td align="right">'+status_suma.to_s+'</td> <td align="right">'+'%.2f' % (100*status_suma.to_f/total_seqs.to_f).to_s+' %</td> </tr> </table>' # imprimimos la tabla Unigene Report -------------------------------------------------------------------------------------------- new_genes = tcode_array[0][0] + tcode_array[1][0] total_uni = (seqs_number1 + new_genes + ncrna_total + tcode_array[2][0]) stats_file.puts html_uni stats_file.puts ' <tr> <td align="left">With orthologue in DBs</td> <td align="right">'+seqs_number1.to_s+'</td> <td align="right">'+'%.2f' % (100*seqs_number1.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Putative New Genes</td> <td align="right">'+new_genes.to_s+'</td> <td align="right">'+'%.2f' % (100*new_genes.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">ncRNAs</td> <td align="right">'+ncrna_total.to_s+'</td> <td align="right">'+'%.2f' % (100*ncrna_total.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Unknown</td> <td align="right">'+tcode_array[2][0].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[2][0].to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Total</td> <td align="right">'+total_uni.to_s+'</td> <td align="right">'+'%.2f' % (100*total_uni.to_f/total_seqs.to_f).to_s+' %</td> </tr> </table>' # imprimimos la tabla Database Usage -------------------------------------------------------------------------------------------- stats_file.puts html_db db_names=["UserDB", "SwissProt", "TrEMBL"] total_db = 0 for i in 0..db_usage.length-1 do i total_db += db_usage[i] stats_file.puts ' <tr> <td align="left">'+db_names[i].to_s+'</td> <td align="right">'+db_usage[i].to_s+'</td> <td align="right">'+'%.2f' % (100*db_usage[i].to_f/total_seqs.to_f).to_s+' %</td> </tr>' end no_db = seqs_number2 + ncrna_total.to_i stats_file.puts ' <tr> <td align="left">None</td> <td align="right">'+no_db.to_s+'</td> <td align="right">'+'%.2f' % (100*no_db.to_f/total_seqs.to_f).to_s+' %</td> </tr>' total_db += no_db stats_file.puts ' <tr> <td align="left">Total</td> <td align="right">'+total_db.to_s+'</td> <td align="right">'+'%.2f' % (100*total_db.to_f/total_seqs.to_f).to_s+' %</td> </tr> </table>' # imprimimos la tabla Report guiding assembly quality ------------------------------------------------------------- stats_file.puts html_as stats_file.puts ' <tr> <td align="left">Unigenes</td> <td align="right">'+total_seqs.to_s+'</td> <td align="right">'+'%.2f' % (100*total_seqs.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Unigenes >'+size_filter2.to_s+'pb</td> <td align="right">'+uni_500.to_s+'</td> <td align="right">'+'%.2f' % (100*uni_500.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Unigenes >'+size_filter1.to_s+'pb</td> <td align="right">'+uni_200.to_s+'</td> <td align="right">'+'%.2f' % (100*uni_200.to_f/total_seqs.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left">Longest unigene</td> <td align="right">'+longest_one.to_s+'</td> <td align="right">-</td> </tr>' stats_file.puts ' <tr> <td align="left">With orthologue <sup>1</sup></td> <td align="right">'+seqs_number1.to_s+'</td> <td align="right">'+'%.2f' % (100*seqs_number1.to_f/total_seqs.to_f).to_s+' %</td> </tr>' if (seqs_number1.to_i > 0) stats_file.puts ' <tr> <td align="left"> Different orthologue IDs</td> <td align="right">'+seq_uniq.to_s+'</td> <td align="right">'+'%.2f' % (100*seq_uniq.to_f/seqs_number1.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Complete transcripts</td> <td align="right">'+status_array[0][0].to_s+'</td> <td align="right">'+'%.2f' % (100*status_array[0][0].to_f/seqs_number1.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Different complete transcripts</td> <td align="right">'+complete_uniq.to_s+'</td> <td align="right">'+'%.2f' % (100*complete_uniq.to_f/seqs_number1.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Misassembled</td> <td align="right">'+error_1_num.to_s+'</td> <td align="right">'+'%.2f' % (100*error_1_num.to_f/seqs_number1.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Putative chimera</td> <td align="right">'+chimera_total.to_s+'</td> <td align="right">'+'%.2f' % (100*chimera_total.to_f/seqs_number1.to_f).to_s+' %</td> </tr>' end stats_file.puts ' <tr> <td align="left">Without orthologue <sup>1</sup></td> <td align="right">'+no_db.to_s+'</td> <td align="right">'+'%.2f' % (100*seqs_number2.to_f/total_seqs.to_f).to_s+' %</td> </tr>' if (no_db.to_i > 0) && (seqs_number2.to_i > 0) stats_file.puts ' <tr> <td align="left"> Coding (all)</td> <td align="right">'+tcode_array[0][0].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[0][0].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Coding > '+size_filter1.to_s+'bp</td> <td align="right">'+tcode_array[0][2].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[0][2].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Coding > '+size_filter2.to_s+'bp</td> <td align="right">'+tcode_array[0][3].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[0][3].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Putative Coding (all)</td> <td align="right">'+tcode_array[1][0].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[1][0].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Putative Coding > '+size_filter1.to_s+'bp</td> <td align="right">'+tcode_array[1][2].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[1][2].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Putative Coding > '+size_filter2.to_s+'bp</td> <td align="right">'+tcode_array[1][3].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[1][3].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Putative ncRNA</td> <td align="right">'+ncrna_total.to_s+'</td> <td align="right">'+'%.2f' % (100*ncrna_total.to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Unknown (all)</td> <td align="right">'+tcode_array[2][0].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[2][0].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Unknown > '+size_filter1.to_s+'bp</td> <td align="right">'+tcode_array[2][2].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[2][2].to_f/no_db.to_f).to_s+' %</td> </tr>' stats_file.puts ' <tr> <td align="left"> Unknown > '+size_filter2.to_s+'bp</td> <td align="right">'+tcode_array[2][3].to_s+'</td> <td align="right">'+'%.2f' % (100*tcode_array[2][3].to_f/no_db.to_f).to_s+' %</td> </tr>' end stats_file.puts ' </table> <sup>1</sup> Percents for subclassifications of this category were calculated using this line as 100% reference.' end stats_file.puts html_end stats_file.close end |
#testcode_stats(size_filter1, size_filter2) ⇒ Object
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 |
# File 'lib/full_lengther_next/classes/fln_stats.rb', line 448 def testcode_stats(size_filter1,size_filter2) seqs_number = 0 uni_500 = 0 uni_200 = 0 longest_one = 0 # total, status coding_stats = [0,'Coding',0,0] p_coding_stats = [0,'Putative Coding',0,0] unknown_stats = [0,'Unknown',0,0] File.open('fln_results/new_coding.txt').each do |line| line.chomp! (name,fasta_length,acc,db_name,status) = line.split("\t") if (line !~ /^Query_id\t/) && (!line.empty?) seqs_number += 1 if (fasta_length.to_i > longest_one) longest_one = fasta_length.to_i end # ------------------------------------------------------------------------- if (fasta_length.to_i >= size_filter1) uni_200 += 1 end if (fasta_length.to_i >= size_filter2) uni_500 += 1 end # ------------------------------------------------------------------------- if (fasta_length.to_i > size_filter1) if (status == 'coding') coding_stats[2] += 1 elsif (status == 'putative_coding') p_coding_stats[2] += 1 elsif (status == 'unknown') unknown_stats[2] += 1 end end if (fasta_length.to_i > size_filter2) if (status == 'coding') coding_stats[3] += 1 elsif (status == 'putative_coding') p_coding_stats[3] += 1 elsif (status == 'unknown') unknown_stats[3] += 1 end end if (status == 'coding') coding_stats[0] += 1 elsif (status == 'putative_coding') p_coding_stats[0] += 1 elsif (status == 'unknown') unknown_stats[0] += 1 end end end status_array = [coding_stats, p_coding_stats, unknown_stats] return [status_array, seqs_number, uni_500, uni_200, longest_one] end |