<commit_before>#
# = bio/shell/plugin/keggapi.rb - plugin for KEGG API
#
# Copyright::   Copyright (C) 2005
#               <NAME> <<EMAIL>>
# License::     Ruby's
#
# $Id: keggapi.rb,v 1.10 2006/02/09 20:48:53 k Exp $
#

module Bio::Shell

  module Private
    def keggapi_definition2tab(list)
      ary = []
      list.each do |entry|
        ary << "#{entry.entry_id}:\t#{entry.definition}"
      end
      return ary
    end
  end

  private

  def keggapi(wsdl = nil)
    if wsdl
      @keggapi = Bio::KEGG::API.new(wsdl)
    else
      @keggapi ||= Bio::KEGG::API.new
    end
    return @keggapi
  end

  # DBGET

  def binfo(db = "all")
    result = keggapi.binfo(db)
    puts result
    return result
  end

  def bfind(str)
    result = keggapi.bfind(str)
    return result
  end

  def bget(str)
    result = keggapi.bget(str)
    if block_given?
      yield result
    else
      return result
    end
  end

  def btit(str)
    result = keggapi.btit(str)
    return result
  end

  def bconv(str)
    result = keggapi.bconv(str)
    return result
  end

  # DATABASES

  def keggdbs
    list = keggapi.list_databases
    result = Bio::Shell.keggapi_definition2tab(list).join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  def keggorgs
    list = keggapi.list_organisms
    result = Bio::Shell.keggapi_definition2tab(list).sort.join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  def keggpathways(org = "map")
    list = keggapi.list_pathways(org)
    result = Bio::Shell.keggapi_definition2tab(list).join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  def kegggenomeseq(org)
    result = ""
    require 'net/ftp'
    Net::FTP.open("ftp.genome.jp", "anonymous") do |ftp|
      path = "/pub/kegg/genomes/#{org}"
      list = ftp.nlst(path)
      file = list.grep(/.*genome$/).shift
      if file<commit_msg>* Bio::Shell::Private module is nolonger extended to Bio::Shell<commit_after>#
# = bio/shell/plugin/keggapi.rb - plugin for KEGG API
#
# Copyright::   Copyright (C) 2005
#               <NAME> <<EMAIL>>
# License::     Ruby's
#
# $Id: keggapi.rb,v 1.11 2006/12/24 08:49:12 k Exp $
#

module Bio::Shell

  module Private

    module_function

    def keggapi_definition2tab(list)
      ary = []
      list.each do |entry|
        ary << "#{entry.entry_id}\t#{entry.definition}"
      end
      return ary
    end
  end

  private

  def keggapi(wsdl = nil)
    if wsdl
      @keggapi = Bio::KEGG::API.new(wsdl)
    else
      @keggapi ||= Bio::KEGG::API.new
    end
    return @keggapi
  end

  # DBGET

  def binfo(db = "all")
    result = keggapi.binfo(db)
    puts result
    return result
  end

  def bfind(str)
    result = keggapi.bfind(str)
    return result
  end

  def bget(str)
    result = keggapi.bget(str)
    if block_given?
      yield result
    else
      puts result
      return result
    end
  end

  def btit(str)
    result = keggapi.btit(str)
    puts result
    return result
  end

  def bconv(str)
    result = keggapi.bconv(str)
    puts result
    return result
  end

  # DATABASES

  def keggdbs
    list = keggapi.list_databases
    result = Bio::Shell::Private.keggapi_definition2tab(list).join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  def keggorgs
    list = keggapi.list_organisms
    result = Bio::Shell::Private.keggapi_definition2tab(list).sort.join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  def keggpathways(org = "map")
    list = keggapi.list_pathways(org)
    result = Bio::Shell::Private.keggapi_definition2tab(list).join("\n")
    puts result
    return list.map {|x| x.entry_id}
  end

  # use KEGG DAS insetad
  def kegggenomeseq(org)
    result = ""
    require 'net/ftp'
    Net::FTP.open("ftp.genome.jp", "anonymous") do |ftp|
      path = "/pub/kegg/genomes/#{org}"
      list = ftp.nlst(path)
      file = list.grep(/.*genome$/).shift
      if file
{'fraction_non_alphanumeric': 0.12382405288583778, 'fraction_numerical': 0.012712941774726672, 'mean_word_length': 2.48141592920354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2862997', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1465, 'n_words': 329}