首页 > 其他分享 >pybedtools 琐碎知识 坑

pybedtools 琐碎知识 坑

时间:2023-02-03 10:23:29浏览次数:67  
标签:saveas head 知识 bedtool pybedtools len filter 琐碎

 

 

 

 

一个坑:pybedtools 使用和不用saveas 会导致结果不同,有时saveas就会清空数据。

 

It looks like filter function doesn't return a BedTool object ready to use.

a = pybedtools.example_bedtool('a.bed')
b = a.filter(lambda x: len(x) > 100)
b.head()

NotImplementedError                       Traceback (most recent call last)
<ipython-input-66-154f9c28629d> in <module>()
      1 a = pybedtools.example_bedtool('a.bed')
      2 b = a.filter(lambda x: len(x) > 100)
----> 3 b.head()
NotImplementedError: head() not supported for non file-based BedTools
 
 

You need to save the generator-based b first:

a = pybedtools.example_bedtool('a.bed')
b = a.filter(lambda x: len(x) > 100)
b = b.saveas()
b.head()

Otherwise head() would consume the first 10 lines; I'm choosing to prevent this by raising the NotImplementedError.

相关文章