[Seqinr-commits] r1704 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 12 19:10:24 CET 2009


Author: lobry
Date: 2009-11-12 19:10:24 +0100 (Thu, 12 Nov 2009)
New Revision: 1704

Added:
   pkg/R/where.is.this.acc.R
Log:
looking for an accession number utility

Added: pkg/R/where.is.this.acc.R
===================================================================
--- pkg/R/where.is.this.acc.R	                        (rev 0)
+++ pkg/R/where.is.this.acc.R	2009-11-12 18:10:24 UTC (rev 1704)
@@ -0,0 +1,52 @@
+where.is.this.acc <- function(acc, ...){
+	#
+	# Argument check:
+	#
+  if(!is.character(acc)) stop("string expected for argument acc")
+  #
+  result <- character(0)
+  #
+  cat("Looking for available databases\n")  
+  banks <- choosebank(...)
+  nbanks <- length(banks)
+  cat(paste("Looking for sequence with accession number", acc,
+  "in the following ACNUC databases:\n"))
+  print(banks)
+  #
+  # Looping over banks:
+  #
+  for(i in seq_len(nbanks)){
+  	  cat(paste("\nTrying to open bank with name --->", banks[i], 
+  	  "<--- ...", sep = ""))
+    bkopenres <- try(choosebank(banks[i]))
+    if(inherits(bkopenres, "try-error")){
+      cat("... opening not OK, skipping this bank.\n")
+  } else {
+    cat("... and opening was OK.\n")
+    cat(paste("==> Trying to find sequence", acc, "in bank", 
+      banks[i], "..."))
+    resquery <- try(query(".tmpquery", paste("AC=", acc)), silent = TRUE)
+    if(inherits(resquery, "try-error")){
+    	 cat("... not found here.\n")
+    } else {
+      cat("... *** FOUND *** here.\n")
+      result <- c(result, banks[i])
+    }
+    closebank()
+  }
+}
+#
+# Print result summary:
+#
+  cat("\n\n")
+  if(length(result) == 0){
+  	  cat(paste("Sequence with accesion number", acc, 
+  	  "was not found in available databases."))
+  	} else {
+    cat(paste("Sequence with accesion number", acc, 
+    "was found in the following database(s):\n"))
+    print(result)
+  }
+  invisible(result)
+}
+



More information about the Seqinr-commits mailing list