| Bioinformatics Toolbox™ | ![]() |
fastawrite(File, Data)
fastawrite(File, Header, Sequence)
| File | String specifying either a file name or a path and file name for saving the FASTA-formatted data. If you specify only a file name, the file is saved to the MATLAB Current Directory. |
| Data | Any of the following:
|
| Header | String or name of variable containing information about the sequence. This text will be included in the header of the FASTA-formatted file, File. |
| Sequence | String or name of variable containing an amino acid or nucleotide sequence using the standard IUB/IUPAC letter or integer codes. For a list of valid characters, see Amino Acid Lookup or Nucleotide Lookup. |
fastawrite(File, Data) writes the contents of Data to File, a FASTA-formatted file.
fastawrite(File, Header, Sequence) writes the specified header and sequence information to File, a FASTA-formatted file.
Tip To append FASTA-formatted data to an existing file, simply specify that file name, and the data will be added to the end of the file. If you are using fastawrite in a script, you can disable the append warning message by entering the following command lines before the fastawrite command: warnState = warning %Save the current warning state
warning('off','Bioinfo:fastawrite:AppendToFile'); Then entering the following command line after the fastawrite command: warning(warnState) %Reset warning state to previous settings |
Writing a Coding Region to a FASTA-Formatted File
Retrieve the sequence for the human p53 gene from the GenBank database.
seq = getgenbank('NM_000546');Find the CDS line in the FEATURES information.
cdsline = strmatch('CDS',seq.Features)
cdsline =
23Read the coordinates of the coding region in the CDS line.
[start,stop] = strread(seq.Features(cdsline,:),'%*s%d..%d') start = 252 stop = 1433
Extract the coding region.
codingSeq = seq.Sequence(start:stop);
Write the coding region to a FASTA-formatted file, specifying Coding region for p53 for the Header in the file, and p53coding.txt for the file name.
fastawrite('p53coding.txt','Coding region for p53',codingSeq);Saving Multiple Sequences to a FASTA-Formatted File
Write two nucleotide sequences to a MATLAB structure containing the fields Header and Sequence.
data(1).Sequence = 'ACACAGGAAA'; data(1).Header = 'First sequence'; data(2).Sequence = 'ACGTCAGGTC'; data(2).Header = 'Second sequence';
Write the sequences to a FASTA-formatted file, specifying my_sequences.txt for the file name.
fastawrite('my_sequences.txt', data)
Display the FASTA-formatted file, my_sequences.txt.
type('my_sequences.txt')
>First sequence
ACACAGGAAA
>Second sequence
ACGTCAGGTC
Appending Sequences to a FASTA-Formatted File
If you haven't already done so, create the FASTA-formatted file, my_sequences.txt, described in Saving Multiple Sequences to a FASTA-Formatted File.
Append a third sequence to the file.
fastawrite('my_sequences.txt','Third sequence','TACTGACTTC')
Display the FASTA-formatted file, my_sequences.txt.
type('my_sequences.txt')
>First sequence
ACACAGGAAA
>Second sequence
ACGTCAGGTC
>Third sequence
TACTGACTTCBioinformatics Toolbox functions: fastaread, genbankread, genpeptread, getgenbank, getgenpept, multialignwrite, seqtool
![]() | fastaread | featuresmap | ![]() |
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |