annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/pybedtools/filenames.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 """
jpayne@68 2 Provides access to example files and keeps track of all temp files created
jpayne@68 3 during a Python session.
jpayne@68 4 """
jpayne@68 5 import os
jpayne@68 6
jpayne@68 7 TEMPFILES = []
jpayne@68 8
jpayne@68 9
jpayne@68 10 def data_dir():
jpayne@68 11 """
jpayne@68 12 Returns the data directory that contains example files for tests and
jpayne@68 13 documentation.
jpayne@68 14 """
jpayne@68 15 return os.path.join(os.path.dirname(__file__), "test", "data")
jpayne@68 16
jpayne@68 17
jpayne@68 18 def example_filename(fn):
jpayne@68 19 """
jpayne@68 20 Return a bed file from the pybedtools examples directory. Use
jpayne@68 21 func:`list_example_files` to see a list of files that are included.
jpayne@68 22 """
jpayne@68 23 fn = os.path.join(data_dir(), fn)
jpayne@68 24 if not os.path.exists(fn):
jpayne@68 25 msg = "%s does not exist" % fn
jpayne@68 26 raise FileNotFoundError(msg)
jpayne@68 27 return fn
jpayne@68 28
jpayne@68 29
jpayne@68 30 def list_example_files():
jpayne@68 31 """
jpayne@68 32 Returns a list of files in the examples dir. Choose one and pass it to
jpayne@68 33 :func:`example_filename` to get the full path to an example file.
jpayne@68 34
jpayne@68 35 Example usage:
jpayne@68 36
jpayne@68 37 >>> from pybedtools import BedTool
jpayne@68 38 >>> choices = list_example_files()
jpayne@68 39 >>> assert 'a.bed' in choices
jpayne@68 40 >>> bedfn = example_filename('a.bed')
jpayne@68 41 >>> mybedtool = BedTool(bedfn)
jpayne@68 42
jpayne@68 43 """
jpayne@68 44 candidate_fns = os.listdir(data_dir())
jpayne@68 45 exts = (".bed", ".gff", ".gtf", ".bed.gz", ".bam", ".gff.gz")
jpayne@68 46 valid_fns = [f for f in candidate_fns if f.endswith(exts)]
jpayne@68 47 return sorted(valid_fns)