Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick speedup in loading/model_loading.py #15

Closed
psalvy opened this issue Jan 21, 2015 · 0 comments
Closed

Quick speedup in loading/model_loading.py #15

psalvy opened this issue Jan 21, 2015 · 0 comments

Comments

@psalvy
Copy link

psalvy commented Jan 21, 2015

Hi there,

I just realized the way compartments were being uploaded is quite unefficient:

def loadCompartments(self, modellist, session):
    for model in modellist:
        for component in model.metabolites:
            if component.id is not None:
                if not session.query(Compartment).filter(Compartment.name == component.id[-1:len(component.id)]).count():
                    compartmentObject = Compartment(name = component.id[-1:len(component.id)])
                    session.add(compartmentObject)

This syntax generates ~1000 transactions, which takes around 5-10s
Since the number of compartments is supposedly reduced, I believe this approach might be better:

def loadCompartments(self, modellist):
        compartments_all = set()
        for model in modellist:
            for component in model.metabolites:
                if component.id is not None:
                        compartments_all.add(component.id[-1])
            for symbol in compartments_all:
                if not self.session.query(Compartment).filter(Compartment.symbol == symbol).count():
                    compartmentObject = Compartment(symbol = symbol)
                    self.session.add(compartmentObject)

This generates only as much transactions as there are compartments in a model (usually 3-5).

Anyway, it's only a static 5-10s of speed up, but over time it adds up to a lot if you do intensive testing. And it is also less stringent on your DB, if you're the DB-happiness-caring type like I am.

Best,

Pierre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants