as.reanno: Converts an S3 reanno into a S4 reanno

View source: R/seqpac_S4classes.R

as.reannoR Documentation

Converts an S3 reanno into a S4 reanno

Description

as.reanno Converts an S3 reanno object (list) to an S4 reanno object

Usage

as.reanno(from)

Arguments

from

S3 reanno object.

Details

Seqpac comes with two versions of the reanno object, either S4 or S3. The S3 is simply a list where each object can be received using the $-sign. The S4 version is a newer type of R object with predefined slots, that is received using the @-sign. This function converts an S3 reanno object (list) to an S4 object. You can also use the S4 coercion method "as" to turn an S4 into an S3. See examples below.

Value

An S4 reanno object.

See Also

https://github.com/Danis102 for updates on the current package.

Other PAC reannotation: add_reanno(), import_reanno(), make_conv(), make_reanno(), map_reanno(), simplify_reanno()

Examples


##### Create an reanno object

##  First load a PAC- object

load(system.file("extdata", "drosophila_sRNA_pac_filt_anno.Rdata", 
                   package = "seqpac", mustWork = TRUE))
 
##  Then specify paths to fasta references
# If you are having problem see the vignette small RNA guide for more info.
 
 trna_file <- system.file("extdata/trna", "tRNA.fa", 
                          package = "seqpac", mustWork = TRUE)
 trna_dir <- dirname(trna_file)
 
 if(!sum(stringr::str_count(list.files(trna_dir), ".ebwt")) ==6){     
     Rbowtie::bowtie_build(trna_file, 
                           outdir=trna_dir, 
                           prefix="tRNA", force=TRUE)
                           }
 
 ref_paths <- list(trna= trna_file)
                                    
##  Add output path of your choice.
# Here we use the R temporary folder depending on platform
 output <- paste0(tempdir(),"/seqpac/test")

## Make sure it is empty (otherwise you will be prompted for a question)
out_fls  <- list.files(output, recursive=TRUE)
closeAllConnections()
suppressWarnings(file.remove(paste(output, out_fls, sep="/")))

##  Then map your PAC-object against the fasta references
 map_reanno(pac, ref_paths=ref_paths, output_path=output,
               type="internal", mismatches=0,  import="biotype", 
               threads=2, keep_temp=FALSE, override=TRUE)

##  Then import and generate a reanno-object of the temporary bowtie-files
reanno <- make_reanno(output, PAC=pac, mis_fasta_check = TRUE)
                                    
## Now make some search terms against reference names to create shorter names
# Theses can be used to create factors in downstream analysis
# One search hit (regular expressions) gives one new short name 
bio_search <- list(trna =c("_tRNA", "mt:tRNA"))
 
 
## You can merge directly with your PAC-object by adding your original 
# PAC-object, that you used with map_reanno, to merge_pac option.
 pac <- add_reanno(reanno, bio_search=bio_search, 
                       type="biotype", bio_perfect=FALSE, 
                       mismatches = 0, merge_pac=pac)
                       
                       
## Turn your S3 list to an S4 reanno-object
isS4(reanno)
names(reanno)
table(overview(reanno)$trna)
 
reanno_s3 <- as(reanno, "list")
isS4(reanno_s3)   

# Turns S3 reanno object into a S4 
reanno_s4 <- as.reanno(reanno_s3)
isS4(reanno_s4) 
 

Danis102/seqpac documentation built on Aug. 26, 2023, 10:15 a.m.