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