1
2
3
4
5
6
7
8 """A set of generic bits of code under Bio.GFF (DEPRECATED).
9
10 This is part of the "old" Bio.GFF module by Michael Hoffman, which offered
11 access to a MySQL database holding GFF data loaded by BioPerl. This code has
12 now been deprecated, and will probably be removed in order to free the Bio.GFF
13 namespace for a new GFF parser in Biopython (including GFF3 support).
14 """
15
16 import os
17 import sys
18 import tempfile
19
21 """
22 a dictionary of lists
23 """
29
32 try:
33 return dict.__getitem__(self, key)
34 except KeyError:
35 return None
36
39 dict_copy = {}
40 for key in self:
41 dict_copy[key] = str(self[key])
42 return str(dict_copy)
43
46 return str(map(lambda x: str(x), self))
47
49 - def __init__(self, suffix = ".python-temp", keep = 0):
50 self.removed = 0
51 self.keep = keep
52
53 file.__init__(self, tempfile.mktemp(suffix), "w")
54
57
59 if self.keep == 0:
60 if self.removed == 0:
61 try:
62 try:
63 self.close()
64 os.remove(self.name)
65 finally:
66 self.removed = 1
67 except OSError:
68 pass
69
72
74 """
75 the data is stored in _data
76 """
79
88
89
90 -def defline_text(defline):
91 if defline[0] == ">":
92 return defline[1:]
93 else:
94 return defline
95
97 """
98 Returns 1 if x is a tuple or list (sequence types that can nest)
99 Returns 0 otherwise
100
101 >>> is_nestable("string")
102 0
103 >>> is_nestable((0,))
104 1
105 >>> is_nestable(range(5))
106 1
107 """
108 return isinstance(x, (tuple, list))
109
111 """
112 returns strings of list
113 """
114 try:
115 return '[%s]' % ', '.join(map(str, l))
116 except TypeError:
117 return str(l)
118
119 -def reverse_text(text):
120 """
121 >>> reverse_text('abracadabra')
122 'arbadacarba'
123 """
124 l = list(text)
125 l.reverse()
126 return ''.join(l)
127
129 """
130 >>> unparsed_args = ["moocow"]
131 >>> args = ArgsParser(unparsed_args, [('infile', 'defaultin'), ('outfile', 'defaultout')])
132 >>> args.infile
133 'moocow'
134 >>> args.outfile
135 'defaultout'
136 """
138 for i, default in enumerate(defaults):
139 try:
140 self.__dict__[default[0]] = args[i]
141 continue
142 except TypeError:
143 pass
144 except IndexError:
145 pass
146 self.__dict__[default[0]] = default[1]
147
149 return [item for item in iterator]
150
152 """Run the Bio.GFF.GenericTools module's doctests (PRIVATE).
153
154 This will try and locate the unit tests directory, and run the doctests
155 from there in order that the relative paths used in the examples work.
156 """
157 import doctest
158 print "Runing doctests..."
159 doctest.testmod()
160 print "Done"
161
162 if __name__ == "__main__":
163 if __debug__:
164 _test()
165