예제 #1
0
파일: HMMER.py 프로젝트: haydnKing/pyHMMER
	def _do_search(self, seq, seqdb, args):

		seq_file = tempfile.NamedTemporaryFile()
		seqdb_file = tempfile.NamedTemporaryFile()
		out_file = tempfile.NamedTemporaryFile()
		hmm_file = tempfile.NamedTemporaryFile()

		SeqIO.write(seq, seq_file, 'fasta')
		SeqIO.write(seqdb, seqdb_file, 'fasta')
		seq_file.flush()
		seqdb_file.flush()

		p = Popen(['jackhmmer', '--qformat', 'fasta', '--tformat', 'fasta', 
			'--chkhmm', hmm_file.name, '--domtblout', out_file.name,] + args + 
			[seq_file.name, seqdb_file.name,], 
				stdout=PIPE, stdin=PIPE, stderr=PIPE)
		out = p.communicate()

		self.matches += matchfile.load(out_file, seq, self.seqdb)

		#load the hmms
		try:
			i = 1
			while True:
				f = "{}-{}.hmm".format(hmm_file.name, i)
				self.hmms.append(hmmfile.read(f)[0])
				os.remove(f)
				i += 1
		except IOError:
			pass

		out_file.close()
		seq_file.close()
		seqdb_file.close()
예제 #2
0
파일: HMMER.py 프로젝트: haydnKing/pyHMMER
	def _do_search(self, hmm, target, args):
		#bail if there isn't any sequence to search
		if not len(target):
			return []

		#write the HMM to a temporary file
		hmm_file = tempfile.NamedTemporaryFile()
		target_file = tempfile.NamedTemporaryFile()
		out_file = tempfile.NamedTemporaryFile()

		hmmfile.write(hmm, hmm_file)
		hmm_file.flush()

		SeqIO.write([target,], target_file, 'fasta')
		target_file.flush()

		p = Popen(['hmmsearch',] + args + ['--tformat', 'fasta', 
			'--domtblout', out_file.name, hmm_file.name, target_file.name,]
			 , stdout=PIPE, stdin=PIPE, stderr=PIPE, preexec_fn=set_limits)
		out = p.communicate()

		if p.returncode != 0:
			if p.returncode == -6 and "alloc" in out[1].lower():
				seq = target.seq
				split = len(seq) / 2
				target.seq = seq[0:split]
				m_left = self._do_search(hmm, target, args)
				target.seq = seq[split:]
				m_right = self._do_search(hmm, target, args)
				for m in m_right:
					m.offset(split)
				target.seq = seq
				return m_left + m_right

			raise RuntimeError('hmmsearch error ({}) : {}'.format(
				p.returncode, out[1]))
		else:
			matches = matchfile.load(out_file, hmm, self.targets)

		out_file.close()
		hmm_file.close()
		target_file.close()
		return matches