Skip to contents

This 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.

Usage

read_xlims_file(dna_segs, xlims, reorder_dna_segs = FALSE)

Arguments

dna_segs

Either a character vector containing dna_seg labels, or a list of dna_seg objects.

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 of dna_segs will be changed to match the order in which they first appear in the xlims file. Additionally, any dna_seg that was not present in the xlims file will be removed. Then, this function will return a list with the reordered dna_segs and parsed xlims as elements, instead of just the xlims.

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:

x0x1seg_label200012000
Genome_2100010000Genome_16000
16000Genome_33000040000Genome_2

Author

Mike Puijk

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"