Return all tax_ids in node table
505030
def tax_ids(self):
        '''
        
        '''
        fetch = select([self.nodes.c.tax_id]).execute().fetchall()
        ids = [t[0] for t in fetch]
        return ids
764882
def getAllNodeUids(self):
        '''
            
        '''
        ret = set()

        for child in self:
            ret.update(child.getAllNodeUids())

        return ret
225826
def _get_lineage(self, tax_id, merge_obsolete=True):
        

        # Be sure we aren't working with an obsolete tax_id
        if merge_obsolete:
            tax_id = self._get_merged(tax_id)

        # Note: joining with ranks seems like a no-op, but for some
        # reason it results in a faster query using sqlite, as well as
        # an ordering from leaf --> root. Might be a better idea to
        # sort explicitly if this is the expected behavior, but it
        # seems like for the most part, the lineage is converted to a
        # dict and the order is irrelevant.
        cmd = """
        WITH RECURSIVE a AS (
         SELECT tax_id, parent_id, rank
          FROM {nodes}
          WHERE tax_id = {}
        UNION ALL
         SELECT p.tax_id, p.parent_id, p.rank
          FROM a JOIN {nodes} p ON a.parent_id = p.tax_id
        )
        SELECT a.rank, a.tax_id FROM a
        JOIN {ranks} using(rank)
        """.format(self.placeholder, nodes=self.nodes, ranks=self.ranks_table)

        # with some versions of sqlite3, an error is raised when no
        # rows are returned; with others, an empty list is returned.
        try:
            with self.engine.connect() as con:
                result = con.execute(cmd, (tax_id,))
                # reorder so that root is first
                lineage = result.fetchall()[::-1]
        except sqlalchemy.exc.ResourceClosedError:
            lineage = []

        if not lineage:
            raise ValueError('tax id "{}" not found'.format(tax_id))

        return lineage
102184
def _get_lineage_table(self, tax_ids, merge_obsolete=True):
        

        try:
            with self.engine.connect() as con:
                # insert tax_ids into a temporary table

                temptab = self.prepend_schema(random_name(12))

                cmd = 'CREATE TEMPORARY TABLE "{tab}" (old_tax_id text)'.format(
                    tab=temptab)
                con.execute(cmd)

                log.info('inserting tax_ids into temporary table')
                # TODO: couldn't find an equivalent of "executemany" - does one exist?
                cmd = 'INSERT INTO "{tab}" VALUES ({x})'.format(
                    tab=temptab, x=self.placeholder)
                for tax_id in tax_ids:
                    con.execute(cmd, tax_id)

                log.info('executing recursive CTE')
                cmd = Template("""
                WITH RECURSIVE a AS (
                 SELECT tax_id as tid, 1 AS ord, tax_id, parent_id, rank
                  FROM {{ nodes }}
                  WHERE tax_id in (
                  {% if merge_obsolete %}
                  SELECT COALESCE(m.new_tax_id, "{{ temptab }}".old_tax_id)
                    FROM "{{ temptab }}" LEFT JOIN {{ merged }} m USING(old_tax_id)
                  {% else %}
                  SELECT * from "{{ temptab }}"
                  {% endif %}
                  )
                UNION ALL
                 SELECT a.tid, a.ord + 1, p.tax_id, p.parent_id, p.rank
                  FROM a JOIN {{ nodes }} p ON a.parent_id = p.tax_id
                )
                SELECT a.tid, a.tax_id, a.parent_id, a.rank, tax_name FROM a
                JOIN {{ names }} using(tax_id)
                WHERE names.is_primary
                ORDER BY tid, ord desc
                """).render(
                    temptab=temptab,
                    merge_obsolete=merge_obsolete,
                    merged=self.merged,
                    nodes=self.nodes,
                    names=self.names,
                )

                result = con.execute(cmd)
                rows = result.fetchall()

                con.execute('DROP TABLE "{}"'.format(temptab))
                log.info('returning lineages')
                if not rows:
                    raise ValueError('no tax_ids were found')
                else:
                    returned = {row[0] for row in rows}
                    # TODO: compare set membership, not lengths
                    if len(returned) < len(tax_ids):
                        msg = ('{} tax_ids were provided '
                               'but only {} were returned').format(
                                   len(tax_ids), len(returned))
                        log.error('Input tax_ids not represented in output:')
                        log.error(sorted(set(tax_ids) - returned))
                        raise ValueError(msg)

                return rows

        except sqlalchemy.exc.ResourceClosedError:
            raise ValueError('tax id "{}" not found'.format(tax_id))
733144
def from_taxtable(cls, taxtable_fp):
        
        r = csv.reader(taxtable_fp)
        headers = next(r)
        rows = (collections.OrderedDict(list(zip(headers, i))) for i in r)

        row = next(rows)
        root = cls(rank=row['rank'], tax_id=row[
                   'tax_id'], name=row['tax_name'])
        path_root = headers.index('root')
        root.ranks = headers[path_root:]
        for row in rows:
            rank, tax_id, name = [
                row[i] for i in ('rank', 'tax_id', 'tax_name')]
            path = [_f for _f in list(row.values())[path_root:] if _f]
            parent = root.path(path[:-1])
            parent.add_child(cls(rank, tax_id, name=name))

        return root
118085
def get_rows(self):
        """"""
        table = self.soup.find_all('tr')[1:-3]
        return [row for row in table if row.contents[3].string]
957661
def _get_goid2dbids(associations):
        """"""
        go2ids = cx.defaultdict(set)
        for ntd in associations:
            go2ids[ntd.GO_ID].add(ntd.DB_ID)
        return dict(go2ids)
250953
def desc_taxa(taxid, ncbi, outFH, just_taxids=False):
    
    # Main feature of the script is to get all taxa within a given group.	
    descendent_taxa = ncbi.get_descendant_taxa(taxid)
    descendent_taxa_names = ncbi.translate_to_names(descendent_taxa)

    if just_taxids:
        for taxid in descendent_taxa:
            outFH.write(str(taxid) + '\n')
    else:
        for dtn, dt in zip(descendent_taxa_names, descendent_taxa):
            x = [str(x) for x in [taxid, dt, dtn]]
            outFH.write('\t'.join(x) + '\n')
888068
def getidfkeyswithnodes():
    """"""
    idf = IDF(StringIO(""))
    keys = idfobjectkeys(idf)
    keysfieldnames = ((key, idf.newidfobject(key.upper()).fieldnames) 
                for key in keys)
    keysnodefdnames = ((key,  (name for name in fdnames 
                                if (name.endswith('Node_Name')))) 
                            for key, fdnames in keysfieldnames)
    nodekeys = [key for key, fdnames in keysnodefdnames if list(fdnames)]
    return nodekeys
341640
def taxids(self):
        
        r = self.session.query(distinct(models.Entry.taxid)).all()
        return [x[0] for x in r]
396846
def _get_row(self, id):
        """"""
        return {name: d['func'](id) for (name, d) in self._columns.items()}
813405
def _get_rows(self, table):
        """"""

        childnodes = table.childNodes
        qname_childnodes = [(s.qname[1], s) for s in childnodes]
        return [node for name, node in qname_childnodes
                if name == u'table-row']
692408
def getData4ID(self, tablename, ID):
		""""""
			   
		fields = self._getFieldsInDB(tablename)
		#DATE_ADD(EndDate, INTERVAL 8 DAY), TIMEDIFF(DATE_ADD(EndDate, INTERVAL 7 DAY), NOW()), TIMEDIFF(EndDate, StartDate)
		SQL = '''SELECT *,DATE_ADD(EndDate, INTERVAL %s DAY),TIMEDIFF(DATE_ADD(EndDate, INTERVAL %s DAY), NOW()),TIMEDIFF(EndDate, StartDate) 
				 FROM %s WHERE ID=%s''' % (self.store_time, self.store_time, tablename, ID)

		array_data = self.execQuery(SQL)
		
		if len(array_data) > 0:
			for x in range( len(fields) ):
				self.data[fields[x]] = array_data[0][x]
			self.data['date_expiration']  = array_data[0][-3]
			self.data['time_expiration']  = array_data[0][-2]
			self.data['time_computation'] = array_data[0][-1]

		return self.data
240279
def all(cls, otp=False, ccid=False, u2f=False):
        """"""
        pids = set([
            cls.YUBIKEY,
            cls.NEO_OTP,
            cls.NEO_OTP_CCID,
            cls.NEO_CCID,
            cls.NEO_U2F,
            cls.NEO_OTP_U2F,
            cls.NEO_U2F_CCID,
            cls.NEO_OTP_U2F_CCID,
            cls.NEO_SKY,
            cls.YK4_OTP,
            cls.YK4_U2F,
            cls.YK4_OTP_U2F,
            cls.YK4_CCID,
            cls.YK4_OTP_CCID,
            cls.YK4_U2F_CCID,
            cls.YK4_OTP_U2F_CCID,
            cls.PLUS_U2F_OTP
        ])

        if otp:
            pids.difference_update(set([
                cls.NEO_CCID,
                cls.NEO_U2F,
                cls.NEO_U2F_CCID,
                cls.NEO_SKY,
                cls.YK4_U2F,
                cls.YK4_CCID,
                cls.YK4_U2F_CCID
            ]))

        if ccid:
            pids.difference_update(set([
                cls.YUBIKEY,
                cls.NEO_OTP,
                cls.NEO_U2F,
                cls.NEO_OTP_U2F,
                cls.NEO_SKY,
                cls.YK4_OTP,
                cls.YK4_U2F,
                cls.YK4_OTP_U2F,
                cls.PLUS_U2F_OTP
            ]))

        if u2f:
            pids.difference_update(set([
                cls.YUBIKEY,
                cls.NEO_OTP,
                cls.NEO_OTP_CCID,
                cls.NEO_CCID,
                cls.YK4_OTP,
                cls.YK4_CCID,
                cls.YK4_OTP_CCID
            ]))

        return pids
1208482
def _get_table_rows(parent_table, table_name, row_name):
        
        if parent_table is None:
            return []
        _table = parent_table.get(table_name)
        _table_rows = []
        if isinstance(_table, list):
            _table_rows = [_table_row.get(row_name) for _table_row in _table]
        elif isinstance(_table, dict):
            _table_rows = _table.get(row_name)
        if not isinstance(_table_rows, list):
            _table_rows = [_table_rows]
        return _table_rows
511381
def add_names(self, tax_id, names, execute=True):
        

        primary_names = [n['tax_name'] for n in names if n.get('is_primary')]
        if len(primary_names) > 1:
            raise ValueError(
                '`is_primary` may be True for no more than one name in `names`')

        statements = []

        for namevals in names:
            if 'tax_id' in namevals:
                del namevals['tax_id']
            statements.extend(
                self.add_name(tax_id=tax_id, execute=False, **namevals))

        if execute:
            self.execute(statements)
        else:
            return statements
1283149
def _current_ids_subquery(self):
        
        return self.values(*self.model.KEY_FIELDS).annotate(max=models.Max('pk')).values('max')