开发者

Count pattern matches in paragraphs separated by empty lines in Python

I want to count matches in rows that have a pattern TRP or PHE or MET - I need to count it per paragraph (separated by empty lines). Then I would like to calculate the percentage of the matches by dividing the matches count by the number of lines in each paragraph. Is there a quick python solution for this?

My input looks like:

THR 61  65.21
LEU 62  63.85
PRO 63  54.61
LEU 64  50.74
ALA 65  57.40
PRO 66  56.49
ASP 67  56.77
PRO 68  55.94
TYR 69  56.06
PRO 70  56.55
GLY 71  57.74
HIS 72  55.69
ASN 73  64.70
PRO 74  65.70
        
ASP 42开发者_Python百科2 65.05
SER 423 53.19
SER 424 45.39
ARG 425 47.80
ALA 426 48.84
ARG 427 46.19
ALA 428 46.81
SER 429 51.64
GLY 430 56.53
GLY 431 69.14
        
ASP 471 59.01
VAL 472 51.82
ASP 473 52.63
GLN 474 45.86
LEU 475 44.30
SER 476 45.83
LEU 477 45.78
THR 478 37.91
PRO 479 44.77
VAL 480 41.47
VAL 481 46.86
PRO 482 46.12
GLY 483 46.38
PRO 484 49.42
PRO 485 57.74

I tried with awk but it is too hard...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜