pybedtools.bedtool.BedTool.saveas

BedTool.saveas(*args, **kwargs)[source]

Make a copy of the BedTool.

Optionally adds trackline to the beginning of the file.

Optionally compresses output using gzip.

if the filename extension is .gz, or compressed=True, the output is compressed using gzip

Returns a new BedTool for the newly saved file.

A newline is automatically added to the trackline if it does not already have one.

Example usage:

>>> a = pybedtools.example_bedtool('a.bed')
>>> b = a.saveas('other.bed')
>>> b.fn
'other.bed'
>>> print(b == a)
True
>>> b = a.saveas('other.bed', trackline="name='test run' color=0,55,0")
>>> open(b.fn).readline()
"name='test run' color=0,55,0\n"
>>> if os.path.exists('other.bed'):
...     os.unlink('other.bed')