XStringSet-io {Biostrings} | R Documentation

## Read/write an XStringSet or XStringViews object from/to a file

### Description

Functions to read/write an XStringSet or XStringViews object from/to a file.

### Usage

      ## XStringSet object
      read.BStringSet(file, format)
      read.DNAStringSet(file, format)
      read.RNAStringSet(file, format)
      read.AAStringSet(file, format)
      write.XStringSet(x, file="", format, width=80)

      ## XStringViews object
      read.XStringViews(file, format, subjectClass, collapse="")
      write.XStringViews(x, file="", format, width=80)

      ## Some related helper functions
      FASTArecordsToCharacter(FASTArecs, use.names=TRUE)
      CharacterToFASTArecords(x)
      FASTArecordsToXStringViews(FASTArecs, subjectClass, collapse="")
      XStringSetToFASTArecords(x)

### Arguments

`file` | Either a character string naming a file or a connection open for reading or writing. If `""` (the default for `write.XStringSet` and `write.XStringViews`), then the functions write to the standard output connection (the console) unless redirected by `sink`.
`format` | Only `"fasta"` is supported for now.
`x` | For `write.XStringSet` and `write.XStringViews`, the object to write to `file`. For `CharacterToFASTArecords`, the (possibly named) character vector to be converted to a list of FASTA records as one returned by `readFASTA`. For `XStringSetToFASTArecords`, the XStringSet object to be converted to a list of FASTA records as one returned by `readFASTA`.
`width` | Only relevant if `format` is `"fasta"`. The maximum number of letters per line of sequence.
`subjectClass` | The class to be given to the subject of the XStringViews object created and returned by the function. Must be the name of one of the direct XString subtypes i.e. `"BString"`, `"DNAString"`, `"RNAString"` or `"AAString"`.
`collapse` | An optional character string to be inserted between the views of the XStringViews object created and returned by the function.
`FASTArecs` | A list of FASTA records as one returned by `readFASTA`.
`use.names` | Whether or not the description line preceding each FASTA records should be used to set the names of the returned vector.

### Details

Only FASTA files are supported for now.

Reading functions `read.BStringSet`, `read.DNAStringSet`, `read.RNAStringSet`, `read.AAStringSet` and `read.XStringViews` load sequences from a file into an XStringSet or XStringViews object.

Writing functions `write.XStringSet` and `write.XStringViews` write an XStringSet or XStringViews object to a file or connection.

`FASTArecordsToCharacter`, `CharacterToFASTArecords`, `FASTArecordsToXStringViews` and `XStringSetToFASTArecords` are helper functions used internally by `write.XStringSet` and `read.XStringViews` for switching between different representations of the same object.

### See Also

`readFASTA`, `writeFASTA`, XStringSet-class, XStringViews-class, BString-class, DNAString-class, RNAString-class, AAString-class

### Examples

      file <- system.file("extdata", "someORF.fa", package="Biostrings")
      x <- read.DNAStringSet(file, "fasta")
      x
      write.XStringSet(x, format="fasta") # writes to the console

      ## Converting 'x'...
      ## ... to a list of FASTA records (as one returned by the "readFASTA" function)
      x1 <- XStringSetToFASTArecords(x)
      ## ... to a named character vector
      x2 <- FASTArecordsToCharacter(x1) # same as 'as.character(x)'

[Package Biostrings version 2.8.18 Index]