Search code examples
pythonregexfindall

Extract word uptill certain symbol


Hi I have this uniprot gff data that looks like

+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+
| Entry  | check  | start | end  |                                               Domains                                               |
+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+
| O75581 | Repeat |    63 |  106 |  Note=LDL-receptor class B 1                                                                         |
| O75581 | Repeat |   150 |  193 |  Note=LDL-receptor class B 3                                                                         |
| O75581 | Domain |   282 |  324 |  Note=EGF-like 1                                                                                     |
| O75581 | Domain |  1248 | 1286 |  Note=LDL-receptor class A 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| O75581 | Domain |  1287 | 1323 |  Note=LDL-receptor class A 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| O75581 | Domain |  1325 | 1361 |  Note=LDL-receptor class A 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00124 |
| P13688 | Domain |    35 |  142 |  Note=Ig-like V-type;Ontology_term=ECO:0000250;evidence=ECO:0000250|UniProtKB:P31997                 |
| P13688 | Domain |   145 |  232 |  Note=Ig-like C2-type 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P13688 | Domain |   237 |  317 |  Note=Ig-like C2-type 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P13688 | Domain |   323 |  413 |  Note=Ig-like C2-type 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00114      |
| P19022 | Domain |   160 |  267 |  Note=Cadherin 1;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| P19022 | Domain |   268 |  382 |  Note=Cadherin 2;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| P19022 | Domain |   383 |  497 |  Note=Cadherin 3;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00043             |
| Q13586 | Domain |   132 |  200 |  Note=SAM;Ontology_term=ECO:0000255;evidence=ECO:0000255|PROSITE-ProRule:PRU00184                    |
| P04629 | Repeat |    90 |  113 |  Note=LRR 1                                                                                          |
| P04629 | Repeat |   116 |  137 |  Note=LRR 2                                                                                          |
+--------+--------+-------+------+------------------------------------------------------------------------------------------------------+

I am trying to extract the domain names column df['Domains]. With the following code, I am close to getting the first 2 3 words of the domain name but doesn't work universally.

for row in df['Domains']:
    print(re.findall(r'Note=(\w*)(.?)(\w*)', row))

which gives something like this

[('LDL', '-', 'receptor')]
[('LDL', '-', 'receptor')]
[('EGF', '-', 'like')]
[('Ig', '-', 'like')]
[('Ig', '-', 'like')]`

So, I wish to change my approach and get everything starting after Note= and ends before ; or end of line. How may I get this?


Solution

  • Could you please try following.

    for row in df['Domains']:
        print(re.findall(r'Note=([^;]*)', row))