예제 #1
0
    def add_metacyc_pathway(self,metacyc_pathway_id,generic = False):
        biocyc.set_organism('meta')
        ptw = biocyc.get(metacyc_pathway_id)

        network = self.scrap_metacyc_path(ptw,generic)
        self.convert_compounds_into_modelseedid(network)


        pathway = network.get_pathway()
        if pathway:
            target_reaction = pathway[-1]
            last_reaction = biocyc.get(target_reaction)
            products = last_reaction.compounds_right
            targets = []

            for product in products:
                modelseedids = self.__compoundsIdConverter.convert_dbID_into_modelSeedId("MetaCyc",product.id)
                if modelseedids is not None:
                    targets.extend(modelseedids)

            self.__pathways_map[ptw.id] = network
            self.target_pathways_map[ptw.id]=targets
예제 #2
0
    def get_pathway_by_taxid_and_target(self,taxid,target):
        paths_tax_range = []
        taxa = NCBITaxa()
        lineage = taxa.get_lineage(taxid)
        for path in self.target_pathways_map:
            pathway = biocyc.get(path)

            taxonomic_range = pathway.taxonomic_range
            for s in taxonomic_range:
                taxid = int(s.id.replace("TAX-", ""))
                if taxid in lineage:
                    paths_tax_range.append(path)

        pathways = self.get_pathway_by_target(target)
        for p in paths_tax_range:
            if p in pathways:
                return p
예제 #3
0
파일: metaviz.py 프로젝트: ebeau/pathomx
    def setupSection(self, label, pathway_config):
        # SHOW PATHWAYS
        gb = QGroupBox(label)
        vbox = QVBoxLayout()
        # Populate the list boxes
        self.label[label]['lw_pathways'] = ui.QBioCycPathwayTreeWidget([
            'Biosynthesis',
            'Degradation',
            'Energy-Metabolism',
        ])

        fwd_map = lambda x: biocyc.find_pathway_by_name(x).id
        rev_map = lambda x: biocyc.get(x).name

        self.config.hooks['QBioCycPathwayTreeWidget'] = self.config.hooks[
            'QCheckTreeWidget']  # Works the same
        self.config.add_handler(pathway_config,
                                self.label[label]['lw_pathways'],
                                (fwd_map, rev_map))

        self.label[label]['lw_regExp'] = QLineEdit()

        vbox.addWidget(self.label[label]['lw_pathways'])
        vbox.addWidget(QLabel('Select/deselect matching pathways by name:'))
        vboxh = QHBoxLayout()

        vboxh.addWidget(self.label[label]['lw_regExp'])

        addfr = QPushButton('-')
        addfr.clicked.connect(self.onRegexpRemove)
        addfr.setObjectName(label)
        addfr.setFixedWidth(24)

        remfr = QPushButton('+')
        remfr.clicked.connect(self.onRegexpAdd)
        remfr.setObjectName(label)
        remfr.setFixedWidth(24)

        vboxh.addWidget(addfr)
        vboxh.addWidget(remfr)
        vbox.addLayout(vboxh)

        gb.setLayout(vbox)
        self.layout.addWidget(gb)
예제 #4
0
파일: metaviz.py 프로젝트: pradal/pathomx
    def setupSection(self, label, pathway_config):
        # SHOW PATHWAYS
        gb = QGroupBox(label)
        vbox = QVBoxLayout()
        # Populate the list boxes
        self.label[label]['lw_pathways'] = QListWidget()
        self.label[label]['lw_pathways'].setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.label[label]['lw_pathways'].addItems(self.all_pathways)
        self.label[label]['lw_pathways'].sortItems(Qt.AscendingOrder)

        fwd_map = lambda x: biocyc.find_pathway_by_name(x).id
        rev_map = lambda x: biocyc.get(x).name

        self.config.add_handler(pathway_config, self.label[label]['lw_pathways'], (fwd_map, rev_map))
        #for p in selected_pathways:
        #    self.label[label]['lw_pathways'].findItems(p, Qt.MatchExactly)[0].setSelected(True)

        self.label[label]['lw_regExp'] = QLineEdit()

        vbox.addWidget(self.label[label]['lw_pathways'])
        vbox.addWidget(QLabel('Select/deselect matching pathways by name:'))
        vboxh = QHBoxLayout()

        vboxh.addWidget(self.label[label]['lw_regExp'])

        addfr = QPushButton('-')
        addfr.clicked.connect(self.onRegexpRemove)
        addfr.setObjectName(label)
        addfr.setFixedWidth(24)

        remfr = QPushButton('+')
        remfr.clicked.connect(self.onRegexpAdd)
        remfr.setObjectName(label)
        remfr.setFixedWidth(24)

        vboxh.addWidget(addfr)
        vboxh.addWidget(remfr)
        vbox.addLayout(vboxh)

        gb.setLayout(vbox)
        self.layout.addWidget(gb)
예제 #5
0
파일: loader.py 프로젝트: cgratie/pathomx
    def setupSection(self, label, pathway_config):
        # SHOW PATHWAYS
        gb = QGroupBox(label)
        vbox = QVBoxLayout()
        # Populate the list boxes
        self.label[label]['lw_pathways'] = ui.QBioCycPathwayTreeWidget([
            'Biosynthesis',
            'Degradation',
            'Energy-Metabolism',
            ])

        fwd_map = lambda x: biocyc.find_pathway_by_name(x).id
        rev_map = lambda x: biocyc.get(x).name

        self.config.hooks['QBioCycPathwayTreeWidget'] = self.config.hooks['QCheckTreeWidget']  # Works the same
        self.config.add_handler(pathway_config, self.label[label]['lw_pathways'], (fwd_map, rev_map))

        self.label[label]['lw_regExp'] = QLineEdit()

        vbox.addWidget(self.label[label]['lw_pathways'])
        vbox.addWidget(QLabel('Select/deselect matching pathways by name:'))
        vboxh = QHBoxLayout()

        vboxh.addWidget(self.label[label]['lw_regExp'])

        addfr = QPushButton('-')
        addfr.clicked.connect(self.onRegexpRemove)
        addfr.setObjectName(label)
        addfr.setFixedWidth(24)

        remfr = QPushButton('+')
        remfr.clicked.connect(self.onRegexpAdd)
        remfr.setObjectName(label)
        remfr.setFixedWidth(24)

        vboxh.addWidget(addfr)
        vboxh.addWidget(remfr)
        vbox.addLayout(vboxh)

        gb.setLayout(vbox)
        self.layout.addWidget(gb)
예제 #6
0
    def get_pathway_by_taxID(self,taxID):
        # paths_species = []
        paths_tax_range = []
        taxa = NCBITaxa()
        lineage = taxa.get_lineage(taxID)
        for path in self.target_pathways_map:
            pathway = biocyc.get(path)

            # species = pathway.species
            # for s in species:
            #     if re.search("TAX-",s.id):
            #         id = int(s.id.replace("TAX-", ""))
            #         if id in lineage:
            #             paths_species.append((path,pathway.name))

            taxonomic_range = pathway.taxonomic_range
            for s in taxonomic_range:
                taxid = int(s.id.replace("TAX-",""))
                if taxid in lineage:
                    paths_tax_range.append(path)

        # res

        return paths_tax_range
예제 #7
0
    if input_data is not None:
        datam = input_data.mean()
        # We need BioCyc identifiers
        if 'BioCyc' in input_data.columns.names:
            if type(input_data.columns) == pd.MultiIndex:
                entities = [k[input_data.columns.names.index('BioCyc')] for k in input_1.columns.values]
            else:
                entities = input_data.columns.values
            # Map to BioCyc if not already
            biocyc_entities = []
            for e in entities:
                if hasattr(e, 'id'):
                    biocyc_entities.append(e)
                elif type(e) is str:
                    try:
                        biocyc_entities[n] = biocyc.get(o)
                    except:
                        biocyc_entities[n] = None   
                else:
                    biocyc_entities.append(None)
            
            datas = [(e,s) for e,s in zip(biocyc_entities, datam.values) if e is not None]
            data.extend(datas)

print "%d entities with data" % len(data)

results = mining(data, target=config['/Data/MiningTarget'], 
                       include=config['include_pathways'],
                       exclude=config['exclude_pathways'],
                       no_of_results=config['/Data/MiningDepth'], 
                       algorithm=config['/Data/MiningType'], 
예제 #8
0
        if 'BioCyc' in input_data.columns.names:
            if type(input_data.columns) == pd.MultiIndex:
                entities = [
                    k[input_data.columns.names.index('BioCyc')]
                    for k in input_1.columns.values
                ]
            else:
                entities = input_data.columns.values
            # Map to BioCyc if not already
            biocyc_entities = []
            for e in entities:
                if hasattr(e, 'id'):
                    biocyc_entities.append(e)
                elif type(e) is str:
                    try:
                        biocyc_entities[n] = biocyc.get(o)
                    except:
                        biocyc_entities[n] = None
                else:
                    biocyc_entities.append(None)

            datas = [(e, s) for e, s in zip(biocyc_entities, datam.values)
                     if e is not None]
            data.extend(datas)

print "%d entities with data" % len(data)

results = mining(
    data,
    target=config['/Data/MiningTarget'],
    include=config['include_pathways'],
예제 #9
0
if suggested_pathways is not None:
    # Pathways should come in as a column set named 'BioCyc' but containing Pathway objects
    if 'BioCyc' in suggested_pathways.columns.names:
        if type(suggested_pathways.columns) == pd.Index:
            ps = suggested_pathways.columns.values
        elif type(suggested_pathways.columns) == pd.MultiIndex:
            ps = suggested_pathways.columns.values[
                suggested_pathways.columns.names.index('BioCyc')]

    pathways = []
    for p in ps:
        if type(p) == Pathway:
            pathways.append(p)
        else:
            try:
                p = biocyc.get(id)
            except:
                pass
            else:
                if type(p) == Pathway:
                    pathways.append(p)
else:
    pathways = []
pathways.extend([biocyc.get(p) for p in config['show_pathways']])
pathways = [p for p in pathways if p.id not in config['hide_pathways']]

pathways = list(set(pathways))

print("Forcing display of %s" % config['show_pathways'])
print("Suppressing display of %s" % config['hide_pathways'])
예제 #10
0
count = 0

for n, l in enumerate(labels):
    if current_biocyc[n] is not None:
        continue

    o = lku(l)
    # Note that the BioCyc module returns an object, so we need to convert to ID if it is
    if hasattr(o, 'id'):
        current_biocyc[n] = o
        count += 1


    elif type(o) is str:
        try:
            current_biocyc[n] = biocyc.get(o)
        except:
            current_biocyc[n] = None
        else:
            count += 1


    else:
        current_biocyc[n] = None

print("Matched %d identifiers" % count)

cross_maps = {}
if 1 == 0:
    for m, f in {'BiGG': 'bigg', 'HMDB': 'hmdb', 'KEGG': 'kegg'}.items():
        lku = reverse_map_generator(f)
예제 #11
0
파일: metaviz.py 프로젝트: rosh89/pathomx
if suggested_pathways is not None:
    # Pathways should come in as a column set named 'BioCyc' but containing Pathway objects
    if 'BioCyc' in suggested_pathways.columns.names:
        if type(suggested_pathways.columns) == pd.Index:
            ps = suggested_pathways.columns.values
        elif type(suggested_pathways.columns) == pd.MultiIndex:
            ps = suggested_pathways.columns.values[ suggested_pathways.columns.names.index('BioCyc') ]
            
    pathways = []
    for p in ps:
        if type(p) == Pathway:
            pathways.append(p)
        else:
            try:
                p = biocyc.get(id)
            except:
                pass
            else:
                if type(p) == Pathway:
                    pathways.append(p)
else:
    pathways = []
pathways.extend( [biocyc.get(p) for p in config['show_pathways'] ])
pathways = [p for p in pathways if p.id not in config['hide_pathways']]

pathways = list( set( pathways ) )

print("Forcing display of %s" % config['show_pathways'])
print("Suppressing display of %s" % config['hide_pathways'])
예제 #12
0
fetch_queue = pathways = [
            'Biosynthesis',
            'Degradation',
            'Energy-Metabolism',
            ]

fetched = []
added_this_loop = None

while len(fetch_queue) > 0:
    added_this_loop = 0
    to_add = []
    for p in fetch_queue:
        print p
        pw = biocyc.get(p)
        to_add.extend(pw._super_pathways)
        to_add.extend(pw._subclasses)
        to_add.extend(pw._instances)
        
    to_add = [p for p in to_add if p not in fetched]
    fetch_queue = to_add
    fetched.extend(to_add)    
    
DEFAULT_PATHWAYS = fetched

total_n = len(DEFAULT_PATHWAYS)
for n, p in enumerate(DEFAULT_PATHWAYS):
    pw = biocyc.get(p)
    print "P", pw, pw.id, "(%d/%d)" % (n, total_n)
    for r in pw.reactions:
예제 #13
0
count = 0

for n, l in enumerate(labels):
    if current_biocyc[n] is not None:
        continue

    o = lku(l)
    # Note that the BioCyc module returns an object, so we need to convert to ID if it is
    if hasattr(o, 'id'):
        current_biocyc[n] = o
        count += 1

    elif type(o) is str:
        try:
            current_biocyc[n] = biocyc.get(o)
        except:
            current_biocyc[n] = None
        else:
            count += 1

    else:
        current_biocyc[n] = None

print("Matched %d identifiers" % count)

cross_maps = {}
if 1 == 0:
    for m, f in {'BiGG': 'bigg', 'HMDB': 'hmdb', 'KEGG': 'kegg'}.items():
        lku = reverse_map_generator(f)
        cm = []
예제 #14
0
fetch_queue = pathways = [
    'Biosynthesis',
    'Degradation',
    'Energy-Metabolism',
]

fetched = []
added_this_loop = None

while len(fetch_queue) > 0:
    added_this_loop = 0
    to_add = []
    for p in fetch_queue:
        print p
        pw = biocyc.get(p)
        to_add.extend(pw._super_pathways)
        to_add.extend(pw._subclasses)
        to_add.extend(pw._instances)

    to_add = [p for p in to_add if p not in fetched]
    fetch_queue = to_add
    fetched.extend(to_add)

DEFAULT_PATHWAYS = fetched

total_n = len(DEFAULT_PATHWAYS)
for n, p in enumerate(DEFAULT_PATHWAYS):
    pw = biocyc.get(p)
    print "P", pw, pw.id, "(%d/%d)" % (n, total_n)
    for r in pw.reactions: