annotate ving.R @ 6:97ae4ee7a6a2 draft default tip

Uploaded
author rlegendre
date Thu, 30 Jul 2015 03:19:23 -0400
parents 0cec66d7f637
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1 #! /usr/bin/Rscript
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
2
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
3 RetreiveAndDestroy=function(opt,root,stem,regexp,SearchNames,Out,isValue,NbFound,StockNames) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
4 Bool=lapply(paste(root,SearchNames,stem,sep=""),grepl,opt)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
5 names(Bool)=StockNames
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
6 Pos=lapply(Bool,which)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
7 names(Pos)=StockNames
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
8 disable=c()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
9 for(i in StockNames) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
10 nbmatch=length(Pos[[i]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
11 if(nbmatch>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
12 NbFound[[i]]=NbFound[[i]]+nbmatch
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
13 disable=c(disable,-1*Pos[[i]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
14 if(is.null(Out[[i]])) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
15 if(isValue[[i]]!=0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
16 if(regexp=="next") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
17 Out[[i]]=opt[Pos[[i]]+1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
18 disable=c(disable,-1*(Pos[[i]]+1))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
19 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
20 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
21 Out[[i]]=sub(regexp,"\\1",opt[Pos[[i]]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
22 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
23 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
24 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
25 Out[[i]]=TRUE
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
26 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
27 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
28 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
29 if(isValue[[i]]!=0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
30 if(regexp=="next") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
31 Out[[i]]=c(Out[[i]],opt[Pos[[i]]+1])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
32 disable=c(disable,-1*(Pos[[i]]+1))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
33 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
34 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
35 Out[[i]]=c(Out[[i]],sub(regexp,"\\1",opt[Pos[[i]]]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
36 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
37 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
38 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
39 Out[[i]]=c(Out[[i]],TRUE)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
40 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
41 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
42 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
43 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
44 if(length(disable)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
45 opt=opt[disable]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
46 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
47 Out[["ARGUMENT"]]=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
48 Out[["ARGUMENT"]][["opt"]]=opt
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
49 Out[["ARGUMENT"]][["NbFound"]]=NbFound
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
50 return(Out)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
51 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
52
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
53 getopt=function (spec=NULL,opt=commandArgs()) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
54 FindArgs=which(opt=="--args")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
55 if(length(FindArgs)!=1) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
56 stop(length(FindArgs)," --args found where 1 expected.",call.=F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
57 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
58 ExecName=sub("--file=","",opt[FindArgs-1])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
59
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
60 if(FindArgs<length(opt)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
61 opt=opt[(FindArgs+1):length(opt)]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
62 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
63 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
64 opt=""
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
65 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
66
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
67 min.columns=5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
68 colNames=c("LongName","ShortName","Flag","Mod","Default")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
69 max.columns=6
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
70 DimSpec=dim(spec)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
71 if(DimSpec[2]>min.columns) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
72 colNames=c(colNames,"Description")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
73 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
74
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
75 if(is.null(spec) | !is.matrix(spec) | (DimSpec[2]<min.columns | DimSpec[2]>max.columns)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
76 stop('argument "spec" is required and must be a matrix with 4|5 columns.',call.=F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
77 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
78 colnames(spec)=colNames
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
79
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
80 spec=as.data.frame(spec,stringsAsFactors=F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
81 #spec validation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
82 if(length(unique(c(spec$ShortName,"ARGUMENT","args")))!=DimSpec[1]+2 | length(unique(spec$LongName))!=DimSpec[1]) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
83 stop('Long|Short names for flags must be unique (Long name : "ARGUMENT" and "args" forbidden).',
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
84 "\n","List of duplicated :",
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
85 "\n","Short: ",paste(spec$ShortName[duplicated(c(spec$ShortName,"ARGUMENT","args"))],collapse=" "),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
86 "\n","Long: ",paste(spec$ShortName[duplicated(spec$LongName)],collapse=" "),call.=F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
87 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
88 if(length(which(nchar(spec$ShortName)>1))!=0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
89 stop('Short names flags can\'t be longer than 1 character.')
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
90 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
91
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
92 #initialize
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
93 Out=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
94 Short2Long=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
95 NbFound=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
96 isValue=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
97 for(i in 1:DimSpec[1]) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
98 Short2Long[[spec$ShortName[i]]]=spec$LongName[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
99 NbFound[[spec$LongName[i]]]=0
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
100 isValue[[spec$LongName[i]]]=spec$Flag[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
101 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
102
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
103 #Map, retreive and suppress ARGUMENTs and arguments
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
104 #Value ARGUMENT --example=value
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
105 Out=RetreiveAndDestroy(opt,"^--","=.+$",".+=(.+)$",spec$LongName,Out,isValue,NbFound,spec$LongName)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
106 opt=Out[["ARGUMENT"]][["opt"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
107 NbFound=Out[["ARGUMENT"]][["NbFound"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
108 Out[["ARGUMENT"]]=NULL
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
109 #boolean ARGUMENT --example
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
110 Out=RetreiveAndDestroy(opt,"^--","$","$",spec$LongName,Out,isValue,NbFound,spec$LongName)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
111 opt=Out[["ARGUMENT"]][["opt"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
112 NbFound=Out[["ARGUMENT"]][["NbFound"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
113 Out[["ARGUMENT"]]=NULL
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
114 #short name ARGUMENT -t value OR boolean -t
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
115 Out=RetreiveAndDestroy(opt,"^-","$","next",spec$ShortName,Out,isValue,NbFound,spec$LongName)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
116 opt=Out[["ARGUMENT"]][["opt"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
117 NbFound=Out[["ARGUMENT"]][["NbFound"]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
118 Out[["ARGUMENT"]]=NULL
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
119 #Warn about non mapped ARGUMENTs
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
120 if(length(opt)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
121 PosUnkArg=which(grepl("^-",opt))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
122 if(length(PosUnkArg)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
123 message("Error, argument unreconized :","\n",paste(opt[PosUnkArg],collapse="\n"),"\n\n")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
124 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
125 if(length(PosUnkArg)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
126 opt=opt[PosUnkArg*-1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
127 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
128 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
129 #Arguments
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
130 Out[["ARGUMENT"]]=opt
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
131
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
132 #Validation of ARGUMENTs
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
133 for(i in 1:DimSpec[1]) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
134 if(spec$Flag[i]=="0") {#verify boolean arguments
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
135 NbValue=length(Out[[spec$LongName[i]]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
136 if(NbValue>1) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
137 message("Warning : ",spec$LongName[i]," found ",NbValue," times")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
138 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
139 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
140 if(length(Out[[spec$LongName[i]]])==0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
141 Out[[spec$LongName[i]]]=spec$Default[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
142 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
143 library("methods")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
144 Out[[spec$LongName[i]]]=as(Out[[spec$LongName[i]]],spec$Mod[i])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
145 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
146
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
147 return(Out)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
148 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
149
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
150 ## Converts the flag numbers into binary
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
151 integer.base.b=function(x, b=2) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
152 xi=as.integer(x)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
153 if(any(is.na(xi) | ((x-xi)!=0)))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
154 print(list(ERROR="x not integer", x=x))
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
155 N=length(x)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
156 xMax=max(c(x,1))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
157 ndigits=11
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
158 Base.b=array(NA, dim=c(N, ndigits))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
159 for(i in 1:ndigits) {#i=1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
160 Base.b[, ndigits-i+1]=(x %% b)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
161 x=(x %/% b)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
162 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
163 Base.b
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
164 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
165
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
166 ## Checks if color used is an acceptable color
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
167 is.acceptable.color=function(character) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
168 tmp=try(col2rgb(character),TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
169 return(class(tmp)!="try-error")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
170 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
171
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
172 extractFromBam=function(file,which,what) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
173 return(scanBam(file, param=ScanBamParam(which=which,what=what))[[1]][[1]])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
174 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
175
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
176 ## Returns a list from cigar expression
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
177 interpreteCIGAR=function(cigar) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
178 cigar_un=strsplit(unique(cigar),split="")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
179 n_cigar_un=length(cigar_un)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
180 taille_cigar=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
181 analise_cigar=function(cigar_) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
182 cigar_sortie=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
183 acc=""
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
184 for(j in 1:length(cigar_)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
185 if(sum(cigar_[j]==as.character(0:9))==1) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
186 acc=paste(acc,cigar_[j],sep="")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
187 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
188 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
189 cigar_sortie[[length(cigar_sortie)+1]]=as.integer(acc)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
190 cigar_sortie[[length(cigar_sortie)+1]]=cigar_[j]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
191 acc=""
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
192 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
193 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
194 return(cigar_sortie)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
195 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
196 cigar_interprete=lapply(cigar_un,analise_cigar)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
197 names(cigar_interprete)=unique(cigar)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
198
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
199 return(cigar_interprete)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
200 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
201
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
202 # prend un CIGAR splités et retourne la taille occupé par le read sur la séquence génomique (introns compris)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
203 calcule_longueur_cigar=function(cigar_) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
204 lon=0
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
205 N=length(cigar_)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
206 for(j in seq(2,N,2)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
207 if(cigar_[[j]]!="I") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
208 lon=lon+cigar_[[j-1]]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
209 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
210 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
211 return(lon)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
212 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
213
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
214 # prend un CIGAR splités et retourne les positions
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
215 calcule_junction_cigar=function(cigar_) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
216 retour=list()
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
217 lon=0
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
218 N=length(cigar_)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
219 for(j in seq(2,N,2)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
220 if(cigar_[[j]]!="I") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
221 lon=lon+cigar_[[j-1]]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
222 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
223 if(cigar_[[j]]=="N") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
224 retour[[length(retour)+1]]=c(lon-cigar_[[j-1]]+1,lon)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
225 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
226 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
227 return(retour)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
228 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
229
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
230 ## Returns a list of numbers of single read with their coordinates
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
231 compresse_coordonnees=function(debut,fin) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
232 if(length(debut)==0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
233 return(list(numeric(),numeric(),numeric()))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
234 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
235 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
236 tmp=sort(paste(debut,fin,sep="_"))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
237 tmp_rle=rle(tmp)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
238 poids=tmp_rle$lengths
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
239 values_split=strsplit(tmp_rle$values,split="_")
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
240 doit=function(j) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
241 return(as.integer(values_split[[j]][1]))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
242 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
243 debut_uni=sapply(1:length(poids),doit)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
244 doit=function(j) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
245 return(as.integer(values_split[[j]][2]))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
246 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
247 fin_uni=sapply(1:length(poids),doit)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
248 ordre_debut=order(debut_uni)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
249 return(list(debut_uni[ordre_debut],fin_uni[ordre_debut],poids[ordre_debut]))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
250 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
251 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
252
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
253 RDataFileName=function(file) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
254 return(paste(file,".RData",sep=""))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
255 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
256
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
257 ## Function converts and extracts the infos from bamfile
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
258 readBam_=function(file_,insert_max_=2000,stranded_=TRUE,ncore_=1,libraryType_=c("standard","inverse"),fileNameRData_=NA,normalized_=NULL,chrName_=NULL,from_=1,to_=NULL) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
259 suppressPackageStartupMessages(require("Rsamtools"))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
260 suppressPackageStartupMessages(require("GenomicRanges"))
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
261 ## Declaration of variables
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
262 flagstat=numeric(11)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
263 names(flagstat)=c("total","duplicates","mapped","paired","read1","read2","properly paired","itself and mate mapped","singletons","mate mapped on a different chr","QC-failed")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
264 genome_info=scanBamHeader(file_)[[1]]$targets
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
265 noms_chromosomes=names(genome_info)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
266 longueur_chromosomes=as.integer(genome_info)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
267 nombre_chromosomes=length(noms_chromosomes)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
268 brin_F=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
269 brin_R=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
270 brin_F_junction=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
271 brin_R_junction=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
272 pas=c(1,2,6,7)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
273 i_zone=0
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
274 if(is.null(chrName_)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
275 chrName__=noms_chromosomes
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
276 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
277 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
278 chrName__=chrName_
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
279 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
280 ## Fragments identification
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
281 for(i in (1:nombre_chromosomes)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
282 i_zone=i_zone +1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
283 nom_chromo=noms_chromosomes[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
284 lon_chromo=longueur_chromosomes[i]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
285
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
286 if(!(nom_chromo %in% chrName__)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
287 brin_F[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
288 brin_R[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
289 brin_F_junction[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
290 brin_R_junction[[i]]=list(numeric(),numeric(),numeric())
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
291 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
292 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
293 if(is.null(to_)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
294 to_i=lon_chromo
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
295 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
296 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
297 to_i=to_[min(i_zone,length(to_))]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
298 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
299 from_i=from_[min(i_zone,length(from_))]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
300
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
301 commande=paste("RangesList(`",nom_chromo,"`=IRanges(",from_i,",",to_i,"))",sep="")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
302 expr=try(parse(text=commande),TRUE)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
303 ## Function used from GenomicRanges package
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
304 which=eval(expr)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
305 what=c("flag","mpos","cigar","mrnm","isize")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
306 param=ScanBamParam(what=what, which=which)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
307 ## Case of no reads on the chromosome
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
308 start=extractFromBam(file=file_,which=which,what="pos")
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
309 if(length(start)==0 ) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
310 brin_F[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
311 brin_R[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
312 brin_F_junction[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
313 brin_R_junction[[i]]=list(numeric(),numeric(),numeric())
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
314 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
315 else {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
316 strand=extractFromBam(file=file_,which=which,what="strand")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
317 flag=extractFromBam(file=file_,which=which,what="flag")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
318 mpos=extractFromBam(file=file_,which=which,what="mpos")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
319 cigar=extractFromBam(file=file_,which=which,what="cigar")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
320 mrnm=extractFromBam(file=file_,which=which,what="mrnm")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
321 isize=extractFromBam(file=file_,which=which,what="isize")
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
322
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
323 first_read=integer.base.b(flag)[,5]==1
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
324 strand[strand=="+" & !first_read ]="*"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
325 strand[strand=="-" & !first_read ]="+"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
326 strand[strand=="*" & !first_read ]="-"
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
327
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
328 ## CIGAR's interpreter
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
329 cigar_interprete=interpreteCIGAR(cigar)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
330 longueur_cigar=lapply(cigar_interprete,calcule_longueur_cigar)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
331 junction_cigar=lapply(cigar_interprete,calcule_junction_cigar)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
332
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
333 end=start+sapply(1:length(cigar),function(j) longueur_cigar[[cigar[j]]])
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
334
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
335 ## Case of pairend reads
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
336 is_on_same_chr=mrnm==nom_chromo
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
337 is_on_same_chr[is.na(is_on_same_chr)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
338 is_paired=is_on_same_chr & abs(isize) <=insert_max_
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
339 is_paired[first_read & strand=="+" & (isize<0 | isize>insert_max_)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
340 is_paired[!first_read & strand=="+" & (isize>0 | isize < -insert_max_)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
341 is_paired[first_read & strand=="-" & (isize>0 | isize < -insert_max_)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
342 is_paired[!first_read & strand=="-" & (isize<0 | isize>insert_max_)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
343 is_paired[is.na(is_paired)]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
344
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
345 debut_fragment_paired_plus=mpos[!first_read & strand=="+" & is_paired]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
346 fin_fragment_paired_plus=end[!first_read & strand=="+" & is_paired]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
347 debut_fragment_paired_moins=mpos[first_read & strand=="-" & is_paired]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
348 fin_fragment_paired_moins=end[first_read & strand=="-" & is_paired]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
349
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
350 ## Case of single reads
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
351 debut_fragment_singleton_plus=start[!is_paired & strand=="+"]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
352 fin_fragment_singleton_plus=end[!is_paired & strand=="+"]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
353 debut_fragment_singleton_moins=start[!is_paired & strand=="-"]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
354 fin_fragment_singleton_moins=end[!is_paired & strand=="-"]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
355
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
356 ## Fragments
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
357 debut_frag_plus=c(debut_fragment_paired_plus,debut_fragment_singleton_plus)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
358 fin_frag_plus=c(fin_fragment_paired_plus,fin_fragment_singleton_plus)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
359 debut_frag_moins=c(debut_fragment_paired_moins,debut_fragment_singleton_moins)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
360 fin_frag_moins=c(fin_fragment_paired_moins,fin_fragment_singleton_moins)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
361 brin_F[[i]]=compresse_coordonnees(debut_frag_plus,fin_frag_plus)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
362 brin_R[[i]]=compresse_coordonnees(debut_frag_moins,fin_frag_moins)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
363
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
364 ## Junction read
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
365 debut_junction=numeric()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
366 fin_junction=numeric()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
367 brin_junction=numeric()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
368 i_junction=0
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
369 for(j in 1:length(cigar)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
370 junctions_=junction_cigar[[cigar[j]]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
371 if(length(junctions_)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
372 for(k in 1:length(junctions_)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
373 i_junction=i_junction + 1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
374 debut_junction[i_junction]=start[j] + junctions_[[k]][1] - 1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
375 fin_junction[i_junction]=start[j] + junctions_[[k]][2] - 1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
376 brin_junction[i_junction]=as.character(strand[j])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
377 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
378 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
379 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
380 if(i_junction==0) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
381 brin_F_junction[[i]]=list(numeric(),numeric(),numeric())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
382 brin_R_junction[[i]]=list(numeric(),numeric(),numeric())
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
383 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
384 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
385 brin_F_junction[[i]]=compresse_coordonnees(debut_junction[brin_junction=="+"],fin_junction[brin_junction=="+"])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
386 brin_R_junction[[i]]=compresse_coordonnees(debut_junction[brin_junction=="-"],fin_junction[brin_junction=="-"])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
387 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
388
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
389 ## Flagstat interpreter
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
390 flag_bits=integer.base.b(flag)#remplie les données stat pour un flag donné
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
391
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
392 ## flagstat
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
393 ## total
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
394 flagstat[1]=flagstat[1] + sum(flag_bits[,2]==0)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
395 ## duplicates
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
396 flagstat[2]=flagstat[2] + sum((flag_bits[,1]==1)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
397 ## mapped
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
398 flagstat[3]=flagstat[3] + sum((flag_bits[,9]==0)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
399 ## paired
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
400 flagstat[4]=flagstat[4] + sum((flag_bits[,11]==1)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
401 ## read1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
402 flagstat[5]=flagstat[5] + sum((flag_bits[,5]==1)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
403 ## read2
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
404 flagstat[6]=flagstat[6] + sum((flag_bits[,4]==1)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
405 ## iself and mate mapped
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
406 flagstat[8]=flagstat[8] + sum((flag_bits[,11]==1)&(flag_bits[,9]==0)&(flag_bits[,8]==0)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
407 ## singletons
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
408 flagstat[9]=flagstat[9] + sum((flag_bits[,8]==1)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
409 ## QC-failed
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
410 flagstat[11]=flagstat[11] + sum(flag_bits[,2]==1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
411 ## flagstat
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
412 ## mate on a different chr
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
413 flagstat[10]=flagstat[10] + sum((!is_on_same_chr)&(flag_bits[,11]==1)&(flag_bits[,9]==0)&(flag_bits[,8]==0)&(flag_bits[,2]==0))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
414 ## flagstat
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
415 ## properly paired
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
416 flagstat[7]=flagstat[7] + sum(is_paired)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
417 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
418 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
419 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
420
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
421 ## Data storing
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
422 names(brin_F)=noms_chromosomes
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
423 names(brin_R)=noms_chromosomes
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
424 names(brin_F_junction)=noms_chromosomes
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
425 names(brin_R_junction)=noms_chromosomes
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
426
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
427 bamHandler=list()
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
428 if(libraryType_[1]=="inverse") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
429 bamHandler[[1]]=brin_R
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
430 bamHandler[[2]]=brin_F
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
431 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
432 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
433 bamHandler[[1]]=brin_F
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
434 bamHandler[[2]]=brin_R
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
435 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
436 bamHandler[[3]]=longueur_chromosomes
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
437 bamHandler[[4]]=flagstat
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
438 bamHandler[[5]]=stranded_
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
439
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
440 if(libraryType_[1]=="inverse") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
441 bamHandler[[6]]=brin_R_junction
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
442 bamHandler[[7]]=brin_F_junction
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
443 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
444 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
445 bamHandler[[6]]=brin_F_junction
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
446 bamHandler[[7]]=brin_R_junction
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
447 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
448 bamHandler[[8]]=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
449 if(!is.null(normalized_)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
450 for( i in pas) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
451 for(j in 1:nombre_chromosomes) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
452 bamHandler[[i]][[j]][[4]]=normalized_*bamHandler[[i]][[j]][[3]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
453 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
454 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
455 bamHandler[[8]]=TRUE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
456 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
457
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
458 names(bamHandler)=c("F","R","chrLength","flagstat","stranded","junctions_F","junctions_R","norm")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
459 if((is.null(chrName_))&(from_==1)&(is.null(to_))) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
460 if(is.null(fileNameRData_)|is.na(fileNameRData_)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
461 save(bamHandler,file=RDataFileName(file_))
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
462 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
463 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
464 save(bamHandler,file=fileNameRData_)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
465 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
466 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
467 return(bamHandler)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
468 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
469
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
470 ## Returns the sum of two bamHandler objects
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
471 addBam=function(bamHandler1,bamHandler2) {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
472 if(class(bamHandler1)=="try-error"|class(bamHandler2)=="try-error") {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
473 if(class(bamHandler1)=="try-error") {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
474 return(bamHandler2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
475 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
476 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
477 return(bamHandler1)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
478 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
479 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
480 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
481 brin_F=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
482 junctions_brin_F=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
483 brin_R=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
484 junctions_brin_R=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
485 L=length(bamHandler1$F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
486 bamHandler=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
487 if(bamHandler1$norm !=bamHandler2$norm ) {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
488 warning(expr="Two different bam files(normalized and non normalized)!!",immediate.=TRUE)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
489 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
490 for(i in 1:L) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
491 brin_F[[i]]=list(c(bamHandler1$F[[i]][[1]],bamHandler2$F[[i]][[1]]),c(bamHandler1$F[[i]][[2]],bamHandler2$F[[i]][[2]]),c(bamHandler1$F[[i]][[3]],bamHandler2$F[[i]][[3]]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
492 junctions_brin_F[[i]]=list(c(bamHandler1$junctions_F[[i]][[1]],bamHandler2$junctions_F[[i]][[1]]),c(bamHandler1$junctions_F[[i]][[2]],bamHandler2$junctions_F[[i]][[2]]),c(bamHandler1$junctions_F[[i]][[3]],bamHandler2$junctions_F[[i]][[3]]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
493 brin_R[[i]]=list(c(bamHandler1$R[[i]][[1]],bamHandler2$R[[i]][[1]]),c(bamHandler1$R[[i]][[2]],bamHandler2$R[[i]][[2]]),c(bamHandler1$R[[i]][[3]],bamHandler2$R[[i]][[3]]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
494 junctions_brin_R[[i]]=list(c(bamHandler1$junctions_R[[i]][[1]],bamHandler2$junctions_R[[i]][[1]]),c(bamHandler1$junctions_R[[i]][[2]],bamHandler2$junctions_R[[i]][[2]]),c(bamHandler1$junctions_R[[i]][[3]],bamHandler2$junctions_R[[i]][[3]]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
495 if(bamHandler1$norm & bamHandler2$norm) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
496 brin_F[[i]][[4]]=c(bamHandler1$F[[i]][[4]],bamHandler2$F[[i]][[4]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
497 junctions_brin_F[[i]][[4]]=c(bamHandler1$junctions_F[[i]][[4]],bamHandler2$junctions_F[[i]][[4]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
498 brin_R[[i]][[4]]=c(bamHandler1$R[[i]][[4]],bamHandler2$R[[i]][[4]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
499 junctions_brin_R[[i]][[4]]=c(bamHandler1$junctions_R[[i]][[4]],bamHandler2$junctions_R[[i]][[4]])
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
500 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
501 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
502 names(brin_F)=names(bamHandler1$F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
503 names(brin_R)=names(bamHandler2$R)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
504 names(junctions_brin_F)=names(bamHandler1$junctions_F)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
505 names(junctions_brin_R)=names(bamHandler2$junctions_R)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
506 bamHandler[[1]]=brin_F
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
507 bamHandler[[2]]=brin_R
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
508 bamHandler[[3]]=bamHandler1[[3]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
509 bamHandler[[4]]=bamHandler1[[4]] + bamHandler2[[4]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
510 bamHandler[[5]]=bamHandler1[[5]] & bamHandler2[[5]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
511 bamHandler[[6]]=junctions_brin_F
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
512 bamHandler[[7]]=junctions_brin_R
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
513 bamHandler[[8]]=bamHandler1$norm & bamHandler2$norm
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
514 names(bamHandler)=c("F","R","chrLength","flagstat","stranded","junctions_F","junctions_R","norm")
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
515 return(bamHandler)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
516 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
517 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
518
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
519 ## Extracts the signal from bamHandler objects
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
520 extractSignal=function(bamHandlerList,chrName,from=1, to=NULL,normalized_=FALSE) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
521 forward=list()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
522 reverse=list()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
523 chr=which(names(bamHandlerList[[1]]$F)==chrName)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
524 if(is.null(to)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
525 to=bamHandlerList[[1]]$chrLength[chr]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
526 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
527 for(i in 1:length(bamHandlerList)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
528 if(normalized_) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
529 if(bamHandlerList[[i]]$norm) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
530 end=4
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
531 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
532 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
533 end=3
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
534 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
535 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
536 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
537 end=3
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
538 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
539 forward_=numeric(to-from+1)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
540 which_read=which((bamHandlerList[[i]]$F[[chrName]][[2]]>=from)&(bamHandlerList[[i]]$F[[chrName]][[1]]<=to))
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
541 n_reads=length(which_read)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
542 if(n_reads>0) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
543 for(k in which_read) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
544 debut_read=max(1,bamHandlerList[[i]]$F[[chrName]][[1]][k]-from+1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
545 fin_read=min(bamHandlerList[[i]]$F[[chrName]][[2]][k]-from+1,to-from+1)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
546 forward_[debut_read:fin_read]=forward_[debut_read:fin_read]+bamHandlerList[[i]]$F[[chrName]][[end]][k]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
547 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
548 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
549 which_junctions=which((bamHandlerList[[i]]$junctions_F[[chrName]][[2]]>=from)&(bamHandlerList[[i]]$junctions_F[[chrName]][[1]]<=to))
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
550 n_junctions=length(which_junctions)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
551 if(n_junctions>0) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
552 for(k in which_junctions) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
553 debut_junction=max(1,bamHandlerList[[i]]$junctions_F[[chrName]][[1]][k]-from+1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
554 fin_junction=min(bamHandlerList[[i]]$junctions_F[[chrName]][[2]][k]-from+1,to-from+1)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
555 forward_[debut_junction:fin_junction]=forward_[debut_junction:fin_junction]-bamHandlerList[[i]]$junctions_F[[chrName]][[end]][k]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
556 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
557 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
558 reverse_=numeric(to-from+1)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
559 which_read=which((bamHandlerList[[i]]$R[[chrName]][[2]]>=from)&(bamHandlerList[[i]]$R[[chrName]][[1]]<=to))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
560 n_reads=length(which_read)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
561 if(n_reads>0) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
562 for(k in which_read) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
563 debut_read=max(1,bamHandlerList[[i]]$R[[chrName]][[1]][k]-from+1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
564 fin_read=min(bamHandlerList[[i]]$R[[chrName]][[2]][k]-from+1,to-from+1)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
565 reverse_[debut_read:fin_read]=reverse_[debut_read:fin_read]+bamHandlerList[[i]]$R[[chrName]][[end]][k]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
566 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
567 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
568 which_junctions=which((bamHandlerList[[i]]$junctions_R[[chrName]][[2]]>=from)&(bamHandlerList[[i]]$junctions_R[[chrName]][[1]]<=to))
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
569 n_junctions=length(which_junctions)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
570 if(n_junctions>0) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
571 for(k in which_junctions) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
572 debut_junction=max(1,bamHandlerList[[i]]$junctions_R[[chrName]][[1]][k]-from+1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
573 fin_junction=min(bamHandlerList[[i]]$junctions_R[[chrName]][[2]][k]-from+1,to-from+1)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
574 reverse_[debut_junction:fin_junction]=reverse_[debut_junction:fin_junction]-bamHandlerList[[i]]$junctions_R[[chrName]][[end]][k]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
575 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
576 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
577 forward_[forward_<0]=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
578 reverse_[reverse_<0]=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
579 if(bamHandlerList[[i]]$stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
580 forward[[i]]=forward_
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
581 reverse[[i]]=reverse_
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
582 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
583 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
584 forward[[i]]=forward_+reverse_
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
585 reverse[[i]]=numeric(to-from+1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
586 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
587 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
588 chr_=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
589 chr_$F=forward
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
590 chr_$R=reverse
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
591 return(chr_)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
592 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
593
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
594 ## Intern function for readGff function
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
595 my.read.lines2=function(fname) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
596 s=file.info( fname )$size
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
597 buf=readChar( fname, s, useBytes=T)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
598 strsplit( buf,"\n",fixed=T,useBytes=T)[[1]]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
599 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
600
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
601 ## Extracts the annotation infos from Gff file
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
602 readGff=function(file_in, from=1, to=Inf, chr=NULL, infoName=c("ID","Name","Parent","gene","Alias","orf_classification","Ontology_term","Note","GO")) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
603 tmp=try(my.read.lines2(file_in))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
604 if(!is.null(chr)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
605 tmp1=grep(chr, tmp, value=TRUE,useBytes=T)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
606 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
607 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
608 tmp1=tmp
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
609 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
610 N=length(tmp1)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
611 Chr=array()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
612 Start=array()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
613 Stop=array()
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
614 Strand=array()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
615 Type=array()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
616 info=list()
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
617 for(i in 1:length(infoName)) info[[i]]=array()
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
618 names(info)=infoName
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
619 j=1
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
620 for (i in 1:N) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
621 if(substr(tmp1[i],1,1)!="#") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
622 line_split=unlist(strsplit(tmp1[i],"\t",fixed=T,useBytes=T))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
623 if((as.integer(line_split[4])<=to) & (as.integer(line_split[5])>=from)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
624 Chr[j]=line_split[1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
625 Start[j]=as.integer(line_split[4])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
626 Stop[j]=as.integer(line_split[5])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
627 Strand[j]=line_split[7]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
628 Type[j]=line_split[3]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
629 ninth=unlist(strsplit(line_split[9],";",fixed=T,useBytes=T))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
630 element_ninth_empty=rep(TRUE,length(infoName))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
631 for(element_ninth in ninth) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
632 element_ninth_split=unlist(strsplit(element_ninth,"=",fixed=T,useBytes=T))
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
633 if(length(element_ninth_split)==2) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
634 if(element_ninth_split[1] %in% infoName) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
635 info[[element_ninth_split[1]]][j]=element_ninth_split[2]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
636 element_ninth_empty[infoName==element_ninth_split[1]]=FALSE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
637 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
638 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
639 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
640 for(infoName_ in infoName[element_ninth_empty]) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
641 info[[infoName_]][j]="."
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
642 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
643 j=j+1
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
644 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
645 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
646 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
647 retour=data.frame(Chr,Type,Start,Stop,Strand,info,stringsAsFactors=FALSE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
648 return(retour)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
649 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
650
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
651 ## Returns the classic visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
652 plotRNAseq=function(forward,reverse,debut_vue=1,fin_vue=length(forward),chr=NULL,annot=NULL,style=NULL,top=NULL,bottom=NULL,x="",y="",titre="",repeated=FALSE,name_flags="",decal=0,ataxises=NULL,classic_plus_color="navyblue",classic_minus_color="mediumvioletred",stranded=TRUE) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
653 if(repeated) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
654 forward_=numeric(fin_vue)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
655 forward_[debut_vue:fin_vue]=forward
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
656 reverse_=numeric(fin_vue)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
657 reverse_[debut_vue:fin_vue]=reverse
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
658 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
659 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
660 forward_=forward
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
661 reverse_=reverse
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
662 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
663 if(is.null(top)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
664 top=max(forward_[debut_vue:fin_vue])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
665 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
666 if(is.null(bottom)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
667 bottom=max(reverse_[debut_vue:fin_vue])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
668 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
669 if(is.null(ataxises)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
670 plot(c(debut_vue,fin_vue)+decal,c(-bottom,top),ylim=c(-bottom,top),xlab=x,ylab=y,main=titre,col="white",xaxs="i",cex.main=2,yaxt="n",cex.lab=1.8)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
671 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
672 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
673 plot(c(debut_vue,fin_vue)+decal,c(-bottom,top),ylim=c(-bottom,top),xlab=x,ylab=y,main=titre,col="white",xaxs="i",xaxt="n",cex.main=2,yaxt="n",cex.lab=1.8)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
674 ataxisesLabels=as.character(ataxises)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
675 ataxisesLabels[((1:length(ataxises))%%2)==0]=""
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
676 ataxisesLabels[1]=""
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
677 ataxisesLabels[length(ataxises)]=""
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
678 lim=c(-bottom,top)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
679 ataxises_y=pretty(lim,n=4)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
680 ataxisesLabels_y=as.character(abs(ataxises_y))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
681 axis(1,at=ataxises,labels=FALSE,cex.axis=2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
682 axis(1,at=ataxises,labels=ataxisesLabels,cex.axis=2,line=0.4,lwd=0)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
683 axis(2, at=ataxises_y,labels=FALSE,cex.axis=2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
684 axis(2, at=ataxises_y,labels=ataxisesLabels_y,cex.axis=2,line=-0.4,lwd=0)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
685 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
686 polygon(c(debut_vue,debut_vue:fin_vue,fin_vue)+decal,c(0,forward_[debut_vue:fin_vue],0),col=classic_plus_color,border=NA)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
687 if(stranded) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
688 text(fin_vue+(fin_vue-debut_vue)*0.01,top/2,"+",xpd=NA,cex=3)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
689 text(fin_vue+(fin_vue-debut_vue)*0.01,-bottom/2,"-",xpd=NA,cex=3)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
690 text(fin_vue+(fin_vue-debut_vue)*0.025,(top-bottom)/2,"Strand",xpd=NA,cex=2,srt=-90)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
691 polygon(c(debut_vue,debut_vue:fin_vue,fin_vue)+decal,c(0,-reverse_[debut_vue:fin_vue],0),col=classic_minus_color,border=NA)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
692 abline(h=0,lwd=2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
693 abline(h=0,col="white")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
694 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
695 if(name_flags!="") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
696 flags=try(get(name_flags),TRUE)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
697 if(class(flags)!="try-error") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
698 f_=flags[(flags$Chr==chr)&(flags$Stop>=debut_vue)&(flags$Start<=fin_vue),]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
699 N=dim(f_)[1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
700 points(f_$Start,rep(0,N),col=2,pch=19,cex=2)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
701 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
702 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
703 if(decal<=0) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
704 lines(c(0,0),c(top,-bottom),col=1)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
705 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
706 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
707
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
708 ## Intern function for heatmap visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
709 paletteFromColors=function(colMin="blue",colMax="red",n=300,method=c("hsv","rgb")) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
710 colMinRGB=col2rgb(colMin)[,1]/255
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
711 colMaxRGB=col2rgb(colMax)[,1]/255
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
712 seqList=list()
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
713 if(method[1]=="rgb") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
714 for(i in 1:3) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
715 seqList[[i]]=seq(colMinRGB[i],colMaxRGB[i],length.out=n)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
716 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
717 return(rgb(seqList[[1]],seqList[[2]],seqList[[3]]))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
718 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
719 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
720 colMinHSV=rgb2hsv(colMinRGB)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
721 colMaxHSV=rgb2hsv(colMaxRGB)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
722 for(i in 1:3) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
723 seqList[[i]]=seq(colMinHSV[i],colMaxHSV[i],length.out=n)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
724 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
725 return(hsv(seqList[[1]],s=seqList[[2]],v=seqList[[3]]))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
726 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
727 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
728
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
729 ## Retuns the heatmap visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
730 myHeatMap=function(data,debut_vue,fin_vue,ataxises=NULL,lim=NULL,heatmap_max_color="#000055",heatmap_min_color="#FFFFAA",heatmap_palette_method="hsv",textOnLeftSide="") {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
731 palette=paletteFromColors(heatmap_min_color,heatmap_max_color,method=heatmap_palette_method)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
732 if(is.null(lim)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
733 image(debut_vue:fin_vue,1:dim(data)[1],t(data), col=palette,xlab="",ylab="",xaxt="n",yaxt="n")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
734 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
735 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
736 image(debut_vue:fin_vue,1:dim(data)[1],t(data), col=palette,xlab="",ylab="",xaxt="n",yaxt="n",zlim=lim)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
737 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
738 box()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
739 if(is.null(ataxises)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
740 axis(1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
741 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
742 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
743 if(sum(!is.na(ataxises))!=0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
744 axis(1,at=ataxises,labels=FALSE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
745 axis(3,at=ataxises,labels=FALSE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
746 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
747 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
748 if(sum(!is.na(ataxises))!=0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
749 axis(2,at=1:dim(data)[1],labels=rownames(data),las=2,cex.axis=1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
750 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
751 text(fin_vue+(fin_vue-debut_vue)*0.015,(dim(data)[1]+1)/2,textOnLeftSide,xpd=NA,cex=1,srt=-90)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
752 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
753
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
754 ## Returns the title of visualisation
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
755 plotTitle=function(debut_vue=1,fin_vue=length(listForward[[1]]),chr=NULL,style=NULL) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
756 plot(c(0,1),c(0,1),cex=0,ylab="",xlab="",fg="white",axes=FALSE,xaxs="i",yaxs="i")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
757 text(0,0.5,paste(chr,":",debut_vue,"-",fin_vue,sep=""),cex=2.2,adj=0)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
758 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
759
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
760 openGraphicalDevice=function(file,widthPixels,heightPixels,fileType=c("png","jpeg","tiff","bmp","pdf"),resolutionDPI=72) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
761 widthInches=widthPixels/72
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
762 heightInches=heightPixels/72
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
763 doit=function(x) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
764 switch(x,
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
765 png(file,widthInches,heightInches,units="in",res=resolutionDPI),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
766 jpeg=jpeg(file,widthInches,heightInches,units="in",res=resolutionDPI),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
767 tiff=tiff(file,widthInches,heightInches,units="in",res=resolutionDPI),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
768 bmp=bmp(file,widthInches,heightInches,units="in",res=resolutionDPI),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
769 pdf=pdf(file,widthInches,heightInches))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
770 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
771 doit(fileType[1])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
772 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
773
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
774 ## The main function of visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
775 plotVisu=function(file,typeVisu="classic",listForward,listReverse,which=1:length(listForward),stranded=TRUE,
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
776 debut_vue=1,fin_vue=length(listForward[[1]]),chr=NULL,annot=NULL,style=NULL,tops=NULL,bottoms=NULL,marks=NULL,strandMarks=NULL,
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
777 titres="",repeated=FALSE,name_flags="",decal=0,log=TRUE,classic_plus_color="navyblue",classic_minus_color="deeppink3",
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
778 heatmap_max_color="#000055",heatmap_min_color="#FFFFAA",heatmap_palette_method="hsv",heatmap_lane_height=round(10+40/(1+10^((length(which)-12)/9))),
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
779 lines_samples_colors=c(1,3,4,2)[((0:length(listForward))%%4)+1],lines_samples_type_line=((0:length(listForward))%/%4)+1,
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
780 smoothLength=trunc((fin_vue-debut_vue)/1200),annotation_color_by_strand=FALSE,annotation_placed_by_strand=FALSE,display_name=NULL,initialize_label_sizes=NULL,
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
781 fileType="png",resolutionDPI=72) {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
782 if(fin_vue-debut_vue+1>1000000) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
783 openGraphicalDevice(file,1200,400,fileType=fileType,resolutionDPI=resolutionDPI)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
784 plot(0:1,0:1,fg="white",col="white",axes=FALSE,frame=FALSE,xlab="",ylab="")
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
785 text(0.5,0.5,"Window too long !",cex=5)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
786 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
787 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
788 n_element_vue=length(which)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
789 i_data=which[1]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
790 forward_matrice=NULL
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
791 reverse_matrice=NULL
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
792 all_stranded=data[[i_data]]$stranded
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
793 if(!repeated) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
794 for(i in 1:n_element_vue) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
795 i_data=which[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
796 forward_matrice=rbind(forward_matrice,listForward[[i_data]][debut_vue:fin_vue])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
797 reverse_matrice=rbind(reverse_matrice,listReverse[[i_data]][debut_vue:fin_vue])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
798 all_stranded=all_stranded & data[[i_data]]$stranded
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
799 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
800 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
801 else {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
802 for(i in 1:n_element_vue) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
803 i_data=which[i]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
804 forward_matrice=rbind(forward_matrice,listForward[[i_data]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
805 reverse_matrice=rbind(reverse_matrice,listReverse[[i_data]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
806 all_stranded=all_stranded & data[[i_data]]$stranded
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
807 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
808 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
809 rownames(forward_matrice)=titres[which]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
810 rownames(reverse_matrice)=titres[which]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
811 for( i in 1:n_element_vue) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
812 if(smoothLength>1) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
813 lo=smooth(forward_matrice[i,],L=smoothLength)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
814 forward_matrice[i,]=lo
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
815 los=smooth(reverse_matrice[i,],L=smoothLength)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
816 reverse_matrice[i,]=los
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
817 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
818 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
819 if(is.null(annot)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
820 heights_ann=NULL
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
821 annot_selec=NULL
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
822 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
823 else {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
824 annot_selec=annot[(annot$Chr==chr)&(annot$Stop>=debut_vue)&(annot$Start<=fin_vue),]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
825 heights_ann=sizePlotAnnotation(annot=annot_selec,chr=chr,debut=debut_vue,fin=fin_vue,annotation_placed_by_strand=annotation_placed_by_strand,display_name=display_name,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)*50
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
826 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
827 ataxises=pretty((debut_vue:fin_vue)+decal,n=14)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
828 if(log) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
829 label_scal="log2 tag densities"
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
830 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
831 else {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
832 label_scal="tag densities"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
833 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
834 if(debut_vue==1&decal==0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
835 ataxises[1]=1
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
836 }## Classic visualisation
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
837 if(typeVisu=="classic") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
838 height_panels=c(40,rep(200,n_element_vue),heights_ann)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
839 openGraphicalDevice(file,1200,sum(height_panels),fileType=fileType,resolutionDPI=resolutionDPI)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
840 prev=par(no.readonly=TRUE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
841 n_panels=length(height_panels)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
842 layout(matrix(1:n_panels,n_panels,1),heights=height_panels)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
843 par(mar=c(0, 5, 0, 4)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
844 plotTitle(debut_vue=debut_vue,fin_vue=fin_vue,chr=chr)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
845 par(mar=c(2.5, 5, 2.5, 4)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
846 for(element in 1:n_element_vue) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
847 i_data=which[element]
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
848 plotRNAseq(listForward[[i_data]],listReverse[[i_data]],debut_vue,fin_vue,chr,annot_selec,style,top=tops[min(element,length(tops))],bottom=bottoms[min(element,length(bottoms))],y=label_scal,titre=titres[min(i_data,length(titres))],name_flags=name_flags,repeated=repeated,decal=decal,ataxises=ataxises,classic_plus_color=classic_plus_color,classic_minus_color=classic_minus_color,stranded=stranded)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
849 if(!is.null(marks)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
850 if(is.null(tops)) {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
851 top=max(listForward[[i_data]])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
852 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
853 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
854 top=tops[min(element,length(tops))]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
855 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
856 if(is.null(bottoms)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
857 bottom=max(listReverse[[i_data]])
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
858 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
859 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
860 bottom=bottoms[min(element,length(bottoms))]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
861 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
862 if(is.null(strandMarks)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
863 segments(marks,top,y1=-bottom,col=2)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
864 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
865 else {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
866 if(strandMarks==0|!stranded) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
867 segments(marks,0,y1=top,col=2)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
868 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
869 else {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
870 if(strandMarks==1) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
871 segments(marks,0,y1=-bottom,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
872 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
873 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
874 segments(marks,top,y1=-bottom,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
875 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
876 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
877 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
878 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
879 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
880 if(!is.null(annot_selec)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
881 par(mar=c(0,5,1,4)+0.1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
882 plot_annotation(annot_selec,chr,debut=debut_vue,fin=fin_vue,style=style,textSize=1.5,annotation_color_by_strand=annotation_color_by_strand,annotation_placed_by_strand=annotation_placed_by_strand,display_name=display_name,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
883 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
884 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
885 else {## Heatmap visualisation
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
886 if(typeVisu=="heatmap") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
887 if(stranded) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
888 height_panels=c(40,heatmap_lane_height*n_element_vue+28,heights_ann,heatmap_lane_height*n_element_vue+10,100)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
889 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
890 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
891 height_panels=c(40,heatmap_lane_height*n_element_vue+28,heights_ann,100)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
892 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
893 openGraphicalDevice(file,1200,sum(height_panels),fileType=fileType,resolutionDPI=resolutionDPI)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
894 prev=par(no.readonly=TRUE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
895 n_panels=length(height_panels)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
896 layout(matrix(1:n_panels,n_panels,1),heights=height_panels)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
897 par(mar=c(0, 8, 0, 2)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
898 plotTitle(debut_vue=debut_vue,fin_vue=fin_vue,chr=chr)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
899 limIntensity=c(0,max(forward_matrice,reverse_matrice,na.rm=TRUE))
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
900 if(limIntensity[2]==0) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
901 limIntensity[2]=0.01
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
902 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
903 ataxisesLabels=as.character(ataxises)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
904 ataxisesLabels[((1:length(ataxises))%%2)==0]=""
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
905 rownames(forward_matrice)=titres[which]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
906 rownames(reverse_matrice)=titres[which]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
907 par(mar=c(1, 8, 1.8, 2)+0.1,cex=1.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
908 if(stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
909 tmp="Plus strand"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
910 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
911 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
912 tmp="Both strands"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
913 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
914 myHeatMap(forward_matrice[(dim(forward_matrice)[1]):1,],debut_vue+decal,fin_vue+decal,ataxises,lim=limIntensity,heatmap_max_color=heatmap_max_color,heatmap_min_color=heatmap_min_color,heatmap_palette_method=heatmap_palette_method,textOnLeftSide=tmp)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
915 axis(3,at=ataxises,labels=FALSE,cex.axis=1.2)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
916 axis(3,at=ataxises,labels=ataxisesLabels,cex.axis=1.2,line=-0.4,lwd=0)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
917 if(!is.null(marks)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
918 if(is.null(strandMarks)|!all_stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
919 segments(marks,-2,y1=dim(forward_matrice)[1]+2,col=2,lwd=2,xpd=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
920 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
921 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
922 if(strandMarks!=1) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
923 segments(marks,-2,y1=dim(forward_matrice)[1]+2,col=2,lwd=2,xpd=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
924 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
925 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
926 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
927 if(name_flags!="") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
928 flags=try(get(name_flags),TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
929 if(class(flags)!="try-error") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
930 f_=flags[(flags$Chr==chr)&(flags$Stop>=debut_vue)&(flags$Start<=fin_vue),]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
931 N=dim(f_)[1]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
932 points(f_$Start,rep(0,N),col=2,pch=19,cex=2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
933 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
934 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
935 if(!is.null(annot_selec)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
936 par(mar=c(0,8,0,2)+0.1)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
937 plot_annotation(annot_selec,chr,debut=debut_vue,fin=fin_vue,style=style,textSize=0.9,annotation_color_by_strand=annotation_color_by_strand,annotation_placed_by_strand=annotation_placed_by_strand,display_name=display_name,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
938 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
939 if(stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
940 par(mar=c(1, 8, 0, 2)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
941 myHeatMap(reverse_matrice[(dim(reverse_matrice)[1]):1,],debut_vue+decal,fin_vue+decal,ataxises,lim=limIntensity,heatmap_max_color=heatmap_max_color,heatmap_min_color=heatmap_min_color,heatmap_palette_method=heatmap_palette_method,textOnLeftSide="Minus strand")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
942 if(!is.null(marks)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
943 if(is.null(strandMarks)|!all_stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
944 segments(marks,-1,y1=dim(forward_matrice)[1]+1,col=2,lwd=2,xpd=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
945 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
946 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
947 if(strandMarks!=0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
948 segments(marks,-1,y1=dim(forward_matrice)[1]+1,col=2,lwd=2,xpd=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
949 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
950 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
951 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
952 axis(1,at=ataxises,labels=ataxisesLabels,cex.axis=1.2)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
953 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
954 palette=matrix(seq(limIntensity[1],limIntensity[2],length.out=2000),1,2000)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
955 rownames(palette)="0"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
956 par(mar=c(2,18,3, 12)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
957 myHeatMap(palette,1,2000,ataxises=NA,heatmap_max_color=heatmap_max_color,heatmap_min_color=heatmap_min_color,heatmap_palette_method=heatmap_palette_method)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
958 labelAxisHeatmapLegend=pretty(c(limIntensity[1],limIntensity[2]),n=7)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
959 atAxisHeatmapLegend=1+((labelAxisHeatmapLegend-limIntensity[1])/(limIntensity[2]-limIntensity[1]))*1999
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
960 axis(1,at=atAxisHeatmapLegend,labels=FALSE,cex.axis=1.2)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
961 axis(1,at=atAxisHeatmapLegend,labels=labelAxisHeatmapLegend,cex.axis=1.2,line=-0.4,lwd=0)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
962 text(1000,2,label_scal,xpd=NA,font=2,cex=1.4)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
963 }## Lines visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
964 else if(typeVisu=="lines") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
965 legendSize=(floor(n_element_vue/2)+n_element_vue%%2)*40
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
966 height_panels=c(40,legendSize,400,heights_ann)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
967 n_panels=length(height_panels)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
968 openGraphicalDevice(file,1200,sum(height_panels),fileType=fileType,resolutionDPI=resolutionDPI)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
969 prev=par(no.readonly=TRUE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
970 par(mar=c(0, 5, 0,4)+0.1,cex=1.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
971 layout(matrix(c(1:n_panels),n_panels,4),heights=height_panels)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
972 par(mar=c(0, 5, 0,4)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
973 plotTitle(debut_vue=debut_vue,fin_vue=fin_vue,chr=chr)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
974 lines_legend(n_element_vue=n_element_vue,which,titres,lines_samples_colors=lines_samples_colors,lines_samples_type_line=lines_samples_type_line)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
975 par(mar=c(3, 5, 0,4)+0.1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
976 plotlines(forward_matrice,reverse_matrice,which=which,debut_vue, fin_vue , chr, annot, style, tops, bottoms,marks,strandMarks,titres, repeated,name_flags,decal,ataxises=ataxises,n_element_vue=n_element_vue,y=label_scal,lines_samples_colors=lines_samples_colors,lines_samples_type_line=lines_samples_type_line,stranded=stranded)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
977 if(!is.null(annot_selec)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
978 par(mar=c(0,5,0,4)+0.1)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
979 plot_annotation(annot_selec,chr,debut=debut_vue,fin=fin_vue,style=style,textSize=1.5,annotation_color_by_strand=annotation_color_by_strand,annotation_placed_by_strand=annotation_placed_by_strand,display_name=display_name,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
980 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
981
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
982 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
983 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
984 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
985 invisible(dev.off())
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
986 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
987
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
988 ##
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
989 smooth=function(X,L=10) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
990 x_smooth=filter(X,rep(1,L)/L)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
991 x_smooth[is.na(x_smooth)]=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
992 return(x_smooth)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
993 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
994
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
995 ## Returns lines visualisation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
996 plotlines=function(forward_matrice,reverse_matrice,which=1:length(forward), debut_vue=1,fin_vue=length(forward), chr=NULL, annot=NULL, style=NULL, tops=NULL,bottoms=NULL,marks=NULL,strandMarks=NULL, titres="", repeated=FALSE,name_flags="",decal=0,ataxises=NULL,n_element_vue=length(which),y="",lines_samples_colors=c(1,3,4,2)[((0:length(forward))%%4)+1],lines_samples_type_line=((0:length(forward))%%4)+1,stranded=TRUE) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
997 limIntensity=c(-max(bottoms),max(tops))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
998 plot(c(debut_vue,fin_vue)+decal,limIntensity,col="white",ylab=y,main="",xaxs="i",xaxt="n",yaxt="n",cex.lab=1.2,xlab="",cex.lab=1.8)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
999 lty=lines_samples_type_line
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1000 col=lines_samples_colors
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1001 ataxises_y=pretty(limIntensity,n=8)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1002 for(i in ataxises) abline(v=i,lty=2,col="#808080")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1003 for(i in ataxises_y) abline(h=i,lty=2,col="#808080")
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1004 for( i in 1:n_element_vue) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1005 lo=forward_matrice[i,]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1006 lines((debut_vue:fin_vue)+decal,lo,type="l",lty=lty[i],col=col[i],lwd=2,xaxt="n")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1007 if(stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1008 los=-reverse_matrice[i,]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1009 lines((debut_vue:fin_vue)+decal,los,type="l",lty=lty[i],col=col[i],lwd=2,xaxt="n")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1010 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1011 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1012 ataxisesLabels=as.character(ataxises)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1013 ataxisesLabels[((1:length(ataxises))%%2)==0]=""
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1014 ataxisesLabels_y=as.character(abs(ataxises_y))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1015 ataxisesLabels_y[((1:length(ataxises_y))%%2)==0]=""
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1016 axis(1,at=ataxises,labels=FALSE,cex.axis=2)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1017 axis(1,at=ataxises,labels=ataxisesLabels,cex.axis=2,line=0.6,lwd=0)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1018 axis(2, at=ataxises_y,labels=FALSE,cex.axis=2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1019 axis(2, at=ataxises_y,labels=ataxisesLabels_y,cex.axis=2,line=-0.4,lwd=0)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1020 if(stranded) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1021 abline(h=0,lwd=6)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1022 abline(h=0,col="white",lwd=4)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1023 text(fin_vue+(fin_vue-debut_vue)*0.01,tops/2,"+",xpd=NA,cex=3)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1024 text(fin_vue+(fin_vue-debut_vue)*0.01,-bottoms/2,"-",xpd=NA,cex=3)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1025 text(fin_vue+(fin_vue-debut_vue)*0.025,(tops-bottoms)/2,"Strand",xpd=NA,cex=2,srt=-90)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1026 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1027 if(!is.null(marks)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1028 if(is.null(tops)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1029 top=max(listForward[[i_data]])
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1030 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1031 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1032 top=max(tops)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1033 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1034 if(is.null(bottoms)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1035 bottom=max(listReverse[[i_data]])
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1036 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1037 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1038 bottom=max(bottoms)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1039 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1040 if(is.null(strandMarks)) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1041 segments(marks,top,y1=-bottom,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1042 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1043 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1044 if(strandMarks==0|!stranded) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1045 segments(marks,0,y1=top,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1046 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1047 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1048 if(strandMarks==1) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1049 segments(marks,0,y1=-bottom,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1050 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1051 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1052 segments(marks,top,y1=-bottom,col=2)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1053 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1054 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1055 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1056 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1057 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1058
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1059 ## Returns lines legend
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1060 lines_legend=function(n_element_vue,which,titres,lines_samples_colors=c(1,3,4,2)[((0:n_element_vue)%%4)+1],lines_samples_type_line=((0:n_element_vue)%%4)+1) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1061 lty=lines_samples_type_line
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1062 col=lines_samples_colors
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1063 n_y=floor(n_element_vue/2)+n_element_vue%%2
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1064 plot(c(0,4),c(0,-(n_y+1)),col="white", ylab="",xlab="",main="",fg="white",col.axis="white",yaxs="i")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1065 i_style=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1066 for(i in 1:n_y) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1067 i_style=i_style+1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1068 lines(c(1.5,2),-c(i,i),col=col[i_style],lty=lty[i_style],lwd=4)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1069 text(1.48,-i,titres[which[i_style]],cex=2.6,adj=1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1070 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1071 if(n_element_vue>1) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1072 for(i in (n_y+1):n_element_vue) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1073 i_style=i_style+1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1074 lines(c(3.5,4),-c(i,i)+n_y,col=col[i_style],lty=lty[i_style],lwd=4)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1075 text(3.48,-i+n_y,titres[which[i_style]],cex=2.6,adj=1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1076 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1077 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1078 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1079
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1080 ## Returns the shape of plain arrow for the annotation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1081 plain_arrow=function(left,right,y,thickness=1,pickSize=(right-left)*0.1,pickSide=c("right","left","both","none"),col="blue") {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1082 middle=(left+right)/2
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1083 if(pickSide[1]=="right") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1084 pick_point=max(right - pickSize,middle)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1085 polygon(c(left,pick_point,right,pick_point,left),c(y-thickness/2,y-thickness/2,y,y+thickness/2,y+thickness/2),col=col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1086 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1087 if(pickSide[1]=="left") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1088 pick_point=min(left + pickSize,middle)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1089 polygon(c(right,pick_point,left,pick_point,right),c(y-thickness/2,y-thickness/2,y,y+thickness/2,y+thickness/2),col=col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1090 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1091 if(pickSide[1]=="none") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1092 polygon(c(right,left,left,right),c(y-thickness/2,y-thickness/2,y+thickness/2,y+thickness/2),col=col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1093 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1094 if(pickSide[1]=="both") {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1095 pick_point_1=min(left + pickSize,middle)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1096 pick_point_2=max(right - pickSize,middle)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1097 polygon(c(left,pick_point_1,pick_point_2,right,pick_point_2,pick_point_1),c(y,y-thickness/2,y-thickness/2,y,y+thickness/2,y+thickness/2),col=col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1098 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1099 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1100
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1101 ## Returns the size of the panel of the annotation
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1102 sizePlotAnnotation=function(annot,chr,debut,fin,annotation_placed_by_strand=FALSE,display_name=NULL,typeVisu="classic",initialize_label_sizes=NULL) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1103 left=c()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1104 right=c()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1105 labels=c()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1106 annot_chr=annot[annot$Chr==chr,]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1107 N=dim(annot_chr)[1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1108 all_names=annot_chr[,c(display_name,"ID")]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1109 unique_ID=unique(annot_chr$ID)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1110 for(j in 1:length(unique_ID)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1111 left[j]=min(annot_chr$Start[annot_chr$ID==unique_ID[j]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1112 right[j]=max(annot_chr$Stop[annot_chr$ID==unique_ID[j]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1113 all_names=unlist(annot_chr[annot_chr$ID==unique_ID[j],c(display_name,"ID")])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1114 all_names=all_names[all_names!="."]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1115 labels[j]=all_names[1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1116 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1117 if(annotation_placed_by_strand) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1118 y_plot=parking(left,right,debut,fin,annot_chr$Strand=="+",FALSE,labels=labels,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1119 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1120 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1121 y_plot=parking(left,right,debut,fin,biggestOnesInside=FALSE,labels=labels,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1122 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1123 return(max(y_plot)-min(y_plot)+1)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1124 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1125
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1126 ## Function to organise the annotation shapes to display
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1127 parking=function(left,right,debut,fin,plus=rep(TRUE,length(left)),labels=c(),biggestOnesInside=TRUE,typeVisu="classic",initialize_label_sizes=NULL) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1128 if(length(labels)!=0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1129 if(!is.null(initialize_label_sizes)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1130 initialize_=initialize_label_sizes[[typeVisu]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1131 for(i in 1:length(left)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1132 right[i]=max(right[i],left[i]+initialize_$size[initialize_$labels==labels[i]])+(fin-debut)/100
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1133 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1134 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1135 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1136 y=rep(0,length(left))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1137 if(sum(plus)>0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1138 left_plus=left[plus]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1139 right_plus=right[plus]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1140 y_plus=rep(0,sum(plus))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1141 lengths_plus=right_plus-left_plus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1142 for(i in order(lengths_plus,decreasing=TRUE)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1143 otherleft_plus=left_plus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1144 otherleft_plus[i]=NA
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1145 otherright_plus=right_plus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1146 otherright_plus[i]=NA
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1147 placed=FALSE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1148 y_plus[i]=0.5
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1149 while(placed==FALSE) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1150 placed=sum((right_plus[i]>otherleft_plus[y_plus==y_plus[i]])&(left_plus[i]<otherright_plus[y_plus==y_plus[i]]),na.rm=TRUE)==0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1151 if(placed==FALSE) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1152 y_plus[i]=y_plus[i]+1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1153 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1154 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1155 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1156 if(biggestOnesInside) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1157 y[plus]=y_plus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1158 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1159 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1160 y[plus]=sapply(y_plus,function(i) sort(unique(y_plus))[i==sort(unique(y_plus),decreasing=TRUE)])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1161 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1162 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1163 if(sum(!plus)>0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1164 left_minus=left[!plus]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1165 right_minus=right[!plus]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1166 y_minus=rep(0,sum(!plus))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1167 lengths_minus=right_minus-left_minus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1168 for(i in order(lengths_minus,decreasing=TRUE)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1169 otherleft_minus=left_minus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1170 otherleft_minus[i]=NA
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1171 otherright_minus=right_minus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1172 otherright_minus[i]=NA
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1173 placed=FALSE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1174 y_minus[i]=-0.5
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1175 while(placed==FALSE) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1176 placed=sum((right_minus[i]>otherleft_minus[y_minus==y_minus[i]])&(left_minus[i]<otherright_minus[y_minus==y_minus[i]]),na.rm=TRUE)==0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1177 if(placed==FALSE) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1178 y_minus[i]=y_minus[i]-1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1179 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1180 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1181 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1182 if(biggestOnesInside) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1183 y[!plus]=y_minus
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1184 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1185 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1186 y[!plus]=sapply(y_minus,function(i) sort(unique(y_minus))[i==sort(unique(y_minus),decreasing=TRUE)])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1187 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1188 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1189 return(y)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1190 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1191
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1192 ## Function to
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1193 plot_annotation=function(annot,chr,debut,fin,style=NULL,textSize=par("cex"),annotation_color_by_strand=FALSE,annotation_placed_by_strand=FALSE,display_name=NULL,typeVisu="classic",initialize_label_sizes=NULL) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1194 left=c()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1195 right=c()
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1196 labels=c()
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1197 annot_chr=annot[annot$Chr==chr,]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1198 N=dim(annot_chr)[1]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1199 if(N>0) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1200 all_names=annot_chr[,c(display_name,"ID")]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1201 unique_ID=unique(annot_chr$ID)
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1202 for(j in 1:length(unique_ID)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1203 left[j]=min(annot_chr$Start[annot_chr$ID==unique_ID[j]])
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1204 right[j]=max(annot_chr$Stop[annot_chr$ID==unique_ID[j]])
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1205 all_names=unlist(annot_chr[annot_chr$ID==unique_ID[j],c(display_name,"ID")])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1206 all_names=all_names[all_names!="."]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1207 labels[j]=all_names[1]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1208 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1209 if(annotation_placed_by_strand) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1210 y_plot=parking(left,right,debut,fin,annot_chr$Strand=="+",FALSE,labels=labels,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1211 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1212 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1213 y_plot=parking(left,right,debut,fin,biggestOnesInside=FALSE,labels=labels,typeVisu=typeVisu,initialize_label_sizes=initialize_label_sizes)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1214 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1215 plot(c(debut,fin),c(min(y_plot)-0.5,max(y_plot)+0.5),col="white",ylab="",xlab="",fg="white",col.axis="white",xaxs="i",yaxs="i")
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1216 for(j in 1:length(unique_ID)) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1217 annot_ID=annot_chr[annot_chr$ID==unique_ID[j],]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1218 x_text=Inf
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1219 for(i_annot_ID in 1:dim(annot_ID)[1]) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1220 if(annot_ID$Strand[i_annot_ID]=="-") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1221 orientation="left"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1222 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1223 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1224 orientation="right"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1225 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1226 iDraw=FALSE
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1227 if(annot_ID$Strand[i_annot_ID]==".") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1228 tmp="+"
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1229 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1230 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1231 tmp=annot_ID$Strand[i_annot_ID]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1232 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1233 style_demande=style[style$Type==annot_ID$Type[i_annot_ID]&style$Strand==tmp,]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1234 x_text=min(x_text,annot_ID$Start[i_annot_ID])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1235 if(style_demande$shape=="box") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1236 plain_arrow(annot_ID$Start[i_annot_ID],annot_ID$Stop[i_annot_ID],y_plot[j],thickness=0.5, pickSide=orientation,col=style_demande$col,pickSize=(fin-debut)*0.02)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1237 iDraw=TRUE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1238 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1239 if(style_demande$shape=="line") {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1240 segments(annot_ID$Start[i_annot_ID],y_plot[j],annot_ID$Stop[i_annot_ID],y_plot[j],col=style_demande$col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1241 iDraw=TRUE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1242 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1243 if(style_demande$shape=="rectangle") {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1244 plain_arrow(annot_ID$Start[i_annot_ID],annot_ID$Stop[i_annot_ID],y_plot[j],thickness=0.5, pickSide="none",col=style_demande$col)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1245 iDraw=TRUE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1246 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1247 if(style_demande$shape=="arrow") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1248 arrowHeads=pretty(debut:fin,n=50)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1249 x=c(annot_ID$Start[i_annot_ID],arrowHeads[arrowHeads>annot_ID$Start[i_annot_ID]&arrowHeads<annot_ID$Stop[i_annot_ID]],annot_ID$Stop[i_annot_ID])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1250 if(annot_ID$Strand[i_annot_ID]=="-") {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1251 arrows(x[2:length(x)],y_plot[j],x[1:length(x)-1],col=style_demande$col,length=0.08)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1252 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1253 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1254 arrows(x[1:length(x)-1],y_plot[j],x[2:length(x)],col=style_demande$col,length=0.08)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1255 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1256 iDraw=TRUE
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1257 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1258 if(iDraw==FALSE) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1259 segments(annot_ID$Start[i_annot_ID],y_plot[j],annot_ID$Stop[i_annot_ID],y_plot[j],col="black")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1260 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1261 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1262 text(max(x_text,debut),y_plot[j]+0.4,adj=0,labels=labels[j],cex=textSize)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1263 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1264 if(annotation_placed_by_strand) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1265 abline(h=0.125,lty=2,col="black")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1266 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1267 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1268 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1269
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1270 html2rgb=function(codeHTML) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1271 chiffres=c(0:9,"A","B","C","D","E","F")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1272 codeHTMLsplit=unlist(strsplit(codeHTML,split=""))
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1273 red=(((which(chiffres==codeHTMLsplit[2])-1)*16)+(which(chiffres==codeHTMLsplit[3])-1))/255
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1274 green=(((which(chiffres==codeHTMLsplit[4])-1)*16)+(which(chiffres==codeHTMLsplit[5])-1))/255
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1275 blue=(((which(chiffres==codeHTMLsplit[6])-1)*16)+(which(chiffres==codeHTMLsplit[7])-1))/255
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1276 return(c(red,green,blue))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1277 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1278
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1279 rgb2hsv=function(vectRGB) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1280 Cmax=max(vectRGB)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1281 Cmin=min(vectRGB)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1282 delta=Cmax-Cmin
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1283 if(delta==0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1284 H=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1285 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1286 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1287 if(Cmax==vectRGB[1]) H=(1/6)*(((vectRGB[2]-vectRGB[3])/delta)%%6)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1288 if(Cmax==vectRGB[2]) H=(1/6)*(((vectRGB[3]-vectRGB[1])/delta)+2)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1289 if(Cmax==vectRGB[3]) H=(1/6)*(((vectRGB[1]-vectRGB[2])/delta)+4)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1290 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1291 if(delta==0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1292 S=0
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1293 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1294 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1295 S=delta/Cmax
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1296 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1297 V=Cmax
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1298
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1299 return(c(H,S,V))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1300 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1301
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1302 ### =========================================================================
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1303 ### Ving's Main version beta 1.1
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1304 ### -------------------------------------------------------------------------
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1305 ###
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1306 {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1307 if(version$major !="3" & version$minor !="0.2") {
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1308 write("Ving has been developped on R 3.0.2,
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1309 therefore it might misbehave here.",stderr())
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1310 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1311 arg=commandArgs(TRUE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1312 if(length(arg)==0) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1313 write("Ving for visualisation of RNA seq data:
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1314 Usage:
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1315 ./ving.R [options] <input> [<input2> <input3> ...]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1316 Options:
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1317 -o/--output <string> [default:./ouput.png]
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1318 -F/--fileType <integer> [default: same as -o] (png,jpeg,bmp,tiff,pdf)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1319 -R/--resolution <integer> [default: 72 ]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1320 -v/--typeVisu <string> [default: classic ] (classic,lines,heatmap)
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1321 -t/--description-data <string> [default: <filename>]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1322 -n/--normalization-coefficient <string> [default: none ]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1323 -i/--inverseStrand
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1324 -u/--unstranded
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1325 -c/--chromosome-name <string> [default: first one ]
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1326 -S/--start <integer> [default: 1 ]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1327 -E/--end <integer> [default: chr length]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1328 -a/--annotation <filename>
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1329 -r/--typeTranscript <string> [default: <all> ]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1330 -C/--annotation-colors <string> [default: fabulous ]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1331 -s/--annotation-shapes <string> [default: box ] (box,line,rectangle,arrow)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1332 -l/--scale-log
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1333 -y/--symetric-scale
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1334 --classic-plus-color <string> [default: navyblue ]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1335 --classic-minus-color <string> [default: deeppink3 ]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1336 --heatmap-max-color <string> [default: 000055 ]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1337 --heatmap-min-color <string> [default: FFFFAA ]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1338 --heatmap-palette-method <string> [default: hsv ] (hsv,rgb)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1339 --lines-samples-colors <string> [default: black ]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1340 --lines-samples-type-line <string> [default: plain ]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1341 --annotation-color-by-strand <logical> [default: FALSE ]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1342 --annotation-placed-by-strand <logical> [default: FALSE ]
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1343 -L/--smoothLength <integer> [default: NA ]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1344 ",stdout())
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1345 q("no")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1346 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1347 else {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1348 tmp=suppressPackageStartupMessages(require("Rsamtools"))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1349 if(!tmp) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1350 stop("Package Rsamtools required !!")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1351 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1352 tmp=suppressPackageStartupMessages(require("GenomicRanges"))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1353 if(!tmp) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1354 stop("Package GenomicRanges required !!")
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1355 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1356 optArgs=getopt(rbind(
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1357 c('output','o', 1, 'character',"output.png"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1358 c('fileType','F',1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1359 c('resolution','R',1,'numeric',72),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1360 c('typeVisu', 'v', 1, 'character', "classic"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1361 c('description-data','t',1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1362 c('chromosome-name', 'c', 1, 'character', NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1363 c('start', 'S', 1, 'numeric',1),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1364 c('end', 'E', 1, 'numeric',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1365 c('annotation','a',1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1366 c('typeTranscript','r',1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1367 c('annotation-colors','C',1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1368 c('annotation-shapes','s','1','character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1369 c('normalization-coefficient','n','1','character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1370 c('classic-plus-color',1,1,'character',"navyblue"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1371 c('classic-minus-color',2,1,'character',"deeppink3"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1372 c('heatmap-max-color',3,1,'character',"#000055"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1373 c('heatmap-min-color',4,1,'character',"#FFFFAA"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1374 c('heatmap-palette-method',7,1,'character',"hsv"),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1375 c('lines-samples-colors',5,1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1376 c('lines-samples-type-line',6,1,'character',NA),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1377 c('scale-log', 'l',0,'logical',FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1378 c('inverseStrand','i',0,'logical', FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1379 c('unstranded','u',0,'logical', FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1380 c('symetric-scale','y',0,'logical', FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1381 c('annotation-color-by-strand',8,0,'logical',FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1382 c('annotation-placed-by-strand',9,0,'logical',FALSE),
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1383 c('smoothLength','L',1,'numeric',NA)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1384 ))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1385 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1386
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1387 ###################
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1388 ## ARGUMENTS
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1389 #################################################################################
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1390 files=optArgs$ARGUMENT
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1391 ## Case file doesn't exist
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1392 for( i in 1:length(files)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1393 if(!file.exists(files[i])) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1394 stop(paste(files[i],"do not exist!","\n"))
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1395 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1396 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1397 imagefile=optArgs$output
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1398 typeVisu=optArgs$typeVisu
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1399 description_data=optArgs$`description-data`
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1400 chrName=optArgs$`chromosome-name`[1]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1401 start=optArgs$start[1]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1402 end=optArgs$end[1]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1403 annotation=optArgs$annotation
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1404 typeTranscript=optArgs$typeTranscript
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1405 colors=optArgs$`annotation-colors`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1406 shape_data=optArgs$`annotation-shapes`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1407 weight=optArgs$`normalization-coefficient`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1408 classic_plus_color=optArgs$`classic-plus-color`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1409 classic_minus_color=optArgs$`classic-minus-color`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1410 heatmap_max_color=optArgs$`heatmap-max-color`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1411 heatmap_min_color=optArgs$`heatmap-min-color`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1412 heatmap_palette_method=optArgs$`heatmap-palette-method`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1413 lines_samples_colors=optArgs$`lines-samples-colors`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1414 lines_samples_type_line=optArgs$`lines-samples-type-line`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1415 log=optArgs$`scale-log`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1416 inverseStrand=optArgs$inverseStrand
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1417 unstranded=optArgs$unstranded
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1418 symetric=optArgs$`symetric-scale`
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1419 annotation_color_by_strand=optArgs$`annotation-color-by-strand`
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1420 annotation_placed_by_strand=optArgs$`annotation-placed-by-strand`
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1421 smoothLength=optArgs$`smoothLength`
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1422 resolution=optArgs$`resolution`
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1423 fileType=optArgs$`fileType`
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1424
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1425 ###################
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1426 ## MAIN
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1427 ###################################################################################
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1428
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1429 genome_info=scanBamHeader(files[1])[[1]]$targets
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1430 noms_chromosomes=names(genome_info)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1431 longueur_chromosomes=as.integer(genome_info)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1432 nombre_chromosomes=length(noms_chromosomes)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1433
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1434 ## Case no chromosome specified
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1435 if(sum(is.na(chrName))) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1436 chrName=noms_chromosomes[1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1437 write(paste("No chromosome specified, processing chromosome :",chrName,"\n",sep=""),stderr())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1438 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1439
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1440 ## Case false chromosome name
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1441 if(!(chrName %in% noms_chromosomes)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1442 stop(paste("\"",chrName,"\" is not a proper chromosome name"))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1443 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1444
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1445 if(is.na(end)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1446 end=longueur_chromosomes[chrName==noms_chromosomes]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1447 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1448
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1449 if(start > end) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1450 stop("The start is bigger than the end!")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1451 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1452
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1453 ## Case asked coordinates outside the chromosome
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1454 if(start<0|end>longueur_chromosomes[chrName==noms_chromosomes]) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1455 stop("You are outside the chromosome")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1456 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1457
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1458 if(sum(is.na(weight))>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1459 normalized_data=NULL
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1460 isnormalized=FALSE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1461 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1462 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1463 isnormalized=TRUE
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1464 normalized_data=unlist(strsplit(weight,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1465 if(length(files)!=length(normalized_data)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1466 stop("Different number of files and weights ")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1467 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1468 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1469 normalized_data=as.numeric(normalized_data)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1470 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1471 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1472
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1473 if(inverseStrand) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1474 libraryType="inverse"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1475 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1476 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1477 libraryType="standard"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1478 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1479 ## Read the bam file and extract the infos
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1480 doit=function(i,libraryType) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1481 try(readBam_(files[i], libraryType=libraryType, chrName_=chrName, from_=start, to_=end,normalized_=normalized_data[i]))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1482 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1483 data=lapply(1:length(files),doit,libraryType=libraryType)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1484 ctrl=unlist(lapply(data,class))=="try-error"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1485
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1486 if(sum(ctrl)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1487 for(i in which(ctrl)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1488 write(paste("Problem with file :",files[i],"\n",sep=""),stderr())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1489 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1490 stop("At least a file has problem")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1491 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1492
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1493 ## Read the GFF file and extract the infos
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1494 if(sum(is.na(annotation))==0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1495 gff=try(readGff(annotation[1],from=start,to=end,chr=chrName),TRUE)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1496 ctrl=class(gff)=="try-error"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1497 if(sum(ctrl)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1498 stop(paste("Problem with Gff file :",annotation,"\n"))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1499 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1500 if(length(annotation)>1) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1501 for(i in 2:length(annotation)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1502 gff1=try(readGff(annotation[i],from=start,to=end,chr=chrName),TRUE)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1503 ctrl=class(gff1)=="try-error"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1504 if(sum(ctrl)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1505 stop(paste("Problem with Gff file :",gff1,"\n"))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1506 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1507 if(sum(is.na(gff1))==0) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1508 gff=rbind(gff,gff1)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1509 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1510 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1511 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1512 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1513 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1514 gff=NA
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1515 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1516
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1517 if(sum(is.na(description_data))>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1518 description_data=files
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1519 }
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1520
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1521 ## Case of different number of files and description
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1522 if(length(description_data)!=length(files)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1523 stop("Different number of files and description")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1524 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1525
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1526 ## Pooling bam files (if necessary)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1527 description_data_unique=unique(description_data)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1528 data_pooled=list()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1529 for(i_descri in description_data_unique) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1530 i_data_voulu=which(description_data==i_descri)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1531 data_pooled_=data[[i_data_voulu[1]]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1532 if(length(i_data_voulu)>1) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1533 for(i_i_data_voulu in 2:length(i_data_voulu)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1534 data_pooled_=addBam(data_pooled_,data[[i_data_voulu[i_i_data_voulu]]])
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1535 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1536 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1537 data_pooled[[i_descri]]=data_pooled_
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1538 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1539
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1540 if(sum(is.na(typeTranscript)>0)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1541 if(sum(is.na(annotation))==0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1542 typeTranscritSplit=unique(gff$Type)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1543 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1544 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1545 typeTranscritSplit=NA
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1546 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1547 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1548 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1549 typeTranscritSplit=unlist(strsplit(typeTranscript,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1550 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1551
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1552 if((sum(is.na(gff))>0)|(sum(is.na(typeTranscritSplit))>0)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1553 annot=NULL
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1554 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1555 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1556 annot=gff[gff$Type %in% typeTranscritSplit,]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1557 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1558
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1559 ## Check the colors
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1560 if(sum(is.na(colors)>0)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1561 nTypeTranscrit=length(typeTranscritSplit)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1562 if(annotation_color_by_strand) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1563 colorsSplit=c(classic_plus_color,classic_minus_color)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1564 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1565 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1566 colorsSplit=rainbow(nTypeTranscrit+1)[1:nTypeTranscrit]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1567 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1568 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1569 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1570 colorsSplit=unlist(strsplit(colors,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1571 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1572 for(i in 1:length(colorsSplit)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1573 tmp=unlist(strsplit(colorsSplit[i],split=""))
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1574 if(length(tmp)==6|length(tmp)==8) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1575 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1576 colorsSplit[i]=paste("#",colorsSplit[i],sep="")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1577 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1578 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1579 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1580
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1581 tmp=unlist(strsplit(classic_plus_color,split=""))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1582 if(length(tmp)==6|length(tmp)==8) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1583 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1584 classic_plus_color=paste("#",classic_plus_color,sep="")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1585 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1586 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1587 tmp=unlist(strsplit(classic_minus_color,split=""))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1588 if(length(tmp)==6|length(tmp)==8) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1589 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1590 classic_minus_color=paste("#",classic_minus_color,sep="")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1591 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1592 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1593 tmp=unlist(strsplit(heatmap_max_color,split=""))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1594 if(length(tmp)==6|length(tmp)==8) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1595 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1596 heatmap_max_color=paste("#",heatmap_max_color,sep="")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1597 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1598 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1599 tmp=unlist(strsplit(heatmap_min_color,split=""))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1600 if(length(tmp)==6|length(tmp)==8) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1601 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1602 heatmap_min_color=paste("#",heatmap_min_color,sep="")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1603 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1604 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1605 if(sum(is.na(lines_samples_colors))>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1606 lines_samples_colors_split=c(1,3,4,2)[((0:(length(files)-1))%%4)+1]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1607 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1608 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1609 lines_samples_colors_split=unlist(strsplit(lines_samples_colors,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1610 for(i in 1:length(lines_samples_colors_split)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1611 tmp=unlist(strsplit(lines_samples_colors_split[i],split=""))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1612 if(length(tmp)==6|length(tmp)==8) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1613 if(sum(tmp %in% c(0:9,"A","B","C","D","E","F"))==length(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1614 lines_samples_colors_split[i]=paste("#",lines_samples_colors_split[i],sep="")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1615 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1616 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1617 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1618 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1619 colorToCheck=c(colorsSplit,classic_plus_color,classic_minus_color,heatmap_max_color,heatmap_min_color,lines_samples_colors_split)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1620 ctrl=sapply(colorToCheck,is.acceptable.color)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1621 if(sum(!ctrl)>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1622 for(i in which(!ctrl)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1623 write(paste("\"",colorToCheck[i],"\" is not a proper color name.\n",sep=""),stderr())
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1624 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1625 stop("At least one color has a problem")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1626 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1627 if(annotation_color_by_strand) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1628 if(length(colorsSplit)>2) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1629 stop("You have to specify two and only two colors!")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1630 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1631 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1632 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1633 if(length(typeTranscritSplit)!=length(colorsSplit)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1634 stop("Please specify the same number of transcript types and colors")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1635 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1636 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1637 ## Check the line types
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1638 if(sum(is.na(lines_samples_type_line))>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1639 lines_samples_type_line_split=((0:(length(files)-1))%/%4)+1
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1640 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1641 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1642 lines_samples_type_line_split=unlist(strsplit(lines_samples_type_line,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1643 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1644 if(typeVisu=="lines") {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1645 ctrl=sapply(lines_samples_type_line_split,function(x) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1646 tmp=suppressWarnings(as.numeric(x))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1647 if(!is.na(tmp)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1648 return((tmp==floor(tmp))&tmp>=1&tmp<=5)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1649 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1650 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1651 return(FALSE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1652 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1653 })
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1654 if(sum(!ctrl)>0) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1655 for(i in which(!ctrl)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1656 write(paste("\"",lines_samples_type_line_split[i],"\" is not a proper line style.\n",sep=""),stderr())
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1657 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1658 stop("At least one line style has problem")
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1659 }
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1660 lines_samples_type_line_split=as.integer(lines_samples_type_line_split)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1661 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1662 ## Check the shapes
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1663 type_shape=rep(1,length(typeTranscritSplit))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1664
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1665 if(sum(is.na(shape_data)>0)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1666 for( i in 1:length(typeTranscritSplit)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1667 type_shape[i]="box"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1668 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1669 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1670 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1671 shape=unlist(strsplit(shape_data,split=","))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1672 shape=as.array(shape)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1673 if(length(typeTranscritSplit)!=length(shape)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1674 stop("Please specify the same number of transcript types and shapes")
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1675 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1676 else {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1677 for( i in 1:length(typeTranscritSplit)) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1678 type_shape[i]=shape[[i]]
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1679 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1680 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1681 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1682
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1683 ## Style for the annotation
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1684 label=rep(1,length(typeTranscritSplit))
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1685 style=data.frame(Type=c(typeTranscritSplit,typeTranscritSplit),Strand=c(rep("+",length(typeTranscritSplit)),rep("-",length(typeTranscritSplit))),col=NA,shape=NA,label,stringsAsFactors=FALSE)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1686 for(i in 1:length(typeTranscritSplit)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1687 style$shape[style$Type==typeTranscritSplit[i]]=type_shape[i]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1688 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1689 if(annotation_color_by_strand) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1690 style$col[style$Strand=="+"]=colorsSplit[1]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1691 style$col[style$Strand=="-"]=colorsSplit[2]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1692 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1693 else {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1694 for(i in 1:length(typeTranscritSplit)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1695 style$col[style$Type==typeTranscritSplit[i]]=colorsSplit[i]
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1696 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1697 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1698
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1699 ## Main for visualisation
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1700 databychr=extractSignal(data_pooled,chrName,from=start,to=end,normalized_=isnormalized)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1701
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1702 {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1703 reverse=list()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1704 forward=list()
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1705 if(log) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1706 for(i in 1:length(databychr$F)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1707 forward_=numeric()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1708 tmp=log2(1+databychr$F[[i]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1709 forward_[1:length(tmp)]=tmp
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1710 forward[[i]]=forward_
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1711 reverse_=numeric()
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1712 tmp=log2(1+databychr$R[[i]])
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1713 reverse_[1:length(tmp)]=tmp
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1714 reverse[[i]]=reverse_
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1715 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1716 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1717 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1718 forward=databychr$F
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1719 reverse=databychr$R
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1720 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1721 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1722
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1723 if(sum(is.na(smoothLength))>0) {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1724 smoothLength=max(trunc((end-start)/1200),1)
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1725 }
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1726 else {
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1727 smoothLength=smoothLength[1]
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1728 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1729 if(unstranded) {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1730 for(i in 1:length(databychr$F)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1731 if(smoothLength>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1732 lo=smooth(forward[[i]]+reverse[[i]],L=smoothLength)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1733 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1734 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1735 lo=forward[[i]]+reverse[[i]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1736 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1737 forward[[i]]=lo
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1738 los=rep(0,length(lo))
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1739 reverse[[i]]=los
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1740 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1741 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1742 else {
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1743 for(i in 1:length(databychr$F)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1744 if(smoothLength>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1745 lo=smooth(forward[[i]],L=smoothLength)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1746 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1747 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1748 lo=forward[[i]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1749 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1750 forward[[i]]=lo
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1751 if(smoothLength>0) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1752 los=smooth(reverse[[i]],L=smoothLength)
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1753 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1754 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1755 los=reverse[[i]]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1756 }
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1757 reverse[[i]]=los
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1758 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1759 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1760
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1761 group_maximum=rep(1,length(databychr$F))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1762 max_forward=numeric(length(databychr$F))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1763 max_reverse=numeric(length(databychr$F))
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1764 for(i_data in 1:length(databychr$F)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1765 max_forward[i_data]=max(forward[[i_data]],na.rm=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1766 max_reverse[i_data]=max(reverse[[i_data]],na.rm=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1767 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1768 for(i_max in unique(group_maximum)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1769 max_forward[group_maximum==i_max]=max(max_forward[group_maximum==i_max],na.rm=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1770 max_reverse[group_maximum==i_max]=max(max_reverse[group_maximum==i_max],na.rm=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1771 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1772
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1773 if(symetric) {
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1774 for(i_data in 1:length(databychr$F)) {
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1775 max_forward[i_data]=max(max_forward[i_data],max_reverse[i_data],na.rm=TRUE)
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1776 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1777 max_reverse=max_forward
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1778 }
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1779
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1780 if(is.na(fileType)) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1781 imageFileSplit=unlist(strsplit(imagefile,split=".",fixed=TRUE))
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1782 if(length(imageFileSplit)>=2) {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1783 fileType=imageFileSplit[length(imageFileSplit)]
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1784 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1785 else {
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1786 fileType="png"
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1787 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1788 }
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1789
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1790 plotVisu(imagefile,typeVisu=typeVisu,listForward=forward,listReverse=reverse,
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1791 debut_vue=start,fin_vue=end,chr=chrName,annot=annot,repeated=TRUE,
4
5ed41b948030 Uploaded
rlegendre
parents: 1
diff changeset
1792 titres=description_data_unique,name_flags="",style=style,log=log,stranded=!unstranded,
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1793 tops=max_forward,bottoms=max_reverse,
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1794 classic_plus_color=classic_plus_color,classic_minus_color=classic_minus_color,
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1795 heatmap_max_color=heatmap_max_color,heatmap_min_color=heatmap_min_color,heatmap_palette_method=heatmap_palette_method,
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1796 lines_samples_colors=lines_samples_colors_split,lines_samples_type_line=lines_samples_type_line_split,
5
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1797 smoothLength=1,annotation_color_by_strand=annotation_color_by_strand,annotation_placed_by_strand=annotation_placed_by_strand,
0cec66d7f637 Uploaded
rlegendre
parents: 4
diff changeset
1798 fileType=fileType,resolutionDPI=resolution)
1
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1799
5feff08a06ea Uploaded
rlegendre
parents:
diff changeset
1800 }