multiplierz.fasta - BlaisProteomics/multiplierz GitHub Wiki
multiplierz.fasta
The FASTA file format is the canonical format for storing sequence data, including the amino acid sequences used in proteomics applications. Multiplierz provides several functions for creating and manipulating FASTA files, including the decoy sequence databases used for statistical analysis of database search result reliability.
Multiplierz features transparent support for zipped FASTA files; files ending with '.gz' will be opened using Python's built-in gzip support, and providing a filename ending with '.gz' to a writer function will produce a zipped output file. Note that zipped files may not be compatible with database search engines.
parse_to_dict(fastaFile, labelConverter = (lambda x: x), nonredundant_labels = False, filter_string = None)
Reads in a specified FASTA file and returns a label-to-sequence dict. labelConverter can be a function that converts sequence labels in the file to a more convenient form that will be used as keys in the result dict.
parse_to_generator(fasta_file, labelConverter = (lambda x: x), filter_string = None)
Identical to parse_to_dict, except that the return value is a generator object that reads entries from the FASTA file as they are requested; the generator returns (title, sequence) tuples. This is useful in cases where the target file is too large to be read into memory all at once, and random access is not required.
write_fasta(fasta, save_file, write_mode='w')
This takes a list of (title, sequence) pairs as fasta and writes a FASTA format file to save_file.
Writer(filename, line_length = 80)
This class supports iteratively writing FASTA files; this is useful for writing files too large to accumulate into memory. Writer objects have two methods; write(header, sequence) writes an entry to the FASTA file, and close() closes the file.
reverse_database(fasta, outputFile = None, include_forward = False)
Builds a reverse-sequence database, used for false-discovery rate analysis methods. Reverse sequences are annotated with 'rev_' in the beginning of the header line. If include_forward is True, the forward sequences are also included in the output database.
combine(fasta_files, output)
Given a list of FASTA file paths, outputs the concatenation of all files. Make sure that the header labels are distinct across files.