Parse xlims from a file, a set of dna_seg positions for plotting
read_xlims_file.RdThis function parses a file containing a set of xlims, positions
to print for dna_segs. Multiple start and end positions can be provided for
each dna_seg, forming subsegments to plot.
Arguments
- dna_segs
Either a character vector containing
dna_seglabels, or a list ofdna_segobjects.- xlims
A character string containing a file path, or a file connection. See details for file format.
- reorder_dna_segs
Logical. If
TRUE, then the order ofdna_segswill be changed to match the order in which they first appear in thexlimsfile. Additionally, anydna_segthat was not present in thexlimsfile will be removed. Then, this function will return a list with the reordereddna_segsand parsedxlimsas elements, instead of just thexlims.
Value
A list of xlims that can be passed directly to the xlims
argument of plot_gene_map. Each element of the list is a numeric vector
that contains the positions to plot of one dna_seg.
If reorder_dna_segs = TRUE, a list with 2 named elements will
be returned instead (xlims
and either dna_segs or seg_labels, depending on the dna_segs argument).
Details
The file format of xlims corresponds to the output of the outfile_xlims
argument of plot_gene_map. The format in question is a
tab-separated file containing xlims for each dna_seg. Each row
represents one subsegment and has 3 columns, containing the start position,
end position, and dna_seg label, respectively. An example of the format:
| x0 | x1 | seg_label | 2000 | 12000 |
| Genome_2 | 1000 | 10000 | Genome_1 | 6000 |
| 16000 | Genome_3 | 30000 | 40000 | Genome_2 |
Examples
## Parse xlims for 3 dna_segs from a file
dna_seg_labels <- c("Genome_1", "Genome_2", "Genome_3")
xlims_file <- system.file('extdata/xlims.tab', package = 'genoPlotR')
## Example of an xlims file:
cat(readLines(xlims_file), sep = "\n")
#> x0 x1 seg_label
#> 2000 12000 Genome_2
#> 1000 10000 Genome_1
#> 6000 16000 Genome_3
#> 30000 40000 Genome_2
## Parse xlims file, keep order provided by dna_seg_labels
read_xlims_file(dna_seg_labels, xlims_file)
#> [[1]]
#> [1] 1000 10000
#>
#> [[2]]
#> [1] 2000 12000 30000 40000
#>
#> [[3]]
#> [1] 6000 16000
#>
## Parse xlims file, reorder dna_segs based on the xlims file
xlims_read <- read_xlims_file(dna_seg_labels, xlims_file,
reorder_dna_segs = TRUE)
xlims_read$xlims
#> [[1]]
#> [1] 2000 12000 30000 40000
#>
#> [[2]]
#> [1] 1000 10000
#>
#> [[3]]
#> [1] 6000 16000
#>
xlims_read$seg_labels
#> [1] "Genome_2" "Genome_1" "Genome_3"