ExtractBy {SynExtend} | R Documentation

## Extract and organize `XStringSet`s of sequences represented in a `PairSummaries` object.

### Description

Takes in a `PairSummaries` object and an optional vector of cluster representatives. Return an `XStringSet` of the sequences present in the `PairSummaries`, or when cluster representatives are provided, a list of `XStringSet`s of the sequences that make up the provided clusters.

### Usage

    ExtractBy(x,
              y = NULL,
              DBPATH,
              Method = "all",
              DefaultTranslationTable = "11",
              Translate = TRUE,
              Storage = 1,
              Verbose = FALSE)

### Arguments

`x` | A `PairSummaries` object.
`y` | An optional `list` containing the ids of sequences in the `PairSummaries` object.
`DBPATH` | A SQLite connection object or a character string specifying the path to the database file. Constructed from DECIPHER's `Seqs2DB` function.
`Method` | How to extract sequences from the `PairSummaries` object. Currently only the methods “all” and “clusters” are supported.
`Translate` | If `TRUE` return `AAStringSet`s where possible.
`DefaultTranslationTable` | Currently Not Implemented! When implemented will allow for designation of a specific translation table if one is not indicated in the `GeneCalls` attribute of the `PairSummaries` object.
`Storage` | Numeric indicating the approximate size a user wishes to allow for holding `StringSet`s in memory to extract gene sequences, in “Gigabytes”. The lower `Storage` is set, the more likely that `ExtractBy` will need to reaccess `StringSet`s when extracting gene sequences. The higher `Storage` is set, the more sequences `ExtractBy` will attempt to hold in memory, avoiding the need to re-access the source database many times. Set to 1 by default, indicating that `ExtractBy` can store a “Gigabyte” of sequences in memory at a time.
`Verbose` | Logical indicating whether to print progress bars and messages. Defaults to `FALSE`.

### Details

Takes in a `PairSummaries` object and an optional vector of cluster representatives. Return an `XStringSet` of the sequences present in the `PairSummaries`, or when cluster representatives are provided, a list of `XStringSet`s of the sequences that make up the provided clusters.

### Value

Returns either a `XStringSet` or a list of `XStringSet`s.

### Author(s)

Nicholas Cooley npc19@pitt.edu

### See Also

`FindSynteny`, `Synteny-class`, `PairSummaries`, `DisjointSet`

### Examples

    DBPATH <- system.file("extdata",
                          "VignetteSeqs.sqlite",
                          package = "SynExtend")
    Syn <- FindSynteny(dbFile = DBPATH)
    GeneCalls <- vector(mode = "list",
                        length = ncol(Syn))

    GeneCalls[[1L]] <- gffToDataFrame(GFF = system.file("extdata",
                                                        "GCA_006740685.1_ASM674068v1_genomic.gff.gz",
                                                        package = "SynExtend"),
                                      Verbose = TRUE)
    GeneCalls[[2L]] <- gffToDataFrame(GFF = system.file("extdata",
                                                        "GCA_000956175.1_ASM95617v1_genomic.gff.gz",
                                                        package = "SynExtend"),
                                      Verbose = TRUE)
    GeneCalls[[3L]] <- gffToDataFrame(GFF = system.file("extdata",
                                                        "GCA_000875775.1_ASM87577v1_genomic.gff.gz",
                                                        package = "SynExtend"),
                                      Verbose = TRUE)
    names(GeneCalls) <- seq(length(GeneCalls))
    Links <- NucleotideOverlap(SyntenyObject = Syn,
                               GeneCalls = GeneCalls,
                               LimitIndex = FALSE,
                               Verbose = TRUE)
    PredictedPairs <- PairSummaries(SyntenyLinks = Links,
                                    DBPATH = DBPATH,
                                    PIDs = FALSE,
                                    AcceptContigNames = TRUE,
                                    Verbose = TRUE)
    PresentSeqs <- ExtractBy(x = PredictedPairs,
                             Method = "all",
                             DBPATH = DBPATH,
                             Verbose = TRUE)
    Clusters <- DisjointSet(Pairs = PredictedPairs,
                            Verbose = TRUE)
    SeqsByClusters <- ExtractBy(x = PredictedPairs,
                                y = Clusters,
                                Method = "clusters",
                                DBPATH = DBPATH,
                                Verbose = TRUE)

    # Alternatively the same seqs can be accessed from the NCBI FTP site
    # And gene calls can be accessed with the rtracklayer
    ## Not run:
    DBPATH <- tempfile()
    FNAs <- c("ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/006/740/685/GCA_006740685.1_ASM674068v1/GCA_006740685.1_ASM674068v1_genomic.fna.gz",
              "ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/956/175/GCA_000956175.1_ASM95617v1/GCA_000956175.1_ASM95617v1_genomic.fna.gz",
              "ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/875/775/GCA_000875775.1_ASM87577v1/GCA_000875775.1_ASM87577v1_genomic.fna.gz")
    for (m1 in seq_along(FNAs)) {
     X <- readDNAStringSet(filepath = FNAs[m1])
     X <- X[order(width(X),
                  decreasing = TRUE)]

     Seqs2DB(seqs = X,
             type = "XStringSet",
             dbFile = DBPATH,
             identifier = as.character(m1),
             verbose = TRUE)
      }

    GeneCalls <- vector(mode = "list",
                        length = ncol(Syn))
    GeneCalls[[1L]] <- rtracklayer::import(system.file("extdata",
                                                       "GCA_006740685.1_ASM674068v1_genomic.gff.gz",
                                                       package = "SynExtend"))
    GeneCalls[[2L]] <- rtracklayer::import(system.file("extdata",
                                                       "GCA_000956175.1_ASM95617v1_genomic.gff.gz",
                                                       package = "SynExtend"))
    GeneCalls[[3L]] <- rtracklayer::import(system.file("extdata",
                                                       "GCA_000875775.1_ASM87577v1_genomic.gff.gz",
                                                       package = "SynExtend"))
    names(GeneCalls) <- seq(length(GeneCalls))
    Links <- NucleotideOverlap(SyntenyObject = Syn,
                               GeneCalls = GeneCalls,
                               LimitIndex = FALSE,
                               Verbose = TRUE)
    PredictedPairs <- PairSummaries(SyntenyLinks = Links,
                                    DBPATH = DBPATH,
                                    PIDs = FALSE,
                                    AcceptContigNames = TRUE,
                                    Verbose = TRUE)
    PresentSeqs <- ExtractBy(x = PredictedPairs,
                             Method = "all",
                             DBPATH = DBPATH,
                             Verbose = TRUE)
    Clusters <- DisjointSet(Pairs = PredictedPairs,
                            Verbose = TRUE)
    SeqsByClusters <- ExtractBy(x = PredictedPairs,
                                y = Clusters,
                                Method = "clusters",
                                DBPATH = DBPATH,
                                Verbose = TRUE)

    ## End(Not run)

[Package SynExtend version 1.6.0 Index]