コード例 #1
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
    def readFromMysql(self, db, numId, withSeqs=True):
        """ read from mysql database, return None if not found in Db """
        #pmcId = pmcId.strip("pmcA")
        self.numId = numId

        if withSeqs:
            self.seqs = {}
            recs = util.sql(db, "select fileName, seqId, sequence, context from sequences where numId='%s'" % str(numId))
            #if len(recs)==0:
                #return None
            for r in recs:
                filename, seqId, seq, raw = r
                self.seqs[seqId]=(filename, seq, raw)

        row = util.sql(db, "select pmid, pmcId from refs where numId='%s';" % str(numId))
        self.pmid, self.pmcId = row[0]

        recs = util.sql(db, "select * from bestGenomes where numId='%s';" % str(numId))
        if len(recs)>0:
            self.bestGenome = recs[0][1]
        else:
            self.bestGenomes= None

        recs = util.sql(db, "select genomeId, chrom, start, end, numId, seqid, score, groupId from features where numId='%s'; " % str(numId))
        self.chainHits = recs

        #recs = util.sql(db, "select * from blastHits where numId='%s'" % str(pmcId))
        #self.rawHits = IndexedBlastHits(recs)
        #recs = util.sql(db, "select * from filtHits where numId='%s'" % str(pmcId))
        #self.filtHits = IndexedBlastHits(recs)
        #recs = util.sql(db, "select * from blastHitsGenes where numId='%s'" % str(pmcId))
        #self.filtGeneHits = IndexedBlastHits(recs)

        return True
コード例 #2
0
def process_register():
    email = request.form.get("email")
    passwd = get_password(email)
    if len(passwd) > 0:
        return redirect(url_for('register_error', error='already exists'))

    pass1 = request.form.get("pass1")
    pass2 = request.form.get("pass2")

    # validate email
    schema = {'email': {'type': 'string', 'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'}}
    document = {'email': email}
    v = Validator(schema)
    if not v.validate(document):
        return redirect(url_for('register_error', error='email'))
    if not pass1 == pass2:
        return redirect(url_for('register_error', error='pass'))

    from util import escape_sql_characters
    email = escape_sql_characters(email)
    pass1 = escape_sql_characters(pass1)
    insert_query = f"INSERT INTO user_data (email, password) VALUES ('{email}','{pass1}')"
    sql(insert_query, db=db, rollback=True)

    return redirect(url_for('register_success'))
コード例 #3
0
def getNumIdsOrthologs(db, orthologs):
    orthologIds = ["'" + g + "'" for g in orthologs]
    query = "select numId from bestGenes, orthologs where orthologs.geneId in (%s) and bestGenes.geneId=orthologs.geneId;" % ",".join(
        orthologIds)
    recs = util.sql(db, query)
    recs = [str(l[0]) for l in recs]
    return recs
コード例 #4
0
def getOrthologs(db, geneIds):
    geneIds = ["'" + g + "'" for g in geneIds]
    query = "select geneId from orthologs where hsGeneId in (%s);" % ",".join(
        geneIds)
    recs = util.sql(db, query)
    recs = [l[0] for l in recs]
    return recs
コード例 #5
0
def getNumIds(db, geneId, asStrings=False):
    recs = util.sql(db,
                    "select numId from bestGenes where geneId='%s';" % geneId)
    recs = [l[0] for l in recs]
    if asStrings:
        recs = [str(x) for x in recs]
    return recs
コード例 #6
0
    def readFromMysql(self, db, numId, withSeqs=True):
        """ read from mysql database, return None if not found in Db """
        #pmcId = pmcId.strip("pmcA")
        self.numId = numId

        if withSeqs:
            self.seqs = {}
            recs = util.sql(
                db,
                "select fileName, seqId, sequence, context from sequences where numId='%s'"
                % str(numId))
            #if len(recs)==0:
            #return None
            for r in recs:
                filename, seqId, seq, raw = r
                self.seqs[seqId] = (filename, seq, raw)

        row = util.sql(
            db, "select pmid, pmcId from refs where numId='%s';" % str(numId))
        self.pmid, self.pmcId = row[0]

        recs = util.sql(
            db, "select * from bestGenomes where numId='%s';" % str(numId))
        if len(recs) > 0:
            self.bestGenome = recs[0][1]
        else:
            self.bestGenomes = None

        recs = util.sql(
            db,
            "select genomeId, chrom, start, end, numId, seqid, score, groupId from features where numId='%s'; "
            % str(numId))
        self.chainHits = recs

        #recs = util.sql(db, "select * from blastHits where numId='%s'" % str(pmcId))
        #self.rawHits = IndexedBlastHits(recs)
        #recs = util.sql(db, "select * from filtHits where numId='%s'" % str(pmcId))
        #self.filtHits = IndexedBlastHits(recs)
        #recs = util.sql(db, "select * from blastHitsGenes where numId='%s'" % str(pmcId))
        #self.filtGeneHits = IndexedBlastHits(recs)

        return True
コード例 #7
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
def getNumIdsOrthologs(db, orthologs):
    orthologIds = ["'"+g+"'" for g in orthologs]
    query = "select numId from bestGenes, orthologs where orthologs.geneId in (%s) and bestGenes.geneId=orthologs.geneId;" % ",".join(orthologIds)
    recs = util.sql(db, query)
    recs = [str(l[0]) for l in recs]
    return recs
コード例 #8
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
def getOrthologs(db, geneIds):
    geneIds = ["'"+g+"'" for g in geneIds]
    query = "select geneId from orthologs where hsGeneId in (%s);" % ",".join(geneIds)
    recs = util.sql(db, query)
    recs = [l[0] for l in recs]
    return recs
コード例 #9
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
def getIdForSymbol(db, symbol):
    recs = util.sql(db, "select geneId from genes where symbol = %s;", symbol)
    if len(recs)==0:
        return symbol
    else:
        return recs[0][0]
コード例 #10
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
def getHumanOrthologs(db, geneId):
    recs = util.sql(db, "select hsGeneId from orthologs where geneId='%s' " % (geneId))
    recs = [l[0] for l in recs]
    return recs
コード例 #11
0
ファイル: pmcArticle.py プロジェクト: maximilianh/maxtools
def getNumIds(db, geneId, asStrings=False):
    recs = util.sql(db, "select numId from bestGenes where geneId='%s';" % geneId)
    recs = [l[0] for l in recs]
    if asStrings:
        recs = [str(x) for x in recs]
    return recs
コード例 #12
0
def getIdForSymbol(db, symbol):
    recs = util.sql(db, "select geneId from genes where symbol = %s;", symbol)
    if len(recs) == 0:
        return symbol
    else:
        return recs[0][0]
コード例 #13
0
def getHumanOrthologs(db, geneId):
    recs = util.sql(
        db, "select hsGeneId from orthologs where geneId='%s' " % (geneId))
    recs = [l[0] for l in recs]
    return recs
コード例 #14
0
if not tables['db config']:
    config['overwrite']['db_config_modify'] = "True"
if not tables['books']:
    config['overwrite']['books_table_modify'] = "True"
    config['DEFAULT']['import books'] = "True"
if not tables['users']: config['overwrite']['user_table_modify'] = "True"
if not tables['reviews']: config['overwrite']['reviews_table_modify'] = "True"

print(dict(config['overwrite']))
print("Decisions made.\nWorking on:")
# Creating tables one by one
# db config
print("DB Config table.")
if config['overwrite']['db_config_modify'] == "True":
    if tables['db config']:
        sql(config['queries']['drop db config'], db=db, rollback=True)
    sql(config['queries']['db config'], db=db)
    for key in config['overwrite'].keys():
        add_var(key, config['overwrite'][key], db=db)
for key in config['overwrite'].keys():
    modify_var(key, config['overwrite'][key], db=db)

# Books
print("Books table.")
if config['overwrite']['books_table_modify'] == "True":
    if tables['books']:
        sql(config['queries']['drop books'], rollback=True)
    sql(config['queries']['create books'], db=db)

if config['overwrite']['books_table_modify'] == 'True' or config['DEFAULT'][
        'import books'] == 'True':