HTSeq 2.0.7__cp312-cp312-macosx_10_9_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
HTSeq/utils.py ADDED
@@ -0,0 +1,95 @@
1
+ import itertools
2
+ import warnings
3
+ import os
4
+ import shlex
5
+ import sys
6
+
7
+ import HTSeq
8
+ from HTSeq._HTSeq import *
9
+ from HTSeq._version import __version__
10
+
11
+
12
+ class FileOrSequence:
13
+ """ The construcutor takes one argument, which may either be a string,
14
+ which is interpreted as a file name (possibly with path), or a
15
+ connection, by which we mean a text file opened for reading, or
16
+ any other object that can provide an iterator over strings
17
+ (lines of the file).
18
+
19
+ The advantage of passing a file name instead of an already opened file
20
+ is that if an iterator is requested several times, the file will be
21
+ re-opened each time. If the file is already open, its lines can be read
22
+ only once, and then, the iterator stays exhausted.
23
+
24
+ Furthermore, if a file name is passed that end in ".gz" or ".gzip"
25
+ (case insensitive), it is transparently gunzipped.
26
+ """
27
+
28
+ def __init__(self, filename_or_sequence):
29
+ self.fos = filename_or_sequence
30
+ self.should_close = False
31
+ self.line_no = None
32
+ self.lines = None
33
+
34
+ try:
35
+ os.fspath(self.fos)
36
+ self.fos_is_path = True
37
+ except TypeError:
38
+ # assumed to be a file handle
39
+ self.fos_is_path = False
40
+
41
+ def __enter__(self):
42
+ if self.fos_is_path:
43
+ fos = os.fspath(self.fos)
44
+ self.should_close = True
45
+ if fos.lower().endswith((".gz", ".gzip")):
46
+ lines = gzip.open(self.fos, 'rt')
47
+ else:
48
+ lines = open(self.fos)
49
+ else:
50
+ lines = self.fos
51
+
52
+ self.lines = lines
53
+ return self
54
+
55
+ def __exit__(self, type, value, traceback):
56
+ if self.should_close:
57
+ self.lines.close()
58
+ self.lines = None
59
+
60
+ def __iter__(self):
61
+ self.line_no = 1
62
+ if self.lines is None:
63
+ call_exit = True
64
+ self.__enter__()
65
+ else:
66
+ call_exit = False
67
+ lines = self.lines
68
+
69
+ try:
70
+ for line in lines:
71
+ yield line
72
+ self.line_no += 1
73
+ finally:
74
+ if call_exit:
75
+ self.__exit__(None, None, None)
76
+ self.line_no = None
77
+
78
+ def __repr__(self):
79
+ if isinstance(self.fos, str):
80
+ return "<%s object, connected to file name '%s'>" % (
81
+ self.__class__.__name__, self.fos)
82
+ else:
83
+ return "<%s object, connected to %s >" % (
84
+ self.__class__.__name__, repr(self.fos))
85
+
86
+ def get_line_number_string(self):
87
+ if self.line_no is None:
88
+ if isinstance(self.fos, str):
89
+ return "file %s closed" % self.fos
90
+ else:
91
+ return "file closed"
92
+ if isinstance(self.fos, str):
93
+ return "line %d of file %s" % (self.line_no, self.fos)
94
+ else:
95
+ return "line %d" % self.line_no
@@ -0,0 +1,5 @@
1
+ #!python
2
+
3
+ import HTSeq.scripts.count
4
+
5
+ HTSeq.scripts.count.main()
@@ -0,0 +1,5 @@
1
+ #!python
2
+
3
+ import HTSeq.scripts.count_with_barcodes
4
+
5
+ HTSeq.scripts.count_with_barcodes.main()
@@ -0,0 +1,5 @@
1
+ #!python
2
+
3
+ import HTSeq.scripts.qa
4
+
5
+ HTSeq.scripts.qa.main()