Learn R Programming

tidysq (version 1.2.3)

as.matrix.sq: Convert sq object into matrix

Description

Coerces sequences from a sq object to a matrix, in which rows correspond to sequences and columns to positions.

Usage

# S3 method for sq
as.matrix(x, ...)

Value

A matrix with number of rows the same as number of sequences and number of columns corresponding to the length of the longest sequence in the converted sq object.

Arguments

x

[sq]
An object this function is applied to.

...

further arguments to be passed from or to other methods.

Details

This method for class sq allows converting sequences from the sq object into a matrix. Each row corresponds to the separate sequence from the sq object, whereas each column indicates a single position within a sequence. Dimensions of matrix are determined by the number of sequences (rows) and the length of the longest sequence (columns). If length of a sequence is smaller than the length of the longest sequence, the remaining columns are filled with NA. All attributes of the input sq are lost during the conversion to matrix.

See Also

Functions from output module: as.character.sq(), as.sq(), export_sq(), write_fasta()

Examples

Run this code
# Creating objects to work on:
sq_dna <- sq(c("CGATAGACA", "TGACAAAAC", "GTGACCGTA"),
             alphabet = "dna_bsc")
sq_rna <- sq(c("CUGAAUGCAGUACCGUAAU", "AUGCCGUAAAUGCCAU", "CAGACCANNNAUAG"),
             alphabet = "rna_ext")

# Sequences of the same lengths can be converted easily:
as.matrix(sq_dna)

# Sequences that differ in length are filled with NA to the maximum length:
as.matrix(sq_rna)

Run the code above in your browser using DataLab