-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Description
If I assign pgParameters using the "gene" option, I am able to use this parameter object to plot a Hi-C matrix with plotHicRectangle, however when I try to annotate loop pixels on that map it returns an error due to an apparent discrepancy in chromosome factors.
Example
p <- pgParams(gene = "Fgfr4", assembly = "mm10")
pageCreate(width = 4, height = 2)
h <- plotHicRectangle(data = "/path/to/file.mcool", params = p, x = 0.5, y = 0.5, width = 3, height = 1)
annoPixels(plot = h, data = loops)
Returns the following error:
Error in Ops.factor(loopData[, "chrom1"], object$chrom) :
level sets of factors are different
With the following debug traceback:
7.
stop("level sets of factors are different")
6.
Ops.factor(loopData[, "chrom1"], object$chrom)
5.
which(loopData[, "chrom1"] == object$chrom & loopData[, "chrom2"] ==
object$chrom & loopData[, "start1"] >= plotObject$chromstartAdjusted &
loopData[, "end1"] <= plotObject$chromendAdjusted & loopData[,
"start2"] >= plotObject$chromstartAdjusted & loopData[, "end2"] <= ...
4.
`[.data.frame`(loopData, which(loopData[, "chrom1"] == object$chrom &
loopData[, "chrom2"] == object$chrom & loopData[, "start1"] >=
plotObject$chromstartAdjusted & loopData[, "end1"] <= plotObject$chromendAdjusted &
loopData[, "start2"] >= plotObject$chromstartAdjusted & loopData[, ...
3.
loopData[which(loopData[, "chrom1"] == object$chrom & loopData[,
"chrom2"] == object$chrom & loopData[, "start1"] >= plotObject$chromstartAdjusted &
loopData[, "end1"] <= plotObject$chromendAdjusted & loopData[,
"start2"] >= plotObject$chromstartAdjusted & loopData[, "end2"] <= ...
2.
subset_loops(hic = loopsInternal$plot, loopData = loopData, object = loops,
plotObject = loopsInternal$plot)
1.
annoPixels(plot = h, data = tmp)
Potential cause
It seems to me that this is happening because the seqname levels of the loops (which contains all chromosomes for the genome build) does not match the levels of the Hi-C map or parameters chrom (which is only the individual chromosome containing the gene of interest.
For example, in the example above:
> h$chrom
[1] chr7
Levels: chr7
> p$chrom
[1] chr7
Levels: chr7
> head(seqnames(anchors(loops, "first")))
factor-Rle of length 6 with 1 run
Lengths: 6
Values : chr1
Levels(20): chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 ... chr14 chr15 chr16 chr17 chr18 chr19 chrX
> loopData = plotgardener:::read_pairedData(data = loops, assembly = "mm10")
> head(loopData[, "chrom1"])
[1] chr1 chr1 chr1 chr1 chr1 chr1
20 Levels: chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 ... chrX
> head(which(loopData[, "start1"] >= h$chromstartAdjusted ))
[1] 1242 1243 1244 1245 1246 1247
> head(loopData[, "chrom1"] == h$chrom)
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'head': level sets of factors are different
Work-around
I have been able to work around this in my personal code by adding all the potential chromosomes as levels to the parameter chrom after defining the pgParams object.
For example:
p <- pgParams(gene = "Fgfr4", assembly = "mm10")
levels(p$chrom) = levels(seqnames(anchors(loops, "first")))
Session Info
R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: America/New_York
tzcode source: internal
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods base
other attached packages:
[1] org.Mm.eg.db_3.22.0 plotgardener_1.16.0
[3] org.Hs.eg.db_3.22.0 TxDb.Hsapiens.UCSC.hg38.knownGene_3.22.0
[5] GenomicFeatures_1.62.0 AnnotationDbi_1.72.0
[7] InteractionSet_1.38.0 SummarizedExperiment_1.40.0
[9] Biobase_2.70.0 MatrixGenerics_1.22.0
[11] matrixStats_1.5.0 GenomicRanges_1.62.1
[13] Seqinfo_1.0.0 IRanges_2.44.0
[15] S4Vectors_0.48.0 BiocGenerics_0.56.0
[17] generics_0.1.4 mariner_1.9.2
loaded via a namespace (and not attached):
[1] tidyselect_1.2.1 blob_1.2.4
[3] dplyr_1.1.4 farver_2.1.2
[5] Biostrings_2.78.0 S7_0.2.1
[7] bitops_1.0-9 fastmap_1.2.0
[9] RCurl_1.98-1.17 GenomicAlignments_1.46.0
[11] XML_3.99-0.20 digest_0.6.39
[13] lifecycle_1.0.4 plyranges_1.30.1
[15] KEGGREST_1.50.0 RSQLite_2.4.5
[17] magrittr_2.0.4 dbscan_1.2.3
[19] compiler_4.5.1 rlang_1.1.6
[21] progress_1.2.3 tools_4.5.1
[23] yaml_2.3.12 data.table_1.18.0
[25] rtracklayer_1.70.0 prettyunits_1.2.0
[27] S4Arrays_1.10.1 bit_4.6.0
[29] curl_7.0.0 DelayedArray_0.36.0
[31] RColorBrewer_1.1-3 abind_1.4-8
[33] BiocParallel_1.44.0 HDF5Array_1.38.0
[35] withr_3.0.2 purrr_1.2.0
[37] grid_4.5.1 Rhdf5lib_1.32.0
[39] ggplot2_4.0.1 scales_1.4.0
[41] cli_3.6.5 crayon_1.5.3
[43] rstudioapi_0.17.1 httr_1.4.7
[45] rjson_0.2.23 cachem_1.1.0
[47] DBI_1.2.3 rhdf5_2.54.1
[49] assertthat_0.2.1 parallel_4.5.1
[51] ggplotify_0.1.3 BiocManager_1.30.27
[53] XVector_0.50.0 restfulr_0.0.16
[55] yulab.utils_0.2.2 vctrs_0.6.5
[57] Matrix_1.7-4 jsonlite_2.0.0
[59] gridGraphics_0.5-1 hms_1.1.4
[61] bit64_4.6.0-1 h5mread_1.2.1
[63] strawr_0.0.92 glue_1.8.0
[65] codetools_0.2-20 TxDb.Mmusculus.UCSC.mm10.knownGene_3.10.0
[67] gtable_0.3.6 GenomeInfoDb_1.46.2
[69] BiocIO_1.20.0 UCSC.utils_1.6.0
[71] tibble_3.3.0 pillar_1.11.1
[73] rappdirs_0.3.3 rhdf5filters_1.22.0
[75] R6_2.6.1 lattice_0.22-7
[77] png_0.1-8 Rsamtools_2.26.0
[79] cigarillo_1.0.0 memoise_2.0.1
[81] colourvalues_0.3.11 Rcpp_1.1.0
[83] SparseArray_1.10.6 fs_1.6.6
[85] pkgconfig_2.0.3