示例#1
0
def save_load(hmm):
	f = tempfile.TemporaryFile('w+r')
	hmmfile.write(hmm, f)
	f.seek(0)
	parser = hmmfile.HMMParser()
	hmmout = parser.read(f)[0]
	f.close()
	return hmmout
示例#2
0
	def test_build(self):
		#Should be case insensitive
		hmm = hmmfile.HMM(alphabet='DnA')

		#build the HMM
		for i in build_data:
			hmm.addState(**i)
		hmm.clean()

		#there are the correct number of states
		self.assertEqual(len(hmm.states), len(build_data), 
			"{} states built - should be {}".format(len(hmm.states),
				len(build_data)))

		s = StringIO()

		hmmfile.write(hmm, s)

		s.seek(0)
		hmm2 = hmmfile.read(s)[0]

		for o in hmmfile.OPTIONS:
			if hasattr(hmm, o):
				self.assertEqual(getattr(hmm, o), getattr(hmm2, o))

		def r(l):
			ret = []
			for i in l:
				if type(i) == float:
					ret.append(round(i,5))
				else:
					ret.append(i)
			return ret

		for i,(e,g) in enumerate(zip(hmm.states, hmm2.states)):
			msg = "State {}: {} != {}"
			self.assertEqual(r(e.me), g.me, msg.format(i,e.me,g.me))
			self.assertEqual(r(e.ie), g.ie, msg.format(i,e.ie,g.ie))
			self.assertEqual(r(e.tr), g.tr, msg.format(i,e.tr,g.tr))
			self.assertEqual(e.map,g.map, msg.format(i,e.map,g.map))
			self.assertEqual(e.rf, g.rf, msg.format(i,e.rf,g.rf))
			self.assertEqual(e.cs, g.cs, msg.format(i,e.cs,g.cs))
示例#3
0
def update_models():
	"""Recalculate the HMM models"""
	print "Extracting C-Termini..."
	ct = extract.get_c_terminus(extract.extract(localization=None))
	print "Done. Got {} tails".format(len(ct))
	
	(E, Ep, DYW) = utils.get_tail_consensus()

	print "E"
	j = HMMER.jackhmmer(E,ct)
	j.hmms[-1].name = 'E'
	hmmfile.write(j.hmms[-1], os.path.join(utils.HMMDir, 'E.hmm'))

	print "E+"
	j = HMMER.jackhmmer(Ep,ct)
	j.hmms[-1].name = 'E+'
	hmmfile.write(j.hmms[-1], os.path.join(utils.HMMDir, 'E+.hmm'))

	print "DYW"
	j = HMMER.jackhmmer(DYW,ct)
	j.hmms[-1].name = 'DYW'
	hmmfile.write(j.hmms[-1], os.path.join(utils.HMMDir, 'DYW.hmm'))