#' Calculate the sequence features.
#' @param mir  A vector including the microRNA name, the pre_microRNA sequence and All of the mature microRNA sequences 
#' @param MFE  The Minimum free energy caculated by RNAfold \url{http://rna.tbi.univie.ac.at/cgi-bin/RNAWebSuite/RNAfold.cgi}
#' \code{\link[stringr]{str_count}} which this function wraps.
#' @return A dataframe.
#' @export
#' @examples
#' mir <- c("mmu-mir-6909", "GAUAACAGGGGGGCUGGAAUGGGCACUGCGGAGAACCAUGUGCCUUCCCCGGCCUCCCACAG", "CAGGGGGGCUGGAAUGGGCACU", "UGCCUUCCCCGGCCUCCCACAG")
#' Feature_caculator(mir,-33.9)


Feature_caculator<-function(mir,MFE){
  mature = mir[c(-1,-2)]
  mature_num <-length(mature);
  
  colname <- c("pre_U","pre_C","pre_G","miR_len","miR_U","miR_C","miR_G","nonmiR_len",
"nonmiR_U","nonmiR_C","nonmiR_G","MFE","nMFE","cleavage_site");
  
  feature <- data.frame(t(rep(0,14)),row.names = mir[1])
  names(feature) <- colname
  
  feature[1] <- str_count(mir[2], "U")/nchar(mir[2]);
  
  feature[2] <- str_count(mir[2], "C")/nchar(mir[2]);
  
  feature[3] <- str_count(mir[2], "G")/nchar(mir[2]);
  
  feature[4] <- sum(nchar(mature));
  
  feature[5] <- sum(str_count(mature, "U"))/sum(nchar(mature));
  
  feature[6] <- sum(str_count(mature, "C"))/sum(nchar(mature));
  
  feature[7] <- sum(str_count(mature, "G"))/sum(nchar(mature));
  
  feature[8] <- nchar(mir[2]) - sum(nchar(mature));
  
  feature[9] <- (str_count(mir[2], "U") - sum(str_count(mature, "U")))/feature[8];
  
  feature[10] <- (str_count(mir[2], "C") - sum(str_count(mature, "U")))/feature[8];
  
  feature[11] <- (str_count(mir[2], "G") - sum(str_count(mature, "U")))/feature[8];
  
  feature[12] <- MFE;
  
  feature[13] <- MFE/nchar(mir[2]);
  
  cleavage <- substr(mature, 1, 1);
    
  if (mature_num == 1){
    
    feature[14] = ifelse( (cleavage == "U"),1,-1)
    
  }else {
    
    if (cleavage[1] == "U" & cleavage [2] == "U"){
      
      feature[14] = 1
    
      } else if (cleavage[1] != "U" & cleavage [2] != "U"){
         
          feature[14] = -1
      
      } else {feature[14] = 0}
  }
  
  return(feature)

}
  

 
