Package Bio :: Package GFF :: Module binning
[hide private]
[frames] | no frames]

Source Code for Module Bio.GFF.binning

 1  #!/usr/bin/env python 
 2  # 
 3  # Copyright 2002 by Michael Hoffman.  All rights reserved. 
 4  # This code is part of the Biopython distribution and governed by its 
 5  # license.  Please see the LICENSE file that should have been included 
 6  # as part of this package. 
 7  # 
 8  # note: 
 9  # I used Lincoln Stein's perl Bio::DB::GFF::Util::Binning as a model for this 
10   
11  """Binning support for Bio.GFF (DEPRECATED) 
12   
13  This is part of the "old" Bio.GFF module by Michael Hoffman, which offered 
14  access to a MySQL database holding GFF data loaded by BioPerl. This code has 
15  now been deprecated, and will probably be removed in order to free the Bio.GFF 
16  namespace for a new GFF parser in Biopython (including GFF3 support). 
17  """ 
18   
19 -class Meta(object):
20 MIN_BIN = 1000 21 MAX_BIN = 100000000
22
23 -def query(start=0, stop=Meta.MAX_BIN, minbin=Meta.MIN_BIN, maxbin=Meta.MAX_BIN):
24 args = [] 25 bins = [] 26 tier = maxbin 27 28 if start is None: 29 start=0 30 if stop is None: 31 stop = Meta.MAX_BIN 32 33 while tier >= minbin: 34 tier_start, tier_stop = bot(tier, start), top(tier, stop) 35 if (tier_start == tier_stop): 36 bins.append('fbin=%s') 37 args.append(tier_start) 38 else: 39 bins.append('fbin BETWEEN %s AND %s') 40 args.extend([tier_start, tier_stop]) 41 tier /= 10 42 query = "\n\t OR ".join(bins) 43 44 return query % tuple(args)
45
46 -def bin(start, stop, min, wantarray=0):
47 tier = min 48 while 1: 49 bin_start = int(float(start)/tier) 50 bin_end = int(float(stop)/tier) 51 if bin_start == bin_end: 52 break 53 tier *= 10 54 if wantarray: 55 return tier, bin_start 56 else: 57 return bin_name(tier, bin_start)
58
59 -def bot(tier, pos):
60 return name(tier, int(pos/tier))
61 62 top = bot 63
64 -def name(x, y):
65 return "%d.%06d" % (x, y)
66
67 -def _test(*args, **keywds):
68 import doctest, sys 69 doctest.testmod(sys.modules[__name__], *args, **keywds)
70 71 if __name__ == "__main__": 72 if __debug__: 73 _test() 74