write_fasta allows for standardized FASTA files to be written to disk using a dictionary or a list of two-position lists. Note that it is possible to automatically write a FASTA file when reading in using the output_filename keyword in the function read_fasta.

Unlike read_fasta, write_fasta has a relatively limited set of options, which are documented below.

For usage examples see the Examples page.


protfasta.write_fasta(fasta_data, filename, linelength=60, verbose=False, append_to_fasta=False)[source]

Simple function that takes a dictionary of key to sequence values and writes out a valid FASTA file. No return type, but writes a file to disk according to the location defined by the variable filename.

  • fasta_data (dict or list) – If a dictionary is passed then keys must be identifiers and the values are amino acid sequences. If a list is passed it must be a list where each element contains two sub-elements, a header, and a sequence.
  • filename (string) – Filename to write to. Should end with .fasta or .fa but this is not enforced.
  • linelength (int) – [Default = 60] Length of line to be written for sequence (note this does not effect the header line. 60 is default used by UniProt. If set to 0, None or False no line-length limit is used. Note linelength must be > 5.
  • append_to_fasta (bool) – Whether to append to a fasta file that already exists. If this is set to True, if the file does not exist, protfasta will create a new file. However, if the file does exist, protfasta will simply append additional fasta entries to the existing file. Default=False

No return value is provided but a new FASTA file is written to disk

Return type: