pybedtools 琐碎知识 坑

 

 

 

 

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

 

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.

 
 
 

 


 bedtools是使用率很高的生信工具,将其整合到python中(pybedtools),可以方便的调用,这本来是一件很好的事,但是遗憾的是pybedtools还是很不成熟,存在一些bug

 

https://github.com/daler/pybedtools/issues/172

 

posted @ 2023-02-03 10:15  emanlee  阅读(38)  评论(0编辑  收藏  举报