Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoid using add_instance in Bio.Motif._Motif

  • Loading branch information...
commit 69492c2f65004c451bd7fbc4bc81a1fbe1a85169 1 parent 4c9ba69
Michiel de Hoon authored
Showing with 25 additions and 5 deletions.
  1. +25 −5 Bio/Motif/_Motif.py
View
30 Bio/Motif/_Motif.py
@@ -13,8 +13,7 @@ class Motif(object):
"""
A class representing sequence motifs.
"""
- def __init__(self,alphabet=IUPAC.unambiguous_dna):
- self.instances = None
+ def __init__(self, instances=None, alphabet=IUPAC.unambiguous_dna):
self.counts = None
self.mask = []
self._pwm_is_current = False
@@ -28,6 +27,24 @@ def __init__(self,alphabet=IUPAC.unambiguous_dna):
self.beta=1.0
self.info=None
self.name=""
+ if instances==None:
+ self.instances = None
+ else:
+ import warnings
+ from Bio import BiopythonExperimentalWarning
+ warnings.warn("This is experimental code, and may change in future versions", BiopythonExperimentalWarning)
+ self.instances = []
+ for instance in instances:
+ if self.alphabet==None:
+ self.alphabet=instance.alphabet
+ elif self.alphabet != instance.alphabet:
+ raise ValueError("Alphabets are inconsistent")
+ if self.length==None:
+ self.length = len(instance)
+ elif self.length != len(instance):
+ message = "All instances should have the same length (%d found, %d expected)" % (len(instance), self.length)
+ raise ValueError(message)
+ self.instances.append(instance)
@property
def has_instances(self):
@@ -430,11 +447,14 @@ def reverse_complement(self):
"""
Gives the reverse complement of the motif
"""
- res = Motif()
if self.instances!=None:
- for i in self.instances:
- res.add_instance(i.reverse_complement())
+ instances = []
+ for instance in self.instances:
+ instance = instance.reverse_complement()
+ instances.append(instance)
+ res = Motif(instances)
else: # has counts
+ res = Motif()
res.counts={}
res.counts["A"]=self.counts["T"][:]
res.counts["T"]=self.counts["A"][:]
Please sign in to comment.
Something went wrong with that request. Please try again.