daler/pybedtools — pull request #47 by jakebiesinger (2012-01-25 05:46:08+00:00)
Title: Add as_string option for BedTool.head()

The motivation being that if I just want a slice of a bedtool, I can do:

```
b = pybedtools.BedTool(a.head(3, as_string=True), from_string=True)
```

Other options I tried include ```b = pybedtools.BedTool(a[:3])``` which makes a streaming bedtool:
```
In [7]: print b
chr1 1 100 feature1 0 +
chr1 100 200 feature2 0 +
chr1 150 500 feature3 0 -
In [8]: print b
# nothing here!
```

and ```b = pybedtools.BedTool(list(a[:3])``` which should work according to the docstring but actually results in:
```
In [12]: repr(b)
Out[12]: '[Interval(chr1:1-100), Interval(chr1:100-200), Interval(chr1:150-500)]'
In [13]: str(b)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/wbiesing/src/pybedtools/ in ()
----> 1 str(b)
/home/wbiesing/src/pybedtools/pybedtools/bedtool.py in __str__(self)
802 return open(self.fn).read()
803
--> 804 return '\n'.join(str(i) for i in iter(self)) + '\n'
805
806 def __len__(self):

TypeError: iter() returned non-iterator of type 'list'
```

I'd prefer the slice notation, but I'm not sure how to make a non-streaming bedtool off of it...