# Path: SDDetector/Db/SqliteDB.py
# class SqliteDB(object):
# 
#     def __init__(self, dbfile='', logLevel='DEBUG'):
#         
#         self.dbfile = dbfile
# 
#         if logLevel:
#             self.setLoggingLevel(logLevel)
# 
#         if dbfile:
#             self.conn = sqlite3.connect(dbfile)
#         else:
#             dbfile='/tmp/tmpSqlite.db' 
#             self.conn = sqlite3.connect(dbfile)
#             logging.info("SQLiteDB in {}".format(dbfile))
# 
#     def setLoggingLevel(self, logLevel):
#         logging.basicConfig(level=logLevel)
# 
# 
#     def getListOfTables(self):
#         pass
# 
# Path: SDDetector/Entities/Gene.py
# class Gene(object):
# 
# 
#     def __init__(self, id, seqid, start, end, strand, lTranscripts=[]):
#         """Gene constructor"""
# 
#         self.id = id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.lTranscripts = lTranscripts
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.id,self.seqid,self.start,self.end,self.strand, self.lTranscripts) == (other.id, other.seqid, other.start, other.end, other.strand, other.lTranscripts))
# 
#     def __repr__(self):
#         """Gene representation"""
# 
#         return 'Gene: {}-{}-{}-{}-{}-{}'.format(self.id,self.seqid,self.start,self.end,self.strand, self.lTranscripts)
# 
# Path: SDDetector/Entities/Transcript.py
# class Transcript(object):
# 
# 
#     def __init__(self, id, seqid, start, end, strand, gene_id, lCDS=[]):
#         """Transcript constructor"""
# 
#         self.id = id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.gene_id = gene_id
#         self.lCDS = lCDS
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.id,self.seqid,self.start,self.end,self.strand,self.lCDS, self.gene_id) == (other.id, other.seqid, other.start, other.end, other.strand, other.lCDS, other.gene_id))
# 
#     def __repr__(self):
#         """Transcript representation"""
# 
#         return 'Transcript: {}-{}-{}-{}-{}-{}-{}'.format(self.id,self.seqid,self.start,self.end,self.strand,self.lCDS, self.gene_id)
# 
# Path: SDDetector/Entities/CDS.py
# class CDS(object):
# 
# 
#     def __init__(self,cds_id, seqid, start, end, strand, transcript_id):
#         """Transcript constructor"""
# 
#         self.cds_id = cds_id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.transcript_id = transcript_id
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.cds_id,self.seqid,self.start,self.end,self.strand,self.transcript_id) == (other.cds_id,other.seqid, other.start, other.end, other.strand, other.transcript_id))
# 
#     def __repr__(self):
#         """CDS representation"""
# 
#         return 'CDS: {}'.format(self.cds_id)


import os
import logging
from SDDetector.Db.SqliteDB import SqliteDB
from SDDetector.Entities.Gene import Gene
from SDDetector.Entities.Transcript import Transcript
from SDDetector.Entities.CDS import CDS
                lCDS.extend(transcript.lCDS)

        logging.info('Inserting gene features in db')

        self.conn.executemany('''insert into gene (id, seqid, start,end,strand) values (?,?,?,?,?)''', [(gene.id,gene.seqid,gene.start,gene.end,gene.strand) for gene in lGenes ])

        logging.info('Inserting mRNA features in db')

        self.conn.executemany('''insert into transcript (id, seqid, start,end,strand,gene_id) values (?,?,?,?,?,?)''', [(transcript.id,transcript.seqid,transcript.start,transcript.end,transcript.strand, transcript.gene_id) for transcript in lTranscripts ])

        logging.info('Inserting CDS features in db')

        self.conn.executemany('''insert into CDS (cds_id, seqid, start,end,strand,transcript_id) values (?,?,?,?,?,?)''', [(cds.cds_id,cds.seqid,cds.start,cds.end,cds.strand,cds.transcript_id) for cds in lCDS ])

        self.commit()


    def selectAllGenes(self):
        """Select all genes"""


        lGenes = []
        dGenes = {}
        lTranscripts = []
        dTranscripts = {}
        lCDS = []
        dCDS = {}

        cursor = self.conn.execute('''select id, seqid, start, end, strand from gene''') 
        for row in cursor:        

# Path: SDDetector/Db/SqliteDB.py
# class SqliteDB(object):
# 
#     def __init__(self, dbfile='', logLevel='DEBUG'):
#         
#         self.dbfile = dbfile
# 
#         if logLevel:
#             self.setLoggingLevel(logLevel)
# 
#         if dbfile:
#             self.conn = sqlite3.connect(dbfile)
#         else:
#             dbfile='/tmp/tmpSqlite.db' 
#             self.conn = sqlite3.connect(dbfile)
#             logging.info("SQLiteDB in {}".format(dbfile))
# 
#     def setLoggingLevel(self, logLevel):
#         logging.basicConfig(level=logLevel)
# 
# 
#     def getListOfTables(self):
#         pass
# 
# Path: SDDetector/Entities/Gene.py
# class Gene(object):
# 
# 
#     def __init__(self, id, seqid, start, end, strand, lTranscripts=[]):
#         """Gene constructor"""
# 
#         self.id = id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.lTranscripts = lTranscripts
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.id,self.seqid,self.start,self.end,self.strand, self.lTranscripts) == (other.id, other.seqid, other.start, other.end, other.strand, other.lTranscripts))
# 
#     def __repr__(self):
#         """Gene representation"""
# 
#         return 'Gene: {}-{}-{}-{}-{}-{}'.format(self.id,self.seqid,self.start,self.end,self.strand, self.lTranscripts)
# 
# Path: SDDetector/Entities/Transcript.py
# class Transcript(object):
# 
# 
#     def __init__(self, id, seqid, start, end, strand, gene_id, lCDS=[]):
#         """Transcript constructor"""
# 
#         self.id = id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.gene_id = gene_id
#         self.lCDS = lCDS
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.id,self.seqid,self.start,self.end,self.strand,self.lCDS, self.gene_id) == (other.id, other.seqid, other.start, other.end, other.strand, other.lCDS, other.gene_id))
# 
#     def __repr__(self):
#         """Transcript representation"""
# 
#         return 'Transcript: {}-{}-{}-{}-{}-{}-{}'.format(self.id,self.seqid,self.start,self.end,self.strand,self.lCDS, self.gene_id)
# 
# Path: SDDetector/Entities/CDS.py
# class CDS(object):
# 
# 
#     def __init__(self,cds_id, seqid, start, end, strand, transcript_id):
#         """Transcript constructor"""
# 
#         self.cds_id = cds_id
#         self.seqid = seqid
#         self.start = start
#         self.end = end
#         self.strand = strand
#         self.transcript_id = transcript_id
# 
#     def __eq__(self, other):
#         """Equality on all args"""
#       
#         return ((self.cds_id,self.seqid,self.start,self.end,self.strand,self.transcript_id) == (other.cds_id,other.seqid, other.start, other.end, other.strand, other.transcript_id))
# 
#     def __repr__(self):
#         """CDS representation"""
# 
#         return 'CDS: {}'.format(self.cds_id)


# Path: SDDetector/Db/GeneDB.py
import os
import logging
from SDDetector.Db.SqliteDB import SqliteDB
from SDDetector.Entities.Gene import Gene
from SDDetector.Entities.Transcript import Transcript
from SDDetector.Entities.CDS import CDS

                lCDS.extend(transcript.lCDS)

        logging.info('Inserting gene features in db')

        self.conn.executemany('''insert into gene (id, seqid, start,end,strand) values (?,?,?,?,?)''', [(gene.id,gene.seqid,gene.start,gene.end,gene.strand) for gene in lGenes ])

        logging.info('Inserting mRNA features in db')

        self.conn.executemany('''insert into transcript (id, seqid, start,end,strand,gene_id) values (?,?,?,?,?,?)''', [(transcript.id,transcript.seqid,transcript.start,transcript.end,transcript.strand, transcript.gene_id) for transcript in lTranscripts ])

        logging.info('Inserting CDS features in db')

        self.conn.executemany('''insert into CDS (cds_id, seqid, start,end,strand,transcript_id) values (?,?,?,?,?,?)''', [(cds.cds_id,cds.seqid,cds.start,cds.end,cds.strand,cds.transcript_id) for cds in lCDS ])

        self.commit()


    def selectAllGenes(self):
        """Select all genes"""


        lGenes = []
        dGenes = {}
        lTranscripts = []
        dTranscripts = {}
        lCDS = []
        dCDS = {}

        cursor = self.conn.execute('''select id, seqid, start, end, strand from gene''') 
        for row in cursor:        

            dGenes[row[0]] = Gene(row[0],row[1],row[2],row[3],row[4])