コード例 #1
0
	def test_tot(self):
		"""Histogram total retrieval"""
		a = [1,3,5,2,4,0,7,7.01]
		hist = stats.Histogram(a, n_bins=8)
		#print hist.total
		self.assertTrue(hist.total==len(a))
		hist.add([3,-1])
		self.assertTrue(hist.total==len(a)+2)
コード例 #2
0
	def test(self):
		"""Histogram"""
		a = [1,3,5,2,4,0,7,7.01]
		hist = stats.Histogram()
		hist.init(min(a), max(a), 10)
		hist.add(a)
		self.assertTrue(len(hist.extras) == 0)
		hist.add(12.0)
		self.assertTrue(len(hist.extras) == 1)
コード例 #3
0
	def test_neardist(self):
		"""Nearest distances"""
		comp = protprop.Composition()
		pp = protprop.ProteinProperties()
		aa_classes = ['FY','P','NQ']
		for xi in range(5):
			seq = genMotif(aa_classes, [(0,2),(1,1),(2,2),(0,2),(1,1),(2,2)])
			#print seq
			dists = pp.nearestDistances(seq, aa_classes)
			#print dists
			hist = stats.Histogram(vals=dists['FY'], n_bins=7, min_val=-0.5,max_val=6.5)
			#print hist
			self.assertTrue(hist[1].count==2)
			self.assertTrue(hist[4].count==1)
			self.assertTrue(hist[2].count==0)
コード例 #4
0
	def test_alldist(self):
		"""All distances"""
		comp = protprop.Composition()
		pp = protprop.ProteinProperties()
		aa_classes = ['FY','P','NQ']
		for xi in range(5):
			seq = genMotif(aa_classes, [(0,2),(1,1),(2,2),(0,2),(1,1),(2,2)])
			#print seq
			dists = pp.allDistances(seq, aa_classes)
			#print dists
			hist = stats.Histogram(vals=dists['FY'], n_bins=7, min_val=-0.5,max_val=6.5)
			#print hist
			self.assertTrue(hist[1].count==2)
			self.assertTrue(hist[4].count==1)
			self.assertTrue(hist[2].count==0)
			answer = [1, 5, 6, 4, 5, 1]
			for (a,b) in zip(dists['FY'], answer):
				self.assertTrue(a==b)
コード例 #5
0
                subseq = seq[startpos:(startpos + window_size)]
                if not '*' in subseq:
                    score = quant.quant(subseq, base=options.logarithm_base)
                    if score < min_ent:
                        min_ent = score
                        min_seq = subseq
                    if score > max_ent:
                        max_ent = score
                        max_seq = subseq
                    scores.append(score)
                    n_samples += 1

        data_outs.write("# Minimum-entropy sequence = {}\n".format(min_seq))
        data_outs.write("# Maximum-entropy sequence = {}\n".format(max_seq))

        hist = stats.Histogram([20**s for s in scores], options.num_bins)
        data_outs.write(
            "ent.lower\tent.mid\tent.upper\tcount\tdensity\tcum.count\tcum.density\n"
        )
        n_written = 0
        for b in hist.bins:
            line = "{me.lower:1.4f}\t{me.mid:1.4f}\t{me.upper:1.4f}\t{me.count:d}\t{me.density:1.3E}\t{me.cum:d}\t{me.cumdensity:1.3E}\n".format(
                me=b)
            data_outs.write(line)
            n_written += 1

        # Write out stopping time
        data_outs.write("# Run finished {}\n".format(util.timestamp()))

        # Shut down output
        if not options.out_fname is None:
コード例 #6
0
	def test_bin(self):
		"""Histogram bin value retrieval"""
		a = [1,3,5,2,4,0,7,7.01]
		hist = stats.Histogram(a, n_bins=8)
		self.assertTrue(hist[7].count == 2)
		self.assertTrue(hist[-1].count == 0)
コード例 #7
0
#! /usr/local/bin/python

import sys, os, math, string, random, pickle
import stats

if __name__ == "__main__":
    h = stats.Histogram()
    bin_min = -1.3
    bin_max = 10
    h.init(bin_min, bin_max, 10)
    for i in range(10000):
        x = random.random() * (bin_max - bin_min - 2) + bin_min
        h.add(x)
    print h

    h = stats.Histogram()
    h.init(bin_min, bin_max, 10)
    try:
        h.add("waah")
    except TypeError, te:
        print te
    print h

    h = stats.Histogram()
    print h