Ejemplo n.º 1
0
def createdb(local=None,
             server=None,
             project=None,
             username=None,
             norecs=1000):
    """Create and add some test data"""
    if local != None:
        if os.path.exists(local):
            for i in ['.lock', '.index', '']:
                try:
                    os.remove(local + i)
                except:
                    pass
        DB = PDatabase(local=local)
    elif server != None:
        DB = PDatabase(server=server,
                       username=username,
                       password='******',
                       project=project)

    import string
    import DNAtool.mutation as mutation

    choices = ['a', 'b', 'c', 'd']
    DB.addField('choice', 'text')
    DB.addField('stab', 'text')
    DB.addField('activity', 'text')
    #DB.addField('ekin', 'General')
    E = EkinProject()
    data = E.readDataset('Ekin/test.Ekindat')
    E.insertDataset(data['data'], 'test', fit=data['fit'])
    print 'creating dummy data..'
    j = 0
    count = 0
    for i in range(norecs):
        if j > 3: j = 0
        c = ''
        for k in range(10):
            c += random.choice(string.letters)
        DB.add(c)
        DB.data[c].choice = choices[j]
        DB.data[c].DNASeq = simulate_sequence(300)
        AAseqs3, AAseqs1 = mutation.translate(DB.data[c].DNASeq)
        DB.addProtseq(c, AAseqs3[1][5:80], 1)
        DB.data[c].stab = str(round(random.normalvariate(1, 2), 3))
        DB.data[c].activity = str(round(random.normalvariate(30, 4), 3))
        #DB.data[c].ekin = E
        j += 1
        count += 1
        if count > 3000:
            print 'saving..'
            DB.commit()
            DB.db.cacheMinimize()
            count = 0

    DB.commit()
    return DB
Ejemplo n.º 2
0
def speedTest1():
    """benchmark read and write"""
    DB = PDatabase(server='localhost',port=8090)
    #DB = PDatabase(local='./Data.fs')
    for i in range(100,300):
        DB.add(i)
    for i in range(100,290):
        DB.delete(i)
    DB.commit()
    print DB
    DB.close()
    return
Ejemplo n.º 3
0
def speedTest1():
    """benchmark read and write"""
    DB = PDatabase(server='localhost', port=8090)
    #DB = PDatabase(local='./Data.fs')
    for i in range(100, 300):
        DB.add(i)
    for i in range(100, 290):
        DB.delete(i)
    DB.commit()
    print DB
    DB.close()
    return
Ejemplo n.º 4
0
def createdb(local=None, server=None, project=None, username=None, norecs=1000):
    """Create and add some test data"""
    if local != None:
        if os.path.exists(local):
            for i in ['.lock','.index','']:
                try:
                    os.remove(local+i)
                except:
                    pass
        DB = PDatabase(local=local)
    elif server!=None:
        DB = PDatabase(server=server, username=username,
                    password='******', project=project)

    import string
    import DNAtool.mutation as mutation
    
    choices = ['a','b','c','d']
    DB.addField('choice', 'text')
    DB.addField('stab', 'text')
    DB.addField('activity', 'text')
    #DB.addField('ekin', 'General')
    E = EkinProject()
    data=E.readDataset('Ekin/test.Ekindat')
    E.insertDataset(data['data'], 'test', fit=data['fit'])
    print 'creating dummy data..'
    j=0
    count=0
    for i in range(norecs):
        if j>3: j=0
        c=''
        for k in range(10):
            c += random.choice(string.letters)
        DB.add(c)
        DB.data[c].choice = choices[j]
        DB.data[c].DNASeq = simulate_sequence(300)
        AAseqs3,AAseqs1 = mutation.translate(DB.data[c].DNASeq)
        DB.addProtseq(c, AAseqs3[1][5:80], 1)
        DB.data[c].stab = str(round(random.normalvariate(1,2),3))
        DB.data[c].activity = str(round(random.normalvariate(30,4),3))
        #DB.data[c].ekin = E
        j+=1
        count+=1
        if count>3000:
            print 'saving..'
            DB.commit()
            DB.db.cacheMinimize()
            count=0

    DB.commit()
    return DB
Ejemplo n.º 5
0
def testBlob():
    """write a file as binary data to blob and read back"""
    from ZODB.PersistentMapping import PersistentMapping
    import mimetypes
    from PILView import PILViewer

    DB = PDatabase(server='localhost',port=8090,
              username='******',
              password='******')


    def addfile(fname):
        myblob = Blob()
        b=myblob.open('w')
        o=open(fname)
        data = o.read()
        b.write(data)
        print b.name
        b.close()
        return myblob

    dirlist=os.listdir(os.getcwd())

    for f in dirlist:
        m = mimetypes.guess_type(f)[0]
        if m != None and 'image' in m:
            print f
            b=addfile(f)
            DB.add(f)
            DB.data[f]['testfile']=FileRecord(name=f,blob=b)
    DB.commit()
    for k in DB.data:
        if not DB.data[k].has_key('testfile'):
            continue
        rec = DB.data[k]['testfile']
        myblob = rec.blob
        f = myblob.open("r")
        print f.name

    #app = PILViewer(imgfile=f.name)
    #app.mainloop()
    DB.close()
    return
Ejemplo n.º 6
0
def testBlob():
    """write a file as binary data to blob and read back"""
    from ZODB.PersistentMapping import PersistentMapping
    import mimetypes
    from PILView import PILViewer

    DB = PDatabase(server='localhost',
                   port=8090,
                   username='******',
                   password='******')

    def addfile(fname):
        myblob = Blob()
        b = myblob.open('w')
        o = open(fname)
        data = o.read()
        b.write(data)
        print b.name
        b.close()
        return myblob

    dirlist = os.listdir(os.getcwd())

    for f in dirlist:
        m = mimetypes.guess_type(f)[0]
        if m != None and 'image' in m:
            print f
            b = addfile(f)
            DB.add(f)
            DB.data[f]['testfile'] = FileRecord(name=f, blob=b)
    DB.commit()
    for k in DB.data:
        if not DB.data[k].has_key('testfile'):
            continue
        rec = DB.data[k]['testfile']
        myblob = rec.blob
        f = myblob.open("r")
        print f.name

    #app = PILViewer(imgfile=f.name)
    #app.mainloop()
    DB.close()
    return