# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: plugin.py
# class Plugin:
#     def __init__(self):
#         self.documents = Documents(self)
#         try: self.name
#         except: self.name = self.__class__.__name__.lower()
#         try: self.description
#         except: self.description = 'This plugin has no description.'
#         if self.__class__ is Plugin:
#             raise NotImplementedError
# 
#     @property
#     def user(self):
#         return app.current_user
# 
#     def process(self, request):
#         pass
# 
#     def unload(self):
#         pass
# 
# Path: plugins/dbupload/dbprofile.py
# class biosys_single(TableBase):
#     __tablename__ = 'biosys_562'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     tax_id = Column(String(10))
#     gene_id = Column(String(10))
#     bsid = Column(Integer)
#     Symbol = Column(String(64))
# 
# class Gene(TableBase):
#     __tablename__ = 'allgeneinfo_all'
#     tax_id = Column(String(10))
#     gene_id = Column(String(10), primary_key=True)
#     Symbol = Column(String(64))
#     LocusTag = Column(Text)
#     Synonyms = Column(Text)
#     dbXrefs = Column(Text)
#     chromosome = Column(Text)
#     map_location = Column(Text)
#     description = Column(Text)
#     type_of_gene = Column(Text)
#     Symbol_from_nomenclature_authority = Column(Text)
#     Full_name_from_nomenclature_authority = Column(Text)
#     Nomenclature_status = Column(Text)
#     Other_designations = Column(Text)
#     Modification_date = Column(Date)


from queue import Queue, PriorityQueue
from datetime import *
from database import session
from plugin import Plugin
from .dbupload.dbprofile import biosys_single, Gene
        u = queue.get()
        # visited[u] = False
        Graph[u] = []
        for u_node in session.query(biosys_single).filter(biosys_single.gene_id == u):
            for node in session.query(biosys_single).filter(biosys_single.bsid == u_node.bsid):
                if node.gene_id not in Graph[u]:
                    Graph[u].append(node.gene_id)
        for v in Graph[u]:
            if (v not in visited or dis[v] > dis[u] + 1) and dis[u] + 1 <= maxlen:
                dis[v] = dis[u] + 1
                visited[v] = True
                queue.put(v)


def a_star(src, dst, pathnum):
    p_queue = PriorityQueue()
    global dis
    cnt = 0

    time_monitor = datetime.now()
    if dis[src] == inf:  # if there's no path from src to dst
        yield "None"
        return
    p_queue.put(State(dis[src], 0, src, [src]))
    while not p_queue.empty():
        s = p_queue.get()
        if s.cur == dst:
            yield s.prepath
            cnt += 1
            if cnt == pathnum:

# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: plugin.py
# class Plugin:
#     def __init__(self):
#         self.documents = Documents(self)
#         try: self.name
#         except: self.name = self.__class__.__name__.lower()
#         try: self.description
#         except: self.description = 'This plugin has no description.'
#         if self.__class__ is Plugin:
#             raise NotImplementedError
# 
#     @property
#     def user(self):
#         return app.current_user
# 
#     def process(self, request):
#         pass
# 
#     def unload(self):
#         pass
# 
# Path: plugins/dbupload/dbprofile.py
# class biosys_single(TableBase):
#     __tablename__ = 'biosys_562'
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     tax_id = Column(String(10))
#     gene_id = Column(String(10))
#     bsid = Column(Integer)
#     Symbol = Column(String(64))
# 
# class Gene(TableBase):
#     __tablename__ = 'allgeneinfo_all'
#     tax_id = Column(String(10))
#     gene_id = Column(String(10), primary_key=True)
#     Symbol = Column(String(64))
#     LocusTag = Column(Text)
#     Synonyms = Column(Text)
#     dbXrefs = Column(Text)
#     chromosome = Column(Text)
#     map_location = Column(Text)
#     description = Column(Text)
#     type_of_gene = Column(Text)
#     Symbol_from_nomenclature_authority = Column(Text)
#     Full_name_from_nomenclature_authority = Column(Text)
#     Nomenclature_status = Column(Text)
#     Other_designations = Column(Text)
#     Modification_date = Column(Date)


# Path: plugins/path_finder.py
from queue import Queue, PriorityQueue
from datetime import *
from database import session
from plugin import Plugin
from .dbupload.dbprofile import biosys_single, Gene

        u = queue.get()
        # visited[u] = False
        Graph[u] = []
        for u_node in session.query(biosys_single).filter(biosys_single.gene_id == u):
            for node in session.query(biosys_single).filter(biosys_single.bsid == u_node.bsid):
                if node.gene_id not in Graph[u]:
                    Graph[u].append(node.gene_id)
        for v in Graph[u]:
            if (v not in visited or dis[v] > dis[u] + 1) and dis[u] + 1 <= maxlen:
                dis[v] = dis[u] + 1
                visited[v] = True
                queue.put(v)


def a_star(src, dst, pathnum):
    p_queue = PriorityQueue()
    global dis
    cnt = 0

    time_monitor = datetime.now()
    if dis[src] == inf:  # if there's no path from src to dst
        yield "None"
        return
    p_queue.put(State(dis[src], 0, src, [src]))
    while not p_queue.empty():
        s = p_queue.get()
        if s.cur == dst:
            yield s.prepath
            cnt += 1
            if cnt == pathnum:

                break