Distinct NCBI taxonomy identifiers (``taxid``) in :class:`.models.Entry`

        :return: NCBI taxonomy identifiers
        :rtype: list[int]
341640
def taxids(self):
        
        r = self.session.query(distinct(models.Entry.taxid)).all()
        return [x[0] for x in r]
478993
def _get_identifiers(self, limit):
        

        LOG.info("getting identifier mapping")
        line_counter = 0
        f = '/'.join((self.rawdir, self.files['identifiers']['file']))
        myzip = ZipFile(f, 'r')
        # assume that the first entry is the item
        fname = myzip.namelist()[0]
        foundheader = False

        # TODO align this species filter with the one above
        # speciesfilters = 'Homo sapiens,Mus musculus,Drosophila melanogaster,
        # Danio rerio, Caenorhabditis elegans,Xenopus laevis'.split(',')

        speciesfilters = 'Homo sapiens,Mus musculus'.split(',')
        with myzip.open(fname, 'r') as csvfile:
            for line in csvfile:
                # skip header lines
                if not foundheader:
                    if re.match(r'BIOGRID_ID', line.decode()):
                        foundheader = True
                    continue

                line = line.decode().strip()
                # BIOGRID_ID
                # IDENTIFIER_VALUE
                # IDENTIFIER_TYPE
                # ORGANISM_OFFICIAL_NAME
                # 1	814566	ENTREZ_GENE	Arabidopsis thaliana
                (biogrid_num, id_num, id_type,
                 organism_label) = line.split('\t')

                if self.test_mode:
                    graph = self.testgraph
                    # skip any genes that don't match our test set
                    if int(biogrid_num) not in self.biogrid_ids:
                        continue
                else:
                    graph = self.graph

                model = Model(graph)

                # for each one of these,
                # create the node and add equivalent classes
                biogrid_id = 'BIOGRID:'+biogrid_num
                prefix = self.localtt[id_type]

                # TODO make these filters available as commandline options
                # geneidtypefilters='NCBIGene,OMIM,MGI,FlyBase,ZFIN,MGI,HGNC,
                #                   WormBase,XenBase,ENSEMBL,miRBase'.split(',')
                geneidtypefilters = 'NCBIGene,MGI,ENSEMBL,ZFIN,HGNC'.split(',')
                # proteinidtypefilters='HPRD,Swiss-Prot,NCBIProtein'
                if (speciesfilters is not None) \
                        and (organism_label.strip() in speciesfilters):
                    line_counter += 1
                    if (geneidtypefilters is not None) \
                            and (prefix in geneidtypefilters):
                        mapped_id = ':'.join((prefix, id_num))
                        model.addEquivalentClass(biogrid_id, mapped_id)
                    # this symbol will only get attached to the biogrid class
                    elif id_type == 'OFFICIAL_SYMBOL':
                        model.addClassToGraph(biogrid_id, id_num)
                    # elif (id_type == 'SYNONYM'):
                    #   FIXME - i am not sure these are synonyms, altids?
                    #   gu.addSynonym(g,biogrid_id,id_num)

                if not self.test_mode and limit is not None and line_counter > limit:
                    break

        myzip.close()

        return
1016005
def filtered_search(self,
               id_list: Iterable,
               negated_classes: Iterable,
               limit: Optional[int],
               taxon_filter: Optional,
               category_filter: Optional,
               method: Optional) -> SimResult:
        
        pass
1051154
def _init_taxid2asscs(self):
        """"""
        taxid2asscs = cx.defaultdict(list)
        for ntanno in self.associations:
            taxid2asscs[ntanno.tax_id].append(ntanno)
        assert len(taxid2asscs) != 0, "**FATAL: NO TAXIDS: {F}".format(F=self.filename)
        # """Print the number of taxids stored."""
        prt = sys.stdout
        num_taxids = len(taxid2asscs)
        prt.write('{N} taxids stored'.format(N=num_taxids))
        if num_taxids < 5:
            prt.write(': {Ts}'.format(Ts=' '.join(sorted(str(t) for t in taxid2asscs))))
        prt.write('\n')
        return dict(taxid2asscs)
970726
def _get_distinct_objs(objs):
    
    ids = set()
    res = []
    for obj in objs:
        if not id(obj) in ids:
            ids.add(id(obj))
            res.append(obj)
    return res
1244550
def search(self,
               id_list: Iterable,
               negated_ids: Iterable,
               limit: Optional[int],
               taxon_filter: Optional,
               category_filter: Optional,
               method: Optional)-> SimResult:
        
        pass
962762
def get_identifiers_from_input_file(input_file_name):
    
    valid_identifiers = ['address', 'zipcode', 'unit', 'city', 'state', 'slug', 'block_id', 'msa',
                         'num_bins', 'property_type', 'client_value', 'client_value_sqft', 'meta']
    mode = 'r'
    if sys.version_info[0] < 3:
        mode = 'rb'
    with io.open(input_file_name, mode) as input_file:
        result = [{identifier: val for identifier, val in list(row.items())
                   if identifier in valid_identifiers}
                  for row in csv.DictReader(input_file, skipinitialspace=True)]
        return result
49152
def filter_keep_phenotype_entry_ids(self, entry):
        '''
            
        '''
        omim_id = str(entry['mimNumber'])
        otype = self.globaltt['obsolete']
        if omim_id in self.omim_type:
            otype = self.omim_type[omim_id]
            if otype == self.globaltt['obsolete'] and omim_id in self.omim_replaced:
                omim_id = self.omim_replaced[omim_id]
                otype = self.omim_type[omim_id]
            # else:  # removed or multiple

        if otype not in (
                self.globaltt['Phenotype'], self.globaltt['has_affected_feature']):
            omim_id = None
        return omim_id
930151
def idsKEGG(organism):
    
    ORG=urlopen("http://rest.kegg.jp/list/"+organism).read()
    ORG=ORG.split("\n")
    final=[]
    for k in ORG:
        final.append(k.split("\t"))
    df=pd.DataFrame(final[0:len(final)-1])[[0,1]]
    df.columns=['KEGGid','description']
    field = pd.DataFrame(df['description'].str.split(';',1).tolist())[0]
    field = pd.DataFrame(field)
    df = pd.concat([df[['KEGGid']],field],axis=1)
    df.columns=['KEGGid','gene_name']
    df=df[['gene_name','KEGGid']]
    return df
374736
def get_species(taxdump_file, select_divisions=None,
                exclude_divisions=None, nrows=None):
    """"""
    
    if select_divisions and exclude_divisions:
        raise ValueError('Cannot specify "select_divisions" and '
                         '"exclude_divisions" at the same time.')

    select_taxon_ids = _get_species_taxon_ids(
        taxdump_file,
        select_divisions=select_divisions,
        exclude_divisions=exclude_divisions)
    select_taxon_ids = set(select_taxon_ids)
    
    with tarfile.open(taxdump_file) as tf:
        with tf.extractfile('names.dmp') as fh:    
            df = pd.read_csv(fh, header=None, sep='|',
                             encoding='ascii', nrows=nrows)

    # only keep information we need
    df = df.iloc[:, [0, 1, 3]]

    # only select selected species
    df = df.loc[df.iloc[:, 0].isin(select_taxon_ids)]

    # remove tab characters flanking each "name class" entry
    df.iloc[:, 2] = df.iloc[:, 2].str.strip('\t')

    # select only "scientific name" and "common name" rows
    df = df.loc[df.iloc[:, 2].isin(['scientific name', 'common name'])]

    # remove tab characters flanking each "name" entry 
    df.iloc[:, 1] = df.iloc[:, 1].str.strip('\t')
    
    # collapse common names for each scientific name
    common_names = defaultdict(list)
    cn = df.loc[df.iloc[:, 2] == 'common name']
    for _, row in cn.iterrows():
        common_names[row.iloc[0]].append(row.iloc[1])
        
    # build final dataframe (this is very slow)
    sn = df.loc[df.iloc[:, 2] == 'scientific name']
    species = []
    for i, row in sn.iterrows():
        species.append([row.iloc[0], row.iloc[1],
                        '|'.join(common_names[row.iloc[0]])])
    species_df = pd.DataFrame(species).set_index(0)
    species_df.columns = ['scientific_name', 'common_names']
    species_df.index.name = 'taxon_id'
    return species_df
1073374
def unique_identifier(self):
        
        for t in IDENTIFIER_PRIORITY:
            found = self._tree.getroot().find('.//mods:identifier[@type="%s"]' % t, NS)
            if found is not None:
                return found.text
338816
def get_organism_hosts(cls, entry):
        

        query = "./organismHost/dbReference[@type='NCBI Taxonomy']"
        return [models.OrganismHost(taxid=x.get('id')) for x in entry.iterfind(query)]
491946
def filter_entries(entries, config):
    """"""
    def in_genus_list(species, genus_list):
        for genus in genus_list:
            if species.startswith(genus.capitalize()):
                return True
        return False

    new_entries = []
    for entry in entries:
        if config.type_material and config.type_material != ['any']:
            requested_types = map(lambda x: config._RELATION_TO_TYPE_MATERIAL[x], config.type_material)
            if not entry['relation_to_type_material'] or entry['relation_to_type_material'] not in requested_types:
                 logging.debug("Skipping assembly with no reference to type material or reference to type material does not match requested")
                 continue 
            else:
                print(entry['relation_to_type_material'])
        if config.genus and not in_genus_list(entry['organism_name'], config.genus):
            logging.debug('Organism name %r does not start with any in %r, skipping',
                          entry['organism_name'], config.genus)
            continue
        if config.species_taxid and entry['species_taxid'] not in config.species_taxid:
            logging.debug('Species TaxID %r does not match with any in %r, skipping',
                          entry['species_taxid'], config.species_taxid)
            continue
        if config.taxid and entry['taxid'] not in config.taxid:
            logging.debug('Organism TaxID %r does not match with any in %r, skipping',
                          entry['taxid'], config.taxid)
            continue
        if not config.is_compatible_assembly_accession(entry['assembly_accession']):
            logging.debug('Skipping entry with incompatible assembly accession %r', entry['assembly_accession'])
            continue
        if not config.is_compatible_assembly_level(entry['assembly_level']):
            logging.debug('Skipping entry with assembly level %r', entry['assembly_level'])
            continue
        if config.refseq_category != 'all' \
                and entry['refseq_category'] != config.get_refseq_category_string(config.refseq_category):
            logging.debug('Skipping entry with refseq_category %r, not %r', entry['refseq_category'],
                          config.refseq_category)
            continue
        new_entries.append(entry)

    return new_entries
762944
def entities(self, name_id):
        
        cni = code(name_id)
        return list(self._db[cni].keys())
659690
def get_ncbi_taxon_num_by_label(label):
        
        req = {'db': 'taxonomy', 'retmode': 'json', 'term': label}
        req.update(EREQ)

        request = SESSION.get(ESEARCH, params=req)
        LOG.info('fetching: %s', request.url)
        request.raise_for_status()
        result = request.json()['esearchresult']

        # Occasionally eutils returns the json blob
        # {'ERROR': 'Invalid db name specified: taxonomy'}
        if 'ERROR' in result:
            request = SESSION.get(ESEARCH, params=req)
            LOG.info('fetching: %s', request.url)
            request.raise_for_status()
            result = request.json()['esearchresult']

        tax_num = None
        if 'count' in result and str(result['count']) == '1':
            tax_num = result['idlist'][0]
        else:
            # TODO throw errors
            LOG.warning('ESEARCH for taxon label "%s"  returns %s', label, str(result))

        return tax_num
204587
def get_previous_identifiers(self):
        
        previous_identifiers = None
        stack = self.get_run_as_identifiers_stack()  # TBD:  must confirm logic

        if stack:
            if (len(stack) == 1):
                previous_identifiers = self.identifiers
            else:
                # always get the one behind the current
                previous_identifiers = stack[1]
        return previous_identifiers
1165545
def as_id_dict(self):
		
		d = {}
		for row in self:
			if row.experiment_id not in d:
				d[row.experiment_id] = {}
			if (row.time_slide_id, row.veto_def_name, row.datatype, row.sim_proc_id) in d[row.experiment_id]:
				# entry already exists, raise error
				raise KeyError("duplicate entries in experiment_summary table")
			d[row.experiment_id][(row.time_slide_id, row.veto_def_name, row.datatype, row.sim_proc_id)] = row.experiment_summ_id

		return d