Ejemplo n.º 1
0
    def __init__(self, query):
        JobThread.__init__(self)

        self._query = query
        self._ice_client = ICEClient(query['ice']['url'],
                                     query['ice']['username'],
                                     query['ice']['password'],
                                     group_names=query['ice'].get(
                                         'groups', None))

        self._ice_ids = query['ice_ids']
        self._data = {}
Ejemplo n.º 2
0
    def __init__(self, url, username, psswrd, group_names=None):
        self.__ice_client = ICEClient(url, username, psswrd)

        if group_names is None:
            group_names = []

        self.__group_ids = [group_id
                            for name, group_id
                            in self.__ice_client.get_groups().iteritems()
                            if name in group_names]
Ejemplo n.º 3
0
    def setUpClass(cls):
        try:
            std_input = raw_input
        except NameError:
            std_input = input

        ice_url = std_input('ICE url: ')
        username = std_input('ICE username: '******'ICE password: ')
        cls.__ice_client = ICEClient(ice_url, username, password)
Ejemplo n.º 4
0
class BuildGenieBase(JobThread):
    '''Base class for build applications.'''
    def __init__(self, query):
        JobThread.__init__(self)

        self._query = query
        self._ice_client = ICEClient(query['ice']['url'],
                                     query['ice']['username'],
                                     query['ice']['password'],
                                     group_names=query['ice'].get(
                                         'groups', None))

        self._ice_ids = query['ice_ids']
        self._data = {}

    def get_order(self):
        '''Gets a plasmids constituent parts list for ordering.'''
        entries = {}

        for ice_id in self._ice_ids:
            data = self._get_data(ice_id)

            for part in data[0].get_metadata()['linkedParts']:
                data = self._get_data(part['partId'])
                entries[data[1]] = list(data[2:])

        # Format into list of lists:
        return [[key] + entries[key] for key in sorted(entries)]

    def _get_data(self, ice_id):
        '''Gets data from ICE entry.'''
        if ice_id in self._data:
            return self._data[ice_id]

        ice_entry = self._ice_client.get_ice_entry(ice_id)
        metadata = ice_entry.get_metadata()
        data = ice_entry, \
            metadata['partId'], \
            metadata['name'], \
            metadata['type'], \
            ice_entry.get_parameter('Type'), \
            re.sub('\\s*\\[[^\\]]*\\]\\s*', ' ',
                   metadata['shortDescription']).replace(' - ', '_'), \
            ice_entry.get_seq()

        self._data[ice_id] = data

        return data
Ejemplo n.º 5
0
class ICEInterface(object):
    '''Class to inferface with ICE.'''

    def __init__(self, url, username, psswrd, group_names=None):
        self.__ice_client = ICEClient(url, username, psswrd)

        if group_names is None:
            group_names = []

        self.__group_ids = [group_id
                            for name, group_id
                            in self.__ice_client.get_groups().iteritems()
                            if name in group_names]

    def get_dna(self, ice_id):
        '''Gets DNA object from ICE.'''
        return self.__ice_client.get_ice_entry(ice_id).get_dna()

    def submit(self, designs):
        '''Writes plasmids and dominoes to ICE.'''
        for design in designs:
            self.__write_plasmid(design)
            self.__write_dominoes(design)

    def __write_plasmid(self, design):
        '''Writes plasmids to ICE.'''
        ice_entry = ICEEntry(typ='PLASMID')
        self.__ice_client.set_ice_entry(ice_entry)
        self.__add_permissions(ice_entry)
        design['ice_id'] = ice_entry.get_ice_id()

        _set_metadata(ice_entry, design['name'], ' '.join(design['design']),
                      'PLASMID')

        ice_entry.set_dna(design['plasmid'])
        self.__ice_client.set_ice_entry(ice_entry)

        # Add link from plasmid -> parts:
        for part_id in design['design']:
            self.__ice_client.add_link(design['ice_id'], part_id)

    def __write_dominoes(self, design):
        '''Writes dominoes to ICE, or retrieves them if pre-existing.'''
        seq_entries = {}

        for domino in design['dominoes']:
            seq = domino[1][0][0] + domino[1][1][0]

            if seq in seq_entries:
                ice_entry = seq_entries[seq]
            else:
                ice_entries = self.__ice_client.get_ice_entries_by_seq(seq)

                if len(ice_entries) == 0:
                    dna = _get_domino_dna('name', seq, domino[1][0][0],
                                          domino[1][1][0])
                    ice_entry = ICEEntry(dna, 'PART')
                else:
                    ice_entry = ice_entries[0]

            name, description = self.__get_metadata(ice_entry, domino[0])
            _set_metadata(ice_entry, name, description, 'DOMINO')
            self.__ice_client.set_ice_entry(ice_entry)
            self.__add_permissions(ice_entry)

            # Add link from plasmid -> domino:
            self.__ice_client.add_link(
                design['ice_id'], ice_entry.get_ice_id())

            seq_entries[seq] = ice_entry

    def __get_metadata(self, ice_entry, part_ids):
        '''Gets metadata for a domino.'''
        metadata = ice_entry.get_metadata()

        # Set name if necessary:
        name = metadata['name'] if 'name' in metadata \
            else ' - '.join([self.__ice_client.get_ice_entry(prt_id).get_name()
                             for prt_id in part_ids])

        # Update Designs and Pairs in description:
        pairs = metadata['shortDescription'].split(', ') \
            if 'shortDescription' in metadata else []
        pairs.append('_'.join(part_ids))
        description = ', '.join(list(set(pairs)))

        return name, description

    def __add_permissions(self, ice_entry):
        '''Adds permissions for all default groups.'''
        for group_id in self.__group_ids:
            self.__ice_client.add_permission(ice_entry.get_ice_id(), group_id)