This is a test version of Biostars. For the public version, visit https://www.biostars.org.
EC number regular expression

Has anyone posted a regular expression for EC numbers? I think this should work but I'm not 100% sure.

/\(EC (\d+(\.n?[\d\-]+){3})\)/

I also found this other page but it doesn't actually post a comprehensive regular expression for ECs. http://www.enzyme-database.org/regex.php

ec regular-expression enzyme-catalogue perl

2 answers

Looks good. Any examples where the EC number might contain a '-' or an 'n'?

Also, if I might suggest a change that matches the entire EC hierarchy:

EC\d{1,2}(\.\d{0,2}){0,3}

(Add in the '-' and the 'n' if necessary)

I think that this regex implies that EC numbers can have fewer than four tiers, but if I run that regex, it is going to match against literally any number. Therefore maybe it should be changed from {0,3} to {3}:

\d{1,2}(\.\d{1,2}){3}

And then to show that each site is either a dash or 1 or 2 digits (sorry, I don't have an example right now but I'm sure it exists for dashes)

\d{1,2}(\.(\-|\d{1,2})){3}

How does that look? I took out the EC because I found examples in my text where EC doesn't exist.

Oh, the EC is optional in your data! Boy are we gonna wade through a bunch of false positives!

The diff between our regexes is that while mine matches the entire hierarchy, including the roots (like "EC2"), yours necessitates all levels in the hierarchy. But if the data has only full EC numbers, your Regex does the job better than mine.

I googled a bit but never encountered any EC number that used a '-', but it can surely be included.

I was parsing some KEGG descriptors and found this to the most useful:

# this is python
import re
query='homoserine dehydrogenase [EC:1.1.1.3]'
def f(x):
    pattern = "(\[EC:)(\d+.)(\d+.)(\d+.)(\d+])"
    match = re.search(pattern, x)
    if match is not None:
        return "".join(match.groups())[1:-1]

f(query)
# 'EC:1.1.1.3'

Log in to answer this question.