def search_and_extract_orfs_matching_protein_database(self,<EOL>unpack,<EOL>search_method,<EOL>maximum_range,<EOL>threads,<EOL>evalue,<EOL>min_orf_length,<EOL>restrict_read_length,<EOL>diamond_database,<EOL>output_search_file,<EOL>hit_reads_fasta,<EOL>hit_reads_orfs_fasta):
<EOL>if unpack.is_zcattable():<EOL><INDENT>clazz = ZcatOrfM<EOL><DEDENT>else:<EOL><INDENT>clazz = OrfM<EOL><DEDENT>orfm = clazz(min_orf_length=min_orf_length,<EOL>restrict_read_length=restrict_read_length)<EOL>extracting_orfm = OrfM(min_orf_length=min_orf_length,<EOL>restrict_read_length=restrict_read_length)<EOL>if search_method == '<STR_LIT>':<EOL><INDENT>search_result = self.hmmsearch(<EOL>output_search_file,<EOL>unpack.read_file,<EOL>unpack,<EOL>unpack.sequence_type(),<EOL>threads,<EOL>evalue,<EOL>orfm<EOL>)<EOL><DEDENT>elif search_method == '<STR_LIT>':<EOL><INDENT>search_result = Diamond(<EOL>database=diamond_database,<EOL>threads=threads,<EOL>evalue=evalue,<EOL>).run(<EOL>unpack.read_file,<EOL>unpack.sequence_type(),<EOL>daa_file_basename=output_search_file<EOL>)<EOL>search_result = [search_result]<EOL><DEDENT>else:  <EOL><INDENT>raise Exception("<STR_LIT>" % search_method)<EOL><DEDENT>orfm_regex = OrfM.regular_expression()<EOL>hits = self._get_sequence_directions(search_result)<EOL>orf_hit_readnames = hits.keys() <EOL>if unpack.sequence_type() == '<STR_LIT>':<EOL><INDENT>hits={(orfm_regex.match(key).groups(<NUM_LIT:0>)[<NUM_LIT:0>] if orfm_regex.match(key) else key): item for key, item in hits.iteritems()}<EOL>hit_readnames = hits.keys() <EOL><DEDENT>else:<EOL><INDENT>hit_readnames=orf_hit_readnames<EOL><DEDENT>hit_reads_fasta, direction_information = self._extract_from_raw_reads(<EOL>hit_reads_fasta,<EOL>hit_readnames,<EOL>unpack.read_file,<EOL>unpack.format(),<EOL>hits<EOL>)<EOL>if not hit_readnames:<EOL><INDENT>hit_read_counts = [<NUM_LIT:0>, len(hit_readnames)]<EOL>result = DBSearchResult(None,<EOL>search_result,<EOL>hit_read_counts,<EOL>None)<EOL>return result, direction_information<EOL><DEDENT>if unpack.sequence_type() == '<STR_LIT>':<EOL><INDENT>self._extract_orfs(<EOL>hit_reads_fasta,<EOL>extracting_orfm,<EOL>orf_hit_readnames,<EOL>hit_reads_orfs_fasta,<EOL>search_method,<EOL>list(search_result[<NUM_LIT:0>].each([SequenceSearchResult.QUERY_ID_FIELD,<EOL>SequenceSearchResult.ALIGNMENT_DIRECTION,<EOL>SequenceSearchResult.QUERY_FROM_FIELD,<EOL>SequenceSearchResult.QUERY_TO_FIELD])<EOL>)<EOL>)<EOL>hit_reads_fasta = hit_reads_orfs_fasta<EOL><DEDENT>slash_endings=self._check_for_slash_endings(hit_readnames)<EOL>result = DBSearchResult(hit_reads_fasta,<EOL>search_result,<EOL>[<NUM_LIT:0>, len([itertools.chain(*hits.values())])],  <EOL>slash_endings)  <EOL>if maximum_range:<EOL><INDENT>n_hits = sum([len(x["<STR_LIT>"]) for x in hits.values()])<EOL><DEDENT>else:<EOL><INDENT>n_hits = len(hits.keys())<EOL><DEDENT>logging.info("<STR_LIT>" % n_hits)<EOL>return result, direction_information<EOL>
As per aa_db_search() except slightly lower level. Search an
        input read set (unpack) and then extract the proteins that hit together
        with their containing nucleotide sequences.

        Parameters
        ----------
        output_search_file: str
            path to hmmsearch output table or diamond basename
        hit_reads_fasta: str
            path to nucleotide sequences containing hit proteins
        hit_reads_orfs_fasta: str
            path to hit proteins, unaligned

        Returns
        -------
        direction_information: dict

            {read_1: False
             ...
             read n: True}

            where True = Forward direction
            and False = Reverse direction

        result: DBSearchResult object containing file locations and hit 
        information