Esempio n. 1
0
    def find_by_location(self, location, return_one=True, require_hit=True):
        '''

        TODO: Deal with whether to have a return one flag or always return
        an array. To accept a solution as a query or to require a naked location.
        I prefer to be able to have as much of the logic that is repeated
        across different protocols handled by the underlying framework and thus
        favor find(solution, by="location") or find(solution, by="components")
        over location=sample['container']['location'];
        find_by_location(location)[0].

        '''

        print location

        hits = list(self.db.find({'container.location': location}))
        if len(hits) > 1:
            print 'Found more than one DB entry for location query.'
            print 'Theres probably something wrong with your database.'
        hit = hits[0]

        if require_hit and (len(hits) == 0):
            raise Exception(
                'Did not find DB hit for query with require_hit enabled.')

        stripped = strip_internal(hit)
        s = Solution(**stripped)
        s.update_units()  # Note - this will fail if the thing being passed in
        # has a dna concentration of unknown or string None...
        return s
Esempio n. 2
0
    def find_by_location(self, location, return_one=True, require_hit=True):
        '''

        TODO: Deal with whether to have a return one flag or always return
        an array. To accept a solution as a query or to require a naked location.
        I prefer to be able to have as much of the logic that is repeated
        across different protocols handled by the underlying framework and thus
        favor find(solution, by="location") or find(solution, by="components")
        over location=sample['container']['location'];
        find_by_location(location)[0].

        '''

        print location

        hits = list(self.db.find({'container.location': location}))
        if len(hits) > 1:
            print 'Found more than one DB entry for location query.'
            print 'Theres probably something wrong with your database.'
        hit = hits[0]

        if require_hit and (len(hits) == 0):
            raise Exception('Did not find DB hit for query with require_hit enabled.')

        stripped = strip_internal(hit)
        s = Solution(**stripped)
        s.update_units() # Note - this will fail if the thing being passed in
        # has a dna concentration of unknown or string None...
        return s
Esempio n. 3
0
class Reaction(object):
    '''An individual reaction, which may be composed of multiple sub-reactions.
    '''

    def __init__(self, reactions=None, module=None, inputs=None, outputs=None,
                 solution=None, incubation=None, name=None, meta=None,
                 params=None, constraints=None):

        self.reactions = reactions
        self.module = module
        self.inputs = inputs
        self.outputs = outputs
        self.name = name
        self.solution = solution
        self.incubation = incubation
        self.meta = meta
        self.params = params
        self.constraints = constraints

        if (solution is not None) and not isinstance(solution, Solution):
            self.solution = Solution(**solution)
            #print self.solution.components
            if self.solution.components is not None:
                self.solution.update_units()

        if isinstance(reactions, list):

            names = set()

            for i,r in enumerate(reactions):

                assert 'name' in r, 'Each reaction must have a name.'
                assert r['name'] not in names, 'Found two reactions with the same name.'
                names.add(r['name'])
                self.reactions[i] = Reaction(**r)

        if params is not None:
            self.params = make_dottable_dict(params)

        if inputs is not None:
            if not isinstance(inputs, list):
                inputs = [inputs]
            for i, ipt in enumerate(inputs):
                assert isinstance(ipt, dict), 'Reaction object tried to load an input but was passed something other than a dict: ' + str(ipt)
                assert ('container' in ipt) and ('location' in ipt['container']), 'an input must have a container and location'

    def named(self, name):

        if isinstance(self.reactions, list):

            for i,r in enumerate(self.reactions):

                assert hasattr(r, 'name'), 'Found reaction without a name when looking for named reaction.'

                if r.name == name:

                    return r

        return None
Esempio n. 4
0
class Reaction(object):
    '''An individual reaction, which may be composed of multiple sub-reactions.
    '''
    def __init__(self,
                 reactions=None,
                 module=None,
                 inputs=None,
                 outputs=None,
                 solution=None,
                 incubation=None,
                 name=None,
                 meta=None,
                 params=None,
                 constraints=None):

        self.reactions = reactions
        self.module = module
        self.inputs = inputs
        self.outputs = outputs
        self.name = name
        self.solution = solution
        self.incubation = incubation
        self.meta = meta
        self.params = params
        self.constraints = constraints

        if (solution is not None) and not isinstance(solution, Solution):
            self.solution = Solution(**solution)
            #print self.solution.components
            if self.solution.components is not None:
                self.solution.update_units()

        if isinstance(reactions, list):

            names = set()

            for i, r in enumerate(reactions):

                assert 'name' in r, 'Each reaction must have a name.'
                assert r[
                    'name'] not in names, 'Found two reactions with the same name.'
                names.add(r['name'])
                self.reactions[i] = Reaction(**r)

        if params is not None:
            self.params = make_dottable_dict(params)

        if inputs is not None:
            if not isinstance(inputs, list):
                inputs = [inputs]
            for i, ipt in enumerate(inputs):
                assert isinstance(
                    ipt, dict
                ), 'Reaction object tried to load an input but was passed something other than a dict: ' + str(
                    ipt)
                assert ('container' in ipt) and (
                    'location' in ipt['container']
                ), 'an input must have a container and location'

    def named(self, name):

        if isinstance(self.reactions, list):

            for i, r in enumerate(self.reactions):

                assert hasattr(
                    r, 'name'
                ), 'Found reaction without a name when looking for named reaction.'

                if r.name == name:

                    return r

        return None