Skip to content

Commit

Permalink
Trim EOL whitespace (PEP8 W291, W293), batch 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrueffer committed Dec 4, 2012
1 parent 3194062 commit b1c8597
Show file tree
Hide file tree
Showing 114 changed files with 756 additions and 811 deletions.
18 changes: 9 additions & 9 deletions BioSQL/BioSeq.py
Expand Up @@ -36,7 +36,7 @@ def __init__(self, primary_id, adaptor, alphabet, start, length):

def __len__(self):
return self._length

def __getitem__(self, index) : # Seq API requirement
#Note since Python 2.0, __getslice__ is deprecated
#and __getitem__ is used instead.
Expand All @@ -49,7 +49,7 @@ def __getitem__(self, index) : # Seq API requirement
raise IndexError(i)
i = i + self._length
elif i >= self._length:
raise IndexError(i)
raise IndexError(i)
return self.adaptor.get_subseq_as_string(self.primary_id,
self.start + i,
self.start + i + 1)
Expand Down Expand Up @@ -96,7 +96,7 @@ def __getitem__(self, index) : # Seq API requirement
self.start + i,
self.start + j)
return Seq(full[::index.step], self.alphabet)

def tostring(self):
"""Returns the full sequence as a python string.
Expand Down Expand Up @@ -138,7 +138,7 @@ def _retrieve_seq(adaptor, primary_id):
"SELECT alphabet, length, length(seq) FROM biosequence" \
" WHERE bioentry_id = %s", (primary_id,))
if not seqs : return
assert len(seqs) == 1
assert len(seqs) == 1
moltype, given_length, length = seqs[0]

try:
Expand All @@ -158,7 +158,7 @@ def _retrieve_seq(adaptor, primary_id):
have_seq = False
del seq
del given_length

moltype = moltype.lower() #might be upper case in database
#We have no way of knowing if these sequences will use IUPAC
#alphabets, and we certainly can't assume they are unambiguous!
Expand Down Expand Up @@ -264,7 +264,7 @@ def _retrieve_features(adaptor, primary_id):
if dbname == "":
dbname = None
lookup[location_id] = (dbname, v)

feature = SeqFeature.SeqFeature(type = seqfeature_type)
feature._seqfeature_id = seqfeature_id #Store the key as a private property
feature.qualifiers = qualifiers
Expand Down Expand Up @@ -327,7 +327,7 @@ def _retrieve_location_qualifier_value(adaptor, location_id):
"SELECT value FROM location_qualifier_value" \
" WHERE location_id = %s", (location_id,))
try:
return value[0]
return value[0]
except IndexError:
return ""

Expand Down Expand Up @@ -371,7 +371,7 @@ def _retrieve_qualifier_value(adaptor, primary_id):

def _retrieve_reference(adaptor, primary_id):
# XXX dbxref_qualifier_value

refs = adaptor.execute_and_fetchall(
"SELECT start_pos, end_pos, " \
" location, title, authors," \
Expand Down Expand Up @@ -427,7 +427,7 @@ def _retrieve_taxon(adaptor, primary_id, taxon_id):
#relies on the taxon table's parent_taxon_id field only (ignoring the
#optional left/right values). This means that it has to make a
#separate SQL query for each entry in the lineage, but it does still
#appear to be *much* faster. See Bug 2494.
#appear to be *much* faster. See Bug 2494.
taxonomy = []
while taxon_id:
name, rank, parent_taxon_id = adaptor.execute_one(
Expand Down
74 changes: 37 additions & 37 deletions BioSQL/BioSeqDatabase.py
Expand Up @@ -23,7 +23,7 @@ def open_database(driver = "MySQLdb", **kwargs):
This function is the easiest way to retrieve a connection to a
database, doing something like:
>>> from BioSeq import BioSeqDatabase
>>> server = BioSeqDatabase.open_database(user="root", db="minidb")
Expand Down Expand Up @@ -105,7 +105,7 @@ def open_database(driver = "MySQLdb", **kwargs):

class DBServer:
"""Represents a BioSQL database continaing namespaces (sub-databases).
This acts like a Python dictionary, giving access to each namespace
(defined by a row in the biodatabase table) as a BioSeqDatabase object.
"""
Expand All @@ -115,7 +115,7 @@ def __init__(self, conn, module, module_name=None):
module_name = module.__name__
self.adaptor = Adaptor(conn, DBUtils.get_dbutils(module_name))
self.module_name = module_name

def __repr__(self):
return self.__class__.__name__ + "(%r)" % self.adaptor.conn

Expand All @@ -131,35 +131,35 @@ def __contains__(self, value):
"""Check if a namespace (sub-database) in this database."""
sql = "SELECT COUNT(name) FROM biodatabase WHERE name=%s;"
return bool(self.adaptor.execute_and_fetch_col0(sql, (value,))[0])

def __iter__(self):
"""Iterate over namespaces (sub-databases) in the database."""
#TODO - Iterate over the cursor, much more efficient
return iter(self.adaptor.list_biodatabase_names())
return iter(self.adaptor.list_biodatabase_names())

if hasattr(dict, "iteritems"):
#Python 2, use iteritems etc
#Python 2, use iteritems etc
def keys(self):
"""List of namespaces (sub-databases) in the database."""
return self.adaptor.list_biodatabase_names()

def values(self):
"""List of BioSeqDatabase objects in the database."""
return [self[key] for key in self.keys()]

def items(self):
"""List of (namespace, BioSeqDatabase) for entries in the database."""
return [(key, self[key]) for key in self.keys()]

def iterkeys(self):
"""Iterate over namespaces (sub-databases) in the database."""
return iter(self)

def itervalues(self):
"""Iterate over BioSeqDatabase objects in the database."""
for key in self:
yield self[key]

def iteritems(self):
"""Iterate over (namespace, BioSeqDatabase) in the database."""
for key in self:
Expand All @@ -169,12 +169,12 @@ def iteritems(self):
def keys(self):
"""Iterate over namespaces (sub-databases) in the database."""
return iter(self)

def values(self):
"""Iterate over BioSeqDatabase objects in the database."""
for key in self:
yield self[key]

def items(self):
"""Iterate over (namespace, BioSeqDatabase) in the database."""
for key in self:
Expand All @@ -188,13 +188,13 @@ def __delitem__(self, name):

def remove_database(self, db_name):
"""Remove a namespace and all its entries (OBSOLETE).
Try to remove all references to items in a database.
server.remove_database(name)
In keeping with the dictionary interface, you can now do this:
del server[name]
"""
import warnings
Expand All @@ -208,7 +208,7 @@ def new_database(self, db_name, authority=None, description=None):
"""
# make the database
sql = r"INSERT INTO biodatabase (name, authority, description)" \
r" VALUES (%s, %s, %s)"
r" VALUES (%s, %s, %s)"
self.adaptor.execute(sql, (db_name, authority, description))
return BioSeqDatabase(self.adaptor, db_name)

Expand All @@ -234,7 +234,7 @@ def load_database_sql(self, sql_file):
elif line.strip(): # only include non-blank lines
sql += line.strip()
sql += ' '

# two ways to load the SQL
# 1. PostgreSQL can load it all at once and actually needs to
# due to FUNCTION defines at the end of the SQL which mess up
Expand Down Expand Up @@ -387,7 +387,7 @@ def list_bioentry_display_ids(self, dbid):

def list_any_ids(self, sql, args):
"""Return ids given a SQL statement to select for them.
This assumes that the given SQL does a SELECT statement that
returns a list of items. This parses them out of the 2D list
they come as and just returns them in a list.
Expand All @@ -413,7 +413,7 @@ def get_subseq_as_string(self, seqid, start, end):
# """select SUBSTRING(seq FROM %s FOR %s)
# from biosequence where bioentry_id = %s""",
# (start+1, length, seqid))[0]
#
#
# Convert to a string on returning for databases that give back
# unicode. Shouldn't need unicode for sequences so this seems safe.
return str(self.execute_one(
Expand Down Expand Up @@ -441,7 +441,7 @@ def execute_and_fetchall(self, sql, args=None):

class BioSeqDatabase:
"""Represents a namespace (sub-database) within the BioSQL database.
i.e. One row in the biodatabase table, and all all rows in the bioentry
table associated with it.
"""
Expand All @@ -452,12 +452,12 @@ def __init__(self, adaptor, name):

def __repr__(self):
return "BioSeqDatabase(%r, %r)" % (self.adaptor, self.name)

def get_Seq_by_id(self, name):
"""Gets a DBSeqRecord object by its name
Example: seq_rec = db.get_Seq_by_id('ROA1_HUMAN')
The name of this method is misleading since it returns a DBSeqRecord
rather than a DBSeq ojbect, and presumably was to mirror BioPerl.
"""
Expand Down Expand Up @@ -504,7 +504,7 @@ def get_all_primary_ids(self):
These maybe ids (display style) or accession numbers or
something else completely different - they *are not*
meaningful outside of this database implementation.
Please use .keys() instead of .get_all_primary_ids()
"""
import warnings
Expand Down Expand Up @@ -543,35 +543,35 @@ def __contains__(self, value):
return False
return bool(self.adaptor.execute_and_fetch_col0(sql,
(self.dbid, bioentry_id))[0])

def __iter__(self):
"""Iterate over ids (which may not be meaningful outside this database)."""
#TODO - Iterate over the cursor, much more efficient
return iter(self.adaptor.list_bioentry_ids(self.dbid))
return iter(self.adaptor.list_bioentry_ids(self.dbid))

if hasattr(dict, "iteritems"):
#Python 2, use iteritems etc
#Python 2, use iteritems etc
def keys(self):
"""List of ids which may not be meaningful outside this database."""
return self.adaptor.list_bioentry_ids(self.dbid)

def values(self):
"""List of DBSeqRecord objects in the namespace (sub database)."""
return [self[key] for key in self.keys()]

def items(self):
"""List of (id, DBSeqRecord) for the namespace (sub database)."""
return [(key, self[key]) for key in self.keys()]

def iterkeys(self):
"""Iterate over ids (which may not be meaningful outside this database)."""
return iter(self)

def itervalues(self):
"""Iterate over DBSeqRecord objects in the namespace (sub database)."""
for key in self:
yield self[key]

def iteritems(self):
"""Iterate over (id, DBSeqRecord) for the namespace (sub database)."""
for key in self:
Expand All @@ -581,12 +581,12 @@ def iteritems(self):
def keys(self):
"""Iterate over ids (which may not be meaningful outside this database)."""
return iter(self)

def values(self):
"""Iterate over DBSeqRecord objects in the namespace (sub database)."""
for key in self:
yield self[key]

def items(self):
"""Iterate over (id, DBSeqRecord) for the namespace (sub database)."""
for key in self:
Expand All @@ -603,12 +603,12 @@ def lookup(self, **kwargs):
lookup_func = getattr(self.adaptor, lookup_name)
seqid = lookup_func(self.dbid, v)
return BioSeq.DBSeqRecord(self.adaptor, seqid)

def get_Seq_by_primary_id(self, seqid):
"""Get a DBSeqRecord by the primary (internal) id (OBSOLETE).
Rather than db.get_Seq_by_primary_id(my_id) use db[my_id]
The name of this method is misleading since it returns a DBSeqRecord
rather than a DBSeq ojbect, and presumably was to mirror BioPerl.
"""
Expand Down Expand Up @@ -663,7 +663,7 @@ def load(self, record_iterator, fetch_NCBI_taxonomy=False):
"'%s' AND version = '%s' AND biodatabase_id = '%s')"
self.adaptor.execute(sql % (gi, self.dbid, accession, version, self.dbid))
if self.adaptor.cursor.fetchone():
raise self.adaptor.conn.IntegrityError("Duplicate record "
raise self.adaptor.conn.IntegrityError("Duplicate record "
"detected: record has not been inserted")
#End of hack
db_loader.load_seqrecord(cur_record)
Expand Down
6 changes: 3 additions & 3 deletions BioSQL/DBUtils.py
Expand Up @@ -26,7 +26,7 @@ def last_id(self, cursor, table):
cursor.execute(sql)
rv = cursor.fetchone()
return rv[0]

def execute(self, cursor, sql, args=None):
"""Just execute an sql command.
"""
Expand Down Expand Up @@ -58,7 +58,7 @@ def last_id(self, cursor, table):
#Google suggests this is the new way,
#same fix also suggested by Eric Gibert:
return cursor.lastrowid

_dbutils["MySQLdb"] = Mysql_dbutils


Expand All @@ -70,7 +70,7 @@ def next_id(self, cursor, table):
cursor.execute(sql)
rv = cursor.fetchone()
return rv[0]

def last_id(self, cursor, table):
table = self.tname(table)
sql = r"select currval('%s_pk_seq')" % table
Expand Down

0 comments on commit b1c8597

Please sign in to comment.