Skip to contents

Visualises the result from get_df_enrichment for a single motif by producing a plotly bar plot with the motif enrichment comparisons for one comparison dataset pair.

Usage

plot_enrichment_individual(
  result,
  enrichment_df,
  comparison_i,
  motif_i,
  label_colours,
  reference_index = 1,
  html_tags = TRUE
)

Arguments

result

A list with the following elements:

peaks

A list of peak files generated using read_peak_file.

alignments

A list of alignment files.

exp_type

A character vector of experiment types.

exp_labels

A character vector of experiment labels.

read_count

A numeric vector of read counts.

peak_count

A numeric vector of peak counts.

enrichment_df

A data frame containing the motif enrichment results, produced using get_df_enrichment.

comparison_i

The index of the comparison dataset to plot.

motif_i

The index of the motif to plot.

label_colours

A vector with colours (valid names or hex codes) to use for "No" and "Yes" bar segments.

reference_index

An integer specifying the index of the peak file to use as the reference dataset for comparison. Indexing starts from 1. (default = 1)

html_tags

Logical. If TRUE, returns the plot as a tagList object.

Value

A plotly object with the peak motif enrichment data. If html_tags is TRUE, the function returns a tagList object instead.

See also

Examples

data("CTCF_ChIP_peaks", package = "MotifPeeker")
data("CTCF_TIP_peaks", package = "MotifPeeker")
data("motif_MA1102.3", package = "MotifPeeker")
data("motif_MA1930.2", package = "MotifPeeker")
input <- list(
    peaks = list(CTCF_ChIP_peaks, CTCF_TIP_peaks),
    exp_type = c("ChIP", "TIP"),
    exp_labels = c("CTCF_ChIP", "CTCF_TIP"),
    read_count = c(150, 200),
    peak_count = c(100, 120)
)
segregated_input <- segregate_seqs(input$peaks[[1]], input$peaks[[2]])
motifs <- list(
    motifs = list(motif_MA1930.2, motif_MA1102.3),
    motif_labels = list("MA1930.2", "MA1102.3")
)
    
# \donttest{
    if (requireNamespace("BSgenome.Hsapiens.UCSC.hg38")) {
        genome_build <-
            BSgenome.Hsapiens.UCSC.hg38::BSgenome.Hsapiens.UCSC.hg38
        enrichment_df <- get_df_enrichment(
            input, segregated_input, motifs, genome_build, reference_index = 1,
            workers = 1
        )
        label_colours <- c("red", "cyan")
    
        plt <- plot_enrichment_individual(
            input, enrichment_df, comparison_i = 2, motif_i = 1,
            label_colours = label_colours, reference_index = 1, html_tags = FALSE
        )
        print(plt)
    }
#> <div class="plotly html-widget html-fill-item" id="htmlwidget-8a1f8f4a61c98a07d1d5" style="width:100%;height:400px;"></div>
#> <script type="application/json" data-for="htmlwidget-8a1f8f4a61c98a07d1d5">{"x":{"data":[{"orientation":"v","width":[0.89999999999999991,0.90000000000000013,0.90000000000000036,0.90000000000000036,0.90000000000000036,0.90000000000000036],"base":[66,50,48,49,15,3],"x":[1,2,3,4,5,6],"y":[34,70,79,78,67,54],"text":["<b>Peak Count:<\/b> 34 (68.42%)","<b>Peak Count:<\/b> 70 (72.53%)","<b>Peak Count:<\/b> 79 (62.2%)","<b>Peak Count:<\/b> 78 (61.42%)","<b>Peak Count:<\/b> 67 (81.71%)","<b>Peak Count:<\/b> 54 (94.74%)"],"type":"bar","textposition":"none","marker":{"autocolorscale":false,"color":"rgba(255,0,0,1)","line":{"width":1.8897637795275593,"color":"transparent"}},"name":"No","legendgroup":"No","showlegend":true,"xaxis":"x","yaxis":"y","hoverinfo":"text","frame":null},{"orientation":"v","width":[0.89999999999999991,0.90000000000000013,0.90000000000000036,0.90000000000000036,0.90000000000000036,0.90000000000000036],"base":[0,0,0,0,0,0],"x":[1,2,3,4,5,6],"y":[66,50,48,49,15,3],"text":["<b>Peak Count:<\/b> 66 (31.58%)","<b>Peak Count:<\/b> 50 (27.47%)","<b>Peak Count:<\/b> 48 (37.8%)","<b>Peak Count:<\/b> 49 (38.58%)","<b>Peak Count:<\/b> 15 (18.29%)","<b>Peak Count:<\/b> 3 (5.26%)"],"type":"bar","textposition":"none","marker":{"autocolorscale":false,"color":"rgba(0,255,255,1)","line":{"width":1.8897637795275593,"color":"transparent"}},"name":"Yes","legendgroup":"Yes","showlegend":true,"xaxis":"x","yaxis":"y","hoverinfo":"text","frame":null}],"layout":{"margin":{"t":23.305936073059364,"r":7.3059360730593621,"b":59.898613393879913,"l":43.105022831050235},"plot_bgcolor":"rgba(235,235,235,1)","paper_bgcolor":"rgba(255,255,255,1)","font":{"color":"rgba(0,0,0,1)","family":"","size":14.611872146118724},"xaxis":{"domain":[0,1],"automargin":true,"type":"linear","autorange":false,"range":[0.40000000000000002,6.5999999999999996],"tickmode":"array","ticktext":["All<br /> CTCF_ChIP <br />Peaks","All<br /> CTCF_TIP <br />Peaks","Common<br /> CTCF_ChIP <br />Peaks","Common<br /> CTCF_TIP <br />Peaks","Unique<br /> CTCF_ChIP <br />Peaks","Unique<br /> CTCF_TIP <br />Peaks"],"tickvals":[1,2,3,3.9999999999999996,5,6],"categoryorder":"array","categoryarray":["All<br /> CTCF_ChIP <br />Peaks","All<br /> CTCF_TIP <br />Peaks","Common<br /> CTCF_ChIP <br />Peaks","Common<br /> CTCF_TIP <br />Peaks","Unique<br /> CTCF_ChIP <br />Peaks","Unique<br /> CTCF_TIP <br />Peaks"],"nticks":null,"ticks":"outside","tickcolor":"rgba(51,51,51,1)","ticklen":3.6529680365296811,"tickwidth":0.66417600664176002,"showticklabels":true,"tickfont":{"color":"rgba(77,77,77,1)","family":"","size":11.68949771689498},"tickangle":-45,"showline":false,"linecolor":null,"linewidth":0,"showgrid":true,"gridcolor":"rgba(255,255,255,1)","gridwidth":0.66417600664176002,"zeroline":false,"anchor":"y","title":{"text":"Peak Groups","font":{"color":"rgba(0,0,0,1)","family":"","size":14.611872146118724}},"hoverformat":".2f"},"yaxis":{"domain":[0,1],"automargin":true,"type":"linear","autorange":false,"range":[-6.3500000000000005,133.34999999999999],"tickmode":"array","ticktext":["0","50","100"],"tickvals":[0,50,99.999999999999986],"categoryorder":"array","categoryarray":["0","50","100"],"nticks":null,"ticks":"outside","tickcolor":"rgba(51,51,51,1)","ticklen":3.6529680365296811,"tickwidth":0.66417600664176002,"showticklabels":true,"tickfont":{"color":"rgba(77,77,77,1)","family":"","size":11.68949771689498},"tickangle":-0,"showline":false,"linecolor":null,"linewidth":0,"showgrid":true,"gridcolor":"rgba(255,255,255,1)","gridwidth":0.66417600664176002,"zeroline":false,"anchor":"x","title":{"text":"Peak Count","font":{"color":"rgba(0,0,0,1)","family":"","size":14.611872146118724}},"hoverformat":".2f"},"shapes":[{"type":"rect","fillcolor":null,"line":{"color":null,"width":0,"linetype":[]},"yref":"paper","xref":"paper","x0":0,"x1":1,"y0":0,"y1":1}],"showlegend":true,"legend":{"bgcolor":"rgba(255,255,255,1)","bordercolor":"transparent","borderwidth":1.8897637795275593,"font":{"color":"rgba(0,0,0,1)","family":"","size":11.68949771689498},"title":{"text":"Motif Present","font":{"color":"rgba(0,0,0,1)","family":"","size":14.611872146118724}},"traceorder":"reversed"},"hovermode":"closest","barmode":"relative"},"config":{"doubleClick":"reset","modeBarButtonsToAdd":["hoverclosest","hovercompare"],"showSendToCloud":false},"source":"A","attrs":{"3aa720e24b46":{"x":{},"y":{},"fill":{},"text":{},"type":"bar"}},"cur_data":"3aa720e24b46","visdat":{"3aa720e24b46":["function (y) ","x"]},"highlight":{"on":"plotly_click","persistent":false,"dynamic":false,"selectize":false,"opacityDim":0.20000000000000001,"selected":{"opacity":1},"debounce":0},"shinyEvents":["plotly_hover","plotly_click","plotly_selected","plotly_relayout","plotly_brushed","plotly_brushing","plotly_clickannotation","plotly_doubleclick","plotly_deselect","plotly_afterplot","plotly_sunburstclick"],"base_url":"https://plot.ly"},"evals":[],"jsHooks":[]}</script>
# }