R/uploadEnvDataRequest.R

Defines functions uploadEnvDataRequest

Documented in uploadEnvDataRequest

#' Upload an Env-Data request for Annotation
#' 
#' @param csv.file Location and name of \code{.csv} file to annotate, either a MoveBank track or file generated by \code{\link{createEnvDataGrid}}
#' @param xml.file Location and name of \code{.xml} file that contains the request instructions - almost certainly generated by \code{\link{createEnvDataRequest}}
#' @param {login,password} login and password for EnvData (NOT the same as MoveBank login and password)
#' @param link.file name of link to access status and final annotated data
#' 
#' @details The function will fill out the data annotation form on the EnvData annotation tool at \link{http://www.bioinfo.mpg.de/orn-gateway/services2.jsp}.  It will also create a link to the status report of the annotation request, and will attempt to automatically open that page.   
#' @export
#' 
#' @example ./examples/EnvDataExample.r
#' 
uploadEnvDataRequest <- function(csv.file, xml.file, 
                                 login=NULL, password=NULL, 
                                 link.file = "annotation_status_link.url"){
  
  CSV_upload <- fileUpload(filename = csv.file, contentType="text/plain")
  XML_upload <- fileUpload(filename = xml.file, contentType="text/xml")
  h <- basicHeaderGatherer()
  b <- basicHeaderGatherer()
  
  if(is.null(login)){
    login <- readline(prompt="Enter login: ")
    password <- readline(prompt="Enter password: ")
  }
  
  postForm('http://www.bioinfo.mpg.de/orn-gateway/request-annotation-xml-2.jsp', 
           request = XML_upload, tracks = CSV_upload, 
           .params = list(login = login, password = password), 
           .opts = curlOptions(headerfunction = h$update, writefunction = b$update, verbose = TRUE))
  
  url <- h$value()['Location']
  cat("[InternetShortcut]\n URL=",h$value()['Location'], file = link.file)
  try(shell(link.file))
  return(h$value())
}
ABoVE-AotM/above documentation built on May 28, 2020, 6:08 a.m.