Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readability + PEP8 changes #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions pygr/blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ def read_blast_alignment(ofile, srcDB, destDB, al=None, pipeline=None,
object.
"""
p = BlastHitParser()
d = dict(id='src_id', start='src_start', stop='src_end', ori='src_ori',
idDest='dest_id', startDest='dest_start',
stopDest='dest_end', oriDest='dest_ori')
d = dict(id='src_id',
start='src_start',
stop='src_end',
ori='src_ori',
idDest='dest_id',
startDest='dest_start',
stopDest='dest_end',
oriDest='dest_ori')
if translateSrc:
srcDB = translationDB.get_translation_db(srcDB)
if translateDest:
Expand Down Expand Up @@ -96,7 +101,7 @@ def start_blast(cmd, seq, seqString=None, seqDict=None, **kwargs):
else: # just write one query sequence
seqID = write_fasta(p.stdin, seqString)
if p.wait(): # blast returned error code
raise OSError('command %s failed' % ' '.join(cmd))
raise OSError('command {0} failed'.format(' '.join(cmd)))
return seqID, p


Expand Down Expand Up @@ -253,7 +258,7 @@ def blast_index_paths(self):
except AttributeError:
pass
for m in self.blastIndexDirs: # NOW TRY STANDARD LOCATIONS
if m=='FILEPATH':
if m == 'FILEPATH':
yield self.filepath
continue
elif m == os.path.expanduser:
Expand All @@ -277,7 +282,7 @@ def formatdb(self, filepath=None):
return self.run_formatdb(testpath)
except (IOError, OSError): # BUILD FAILED
pass
raise IOError("cannot build BLAST database for %s" % (self.filepath, ))
raise IOError("cannot build BLAST database for {0}".format(self.filepath, ))

def raw_fasta_stream(self, ifile=None, idFilter=None):
'''Return a stream of fasta-formatted sequences.
Expand All @@ -303,7 +308,7 @@ def blast_program(self, seq, blastprog=None):
try: # apply program transformation if provided
blastprog = self._blast_prog_dict[blastprog]
if blastprog.startswith('#'): # not permitted by this class!
raise ValueError('Use %s for %s' % (blastprog[1:], oldprog))
raise ValueError('Use {0} for {1}'.format(blastprog[1:], oldprog))
except KeyError:
pass # no program transformation to apply, so nothing to do...
return blastprog
Expand Down Expand Up @@ -457,15 +462,15 @@ def index_unpacked_ids(self, unpack_f=None):
for s in unpack_f(id):
if s == id:
continue # DON'T STORE TRIVIAL MAPPINGS!!
s=s.upper() # NCBI FORCES ID TO UPPERCASE?!?!
s = s.upper() # NCBI FORCES ID TO UPPERCASE?!?!
try:
if t[s]!=id and t[s] is not None:
t[s]=None # s NOT UNIQUE, CAN'T BE AN IDENTIFIER!!
if t[s] != id and t[s] is not None:
t[s] = None # s NOT UNIQUE, CAN'T BE AN IDENTIFIER!!
except KeyError:
t[s]=id # s UNIQUE, TRY USING s AS AN IDENTIFIER
t[s] = id # s UNIQUE, TRY USING s AS AN IDENTIFIER
for id in t.itervalues():
if id is not None: # OK THERE ARE REAL MAPPINGS STORED, SO USE THIS
self._unpacked_dict=t # SAVE THE MAPPING TO REAL IDENTIFIERS
self._unpacked_dict = t # SAVE THE MAPPING TO REAL IDENTIFIERS
return
# NO NON-TRIVIAL MAPPINGS, SO JUST SAVE EMPTY MAPPING
self._unpacked_dict={}
Expand All @@ -485,7 +490,7 @@ def get_real_id(self, bogusID, unpack_f=None):
except KeyError:
pass # KEEP TRYING...
# FOUND NO MAPPING, SO RAISE EXCEPTION
raise KeyError("no key '%s' in database %s" % (bogusID,
raise KeyError("no key '{0}' in database {1}".format(bogusID,
repr(self.seqDB)))

def __getitem__(self, seqID):
Expand Down