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 exceptions
17 import os
18 import sys
19 import tempfile
20
22 """
23 a dictionary of lists
24 """
30
33 try:
34 return dict.__getitem__(self, key)
35 except KeyError:
36 return None
37
40 dict_copy = {}
41 for key in self:
42 dict_copy[key] = str(self[key])
43 return str(dict_copy)
44
47 return str(map(lambda x: str(x), self))
48
50 - def __init__(self, suffix = ".python-temp", keep = 0):
51 self.removed = 0
52 self.keep = keep
53
54 file.__init__(self, tempfile.mktemp(suffix), "w")
55
58
60 if self.keep == 0:
61 if self.removed == 0:
62 try:
63 try:
64 self.close()
65 os.remove(self.name)
66 finally:
67 self.removed = 1
68 except exceptions.OSError:
69 pass
70
73
75 """
76 the data is stored in _data
77 """
80
89
90
91 -def defline_text(defline):
92 if defline[0] == ">":
93 return defline[1:]
94 else:
95 return defline
96
98 """
99 Returns 1 if x is a tuple or list (sequence types that can nest)
100 Returns 0 otherwise
101
102 >>> is_nestable("string")
103 0
104 >>> is_nestable((0,))
105 1
106 >>> is_nestable(range(5))
107 1
108 """
109 return isinstance(x, (tuple, list))
110
112 """
113 returns strings of list
114 """
115 try:
116 return '[%s]' % ', '.join(map(str, l))
117 except TypeError:
118 return str(l)
119
120 -def reverse_text(text):
121 """
122 >>> reverse_text('abracadabra')
123 'arbadacarba'
124 """
125 l = list(text)
126 l.reverse()
127 return ''.join(l)
128
130 """
131 >>> unparsed_args = ["moocow"]
132 >>> args = ArgsParser(unparsed_args, [('infile', 'defaultin'), ('outfile', 'defaultout')])
133 >>> args.infile
134 'moocow'
135 >>> args.outfile
136 'defaultout'
137 """
139 for i, default in enumerate(defaults):
140 try:
141 self.__dict__[default[0]] = args[i]
142 continue
143 except TypeError:
144 pass
145 except IndexError:
146 pass
147 self.__dict__[default[0]] = default[1]
148
150 return [item for item in iterator]
151
153 """Run the Bio.GFF.GenericTools module's doctests (PRIVATE).
154
155 This will try and locate the unit tests directory, and run the doctests
156 from there in order that the relative paths used in the examples work.
157 """
158 import doctest
159 print "Runing doctests..."
160 doctest.testmod()
161 print "Done"
162
163 if __name__ == "__main__":
164 if __debug__:
165 _test()
166