.packageName <- "RSNPper"

doGeneinfo = function(xmlTextVec) {
cc = xmlTreeParse(paste(xmlTextVec, collapse=""), asText=TRUE)
 rtr = xmlRoot(cc)
 tinf = xmlAttrs(rtr)
 tn = names(tinf)
 tinf = t(matrix(tinf))
 colnames(tinf) = tn

isSca = c("GENEID", "NAME", "CHROM", "STRAND", "PRODUCT", "NSNPS")
toolInfo = xmlAttrs(xmlRoot(cc))
getBas = function(x) lapply(xmlChildren(x), xmlValue)
genes = xmlChildren(xmlRoot(cc)[[1]])
BAS = lapply(genes,getBas)
basmat = t(sapply(BAS, function(x) unlist(x[isSca])))
GS = xmlChildren(xmlRoot(cc)[[1]])
TX = lapply(GS, function(x) xmlChildren(x)[["TRANSCRIPT"]])
CS = lapply(GS, function(x) xmlChildren(x)[["CODINGSEQ"]])
LI = lapply(GS, function(x) xmlChildren(x)[["LINKS"]])
AC = lapply(GS, function(x) xmlChildren(x)[["ACCESSION"]])
SE = lapply(TX, xmlChildren)
CSE = lapply(CS, xmlChildren)
CLI = lapply(LI, xmlChildren)
CAC = lapply(AC, xmlChildren)
TXSE = t(sapply(SE, function(x) sapply(x, xmlValue)))
colnames(TXSE) = paste("TX", colnames(TXSE))
TCSE = t(sapply(CSE, function(x) sapply(x, xmlValue)))
colnames(TCSE) = paste("CODSEQ", colnames(TCSE))
TLI = t(sapply(CLI, function(x) sapply(x, xmlValue)))
TCAC = t(sapply(CAC, function(x) sapply(x, xmlValue)))
ini = data.frame(cbind(basmat,TXSE, TCSE, TLI),row.names=NULL)#, TCAC)
ans = cbind(ini, data.frame(TCAC,row.names=NULL))
new("SNPperGeneMeta", allGeneMeta=ans, toolInfo=tinf)
}

doSnpinfo = function(xmlTextVec) {
#
# (c) 2006 VJ Carey
# Function parses result of a call to snpper.chip.org
# the call is a snpinfo XML-RPC call
# the input here is a text vector result of
# useSNPper(cmd="snpinfo", parm="&[rsnumnoprefix]")
#
 tr = xmlTreeParse(paste(xmlTextVec, collapse=""), asText=TRUE)
 rtr = xmlRoot(tr)
 tinf = xmlAttrs(rtr)
 tn = names(tinf)
 tinf = t(matrix(tinf))
 colnames(tinf) = tn
 targ = xmlChildren(rtr)$SNPINFO
 elems = names(targ)
 uel = unique(elems)
 isSca = c("DBSNPID", "TSCID", "CHROMOSOME", "POSITION", "ALLELES",
   "VALIDATED")
 basic = sapply(targ[match(isSca,elems)], xmlValue)
 list(basic, rtr)
 GL = xmlChildren(targ)[names(xmlChildren(targ)) == "GENELINK"] 
 GLframe = t(sapply(GL, function(x)xmlAttrs(xmlChildren(x)[[1]])))

 ZZ = lapply(GL, function(x) xmlChildren(x[[1]]))
ZZZ = lapply(ZZ, function(x)sapply(x, function(z) xmlValue(z))) 

 SUBM = xmlChildren(targ)[names(xmlChildren(targ)) == "SUBMITTERS"]
 FREQ = xmlChildren(targ)[names(xmlChildren(targ)) == "SNPFREQDATA"]
 FRQframe = data.frame(t(sapply(xmlChildren(FREQ[[1]]), xmlAttrs)),row.names=NULL)
 al = lapply(xmlChildren(FREQ[[1]]), xmlChildren)
 majorf = sapply(al,function(x)xmlValue(x[[1]]))
 minorf = sapply(al,function(x)xmlValue(x[[2]]))
 Z=lapply(xmlChildren(FREQ[[1]]), xmlChildren)
 allfr =t(sapply(Z, function(x)unlist(lapply(x, function(z)xmlAttrs(z)))))
 doRole <- function(x) { nx = names(x); v = rep(NA,length(nx)) ;
  names(v) = nx; val = unlist(x); v[names(val)] = val; v }
 cont = t(sapply(ZZZ,doRole))
 GLframe = data.frame(cbind(GLframe,cont),row.names=NULL)
 x = list(basic=unlist(basic), popDetails=data.frame(FRQframe,allfr,majorf,minorf,row.names=NULL),
   submitters=SUBM, geneDetails=GLframe)
 DF = t(matrix((unlist(basic))))
 colnames(DF) = names(unlist(basic))
 new("SNPperMeta", popDetails= x$popDetails, geneDetails=x$geneDetails,
    submitters=SUBM, toolInfo=tinf, DF)
}
 

setClass("fromSNPper", representation(toolInfo="matrix"), "VIRTUAL")

setClass("SNPperMeta", representation(
  popDetails="data.frame", geneDetails="data.frame", 
  submitters="ANY"), contains=c("matrix", "fromSNPper"))

setGeneric("popDetails", function(object)standardGeneric("popDetails"))
setMethod("popDetails", "SNPperMeta", function(object)
 object@popDetails)
setGeneric("geneDetails", function(object)standardGeneric("geneDetails"))
setMethod("geneDetails", "SNPperMeta", function(object)
 object@geneDetails)
setGeneric("submitters", function(object)standardGeneric("submitters"))
setMethod("submitters", "SNPperMeta", function(object)
 object@submitters)
setGeneric("toolInfo", function(object)standardGeneric("toolInfo"))
setMethod("toolInfo", "fromSNPper", function(object)
 object@toolInfo)

setMethod("show", "SNPperMeta", function(object) {
 cat("SNPper SNP metadata:\n")
 print(object@.Data)
 cat("There are details on", nrow(popDetails(object)), "populations\n")
 cat("and", nrow(geneDetails(object)), "connections to gene features\n")
 cat("SNPper info:\n")
 print(toolInfo(object))
})

#-------------

setClass("SNPperGeneMeta", representation(allGeneMeta="data.frame"),
  contains="fromSNPper")
setGeneric("allGeneMeta", function(x) standardGeneric("allGeneMeta"))
setMethod("allGeneMeta", "SNPperGeneMeta", function(x) x@allGeneMeta)
setMethod("show", "SNPperGeneMeta", function(object) {
 cat("SNPper Gene metadata:\n")
 cat("There are ", nrow(allGeneMeta(object)), "entries.\n")
 cat("Basic information:\n")
 print(allGeneMeta(object)[1,])
 cat("SNPper info:\n")
 print(toolInfo(object))
})

.SNPperBaseURL <- "http://snpper.chip.org/bio/rpcserv/dummy?cmd="

.rpcCalls <- list(
 "showcalls"=NULL,
 "genelayout"=list(args="id",
    comment="SNPper gene id, use 'geneinfo' to determine"),
 "geneinfo"=list(args=c("name", "acc", "id"), comment=
     "acc: mRNA accession no., id=SNPper id"),
 "snpinfo"=list(args="id", comment="number after rs in dbSNP id"),
 "snpsetinfo"=list(args="name", comment="SNPper generated set name"),
 "genesinrange"=list(args=c("chr", "s", "e"), 
   comment="chromosome no., start, end"),
 "snpsinrange"=list(args=c("chr", "s", "e"), 
   comment="chromosome no., start, end"),
 "genesnps"=list(args=c("id", "acc", "sub"), 
   comment="SNPper id, mRNA acc, or submitter"),
 "countsnps"=list(args=c("chr", "s", "e"), 
   comment="chromosome no., start, end"))

geneInfo <- function (name = NA, acc = NA, id = NA, useOldOutput=FALSE) 
{
    require("XML")
    if (all(ng <- is.na(c(name, acc, id)))) 
        stop("must request info on some gene")
    if (sum(ng) != 2) 
        stop("please use only one gene id")
    parms <- c("name", "acc", "id")
    vals <- c(name, acc, id)
    ok <- (1:3)[ng == FALSE]
    if (useOldOutput) {
    suff <- paste("geneinfo&", parms[ok], "=", vals[ok], sep = "")
    Url <- paste(.SNPperBaseURL, suff, sep = "")
Url <- url(Url)
on.exit(close(Url))
    if (libxmlVersion()$major == 1) {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
        return(xmlEventParse(data, ginfoHandler(), asText = TRUE)$dump())
    }
    else return(xmlEventParse(paste(readLines(Url),collapse=" "), ginfoHandler(), asText=TRUE)$dump())
  }
  else return(doGeneinfo(useSNPper("geneinfo&", paste(parms[ok], "=", vals[ok],
	sep = ""))))
}

geneLayout <- function (id = NA) 
{
    require("XML")
    if (is.na(id))
        stop("must request info on some gene")
    if (length(id)>1) stop("not vectorized at present, request only 1 id")
    suff <- paste("genelayout&", "id=", id, sep = "")
    Url <- paste(.SNPperBaseURL, suff, sep = "")
Url <- url(Url)
on.exit(close(Url))
    if (libxmlVersion()$major == 1) {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
        xmlEventParse(data, glayHandler(), asText = TRUE)$dump()
    }
    else xmlEventParse(paste(readLines(Url),collapse=""), glayHandler(), asText=TRUE)$dump()
}

SNPinfo <- function (dbsnpid = NA, useOldOutput=FALSE) 
{
    require("XML")
    id <- dbsnpid
    if (is.na(id))
        stop("must request info on some SNP")
    if (length(id)>1) stop("not vectorized at present, request only 1 id")
    if (length(grep("rs", id))>0) id = gsub("rs", "", id)
if (useOldOutput) {
    suff <- paste("snpinfo&", "id=", id, sep = "")
    Url <- paste(.SNPperBaseURL, suff, sep = "")
Url <- url(Url)
on.exit(close(Url))
    if (libxmlVersion()$major == 1) {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
        return(xmlEventParse(data, snpinfoHandler(), asText = TRUE)$dump())
    }
    else return(xmlEventParse(paste(readLines(Url),collapse=""), snpinfoHandler(),
            asText=TRUE)$dump())
   }
else return(doSnpinfo(useSNPper("snpinfo", paste("&id", id,
     sep="="))))
}

geneSNPs <- function (id = NA, acc=NA) 
{
    require("XML")
    if (!is.na(id) & !is.na(acc)) warning("both id and acc supplied, using id")
    if (length(id)>1) stop("not vectorized at present, request only 1 id")
    if (length(acc)>1) stop("not vectorized at present, request only 1 acc")
    if (!is.na(id))suff <- paste("genesnps&", "id=", id, sep = "")
    if (!is.na(acc))suff <- paste("genesnps&", "acc=", acc, sep = "")
    Url <- paste(.SNPperBaseURL, suff, sep = "")
Url <- url(Url)
on.exit(close(Url))
    if (libxmlVersion()$major == 1) {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
        xmlEventParse(data, sinrangeHandler(), asText = TRUE)$dump()
    }
    else xmlEventParse(paste(readLines(Url),collapse=""), sinrangeHandler(),
            asText=TRUE)$dump()
}

itemsInRange <- function (item="genes", chr, start, end)
{
    require("XML")
    if (is.numeric(start)) stop("please supply start and end as strings")
    if (is.numeric(end)) stop("please supply start and end as strings")
    if (length(chr)>1) stop("not vectorized at present, request only 1 id")

if (item == "genes") {cmd <- "genesinrange"; han <- ginrangeHandler}
else if (item == "snps") {cmd <- "snpsinrange"; han <- sinrangeHandler}
#else if (item == "nsnps"|item=="countsnps") {cmd <- "countsnps"; han <- nsnpHandler}
else if (item == "nsnps"|item=="countsnps") 
   {
#   warning("countsnps command not returning valid "XML", using string parsing")
   cmd <- "countsnps"
   }
else stop("item must be 'genes' or 'snps' or 'countsnps'")

if (item != "nsnps" & item != "countsnps")
    suff <- paste(cmd, "&chr=", chr,
            "&s=", start, "&e=", end, sep = "")
else
    suff <- paste(cmd, "&chr=", chr,
            "&start=", start, "&end=", end, sep = "")
    Url <- paste(.SNPperBaseURL, suff, sep = "")
Url <- url(Url)
on.exit(close(Url))
#
# following is a patch-up because "XML" parsing fails with countsnps
# command (chip returns a tag with slashes in it)
#
if (item == "nsnps"|item=="countsnps") 
        {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
#print(data) -- shows some inconsistency in RPC response from chip
# parsing below seems OK
        ind <- regexpr("NON.*TOT",data)
        rem <- substr(data,ind+7,50000)
        r2 <- regexpr("<",rem)
        rem <- substr(rem,1,r2-1)
        tmp <- as.numeric(strsplit(rem,"/")[[1]][1:3])
        names(tmp) <- c("total","exonic","nonsyn")
        return(tmp)
        }
else
    if (libxmlVersion()$major == 1) {
        data <- paste(scan(Url, "", quiet=TRUE), collapse = " ")
        xmlEventParse(data, han(), asText = TRUE)$dump()
    }
    else xmlEventParse(paste(readLines(Url),collapse=""), han(),
            asText=TRUE)$dump()
}

outPaste <- function (x, y) 
as.character(outer(x, y, function(x, y) paste(x, y, sep = ".")))

dot <- function(x,y) paste(x,y,sep=".")

ginfoHandler <- function() {
 toolInfo <- NULL
 snppergid <- NULL
#
# setup for flat text info
#
 txtTags <- c("NAME", "CHROM", "STRAND", "PRODUCT",
        "LOCUSLINK", "OMIM", "UNIGENE",
	"SWISSPROT", "NSNPS", "REFSEQACC", "MRNAACC")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 curCon <- NULL
 curConTag <- NULL
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
 startElement = function(x, atts, ...)
  {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  else if (x == "GENE")
    {
    snppergid <<- atts
    names(snppergid) <<- "snpper.ID"
    }
  else if (x %in% contextTags)
    curCon <<- x
  else if (x %in% d1Tags)
    {
    curConTag <<- dot(curCon,x)
    }
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  else if (x %in% contextTags)
    curCon <<- NULL
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  if (!is.null(curConTag) && !is.na(match(curConTag,d1names)))
       {
       d1vals[curConTag] <<- x
       curConTag <<- NULL
       }
  }
 dump = function() {
  obj <- c(snppergid,atoms,d1vals)
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}
 
useSNPper2 <- function (cmd, parmstring) 
readLines(paste(.SNPperBaseURL, cmd, parmstring, sep = ""))

useSNPper <- function (cmd, parmstring) 
{
targ <- url(paste(.SNPperBaseURL, cmd, parmstring, sep = ""))
open(targ)
on.exit(close(targ))
readLines(targ)
}

glayHandler <- function() {
 toolInfo <- NULL
#
# setup for flat text info
#
 txtTags <- c("ID", "NAME", "CHROM")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 curCon <- NULL
 curConTag <- NULL
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
#
# variable length data on exons!
#
 inExon <- FALSE
 curex <- 0
 ies <- FALSE
 iee <- FALSE
 elist <- list()
#
#
#
 startElement = function(x, atts, ...)
  {
  if (x == "EXON")
    {
    inExon <<- TRUE
    curex <<- curex+1
    }
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  else if (x %in% contextTags)
    curCon <<- x
  else if (x %in% d1Tags)
    {
    curConTag <<- dot(curCon,x)
    if (inExon & x=="START") ies <<- TRUE
    if (inExon & x=="END") iee <<- TRUE
    }
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  else if (x %in% contextTags)
    curCon <<- NULL
  else  if (inExon & x=="START") ies <<- FALSE
  else  if (inExon & x=="END") iee <<- FALSE
  else if (x == "EXON")
    inExon <<- FALSE
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  if (!is.null(curConTag) && !is.na(match(curConTag,d1names)))
       {
       d1vals[curConTag] <<- x
       curConTag <<- NULL
       }
  if (ies) 
    {
    elist[[curex]] <<- rep(NA,2)
    pre <- paste("exon",curex,sep="")
    names(elist[[curex]]) <<- paste(pre,c("start", "end"),sep=".")
    elist[[curex]][1] <<- x
    }
  if (iee)
    elist[[curex]][2] <<- x
  }
 dump = function() {
  obj <- c(atoms,d1vals,unlist(elist))
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}

snpinfoHandler <- function() {
 toolInfo <- NULL
#
# setup for flat text info
#
 txtTags <- c("DBSNPID", "TSCID", "CHROMOSOME",
   "POSITION", "ALLELES", "ROLE", "RELPOS", "AMINO",
   "AMINOPOS")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
#
# attribute data on gene
#
 gdata <- NULL
#
#
#
 startElement = function(x, atts, ...)
  {
  if (x == "GENE")
    gdata <<- atts
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  }
 dump = function() {
  obj <- c(atoms,gdata)
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}

ginrangeHandler <- function() {
 toolInfo <- NULL
#
# setup for flat text info
#
 txtTags <- c("NAME", "CHROM", "PRODUCT", "NSNPS")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
#
# attribute data on genesinrange
#
 gdata <- NULL
#
#
#
 glist <- list()
 curg <- 1
 startElement = function(x, atts, ...)
  {
  if (x == "GENESINRANGE")
    gdata <<- atts
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  if (x == "GENE")
    {
    glist[[curg]] <<- atoms
    atoms[1:length(atoms)] <<- " "
    curg <<- curg+1
    }
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  }
 dump = function() {
  obj <- c(glist,gdata)
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}

sinrangeHandler <- function() {
#
# also works for genesnps call
#
 toolInfo <- NULL
#
# setup for flat text info
#
 txtTags <- c("DBSNPID", "TSCID", "CHROMOSOME",
   "POSITION", "ALLELES", "ROLE", "RELPOS", "AMINO",
   "AMINOPOS")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
#
# attribute data on snps
#
 gdata <- NULL
#
# annotation
 adata <- NULL
#
#
#
 snpl <- list()
 curel <- 1
 startElement = function(x, atts, ...)
  {
  if (x == "SNPSINRANGE" | x == "GENESNPS")
    gdata <<- atts
  if (x == "GENE")
    adata <<- atts
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  if (x == "SNPINFO")
    {
    snpl[[curel]] <<- c(atoms,adata)
    atoms[1:length(atoms)] <<- " "
    curel <<- curel+1
    }
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  }
 dump = function() {
  obj <- c(snpl,gdata)
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}

nsnpHandler <- function() {
 toolInfo <- NULL
#
# setup for flat text info
#
 txtTags <- c("TOTAL/EXONIC/NONSYN")
 status <- rep(FALSE,length(txtTags))
 atoms <- rep(" ",length(txtTags))
 names(status) <- txtTags
 names(atoms) <- txtTags
#
# setup for depth 1 info
#
 contextTags <- c("TRANSCRIPT","CODINGSEQ")
 d1Tags <- c("START", "END")
 d1vals <- rep(" ", length(contextTags)*length(d1Tags))
 d1names <- outPaste(contextTags,d1Tags)
 names(d1vals) <- d1names
#
# attribute data on gene
#
 gdata <- NULL
#
#
#
 startElement = function(x, atts, ...)
  {
  if (x == "GENE")
    gdata <<- atts
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- TRUE
  else if (x == "SNPPER-RPC")
    toolInfo <<- atts
  }
 endElement = function(x, ...) {
  if (x %in% txtTags)
    status[match(x,txtTags)] <<- FALSE
  }
 text = function(x, atts, ...) {
  if (any(status)) atoms[status==TRUE] <<- x # careful with elses!
  }
 dump = function() {
  obj <- c(atoms,gdata)
  attr(obj,"toolInfo") <- toolInfo
  obj
 }
 list(startElement=startElement, endElement=endElement, text=text,
       dump=dump)
}
.onLoad <- function(libname, pkgname) {
    require("methods")
}

# don't know where it came from, and it is causing loading
# problems -- sincerely, VJ Carey, 19 Sept 2006

#.onAttach <- function(libname, pkgname) {
#    suppressWarnings(require("Biobase")) && addVigs2WinMenu("RSNPper")
#}
