Esempio n. 1
0
 def complement(self, item):
     """Returns complement of item, using data from self.Complements.
     
     Always tries to return same type as item: if item looks like a dict,
     will return list of keys.
     """
     if not self.Complements:
         raise TypeError, "Tried to complement sequence using alphabet without complements."
     try:
         return item.translate(self.ComplementTable)
     except (AttributeError, TypeError):
         item = iterable(item)
         get = self.Complements.get
         return item.__class__([get(i, i) for i in item])
Esempio n. 2
0
 def complement(self, item):
     """Returns complement of item, using data from self.Complements.
     
     Always tries to return same type as item: if item looks like a dict,
     will return list of keys.
     """
     if not self.Complements:
         raise TypeError, \
         "Tried to complement sequence using alphabet without complements."
     try:
         return item.translate(self.ComplementTable)
     except (AttributeError, TypeError):
         item = iterable(item)
         get = self.Complements.get
         return item.__class__([get(i, i) for i in item])
Esempio n. 3
0
 def __init__(self, Spans=[]):
     """Returns a new Range object with data in Spans.
     """
     result = SpansOnly()
     #need to check if we got a single Span, since they define __iter__.
     if isinstance(Spans, Span):
         result.append(Spans)
     elif hasattr(Spans, 'Spans'):   #probably a single range object?
         result.extend(Spans.Spans)
     else:
         for s in iterable(Spans):
             if hasattr(s, 'Spans'):
               result.extend(s.Spans)
             else:
                 result.append(s)
     self.Spans = result
Esempio n. 4
0
 def __init__(self, Spans=[]):
     """Returns a new Range object with data in Spans.
     """
     result = SpansOnly()
     #need to check if we got a single Span, since they define __iter__.
     if isinstance(Spans, Span):
         result.append(Spans)
     elif hasattr(Spans, 'Spans'):   #probably a single range object?
         result.extend(Spans.Spans)
     else:
         for s in iterable(Spans):
             if hasattr(s, 'Spans'):
               result.extend(s.Spans)
             else:
                 result.append(s)
     self.Spans = result
Esempio n. 5
0
def list_extender(obj, field, val):
    """Adds val to list in obj.field, creating list if necessary."""
    try:
        getattr(obj, field).extend(iterable(val))
    except AttributeError:
        setattr(obj, field, list(val))
Esempio n. 6
0
def list_extender(obj, field, val):
    """Adds val to list in obj.field, creating list if necessary."""
    try:
        getattr(obj, field).extend(iterable(val))
    except AttributeError:
        setattr(obj, field, list(val))