Hatena::Groupkdri

KazusaAPI開発日誌 このページをアンテナに追加 RSSフィード

2009-02-04Gendoo multi

Gendoo Galaxy Tool にヒストリから入力できるようにする

|  Gendoo Galaxy Tool にヒストリから入力できるようにする - KazusaAPI開発日誌 を含むブックマーク はてなブックマーク -  Gendoo Galaxy Tool にヒストリから入力できるようにする - KazusaAPI開発日誌  Gendoo Galaxy Tool にヒストリから入力できるようにする - KazusaAPI開発日誌 のブックマークコメント

Filter and Sort ツールの Filter (Tools/stats/filter1.xml) を参考にしました。


ソースコード

tool_conf.xml の変更分
  <section name="DBCLS Tools" id="dbcls_tools">
   <tool file="dbcls/gendoo.xml" />
   <tool file="dbcls/gendoo_multi.xml" />
  </section> 
tools/dbcls/gendoo_multi.xml
<tool id="GendooTable" name="Gendoo Table">
  <description>table browser</description>
  <command interpreter="ruby">gendoo_multi.rb $input $dsn $out_file</command>
  <inputs>
    <param format="tabular" name="input" type="data" label="Query" help="Query missing? See TIP below."/>
    <param name="dsn" type='select'>
       <label>Data Source Name (DSN)</label>
       <option value='human'>Homo sapiense</option>
       <option value='synecho'>Synechocystis sp. PCC 6803</option>
       <option value='meso'>Mesorhizobium loti MAFF303099</option>
       <option value='lotus'>Lotus japonicas</option>
    </param>
  </inputs>
  <outputs>
    <data format="input" name="out_file" metadata_source="input" />
  </outputs>
  <tests>
    <test>
    </test>
    <test>
    </test>
  </tests>
  <help>

.. class:: infomark

**TIP:** Attempting to apply a filtering condition may throw exceptions if the data type (e.g., string, integer) in every line of the columns being filtered is not app
ropriate for the condition (e.g., attempting certain numerical calculations on strings).  If an exception is thrown when applying the condition to a line, that line is
 skipped as invalid for the filter condition.  The number of invalid skipped lines is documented in the resulting history item as a "Condition/data issue".

.. class:: infomark

**TIP:** If your data is not TAB delimited, use *Text Manipulation-&gt;Convert*

-----

  </help>
</tool>



tools/dbcls/gendoo_multi.rb
require 'open-uri'

class Matcher
  def self.ig_and_pvalue
    /<td class="\S+" title="IG=(\d.*?), p-value=(\d.*?)">/
  end

  def self.meshid_and_term(dsn)
    /gendoo.cgi\?meshid=(D\d+)\&taxonomy=#{dsn}">(\w+.*?\w+)<\/a>/
  end
  
  def self.aspect
    /<h2><a name="\w+">(\w+.*?\w+)<\/a><\/h2>/
  end
end


input_file, dsn, out_file = ARGV
input = File.open(input_file).read.split("\s").map {|x| x.strip }

# http://gendoo.dbcls.jp/pre/cgi-bin/gendoo.cgi?geneid=slr1311%0D%0Aslr1312&genename=&taxonomy=synecho&submit=Search
queries = input.join("%0D%0A")
url = "http://gendoo.dbcls.jp/pre/cgi-bin/gendoo.cgi?geneid=#{queries}&genename=&taxonomy=#{dsn}&submit=Search"

text = open(url).read
i = 0
File.open(out_file, 'w') do |f|                     
  aspect = ''
  meshid = ''
  term = ''
  text.split("\n").each do |line|
    case line
    when Matcher.ig_and_pvalue
      ig = $1
      pvalue = $2
      query = input[i]
      i += 1
      i = 0 if i == input.size
      f.puts [dsn, query, meshid, aspect, term, ig, pvalue].join("\t")
    when Matcher.meshid_and_term(dsn)
      meshid = $1
      term = $2
    when Matcher.aspect
      aspect = $1
    end
  end
end
puts "Gendoo: #{input.join(',')} related diseases, drugs, ..."

01

トラックバック - http://kdri.g.hatena.ne.jp/nakao_mitsuteru/20090204