forked from cran/PopGenome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_gff_info.R
74 lines (53 loc) · 1.89 KB
/
get_gff_info.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
get_gff_info <- function(object=FALSE, gff.file, chr, position, feature=FALSE, extract.gene.names = FALSE){
chr <- as.character(chr)
#if(nchar(chr)==1){
# chr <- c(chr,"z") # for find_lines_GFF_Human
#}else{
# chr <- strsplit(chr,split="")[[1]]
#}
if(extract.gene.names){
region <- .Call("find_lines_GFF_Human2",gff.file,chr)
start <- region[1]
end <- region[2]
gff.table <- read.table(gff.file,sep="\t",colClasses=c("NULL","NULL","character",rep("NULL",5),"character"),
skip = start - 1, nrows = end - start + 1)
ids <- which(gff.table[,1]=="gene")
gff.table <- gff.table[ids, ]
return(gff.table[,2])
}
if(feature[1]!=FALSE){
region <- .Call("find_lines_GFF_Human2",gff.file,chr)
start <- region[1]
end <- region[2]
gff.table <- read.table(gff.file,sep="\t",colClasses=c(rep("NULL",2),"character",rep("integer",2),rep("NULL",4)),
skip = start - 1, nrows = end - start + 1)
featids <- which(gff.table[,1]==feature)
poslist <- apply(gff.table[featids,2:3],1,function(x){return(x[1]:x[2])})
return(poslist)
}
if(is(object)=="logical"){
chr <- as.character(chr)
region <- .Call("find_lines_GFF_Human2",gff.file,chr)
start <- region[1]
end <- region[2]
info <- .Call("get_gff_info_C",start,end,gff.file,position)
return(info)
}
if(is(object)=="GENOME"){
chr <- as.character(chr)
region <- .Call("find_lines_GFF_Human2",gff.file,chr)
start <- region[1]
end <- region[2]
RET.INFO <- vector("list",length(position))
for(xx in 1:length(position)){
region <- position[xx]
region <- [email protected]@biallelic.sites[[region]]
info <- sapply(region,function(x){return(.Call("get_gff_info_C",start,end,gff.file,x))})
names(info) <- region
RET.INFO[[xx]] <- info
}
RET.INFO <- as.matrix(RET.INFO)
rownames(RET.INFO) <- position
return(RET.INFO)
}
}