pybedtools.bedtool.BedTool.filter

BedTool.filter(func, *args, **kwargs)[source]

Filter features by user-defined function.

Takes a function func that is called for each feature in the BedTool object and returns only those for which the function returns True.

args and **kwargs are passed directly to *func.

Returns a streaming BedTool; if you want the filename then use the .saveas() method.

>>> a = pybedtools.example_bedtool('a.bed')
>>> subset = a.filter(lambda b: b.chrom == 'chr1' and b.start < 150)
>>> len(a), len(subset)
(4, 2)

so it has extracted 2 records from the original 4.