Skip to content

Commit

Permalink
Minor changes/clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
dvklopfenstein committed Jul 20, 2015
1 parent 4b3f421 commit 630ae60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions goatools/obo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def __iter__(self):
with open(self.obo_file) as fstream:
rec_curr = None # Stores current GO Term
for lnum, line in enumerate(fstream):
line = line.rstrip() # chomp
# obo lines start with any of: [Term], [Typedef], /^\S+:/, or /^\s*/
if line[0:6] == "[Term]":
rec_curr = self._init_GOTerm_ref(rec_curr, "Term", lnum)
Expand All @@ -138,6 +137,7 @@ def __iter__(self):
# def: "The maintenance of ...
# is_a: GO:0007005 ! mitochondrion organization
elif rec_curr is not None:
line = line.rstrip() # chomp
if ":" in line:
self._add_to_ref(rec_curr, line, lnum)
elif line == "":
Expand All @@ -146,6 +146,9 @@ def __iter__(self):
rec_curr = None
else:
self._die("UNEXPECTED LINE CONTENT: {L}".format(L=line), lnum)
# Return last record, if necessary
if rec_curr is not None:
yield rec_curr

def _init_GOTerm_ref(self, rec_curr, name, lnum):
"""Initialize new reference and perform checks."""
Expand All @@ -157,7 +160,7 @@ def _init_GOTerm_ref(self, rec_curr, name, lnum):

def _add_to_ref(self, rec_curr, line, lnum):
"""Add new fields to the current reference."""
mtch = re.match(r'^(\S+):\s*(\S.*)\s*$', line)
mtch = re.match(r'^(\S+):\s*(\S.*)$', line)
if mtch:
field_name = mtch.group(1)
field_value = mtch.group(2)
Expand Down
16 changes: 9 additions & 7 deletions tests/test_oboreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ def test_run(msg, tag, use_alt=False):
def test_oboreader_equal_(dag_fin):
"""Test that the contents of the original DAG and the alternate DAG are the same."""
sys.stdout.write("\n\nTEST GODag EQUALITY USING {} ...\n\n".format(dag_fin))
# 1. Read the obo file using the original OBOReader.
tic = timeit.default_timer()
dag_orig = GODag(dag_fin)
sys.stdout.write("Original OBOReader Elapsed HMS: {}\n\n".format(
str(datetime.timedelta(seconds=(timeit.default_timer()-tic)))))
# 2. Read the obo file using the alternate OBOReader.
# 1. Read the obo file using the alternate OBOReader.
tic = timeit.default_timer()
dag_alt = GODag(dag_fin, True)
sys.stdout.write("Alternate OBOReader Elapsed HMS: {}\n\n".format(
str(datetime.timedelta(seconds=(timeit.default_timer()-tic)))))
# 2. Read the obo file using the original OBOReader.
tic = timeit.default_timer()
dag_orig = GODag(dag_fin)
sys.stdout.write("Original OBOReader Elapsed HMS: {}\n\n".format(
str(datetime.timedelta(seconds=(timeit.default_timer()-tic)))))
# 3. Test that the contents of each GODag are the same.
#if len(dag_orig) != len(dag_alt): raise Exception("LENGTHES NOT THE SAME")
if len(dag_orig) != len(dag_alt): raise Exception("LENGTHES NOT THE SAME")
for goid, goorig in dag_orig.items():
goalt = dag_alt[goid]
if goorig.id != goalt.id: raise Exception("id MISMATCH")
Expand Down Expand Up @@ -125,6 +125,8 @@ def test_oboreader_equal_(dag_fin):
dag_fin))




#################################################################
# Tests
#################################################################
Expand Down

0 comments on commit 630ae60

Please sign in to comment.