Permalink
Browse files

Removing add_instance from _from _from_jaspar_sites

  • Loading branch information...
1 parent 4502583 commit f74e39d79c0450e9162883606689b2d564b13047 Michiel de Hoon committed Nov 25, 2012
Showing with 21 additions and 17 deletions.
  1. +21 −17 Bio/Motif/_Motif.py
View
38 Bio/Motif/_Motif.py
@@ -580,24 +580,28 @@ def _from_jaspar_sites(self,stream):
The instances and pwm are OK.
"""
-
- while True:
- ln = stream.readline()# read the header "$>...."
- if ln=="" or ln[0]!=">":
+ # Probably this should be in a separate submodule of Bio.Motif
+ self.instances = []
+ for line in stream:
+ if not line.startswith(">"):
break
-
- ln=stream.readline().strip()#read the actual sequence
- i=0
- while ln[i]==ln[i].lower():
- i+=1
- inst=""
- while i<len(ln) and ln[i]==ln[i].upper():
- inst+=ln[i]
- i+=1
- inst=Seq(inst,self.alphabet)
- self.add_instance(inst)
-
- self.set_mask("*"*len(inst))
+ # line contains the header ">...."
+ # now read the actual sequence
+ line = stream.next()
+ instance = ""
+ for c in line.strip():
+ if c==c.upper():
+ instance += c
+ instance = Seq(instance, self.alphabet)
+ length = len(instance)
+ if self.length==None:
+ self.length = length
+ elif length!=self.length:
+ raise ValueError("Inconsistent motif lengths found")
+ self.instances.append(instance)
+ self._pwm_is_current = False
+ self._log_odds_is_current = False
+ self.set_mask("*"*len(instance))
return self

0 comments on commit f74e39d

Please sign in to comment.