code: def write(
      x, alphabet, file, truncate_stop=False, append=False, scores=None
  ):
      """
      Write sequence samples to file.
  
      :param ~torch.Tensor x: One-hot encoded sequences, with size
          ``(data_size, seq_length, alphabet_length)``. May be padded with
          zeros for variable length sequences.
      :param ~np.array alphabet: Alphabet.
      :param str file: Output file, where sequences will be written
          in fasta format.
      :param bool truncate_stop: If True, sequences will be truncated at the
          first stop symbol (i.e. the stop symbol and everything after will not
          be written). If False, the whole sequence will be written, including
          any internal stop symbols.
      :param bool append: If True, sequences are appended to the end of the
          output file. If False, the file is first erased.
      """
      print_alphabet = np.array(list(alphabet) + [""])
      x = torch.cat([x, torch.zeros(list(x.shape[:2]) + [1])], -1)
      if truncate_stop:
          mask = (
              torch.cumsum(
                  torch.matmul(
                      x,
                      torch.tensor(
                          print_alphabet == "*", dtype=torch.double
                      ),
                  ),
                  -1,
              )
              > 0
          ).to(torch.double)
          x = x * (1 - mask).unsqueeze(-1)
          x[:, :, -1] = mask
      else:
          x[:, :, -1] = (torch.sum(x, -1) < 0.5).to(torch.double)
      index = (
          torch.matmul(x, torch.arange(x.shape[-1], dtype=torch.double))
          .to(torch.long)
          .cpu()
          .numpy()
      )
      if scores is None:
          seqs = [
              ">{}\n".format(j) + "".join(elem) + "\n"
              for j, elem in enumerate(print_alphabet[index])
          ]
      else:
          seqs = [
              ">{}\n".format(j) + "".join(elem) + "\n"
              for j, elem in zip(scores, print_alphabet[index])
          ]
      if append:
          open_flag = "a"
      else:
          open_flag = "w"
      with open(file, open_flag) as fw:
          fw.write("".join(seqs))
  
file_path: pyro/pyro/contrib/mue/dataloaders.py
imports: import numpy
  import torch
  from torch.utils.data import Dataset
label_desc: Use image node_id 1 for calling a global function with example usage: write(x, alphabet, file, truncate_stop, append, scores) without return types