-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathavailable.R
107 lines (87 loc) · 2.63 KB
/
available.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#' @rdname import-methods
#' @export
setMethod("availableResolutions", signature(x = "ANY"), function(x, ...) {
.availableResolutions(x, ...)
})
#' @rdname import-methods
#' @export
#' @include CoolFile-class.R
#' @include import-methods.R
setMethod("availableResolutions", signature(x = "CoolFile"), function(x) {
.availableResolutions(path(x))
})
#' @rdname import-methods
#' @export
#' @include HicFile-class.R
setMethod("availableResolutions", signature(x = "HicFile"), function(x) {
.availableResolutions(path(x))
})
#' @rdname import-methods
#' @export
#' @include HicproFile-class.R
setMethod("availableResolutions", signature(x = "HicproFile"), function(x) {
.availableResolutions(path(x), x@bed)
})
#' @rdname import-methods
#' @export
setMethod("availableChromosomes", signature(x = "ANY"), function(x, ...) {
.availableChromosomes(x, ...)
})
#' @rdname import-methods
#' @export
#' @include CoolFile-class.R
setMethod("availableChromosomes", signature(x = "CoolFile"), function(x) {
.availableChromosomes(path(x))
})
#' @rdname import-methods
#' @export
#' @include HicFile-class.R
setMethod("availableChromosomes", signature(x = "HicFile"), function(x) {
.availableChromosomes(path(x))
})
#' @rdname import-methods
#' @export
#' @include HicproFile-class.R
setMethod("availableChromosomes", signature(x = "HicproFile"), function(x) {
.availableChromosomes(path(x), x@bed)
})
.availableResolutions <- function(file, bed = NULL) {
file <- gsub('~', Sys.getenv('HOME'), file)
stopifnot(file.exists(file))
if (.is_cool(file) | .is_mcool(file)) {
return(.lsCoolResolutions(file, verbose = TRUE))
}
if (.is_hic(file)) {
return(.lsHicResolutions(file, verbose = TRUE))
}
if (.is_hicpro_matrix(file)) {
if (is.null(bed)) stop("Regions files not provided.")
return({
bed1 <- vroom::vroom(
bed,
col_names = FALSE,
progress = FALSE,
show_col_types = FALSE,
n_max = 10
)
max(unique(bed1[[3]][1] - bed1[[2]][1]))
})
}
}
.availableChromosomes <- function(file, bed = NULL) {
file <- gsub('~', Sys.getenv('HOME'), file)
stopifnot(file.exists(file))
if (.is_cool(file)) {
return(.cool2seqinfo(file))
}
if (.is_mcool(file)) {
return(.cool2seqinfo(file, resolution = .lsCoolResolutions(file)[1]))
}
if (.is_hic(file)) {
return(.hic2seqinfo(file))
}
if (.is_hicpro_matrix(file)) {
if (is.null(bed)) stop("Regions files not provided.")
return(.hicpro2seqinfo(bed))
}
}