#p_value <- 0.01;
libs <- c("Hmisc");
lapply(libs, require, character.only=T);

input <- function(inputfile) {
  abund <<- read.csv(inputfile, header = TRUE);
}


run <- function() {
  otus <<- colnames(abund);
  otus <<- otus[2:length(otus)];
  abundT <<- t(apply(abund[,-1], 1, as.numeric));
  result <<- rcorr(abundT[,]);
  corr <<- as.matrix(result$r);
  corr[which(result$P>0.01)] <<- 0;
  #cn <<- colnames(pc);
  #cn <<- cn[2:length(cn)];
  #pc <<- pc[,-1];
  #pc <<- apply(pc, 1, as.numeric);
  #pc <<- t(pc);
  #correlations <<- rcorr(pc[,], type=c("pearson"));
  #pc <<- as.matrix(correlations$r);
  #pc[is.na(pc)] <<- 0;
  #empty <- c("");
  #pc[which(correlations$P>p_value)] <<- 0;
}

output <- function(outputfile) {
   write.table(corr, file=outputfile, sep=",", append=FALSE, row.names=unlist(otus), col.names=unlist(otus), na="");
}


