readFasta {ShortRead} | R Documentation

## Read and write FASTA files to or from ShortRead objects

### Description

`readFasta` reads all FASTA-formated files in a directory `dirPath` whose file name matches pattern `pattern`, returning a compact internal representation of the sequences and quality scores in the files. Methods read all files into a single R object; a typical use is to restrict input to a single FASTA file.

`writeFasta` writes an object to a single `file`, using `mode="w"` (the default) to create a new file or `mode="a"` append to an existing file. Attempting to write to an existing file with `mode="w"` results in an error.

### Usage

    readFasta(dirPath, pattern = character(0), ...,
        nrec=-1L, skip=0L)
    ## S4 method for signature 'character'
    readFasta(dirPath, pattern = character(0), ...,
        nrec=-1L, skip=0L)
    writeFasta(object, file, mode="w", ...)
    ## S4 method for signature 'DNAStringSet'
    writeFasta(object, file, mode="w", ...)

### Arguments

`dirPath` | A character vector giving the directory path (relative or absolute) or single file name of FASTA files to be read.
`pattern` | The (`grep`-style) pattern describing file names to be read. The default (`character(0)`) results in (attempted) input of all files in the directory.
`object` | An object to be output in `fasta` format.
`file` | A length 1 character vector providing a path to a file to the object is to be written to.
`mode` | A length 1 character vector equal to either ‘w’ or ‘a’ to write to a new file or append to an existing file, respectively.
`...` | Additional arguments used by methods or, for `writeFasta`, `writeXStringSet`.
`nrec` | See `?readDNAStringSet`.
`skip` | See `?readDNAStringSet`.

### Value

`readFasta` returns a `DNAStringSet`. containing sequences and qualities contained in all files in `dirPath` matching `pattern`. There is no guarantee of order in which files are read.

`writeFasta` is invoked primarily for its side effect, creating or appending to file `file`. The function returns, invisibly, the length of `object`, and hence the number of records written. There is a `writeFasta` method for any class derived from `ShortRead`.

### Author(s)

Martin Morgan

### Examples

    showMethods("readFasta")

    showMethods("writeFasta")

    f1 <- system.file("extdata", "someORF.fa", package="Biostrings")

    rfa <- readFasta(f1)
    sread(rfa)
    id(rfa)

    sp <- SolexaPath(system.file('extdata', package='ShortRead'))
    rfq <- readFastq(analysisPath(sp), pattern="s_1_sequence.txt")

    file <- tempfile()
    writeFasta(rfq, file)
    readLines(file, 8)

    writeFasta(sread(rfq), file)  # no 'id's

[Package ShortRead version 1.42.0 Index]