This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Removing A Single Entry From Biosql Database?

Hi everyone,

forgive me if this is obvious, im a newbie at both SQL and python!

I am in the process of populating a bioSQL database built by loading python-parsed genbank files into a pre-designed schema (http://www.biosql.org/wiki/Schema_Overview)

the bioSQL python module has a function to remove a subdatabase within this schema, but I need to only remove particular entries..

Any Idea if this is possible to do while making sure all associated data from all the tables is removed, rather than just the info from the 'bioentry' table?

thanks in advance!

biopython genbank

1 answer

If by 'single entry' you mean a sequence and its annotation, then using the BioSeqDatabase object just delete the record via it's identifier (key). For example, to remove all the records less than 100 in length,

from BioSQL import BioSeqDatabase
server = BioSeqDatabase.open_database(driver="MySQLdb", user="root",
                     passwd = "", host = "localhost", db="bioseqdb")
db = server["orchids"]
for key in db:
    record = db[key]
    if len(record) < 100:
        del db[key] #this will remove it from the database (once committed)
server.commit() 
server.close()

If you mean something more specific like a particular row in a table, or a particular feature, you have to do some SQL calls.

thanks for this, it is useful but not exactly what I wanted - In reality what I want to do is add a new Subfeature to an existing entry, and I thought that the best way to do that would be to re-create the genbank file and replace the old one.. the problem was that BioSQL wont let you overwrite an entry...

I solved it using ordinary commands to remove a row from the Bioentry table, and it seems that all its associated data disappeared as well.

Now i just need to figure out how to add a subfeature to an existing feature in an existing record!

Log in to answer this question.