Here we pull the mgiid of the features, and make equivalent (or sameAs)
        associations to referenced ids.
        Only adding the ENSEMBL genes and NCBI gene ids.
        Will wait on other ids later.

        :param limit:
        :return:
517019
def _process_mrk_summary_view(self, limit):
        
        if self.test_mode:
            graph = self.testgraph
        else:
            graph = self.graph
        model = Model(graph)
        LOG.info("getting markers and equivalent ids from mrk_summary_view")
        line_counter = 0
        raw = '/'.join((self.rawdir, 'mrk_summary_view'))
        with open(raw, 'r') as fh:
            fh.readline()  # read the header row; skip
            for line in fh:
                line = line.rstrip("\n")
                line_counter += 1

                (accid, logicaldb_key, object_key, preferred,
                 mgiid, subtype, short_description) = line.split('\t')

                if self.test_mode is True:
                    if int(object_key) not in self.test_keys.get('marker'):
                        continue

                if preferred == '1':

                    if self.idhash['marker'].get(object_key) is None:
                        # can't find the marker in the hash; add it here:
                        self.idhash['marker'][object_key] = mgiid
                        LOG.error(
                            "this marker hasn't been seen before %s %s",
                            mgiid, short_description)

                    if accid == mgiid:
                        # don't need to make equivalences to itself
                        continue

                    mapped_id = None
                    if logicaldb_key == '60':
                        mapped_id = 'ENSEMBL:' + accid
                    elif logicaldb_key == '1':
                        # don't need to add the equivalence to itself.
                        continue
                    elif logicaldb_key == '55':
                        mapped_id = 'NCBIGene:' + accid

                    if mapped_id is not None:
                        if mgiid in self.markers['classes'] \
                                or subtype in ['Gene', 'Pseudogene']:
                            model.addClassToGraph(mapped_id, None)
                            model.addEquivalentClass(mgiid, mapped_id)
                        elif mgiid in self.markers['indiv']:
                            model.addIndividualToGraph(mapped_id, None)
                            model.addSameIndividual(mgiid, mapped_id)

                    # could parse the "subtype" string
                    # to get the kind of thing the marker is

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

        return
345708
def cli(ctx, feature_id, old_db, old_accession, new_db, new_accession, organism="", sequence=""):
    
    return ctx.gi.annotations.update_dbxref(feature_id, old_db, old_accession, new_db, new_accession, organism=organism, sequence=sequence)
1299220
def get_similar(self, limit=None):
        

        params = self._get_params()
        if limit:
            params["limit"] = limit

        doc = self._request(self.ws_prefix + ".getSimilar", True, params)

        seq = []
        for node in doc.getElementsByTagName(self.ws_prefix):
            title = _extract(node, "name")
            artist = _extract(node, "name", 1)
            match = _number(_extract(node, "match"))

            seq.append(SimilarItem(Track(artist, title, self.network), match))

        return seq
445655
def parse(self, limit=None):
        
        if limit is not None:
            LOG.info("Only parsing first %d rows", limit)

        ensembl_file = '/'.join((self.rawdir, self.files['ensembl2pathway']['file']))
        self._parse_reactome_association_file(
            ensembl_file, limit, subject_prefix='ENSEMBL', object_prefix='REACT')
        chebi_file = '/'.join((self.rawdir, self.files['chebi2pathway']['file']))
        self._parse_reactome_association_file(
            chebi_file, limit, subject_prefix='CHEBI', object_prefix='REACT')

        return
36215
def getAnnotations_via_tid(self,
                               tids,
                               LIMIT=25,
                               _print=True,
                               crawl=False):
        
        url_base = self.base_url + \
            '/api/1/term/get-annotations/{tid}?key=' + self.api_key
        urls = [url_base.format(tid=str(tid)) for tid in tids]
        return self.get(urls,
                        LIMIT=LIMIT,
                        _print=_print,
                        crawl=crawl)
585474
def _process_stocks(self, limit):
        
        if self.test_mode:
            graph = self.testgraph
        else:
            graph = self.graph
        model = Model(graph)
        line_counter = 0

        raw = '/'.join((self.rawdir, 'stock'))
        LOG.info("building labels for stocks")

        with open(raw, 'r') as f:
            f.readline()  # read the header row; skip
            filereader = csv.reader(f, delimiter='\t', quotechar='\"')
            for line in filereader:
                line_counter += 1

                (stock_id, dbxref_id, organism_id, name, uniquename,
                 description, type_id, is_obsolete) = line
# 2       12153979        1       2       FBst0000002     w[*]; betaTub60D[2] Kr[If-1]/CyO        10670

                stock_num = stock_id
                stock_id = 'FlyBase:'+uniquename
                self.idhash['stock'][stock_num] = stock_id
                stock_label = description

                organism_key = organism_id
                taxon = self.idhash['organism'][organism_key]

                # from what i can tell, the dbxrefs are just more FBst,
                # so no added information vs uniquename

                if not self.test_mode and limit is not None and line_counter > limit:
                    pass
                else:
                    if self.test_mode \
                            and int(stock_num) not in self.test_keys['strain']:
                        continue

                    # tax_label = self.label_hash[taxon]  # unused
                    # add the tax in case it hasn't been already
                    model.addClassToGraph(taxon)
                    model.addIndividualToGraph(stock_id, stock_label, taxon)
                    if is_obsolete == 't':
                        model.addDeprecatedIndividual(stock_id)

        return
1312076
def gene_ids(self):
        
        return self.ensembl.gene_ids_at_locus(
            self.contig, self.start, self.end)
683988
def gffatributes2ids(s):
    
    Name,gene_id,transcript_id,protein_id,exon_id=np.nan,np.nan,np.nan,np.nan,np.nan
    if '=' in s:
        d=dict([i.split('=') for i in s.split(';')])
        if 'Parent' in d:
            d[d['Parent'].split(':')[0]+'_id']=d['Parent'].split(':')[1]
        Name,gene_id,transcript_id,protein_id,exon_id=np.nan,np.nan,np.nan,np.nan,np.nan
        if 'Name' in d:    
            Name=d['Name']
        if 'gene_id' in d:    
            gene_id=d['gene_id']
        if 'transcript_id' in d:    
            transcript_id=d['transcript_id']
        if 'protein_id' in d:    
            protein_id=d['protein_id']
        if 'exon_id' in d:    
            exon_id=d['exon_id']
    return Name,gene_id,transcript_id,protein_id,exon_id
848953
def process_associations(self, limit):
        

        myfile = '/'.join((self.rawdir, self.files['data']['file']))
        f = gzip.open(myfile, 'rb')
        filereader = io.TextIOWrapper(f, newline="")
        filereader.readline()  # remove the xml declaration line
        for event, elem in ET.iterparse(filereader):  # iterparse is not deprecated
            self.process_xml_table(
                elem, 'Article_Breed', self._process_article_breed_row, limit)
            self.process_xml_table(
                elem, 'Article_Phene', self._process_article_phene_row, limit)
            self.process_xml_table(
                elem, 'Breed_Phene', self._process_breed_phene_row, limit)
            self.process_xml_table(
                elem, 'Lida_Links', self._process_lida_links_row, limit)
            self.process_xml_table(
                elem, 'Phene_Gene', self._process_phene_gene_row, limit)
            self.process_xml_table(
                elem, 'Group_MPO', self._process_group_mpo_row, limit)
        f.close()
        return
656785
def reference_id_parts(reference_id):
    
    m = consts.REFERENCE_ID_PATTERN.match(reference_id)
    if m:
        return m.groups()
    raise ValueError('Illegal reference identifier: "%s"' % reference_id)
1054547
def parse(self, limit=None):
        
        if limit is not None:
            LOG.info("Only parsing first %s rows fo each file", str(limit))

        LOG.info("Parsing files...")

        if self.test_only:
            self.test_mode = True

        self._process_diseases(limit)
        self._process_genes(limit)
        self._process_genes_kegg2ncbi(limit)
        self._process_omim2gene(limit)
        self._process_omim2disease(limit)
        self._process_kegg_disease2gene(limit)

        self._process_pathways(limit)
        self._process_pathway_pubmed(limit)
        # self._process_pathway_pathway(limit)
        self._process_pathway_disease(limit)
        self._process_pathway_ko(limit)

        self._process_ortholog_classes(limit)
        # TODO add in when refactoring for #141
        # for f in ['hsa_orthologs', 'mmu_orthologs', 'rno_orthologs',
        #           'dme_orthologs','dre_orthologs','cel_orthologs']:
        #     file = '/'.join((self.rawdir, self.files[f]['file']))
        #     self._process_orthologs(file, limit)  # DONE #

        LOG.info("Finished parsing")

        return
999600
def _clean_up_gene_id(geneid, sp, curie_map):
        
        # special case for MGI
        geneid = re.sub(r'MGI:MGI:', 'MGI:', geneid)

        # rewrite Ensembl --> ENSEMBL
        geneid = re.sub(r'Ensembl', 'ENSEMBL', geneid)

        # rewrite Gene:CELE --> WormBase
        # these are old-school cosmid identifier
        geneid = re.sub(r'Gene:CELE', 'WormBase:', geneid)
        if sp == 'CAEEL':
            if re.match(r'(Gene|ENSEMBLGenome):\w+\.\d+', geneid):
                geneid = re.sub(
                    r'(?:Gene|ENSEMBLGenome):(\w+\.\d+)',
                    r'WormBase:\1', geneid)

        if sp == 'DROME':
            if re.match(r'(ENSEMBLGenome):\w+\.\d+', geneid):
                geneid = re.sub(
                    r'(?:ENSEMBLGenome):(\w+\.\d+)', r'FlyBase:\1', geneid)

        # rewrite GeneID --> NCBIGene
        geneid = re.sub(r'GeneID', 'NCBIGene', geneid)

        # rewrite Gene:Dmel --> FlyBase
        geneid = re.sub(r'Gene:Dmel_', 'FlyBase:', geneid)
        # rewrite Gene:CG --> FlyBase:CG
        geneid = re.sub(r'Gene:CG', 'FlyBase:CG', geneid)

        # rewrite ENSEMBLGenome:FBgn --> FlyBase:FBgn
        geneid = re.sub(r'ENSEMBLGenome:FBgn', 'FlyBase:FBgn', geneid)

        # rewrite Gene:<ensembl ids> --> ENSEMBL:<id>
        geneid = re.sub(r'Gene:ENS', 'ENSEMBL:ENS', geneid)

        # rewrite Gene:<Xenbase ids> --> Xenbase:<id>
        geneid = re.sub(r'Gene:Xenbase:', 'Xenbase:', geneid)

        # TODO this would be much better done as
        # if foo not in selfcurie_map:
        # if re.match(r'(Gene|ENSEMBLGenome):', geneid) or \
        #        re.match(r'Gene_ORFName', geneid) or \
        #        re.match(r'Gene_Name', geneid):
        #    # LOG.warning(
        #    #"Found an identifier I don't know how to fix (species %s): %s",
        #    #   sp, geneid)

        pfxlcl = re.split(r':', geneid)
        pfx = pfxlcl[0]
        if pfx is None or pfx not in curie_map:
            # LOG.warning( "No curie prefix for (species %s): %s", sp, geneid)
            geneid = None
        return geneid
499037
def gene_ids(self, contig=None, strand=None):
        
        return self._all_feature_values(
            column="gene_id",
            feature="gene",
            contig=contig,
            strand=strand)
498594
def _load_sequences_to_reference_gene(self, g_id, force_rerun=False):
        """"""
        protein_seqs_pickle_path = op.join(self.sequences_by_gene_dir, '{}_protein_withseqs.pckl'.format(g_id))

        if ssbio.utils.force_rerun(flag=force_rerun, outfile=protein_seqs_pickle_path):
            protein_pickle_path = self.gene_protein_pickles[g_id]
            protein_pickle = ssbio.io.load_pickle(protein_pickle_path)

            for strain, info in self.strain_infodict.items():
                strain_sequences = SeqIO.index(info['genome_path'], 'fasta')
                strain_gene_functional = info['functional_genes'][g_id]
                if strain_gene_functional:
                    # Pull the gene ID of the strain from the orthology matrix
                    strain_gene_key = self.df_orthology_matrix.at[g_id, strain]
                    new_id = '{}_{}'.format(g_id, strain)
                    if protein_pickle.sequences.has_id(new_id):
                        continue
                    protein_pickle.load_manual_sequence(seq=strain_sequences[strain_gene_key],
                                                        ident=new_id,
                                                        set_as_representative=False)
            protein_pickle.save_pickle(outfile=protein_seqs_pickle_path)

        return g_id, protein_seqs_pickle_path
969516
def loadAnns(self, ids=[]):
        
        if type(ids) == list:
            return [self.anns[id] for id in ids]
        elif type(ids) == int:
            return [self.anns[ids]]
684424
def get_gene_ids(fusion_bed):
    
    with open(fusion_bed, 'r') as f:
        gene_to_id = {}
        regex = re.compile(r'(?P<gene>ENSG\d*)')
        for line in f:
            line = line.split('\t')
            transcript, gene_bit, name = line[3].split(';')
            m = regex.search(gene_bit)
            if m:
                gene_to_id[name] = m.group('gene')
    return gene_to_id
1365235
def transcript_id_of_protein_id(self, protein_id):
        
        results = self._query_transcript_ids(
            "protein_id",
            protein_id,
            feature="CDS")
        if len(results) == 0:
            raise ValueError("Protein ID not found: %s" % protein_id)
        assert len(results) == 1, \
            ("Should have only one transcript ID for a given protein ID, "
             "but found %d: %s" % (len(results), results))
        return results[0]