annotate baseline/Baseline_Main.r @ 93:8fcf31272f6e draft

planemo upload commit a43893724cc769bed8a1f19a5b19ec1ba20cb63c
author rhpvorderman
date Mon, 06 Mar 2023 11:36:32 +0000
parents ba33b94637ca
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
67
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
1 #########################################################################################
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
2 # License Agreement
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
3 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
4 # THIS WORK IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
5 # ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
6 # APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
7 # OR COPYRIGHT LAW IS PROHIBITED.
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
8 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
9 # BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
10 # BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
11 # TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
12 # CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
13 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
14 # BASELIne: Bayesian Estimation of Antigen-Driven Selection in Immunoglobulin Sequences
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
15 # Coded by: Mohamed Uduman & Gur Yaari
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
16 # Copyright 2012 Kleinstein Lab
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
17 # Version: 1.3 (01/23/2014)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
18 #########################################################################################
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
19
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
20 op <- options();
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
21 options(showWarnCalls=FALSE, showErrorCalls=FALSE, warn=-1)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
22 library('seqinr')
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
23 if( F & Sys.info()[1]=="Linux"){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
24 library("multicore")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
25 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
26
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
27 # Load functions and initialize global variables
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
28 source("Baseline_Functions.r")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
29
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
30 # Initialize parameters with user provided arguments
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
31 arg <- commandArgs(TRUE)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
32 #arg = c(2,1,5,5,0,1,"1:26:38:55:65:104:116", "test.fasta","","sample")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
33 #arg = c(1,1,5,5,0,1,"1:38:55:65:104:116:200", "test.fasta","","sample")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
34 #arg = c(1,1,5,5,1,1,"1:26:38:55:65:104:116", "/home/mu37/Wu/Wu_Cloned_gapped_sequences_D-masked.fasta","/home/mu37/Wu/","Wu")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
35 testID <- as.numeric(arg[1]) # 1 = Focused, 2 = Local
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
36 species <- as.numeric(arg[2]) # 1 = Human. 2 = Mouse
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
37 substitutionModel <- as.numeric(arg[3]) # 0 = Uniform substitution, 1 = Smith DS et al. 1996, 5 = FiveS
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
38 mutabilityModel <- as.numeric(arg[4]) # 0 = Uniform mutablity, 1 = Tri-nucleotide (Shapiro GS et al. 2002) , 5 = FiveS
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
39 clonal <- as.numeric(arg[5]) # 0 = Independent sequences, 1 = Clonally related, 2 = Clonally related & only non-terminal mutations
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
40 fixIndels <- as.numeric(arg[6]) # 0 = Do nothing, 1 = Try and fix Indels
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
41 region <- as.numeric(strsplit(arg[7],":")[[1]]) # StartPos:LastNucleotideF1:C1:F2:C2:F3:C3
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
42 inputFilePath <- arg[8] # Full path to input file
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
43 outputPath <- arg[9] # Full path to location of output files
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
44 outputID <- arg[10] # ID for session output
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
45
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
46
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
47 if(testID==5){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
48 traitChangeModel <- 1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
49 if( !is.na(any(arg[11])) ) traitChangeModel <- as.numeric(arg[11]) # 1 <- Chothia 1998
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
50 initializeTraitChange(traitChangeModel)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
51 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
52
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
53 # Initialize other parameters/variables
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
54
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
55 # Initialzie the codon table ( definitions of R/S )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
56 computeCodonTable(testID)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
57
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
58 # Initialize
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
59 # Test Name
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
60 testName<-"Focused"
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
61 if(testID==2) testName<-"Local"
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
62 if(testID==3) testName<-"Imbalanced"
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
63 if(testID==4) testName<-"ImbalancedSilent"
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
64
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
65 # Indel placeholders initialization
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
66 indelPos <- NULL
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
67 delPos <- NULL
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
68 insPos <- NULL
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
69
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
70 # Initialize in Tranistion & Mutability matrixes
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
71 substitution <- initializeSubstitutionMatrix(substitutionModel,species)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
72 mutability <- initializeMutabilityMatrix(mutabilityModel,species)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
73
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
74 # FWR/CDR boundaries
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
75 flagTrim <- F
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
76 if( is.na(region[7])){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
77 flagTrim <- T
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
78 region[7]<-region[6]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
79 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
80 readStart = min(region,na.rm=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
81 readEnd = max(region,na.rm=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
82 if(readStart>1){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
83 region = region - (readStart - 1)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
84 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
85 region_Nuc = c( (region[1]*3-2) , (region[2:7]*3) )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
86 region_Cod = region
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
87
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
88 readStart = (readStart*3)-2
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
89 readEnd = (readEnd*3)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
90
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
91 FWR_Nuc <- c( rep(TRUE,(region_Nuc[2])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
92 rep(FALSE,(region_Nuc[3]-region_Nuc[2])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
93 rep(TRUE,(region_Nuc[4]-region_Nuc[3])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
94 rep(FALSE,(region_Nuc[5]-region_Nuc[4])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
95 rep(TRUE,(region_Nuc[6]-region_Nuc[5])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
96 rep(FALSE,(region_Nuc[7]-region_Nuc[6]))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
97 )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
98 CDR_Nuc <- (1-FWR_Nuc)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
99 CDR_Nuc <- as.logical(CDR_Nuc)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
100 FWR_Nuc_Mat <- matrix( rep(FWR_Nuc,4), ncol=length(FWR_Nuc), nrow=4, byrow=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
101 CDR_Nuc_Mat <- matrix( rep(CDR_Nuc,4), ncol=length(CDR_Nuc), nrow=4, byrow=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
102
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
103 FWR_Codon <- c( rep(TRUE,(region[2])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
104 rep(FALSE,(region[3]-region[2])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
105 rep(TRUE,(region[4]-region[3])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
106 rep(FALSE,(region[5]-region[4])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
107 rep(TRUE,(region[6]-region[5])),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
108 rep(FALSE,(region[7]-region[6]))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
109 )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
110 CDR_Codon <- (1-FWR_Codon)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
111 CDR_Codon <- as.logical(CDR_Codon)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
112
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
113
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
114 # Read input FASTA file
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
115 tryCatch(
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
116 inputFASTA <- baseline.read.fasta(inputFilePath, seqtype="DNA",as.string=T,set.attributes=F,forceDNAtolower=F)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
117 , error = function(ex){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
118 cat("Error|Error reading input. Please enter or upload a valid FASTA file.\n")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
119 q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
120 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
121 )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
122
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
123 if (length(inputFASTA)==1) {
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
124 cat("Error|Error reading input. Please enter or upload a valid FASTA file.\n")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
125 q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
126 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
127
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
128 # Process sequence IDs/names
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
129 names(inputFASTA) <- sapply(names(inputFASTA),function(x){trim(x)})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
130
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
131 # Convert non nucleotide characters to N
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
132 inputFASTA[length(inputFASTA)] = gsub("\t","",inputFASTA[length(inputFASTA)])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
133 inputFASTA <- lapply(inputFASTA,replaceNonFASTAChars)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
134
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
135 # Process the FASTA file and conver to Matrix[inputSequence, germlineSequence]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
136 processedInput <- processInputAdvanced(inputFASTA)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
137 matInput <- processedInput[[1]]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
138 germlines <- processedInput[[2]]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
139 lenGermlines = length(unique(germlines))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
140 groups <- processedInput[[3]]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
141 lenGroups = length(unique(groups))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
142 rm(processedInput)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
143 rm(inputFASTA)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
144
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
145 # # remove clones with less than 2 seqeunces
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
146 # tableGL <- table(germlines)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
147 # singletons <- which(tableGL<8)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
148 # rowsToRemove <- match(singletons,germlines)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
149 # if(any(rowsToRemove)){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
150 # matInput <- matInput[-rowsToRemove,]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
151 # germlines <- germlines[-rowsToRemove]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
152 # groups <- groups[-rowsToRemove]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
153 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
154 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
155 # # remove unproductive seqs
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
156 # nonFuctionalSeqs <- sapply(rownames(matInput),function(x){any(grep("unproductive",x))})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
157 # if(any(nonFuctionalSeqs)){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
158 # if(sum(nonFuctionalSeqs)==length(germlines)){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
159 # write.table("Unproductive",file=paste(outputPath,outputID,".txt",sep=""),quote=F,sep="\t",row.names=F,col.names=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
160 # q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
161 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
162 # matInput <- matInput[-which(nonFuctionalSeqs),]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
163 # germlines <- germlines[-which(nonFuctionalSeqs)]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
164 # germlines[1:length(germlines)] <- 1:length(germlines)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
165 # groups <- groups[-which(nonFuctionalSeqs)]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
166 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
167 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
168 # if(class(matInput)=="character"){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
169 # write.table("All unproductive seqs",file=paste(outputPath,outputID,".txt",sep=""),quote=F,sep="\t",row.names=F,col.names=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
170 # q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
171 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
172 #
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
173 # if(nrow(matInput)<10 | is.null(nrow(matInput))){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
174 # write.table(paste(nrow(matInput), "seqs only",sep=""),file=paste(outputPath,outputID,".txt",sep=""),quote=F,sep="\t",row.names=F,col.names=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
175 # q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
176 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
177
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
178 # replace leading & trailing "-" with "N:
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
179 matInput <- t(apply(matInput,1,replaceLeadingTrailingDashes,readEnd))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
180
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
181 # Trim (nucleotide) input sequences to the last codon
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
182 #matInput[,1] <- apply(matrix(matInput[,1]),1,trimToLastCodon)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
183
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
184 # # Check for Indels
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
185 # if(fixIndels){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
186 # delPos <- fixDeletions(matInput)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
187 # insPos <- fixInsertions(matInput)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
188 # }else{
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
189 # # Check for indels
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
190 # indelPos <- checkForInDels(matInput)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
191 # indelPos <- apply(cbind(indelPos[[1]],indelPos[[2]]),1,function(x){(x[1]==T & x[2]==T)})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
192 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
193
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
194 # If indels are present, remove mutations in the seqeunce & throw warning at end
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
195 #matInput[indelPos,] <- apply(matrix(matInput[indelPos,],nrow=sum(indelPos),ncol=2),1,function(x){x[1]=x[2]; return(x) })
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
196
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
197 colnames(matInput)=c("Input","Germline")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
198
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
199 # If seqeunces are clonal, create effective sequence for each clone & modify germline/group definitions
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
200 germlinesOriginal = NULL
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
201 if(clonal){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
202 germlinesOriginal <- germlines
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
203 collapseCloneResults <- tapply(1:nrow(matInput),germlines,function(i){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
204 collapseClone(matInput[i,1],matInput[i[1],2],readEnd,nonTerminalOnly=(clonal-1))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
205 })
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
206 matInput = t(sapply(collapseCloneResults,function(x){return(x[[1]])}))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
207 names_groups = tapply(groups,germlines,function(x){names(x[1])})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
208 groups = tapply(groups,germlines,function(x){array(x[1],dimnames=names(x[1]))})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
209 names(groups) = names_groups
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
210
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
211 names_germlines = tapply(germlines,germlines,function(x){names(x[1])})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
212 germlines = tapply( germlines,germlines,function(x){array(x[1],dimnames=names(x[1]))} )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
213 names(germlines) = names_germlines
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
214 matInputErrors = sapply(collapseCloneResults,function(x){return(x[[2]])})
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
215 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
216
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
217
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
218 # Selection Analysis
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
219
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
220
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
221 # if (length(germlines)>sequenceLimit) {
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
222 # # Code to parallelize processing goes here
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
223 # stop( paste("Error: Cannot process more than ", Upper_limit," sequences",sep="") )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
224 # }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
225
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
226 # if (length(germlines)<sequenceLimit) {}
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
227
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
228 # Compute expected mutation frequencies
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
229 matExpected <- getExpectedIndividual(matInput)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
230
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
231 # Count observed number of mutations in the different regions
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
232 mutations <- lapply( 1:nrow(matInput), function(i){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
233 #cat(i,"\n")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
234 seqI = s2c(matInput[i,1])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
235 seqG = s2c(matInput[i,2])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
236 matIGL = matrix(c(seqI,seqG),ncol=length(seqI),nrow=2,byrow=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
237 retVal <- NA
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
238 tryCatch(
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
239 retVal <- analyzeMutations2NucUri(matIGL)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
240 , error = function(ex){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
241 retVal <- NA
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
242 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
243 )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
244
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
245
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
246 return( retVal )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
247 })
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
248
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
249 matObserved <- t(sapply( mutations, processNucMutations2 ))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
250 numberOfSeqsWithMutations <- numberOfSeqsWithMutations(matObserved, testID)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
251
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
252 #if(sum(numberOfSeqsWithMutations)==0){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
253 # write.table("No mutated sequences",file=paste(outputPath,outputID,".txt",sep=""),quote=F,sep="\t",row.names=F,col.names=T)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
254 # q()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
255 #}
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
256
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
257 matMutationInfo <- cbind(matObserved,matExpected)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
258 rm(matObserved,matExpected)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
259
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
260
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
261 #Bayesian PDFs
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
262 bayes_pdf = computeBayesianScore(matMutationInfo, test=testName, max_sigma=20,length_sigma=4001)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
263 bayesPDF_cdr = bayes_pdf[[1]]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
264 bayesPDF_fwr = bayes_pdf[[2]]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
265 rm(bayes_pdf)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
266
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
267 bayesPDF_germlines_cdr = tapply(bayesPDF_cdr,germlines,function(x) groupPosteriors(x,length_sigma=4001))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
268 bayesPDF_germlines_fwr = tapply(bayesPDF_fwr,germlines,function(x) groupPosteriors(x,length_sigma=4001))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
269
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
270 bayesPDF_groups_cdr = tapply(bayesPDF_cdr,groups,function(x) groupPosteriors(x,length_sigma=4001))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
271 bayesPDF_groups_fwr = tapply(bayesPDF_fwr,groups,function(x) groupPosteriors(x,length_sigma=4001))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
272
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
273 if(lenGroups>1){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
274 groups <- c(groups,lenGroups+1)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
275 names(groups)[length(groups)] = "All sequences combined"
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
276 bayesPDF_groups_cdr[[lenGroups+1]] = groupPosteriors(bayesPDF_groups_cdr,length_sigma=4001)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
277 bayesPDF_groups_fwr[[lenGroups+1]] = groupPosteriors(bayesPDF_groups_fwr,length_sigma=4001)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
278 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
279
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
280 #Bayesian Outputs
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
281 bayes_cdr = t(sapply(bayesPDF_cdr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
282 bayes_fwr = t(sapply(bayesPDF_fwr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
283 bayes_germlines_cdr = t(sapply(bayesPDF_germlines_cdr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
284 bayes_germlines_fwr = t(sapply(bayesPDF_germlines_fwr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
285 bayes_groups_cdr = t(sapply(bayesPDF_groups_cdr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
286 bayes_groups_fwr = t(sapply(bayesPDF_groups_fwr,calcBayesOutputInfo))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
287
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
288 #P-values
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
289 simgaP_cdr = sapply(bayesPDF_cdr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
290 simgaP_fwr = sapply(bayesPDF_fwr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
291
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
292 simgaP_germlines_cdr = sapply(bayesPDF_germlines_cdr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
293 simgaP_germlines_fwr = sapply(bayesPDF_germlines_fwr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
294
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
295 simgaP_groups_cdr = sapply(bayesPDF_groups_cdr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
296 simgaP_groups_fwr = sapply(bayesPDF_groups_fwr,computeSigmaP)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
297
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
298
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
299 #Format output
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
300
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
301 # Round expected mutation frequencies to 3 decimal places
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
302 matMutationInfo[germlinesOriginal[indelPos],] = NA
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
303 if(nrow(matMutationInfo)==1){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
304 matMutationInfo[5:8] = round(matMutationInfo[,5:8]/sum(matMutationInfo[,5:8],na.rm=T),3)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
305 }else{
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
306 matMutationInfo[,5:8] = t(round(apply(matMutationInfo[,5:8],1,function(x){ return(x/sum(x,na.rm=T)) }),3))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
307 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
308
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
309 listPDFs = list()
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
310 nRows = length(unique(groups)) + length(unique(germlines)) + length(groups)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
311
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
312 matOutput = matrix(NA,ncol=18,nrow=nRows)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
313 rowNumb = 1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
314 for(G in unique(groups)){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
315 #print(G)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
316 matOutput[rowNumb,c(1,2,11:18)] = c("Group",names(groups)[groups==G][1],bayes_groups_cdr[G,],bayes_groups_fwr[G,],simgaP_groups_cdr[G],simgaP_groups_fwr[G])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
317 listPDFs[[rowNumb]] = list("CDR"=bayesPDF_groups_cdr[[G]],"FWR"=bayesPDF_groups_fwr[[G]])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
318 names(listPDFs)[rowNumb] = names(groups[groups==paste(G)])[1]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
319 #if(names(groups)[which(groups==G)[1]]!="All sequences combined"){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
320 gs = unique(germlines[groups==G])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
321 rowNumb = rowNumb+1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
322 if( !is.na(gs) ){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
323 for( g in gs ){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
324 matOutput[rowNumb,c(1,2,11:18)] = c("Germline",names(germlines)[germlines==g][1],bayes_germlines_cdr[g,],bayes_germlines_fwr[g,],simgaP_germlines_cdr[g],simgaP_germlines_fwr[g])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
325 listPDFs[[rowNumb]] = list("CDR"=bayesPDF_germlines_cdr[[g]],"FWR"=bayesPDF_germlines_fwr[[g]])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
326 names(listPDFs)[rowNumb] = names(germlines[germlines==paste(g)])[1]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
327 rowNumb = rowNumb+1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
328 indexesOfInterest = which(germlines==g)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
329 numbSeqsOfInterest = length(indexesOfInterest)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
330 rowNumb = seq(rowNumb,rowNumb+(numbSeqsOfInterest-1))
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
331 matOutput[rowNumb,] = matrix( c( rep("Sequence",numbSeqsOfInterest),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
332 rownames(matInput)[indexesOfInterest],
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
333 c(matMutationInfo[indexesOfInterest,1:4]),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
334 c(matMutationInfo[indexesOfInterest,5:8]),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
335 c(bayes_cdr[indexesOfInterest,]),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
336 c(bayes_fwr[indexesOfInterest,]),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
337 c(simgaP_cdr[indexesOfInterest]),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
338 c(simgaP_fwr[indexesOfInterest])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
339 ), ncol=18, nrow=numbSeqsOfInterest,byrow=F)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
340 increment=0
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
341 for( ioi in indexesOfInterest){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
342 listPDFs[[min(rowNumb)+increment]] = list("CDR"=bayesPDF_cdr[[ioi]] , "FWR"=bayesPDF_fwr[[ioi]])
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
343 names(listPDFs)[min(rowNumb)+increment] = rownames(matInput)[ioi]
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
344 increment = increment + 1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
345 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
346 rowNumb=max(rowNumb)+1
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
347
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
348 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
349 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
350 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
351 colsToFormat = 11:18
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
352 matOutput[,colsToFormat] = formatC( matrix(as.numeric(matOutput[,colsToFormat]), nrow=nrow(matOutput), ncol=length(colsToFormat)) , digits=3)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
353 matOutput[matOutput== " NaN"] = NA
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
354
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
355
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
356
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
357 colnames(matOutput) = c("Type", "ID", "Observed_CDR_R", "Observed_CDR_S", "Observed_FWR_R", "Observed_FWR_S",
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
358 "Expected_CDR_R", "Expected_CDR_S", "Expected_FWR_R", "Expected_FWR_S",
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
359 paste( rep(testName,6), rep(c("Sigma","CIlower","CIupper"),2),rep(c("CDR","FWR"),each=3), sep="_"),
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
360 paste( rep(testName,2), rep("P",2),c("CDR","FWR"), sep="_")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
361 )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
362 fileName = paste(outputPath,outputID,".txt",sep="")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
363 write.table(matOutput,file=fileName,quote=F,sep="\t",row.names=T,col.names=NA)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
364 fileName = paste(outputPath,outputID,".RData",sep="")
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
365 save(listPDFs,file=fileName)
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
366
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
367 indelWarning = FALSE
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
368 if(sum(indelPos)>0){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
369 indelWarning = "<P>Warning: The following sequences have either gaps and/or deletions, and have been ommited from the analysis.";
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
370 indelWarning = paste( indelWarning , "<UL>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
371 for(indels in names(indelPos)[indelPos]){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
372 indelWarning = paste( indelWarning , "<LI>", indels, "</LI>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
373 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
374 indelWarning = paste( indelWarning , "</UL></P>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
375 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
376
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
377 cloneWarning = FALSE
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
378 if(clonal==1){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
379 if(sum(matInputErrors)>0){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
380 cloneWarning = "<P>Warning: The following clones have sequences of unequal length.";
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
381 cloneWarning = paste( cloneWarning , "<UL>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
382 for(clone in names(matInputErrors)[matInputErrors]){
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
383 cloneWarning = paste( cloneWarning , "<LI>", names(germlines)[as.numeric(clone)], "</LI>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
384 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
385 cloneWarning = paste( cloneWarning , "</UL></P>", sep="" )
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
386 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
387 }
ba33b94637ca Uploaded
davidvanzessen
parents: 0
diff changeset
388 cat(paste("Success",outputID,indelWarning,cloneWarning,sep="|"))