labkey.data <- read.table("${input_data}", header=TRUE, check.names=FALSE, sep="\t", quote="") source("SpectraCountFunctions_v8_1.R") ##labkey.data <- read.table("c:/temp/rptData.tsv", header=TRUE, check.names=FALSE, sep="\t",quote="" ) FormatOutputData <- function(d, score.df, out.file="${tsvout: myout}", colProteinName) { colnames(score.df[,1:2]) <- c("Protein","ProteinsInGroup") prot.href.v <- paste("/labkey/ms2/LabelFreeSample/DemoSet/showProtein.view?seqId=", as.character(d$protein), sep="") prot.href.df <- data.frame(unique(cbind(Protein=as.character(d[[colProteinName]]),Protein.href=prot.href.v ))) colnames(prot.href.df) <- c("Protein", "Protein.href") score.df <- merge(score.df, prot.href.df, by="Protein") score.df<- score.df[order(score.df$GroupName), ] score.df$BetaMix <- round(score.df$BetaMix, signif=3) score.df$AlphaMix <- round(score.df$AlphaMix, signif=3) score.df$Difference <- round(score.df$Difference, signif=3) score.df$PValue <- round(score.df$PValue, signif=3) output.df <- data.frame(cbind(score.df[,-(2) ], score.df[2] )) ## show only the annotated rows output.df.rows <- output.df[!is.na(output.df$GroupName),] hasCairo <- require(Cairo); if (hasCairo) { Cairo(file="${imgout:compare_counts_conc.png}", type="png"); ## Cairo(file="C:/temp/compare_counts_conc.png", type="png"); plotdata.1 <- as.numeric(output.df.rows$Difference) plotdata.2b <- as.numeric(log1p(output.df.rows$ConcInB)) plotdata.2a <- as.numeric(log1p(output.df.rows$ConcInA)) plotdata.2 <- plotdata.2b - plotdata.2a plotdata.rows <- cbind(output.df.rows[,1:7], logConcRatio=plotdata.2, output.df.rows[,8:10]) plotdata.rows <- plotdata.rows[order(plotdata.rows$logConcRatio), ] plotdata.rows$logConcRatio <- round(plotdata.rows$logConcRatio, signif=3) plotdata.x <- as.integer(1:nrow(plotdata.rows)) plotdata.rows <- cbind(Rank=plotdata.x, plotdata.rows) write.table(plotdata.rows, file = out.file, sep = "\t", qmethod = "double", row.names=FALSE, col.names=TRUE ) plot(plotdata.rows$Rank, plotdata.rows$Difference, col="blue", main="Comparison of quantitation results vs known concentration ratios", sub="o = quantitation result; + = known concentrations;", ylab="Differnce in ln(scan count + 1)", xlab="Protein Rank", ylim =c(-4,4)); plot(plotdata.rows$Rank, plotdata.rows$logConcRatio ,pch="+", main="", sub="", ylab="", xlab="", ylim=c(-4,4)); dev.off(); } else { write.table(output.df.rows[order(output.df.rows$Difference), ], file = out.file, sep = "\t", qmethod = "double", row.names=FALSE, col.names=TRUE ) } } ## debug(FormatOutputData) colPepId ="peptide" colProteinName = "protein.bestname" peptideDataCols=list(totalPeptideCount="totalpeptidecount") proteinInfoCols=list(ConcInB="protein_customannotations_pepperspikedpr3",ConcInA="protein_customannotations_pepperspikedpr5",GroupName="protein_customannotations_pepperspikedpr2") runGroupNames=list(name="run_rungroups_alpharungroup", true="AlphaMix", false="BetaMix") r1 =RunScoringFunction(labkey.data, functionName="SimpleSpectrumTotals", colPepId, colProteinName, peptideDataCols, proteinInfoCols, runGroupNames) ##write.table(r1[order(r1$Difference), ], file = "C:/temp/result.tsv", sep = "\t", qmethod = "double", row.names=FALSE, col.names=TRUE ) FormatOutputData(labkey.data,r1, colProteinName=colProteinName)