# Path: alphafold/data/parsers.py
# class Msa:
# class TemplateHit:
# class HitMetadata:
#   def __post_init__(self):
#   def __len__(self):
#   def truncate(self, max_seqs: int):
# def parse_fasta(fasta_string: str) -> Tuple[Sequence[str], Sequence[str]]:
# def parse_stockholm(stockholm_string: str) -> Msa:
# def parse_a3m(a3m_string: str) -> Msa:
# def _convert_sto_seq_to_a3m(
#     query_non_gaps: Sequence[bool], sto_seq: str) -> Iterable[str]:
# def convert_stockholm_to_a3m(stockholm_format: str,
#                              max_sequences: Optional[int] = None,
#                              remove_first_row_gaps: bool = True) -> str:
# def _keep_line(line: str, seqnames: Set[str]) -> bool:
# def truncate_stockholm_msa(stockholm_msa_path: str, max_sequences: int) -> str:
# def remove_empty_columns_from_stockholm_msa(stockholm_msa: str) -> str:
# def deduplicate_stockholm_msa(stockholm_msa: str) -> str:
# def _get_hhr_line_regex_groups(
#     regex_pattern: str, line: str) -> Sequence[Optional[str]]:
# def _update_hhr_residue_indices_list(
#     sequence: str, start_index: int, indices_list: List[int]):
# def _parse_hhr_hit(detailed_lines: Sequence[str]) -> TemplateHit:
# def parse_hhr(hhr_string: str) -> Sequence[TemplateHit]:
# def parse_e_values_from_tblout(tblout: str) -> Dict[str, float]:
# def _get_indices(sequence: str, start: int) -> List[int]:
# def _parse_hmmsearch_description(description: str) -> HitMetadata:
# def parse_hmmsearch_a3m(query_sequence: str,
#                         a3m_string: str,
#                         skip_first: bool = True) -> Sequence[TemplateHit]:
# 
# Path: alphafold/data/tools/hmmbuild.py
# class Hmmbuild(object):
#   def __init__(self,
#                *,
#                binary_path: str,
#                singlemx: bool = False):
#   def build_profile_from_sto(self, sto: str, model_construction='fast') -> str:
#   def build_profile_from_a3m(self, a3m: str) -> str:
#   def _build_profile(self, msa: str, model_construction: str = 'fast') -> str:
# 
# Path: alphafold/data/tools/utils.py
# def tmpdir_manager(base_dir: Optional[str] = None):
# def timing(msg: str):


import os
import subprocess
from typing import Optional, Sequence
from absl import logging
from alphafold.data import parsers
from alphafold.data.tools import hmmbuild
from alphafold.data.tools import utils
      ]
      # If adding flags, we have to do so before the output and input:
      if self.flags:
        cmd.extend(self.flags)
      cmd.extend([
          '-A', out_path,
          hmm_input_path,
          self.database_path,
      ])

      logging.info('Launching sub-process %s', cmd)
      process = subprocess.Popen(
          cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      with utils.timing(
          f'hmmsearch ({os.path.basename(self.database_path)}) query'):
        stdout, stderr = process.communicate()
        retcode = process.wait()

      if retcode:
        raise RuntimeError(
            'hmmsearch failed:\nstdout:\n%s\n\nstderr:\n%s\n' % (
                stdout.decode('utf-8'), stderr.decode('utf-8')))

      with open(out_path) as f:
        out_msa = f.read()

    return out_msa

  def get_template_hits(self,
                        output_string: str,

# Path: alphafold/data/parsers.py
# class Msa:
# class TemplateHit:
# class HitMetadata:
#   def __post_init__(self):
#   def __len__(self):
#   def truncate(self, max_seqs: int):
# def parse_fasta(fasta_string: str) -> Tuple[Sequence[str], Sequence[str]]:
# def parse_stockholm(stockholm_string: str) -> Msa:
# def parse_a3m(a3m_string: str) -> Msa:
# def _convert_sto_seq_to_a3m(
#     query_non_gaps: Sequence[bool], sto_seq: str) -> Iterable[str]:
# def convert_stockholm_to_a3m(stockholm_format: str,
#                              max_sequences: Optional[int] = None,
#                              remove_first_row_gaps: bool = True) -> str:
# def _keep_line(line: str, seqnames: Set[str]) -> bool:
# def truncate_stockholm_msa(stockholm_msa_path: str, max_sequences: int) -> str:
# def remove_empty_columns_from_stockholm_msa(stockholm_msa: str) -> str:
# def deduplicate_stockholm_msa(stockholm_msa: str) -> str:
# def _get_hhr_line_regex_groups(
#     regex_pattern: str, line: str) -> Sequence[Optional[str]]:
# def _update_hhr_residue_indices_list(
#     sequence: str, start_index: int, indices_list: List[int]):
# def _parse_hhr_hit(detailed_lines: Sequence[str]) -> TemplateHit:
# def parse_hhr(hhr_string: str) -> Sequence[TemplateHit]:
# def parse_e_values_from_tblout(tblout: str) -> Dict[str, float]:
# def _get_indices(sequence: str, start: int) -> List[int]:
# def _parse_hmmsearch_description(description: str) -> HitMetadata:
# def parse_hmmsearch_a3m(query_sequence: str,
#                         a3m_string: str,
#                         skip_first: bool = True) -> Sequence[TemplateHit]:
# 
# Path: alphafold/data/tools/hmmbuild.py
# class Hmmbuild(object):
#   def __init__(self,
#                *,
#                binary_path: str,
#                singlemx: bool = False):
#   def build_profile_from_sto(self, sto: str, model_construction='fast') -> str:
#   def build_profile_from_a3m(self, a3m: str) -> str:
#   def _build_profile(self, msa: str, model_construction: str = 'fast') -> str:
# 
# Path: alphafold/data/tools/utils.py
# def tmpdir_manager(base_dir: Optional[str] = None):
# def timing(msg: str):


# Path: alphafold/data/tools/hmmsearch.py
import os
import subprocess
from typing import Optional, Sequence
from absl import logging
from alphafold.data import parsers
from alphafold.data.tools import hmmbuild
from alphafold.data.tools import utils

      ]
      # If adding flags, we have to do so before the output and input:
      if self.flags:
        cmd.extend(self.flags)
      cmd.extend([
          '-A', out_path,
          hmm_input_path,
          self.database_path,
      ])

      logging.info('Launching sub-process %s', cmd)
      process = subprocess.Popen(
          cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      with utils.timing(
          f'hmmsearch ({os.path.basename(self.database_path)}) query'):
        stdout, stderr = process.communicate()
        retcode = process.wait()

      if retcode:
        raise RuntimeError(
            'hmmsearch failed:\nstdout:\n%s\n\nstderr:\n%s\n' % (
                stdout.decode('utf-8'), stderr.decode('utf-8')))

      with open(out_path) as f:
        out_msa = f.read()

    return out_msa

  def get_template_hits(self,
                        output_string: str,

                        input_sequence: str) -> Sequence[parsers.TemplateHit]: