jpayne@68: """ jpayne@68: Provides access to example files and keeps track of all temp files created jpayne@68: during a Python session. jpayne@68: """ jpayne@68: import os jpayne@68: jpayne@68: TEMPFILES = [] jpayne@68: jpayne@68: jpayne@68: def data_dir(): jpayne@68: """ jpayne@68: Returns the data directory that contains example files for tests and jpayne@68: documentation. jpayne@68: """ jpayne@68: return os.path.join(os.path.dirname(__file__), "test", "data") jpayne@68: jpayne@68: jpayne@68: def example_filename(fn): jpayne@68: """ jpayne@68: Return a bed file from the pybedtools examples directory. Use jpayne@68: func:`list_example_files` to see a list of files that are included. jpayne@68: """ jpayne@68: fn = os.path.join(data_dir(), fn) jpayne@68: if not os.path.exists(fn): jpayne@68: msg = "%s does not exist" % fn jpayne@68: raise FileNotFoundError(msg) jpayne@68: return fn jpayne@68: jpayne@68: jpayne@68: def list_example_files(): jpayne@68: """ jpayne@68: Returns a list of files in the examples dir. Choose one and pass it to jpayne@68: :func:`example_filename` to get the full path to an example file. jpayne@68: jpayne@68: Example usage: jpayne@68: jpayne@68: >>> from pybedtools import BedTool jpayne@68: >>> choices = list_example_files() jpayne@68: >>> assert 'a.bed' in choices jpayne@68: >>> bedfn = example_filename('a.bed') jpayne@68: >>> mybedtool = BedTool(bedfn) jpayne@68: jpayne@68: """ jpayne@68: candidate_fns = os.listdir(data_dir()) jpayne@68: exts = (".bed", ".gff", ".gtf", ".bed.gz", ".bam", ".gff.gz") jpayne@68: valid_fns = [f for f in candidate_fns if f.endswith(exts)] jpayne@68: return sorted(valid_fns)