- updated the documentation

- added onpenbabel gem (but still issues with need. (so users still need to download and install obabel)
This commit is contained in:
djoumbou 2016-06-28 15:52:27 -06:00
parent e6a10deb22
commit 7b532839d9
18 changed files with 669 additions and 632 deletions

View File

@ -1,4 +1,5 @@
lib/classyfire_api.rb 3449cdc9aef5fb255b1fdc933f7d7653bb1fa960
lib/node_resource.rb 91abffbffddd88d43c4fd5408272fa112e053b8d
lib/classyfire_api.rb af1ffb46316f8e1ef09996ab2ca92f19be33c444
lib/query_resource.rb 645cfb1688a5c44e67e5227fc0e9a77589731f24
lib/entity_resource.rb 6c50b4be6a5eb13b44d7080b19c7033b7a37c7cf
lib/sequence_resource.rb d8c5007781d50d0bc13cbe360b617e2937a19428

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,7 @@
source "https://rubygems.org"
#ruby-2.3.0-dev
gem 'rest-client'
gem 'yard'
gem 'yard'
gem 'activeresource'
gem 'openbabel'

View File

@ -1,16 +1,39 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.6)
activesupport (= 4.2.6)
builder (~> 3.1)
activeresource (4.1.0)
activemodel (~> 4.0)
activesupport (~> 4.0)
rails-observers (~> 0.1.2)
activesupport (4.2.6)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
builder (3.2.2)
domain_name (0.5.20160309)
unf (>= 0.0.5, < 1.0.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
i18n (0.7.0)
json (1.8.3)
mime-types (2.99.1)
minitest (5.9.0)
netrc (0.11.0)
openbabel (2.3.2.2)
rails-observers (0.1.2)
activemodel (~> 4.0)
rest-client (1.8.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
@ -20,6 +43,8 @@ PLATFORMS
ruby
DEPENDENCIES
activeresource
openbabel
rest-client
yard

File diff suppressed because it is too large Load Diff

View File

@ -114,9 +114,9 @@
</div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

123
doc/NodeResource.html Normal file
View File

@ -0,0 +1,123 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: NodeResource
&mdash; Documentation by YARD 0.8.7.6
</title>
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '';
framesUrl = "frames.html#!NodeResource.html";
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="_index.html">Index (N)</a> &raquo;
<span class="title">NodeResource</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Class: NodeResource
</h1>
<dl class="box">
<dt class="r1">Inherits:</dt>
<dd class="r1">
<span class="inheritName">ActiveResource::Base</span>
<ul class="fullTree">
<li>Object</li>
<li class="next">ActiveResource::Base</li>
<li class="next">NodeResource</li>
</ul>
<a href="#" class="inheritanceTree">show all</a>
</dd>
<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">lib/node_resource.rb</dd>
</dl>
<div class="clear"></div>
</div>
<div id="footer">
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.4.0).
</div>
</body>
</html>

View File

@ -183,9 +183,9 @@
</div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -114,9 +114,9 @@
</div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -106,6 +106,19 @@
</ul>
<ul id="alpha_N" class="alpha">
<li class="letter">N</li>
<ul>
<li>
<span class='object_link'><a href="NodeResource.html" title="NodeResource (class)">NodeResource</a></span>
</li>
</ul>
</ul>
<ul id="alpha_Q" class="alpha">
<li class="letter">Q</li>
<ul>
@ -140,9 +153,9 @@
</div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:58 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -50,7 +50,7 @@
<ul id="full_list" class="class">
<li><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></li>
<li><span class='object_link'><a href="ClassyFireAPI.html" title="ClassyFireAPI (module)">ClassyFireAPI</a></span><small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="EntityResource.html" title="EntityResource (class)">EntityResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="QueryResource.html" title="QueryResource (class)">QueryResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="SequenceResource.html" title="SequenceResource (class)">SequenceResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li>
<li><span class='object_link'><a href="ClassyFireAPI.html" title="ClassyFireAPI (module)">ClassyFireAPI</a></span><small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="EntityResource.html" title="EntityResource (class)">EntityResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="NodeResource.html" title="NodeResource (class)">NodeResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="QueryResource.html" title="QueryResource (class)">QueryResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li><li><span class='object_link'><a href="SequenceResource.html" title="SequenceResource (class)">SequenceResource</a></span> &lt; Base<small class='search_info'>Top Level Namespace</small></li>
</ul>
</div>

View File

@ -236,9 +236,9 @@ XML format.</p>
</div></div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -236,9 +236,9 @@ XML format.</p>
</div></div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:58 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -52,67 +52,67 @@
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#get_chemont_node-class_method" title="ClassyFireAPI.get_chemont_node (method)">get_chemont_node</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#get_entity_classification-class_method" title="ClassyFireAPI.get_entity_classification (method)">get_entity_classification</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#get_query-class_method" title="ClassyFireAPI.get_query (method)">get_query</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r1 ">
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#get_sequence_classification-class_method" title="ClassyFireAPI.get_sequence_classification (method)">get_sequence_classification</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#query_status-class_method" title="ClassyFireAPI.query_status (method)">query_status</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r1 ">
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#retrieve_classification-class_method" title="ClassyFireAPI.retrieve_classification (method)">retrieve_classification</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#retrieve_entities_json-class_method" title="ClassyFireAPI.retrieve_entities_json (method)">retrieve_entities_json</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r1 ">
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#retrieve_entities_sdf-class_method" title="ClassyFireAPI.retrieve_entities_sdf (method)">retrieve_entities_sdf</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#submit_queries_from_directory-class_method" title="ClassyFireAPI.submit_queries_from_directory (method)">submit_queries_from_directory</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r1 ">
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#submit_query-class_method" title="ClassyFireAPI.submit_query (method)">submit_query</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r2 ">
<span class='object_link'><a href="ClassyFireAPI.html#submit_query_input_in_chunks-class_method" title="ClassyFireAPI.submit_query_input_in_chunks (method)">submit_query_input_in_chunks</a></span>
<small>ClassyFireAPI</small>
</li>
<li class="r1 ">
<span class='object_link'><a href="ClassyFireAPI.html#submit_random_subset_of_query_input_in_chunks-class_method" title="ClassyFireAPI.submit_random_subset_of_query_input_in_chunks (method)">submit_random_subset_of_query_input_in_chunks</a></span>
<span class='object_link'><a href="ClassyFireAPI.html#submit_query_input_in_chunks-class_method" title="ClassyFireAPI.submit_query_input_in_chunks (method)">submit_query_input_in_chunks</a></span>
<small>ClassyFireAPI</small>
</li>

View File

@ -89,7 +89,7 @@
<strong class="classes">Classes:</strong> <span class='object_link'><a href="EntityResource.html" title="EntityResource (class)">EntityResource</a></span>, <span class='object_link'><a href="QueryResource.html" title="QueryResource (class)">QueryResource</a></span>, <span class='object_link'><a href="SequenceResource.html" title="SequenceResource (class)">SequenceResource</a></span>
<strong class="classes">Classes:</strong> <span class='object_link'><a href="EntityResource.html" title="EntityResource (class)">EntityResource</a></span>, <span class='object_link'><a href="NodeResource.html" title="NodeResource (class)">NodeResource</a></span>, <span class='object_link'><a href="QueryResource.html" title="QueryResource (class)">QueryResource</a></span>, <span class='object_link'><a href="SequenceResource.html" title="SequenceResource (class)">SequenceResource</a></span>
</p>
@ -105,9 +105,9 @@
</div>
<div id="footer">
Generated on Thu Mar 10 15:54:06 2016 by
Generated on Tue Jun 28 15:46:59 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.3.0).
0.8.7.6 (ruby-2.4.0).
</div>
</body>

View File

@ -1,17 +1,18 @@
require 'JSON'
require 'csv'
require 'rest-client'
require 'openbabel'
# require 'node_resource.rb'
module ClassyFireAPI
URL = 'http://classyfire.wishartlab.com'
# Submits a ClassyFire query in a JSON format.
#
# @param label [String] the label of the query.
# @param input [String] the input of the query.
# @param type [String] the type of the query.
# @return [Hash] A Ruby Hash with the id (and other attributes) of the Query or nil
# if there is an error.
# if there is an error. Use JSON.parse to get a the json object.
def ClassyFireAPI.submit_query(label,input, type='STRUCTURE')
begin
q = RestClient.post URL+'/queries', {:label => label, :query_input => input, :query_type => type}.to_json, :accept => :json, :content_type => :json
@ -55,21 +56,15 @@ module ClassyFireAPI
end
end
# Retrieves the classification results for a given entity.
# Return data for the TaxNode with ID chemontid.
#
# @param inchikey [String] the InChIKey of the entity.
# @param format [String] the format of the query, 'text' (either JSON, CSV, or SDF)
# @return [Text] A text file displaying the classification results for the entity in the specified format.
def ClassyFireAPI.get_entity_classification(inchikey,format="json")
# inchikey_id = inchikey.to_s.gsub('InChIKey=','')
# @param chemontid [String] the ChemOnt ID of the entity.
# @return [Text] A text displaying the classification results for the entity in the specified format.
# Use JSON.parse to get a the json object.
def ClassyFireAPI.get_chemont_node(chemontid)
chemont_id = chemontid.to_s.gsub("CHEMONTID:","C")
begin
if format == "json"
RestClient.get "#{URL}/entities/#{inchikey}.#{format}", :accept => :json
elsif format == "sdf"
RestClient.get "#{URL}/entities/#{inchikey}.#{format}", :accept => :sdf
elsif format == "csv"
RestClient.get "#{URL}/entities/#{inchikey}.#{format}", :accept => :csv
end
RestClient.get "#{URL}/tax_nodes/#{chemont_id}.json", :accept => :json
rescue RestClient::ResourceNotFound => e
e.response
rescue RestClient::InternalServerError => e
@ -83,9 +78,10 @@ module ClassyFireAPI
# Retrieves the classification results for a given sequence.
#
# @param the fingerprint [String] the fingerprint (generated from the sequence using Digest::MD5).
# @param fingerprint [String] the fingerprint (generated from the sequence using Digest::MD5).
# @param format [String] the format of the query (Only JSON)
# @return [Text] A text file displaying the classification results for the entity in the specified format.
# @return [Text] A text displaying the classification results for the entity in the specified format.
# Use JSON.parse to get a the json object.
def ClassyFireAPI.get_sequence_classification(fingerprint,format="json")
begin
if format == "json"
@ -102,6 +98,11 @@ module ClassyFireAPI
end
end
# Retrieves the classification results for a given chemical entity.
#
# @param the InChIKey [String] of the entity
# @param The format [String] the format of the query (Only JSON)
# @return [Text] A text file displaying the classification results for the entity in the specified format.
def ClassyFireAPI.get_entity_classification(inchikey,format="json")
inchikey_id = inchikey.to_s.gsub('InChIKey=','')
begin
@ -156,36 +157,43 @@ module ClassyFireAPI
input = []
lines = File.readlines(absolute_path)
i = 0
lines.uniq.each do |line|
i += 1
sline = line.strip.split("\t")
if sline.length == 1
input <<"#{sline[0]}"
elsif sline.length >= 2
input <<"#{sline[1]}\t#{sline[0]}"
elsif sline.length == 2
#ID\tSMILES (OR INCHI, OR VALID IUPAC NAME)
input <<"#{sline[0]}\t#{sline[1]}"
end
input <<"#{sline[0]}"
end
query_ids = []
subdivised_groups = input.uniq.each_slice(slice_length).to_a
puts "nr of subdivised_groups: #{subdivised_groups.length}"
puts subdivised_groups[0]
sleeping_time = 360
initial_nr_of_jobs = 40
# puts subdivised_groups[0]
sleeping_time = 240
initial_nr_of_jobs = 30
i = start
while i < initial_nr_of_jobs
title = File.basename(absolute_path).split(".")[0] + "_yannick" + "_part_#{i}"
if i <= subdivised_groups.length
begin
puts "\n\n\n\n---------------------- -----------"
# begin
puts "submitting #{title}"
puts subdivised_groups[i-1].join("\n")
q = submit_query(title,subdivised_groups[i-1].join("\n"),type)
# puts q
query_ids << JSON.parse(q)['id']
rescue Exception => e
puts e.message
puts e.backtrace.inspect
end
# rescue Exception => e
# puts e.message
# puts e.backtrace.inspect
# end
i = i + 1
else
break
@ -198,7 +206,7 @@ module ClassyFireAPI
while i >= initial_nr_of_jobs && i < subdivised_groups.length
k = 0
for k in (i..(i+80))
for k in (i..(i + initial_nr_of_jobs))
title = File.basename(absolute_path).split(".")[0] + "_yannick" + "_part_#{k}"
i = i + 1
begin
@ -241,71 +249,6 @@ module ClassyFireAPI
end
# Takes a tab-separated file and submit randomly selected structures in bulks of a given size.
#
# For 'STRUCTURE' or 'IUPAC_NAME'query types, each line must contain either
# 1) Only a structural represenation: SMILES, InChI for the 'STRUCTURE' query_type or a IUPAC name
# for the 'IUPAC NAME' query type.
# 2) a tab-separated pair of an ID and the corresponding sructure representation: SMILES, InChI for the
# 'STRUCTURE' query_type or a IUPAC name for the 'IUPAC NAME' query type.
#
# For 'FASTA' query type, just submit the query as a standard FASTA text.
# @param tab_separated_input_file [Text] The path to the input file.
# @param size [Integer] The maximum number of entries for each query input (the whole file
# is fragmented into n part of #slice_length entries each).
# @param type [String] The query_type, 'STRUCTURE' (default) or 'IUPAC_NAME' or 'FASTA'.
def ClassyFireAPI.submit_random_subset_of_query_input_in_chunks(tab_separated_input_file,size, type='STRUCTURE')
@start_time = Time.now
absolute_path = File.expand_path(tab_separated_input_file)
f = File.open(absolute_path, 'r')
input = []
f.each_line do |line|
sline = line.strip.split("\t")
if sline.length == 1
input <<"#{sline[0]}"
elsif sline.length == 2
input <<"#{sline[0]}\t#{sline[1]}"
end
end
query_ids = []
indexes = []
r = 1
while r <= (size)
s = rand(0..(input.length - 1))
unless indexes.include?(s)
indexes<<s
r += 1
end
end
random_subset = indexes.map{|x| input[x]}
subdivised_groups = random_subset.each_slice(100).to_a
sleeping_time = 120
i = 0
while i < subdivised_groups.length
k = 0
for k in (i..(i + 5))
title = File.basename(absolute_path).split(".")[0] + "_yannick" + "_part_#{k+1}"
i = i + 1
begin
puts "submitting #{title}"
q = submit_query(title,subdivised_groups[k].join("\n"),type)
rescue Exception => e
puts e.message
puts e.backtrace.inspect
end
end
i = k
puts "Going to sleep at #{Time.now - @start_time} for #{sleeping_time} s."
sleep(sleeping_time)
puts "Waking up at #{Time.now - @start_time}"
end
end
# Reads a tab separated file, and use the structure representation
#to retrieve the strutcure's classification from ClassyFire.
#
@ -405,7 +348,6 @@ module ClassyFireAPI
# puts "#{key} :: #{h[key]}"
begin
inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0]
# inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip
# puts inchikey
qr = JSON.parse(ClassyFireAPI.get_entity_classification(inchikey,format="json"))
qr['identifier'] = key
@ -421,7 +363,6 @@ module ClassyFireAPI
# puts "#{key} :: #{h[key]}"
begin
inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0]
# inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip
# puts inchikey
qr = JSON.parse(ClassyFireAPI.get_entity_classification(inchikey,format="json"))
qr['identifier'] = key
@ -464,7 +405,6 @@ module ClassyFireAPI
# puts "#{key} :: #{h[key]}"
begin
inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0]
# inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip
# puts inchikey
qr = ClassyFireAPI.get_entity_classification(inchikey,format="sdf")
if qr.include?("The page you were looking for doesn't exist")
@ -485,7 +425,6 @@ module ClassyFireAPI
key = h.keys[-1]
begin
inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0]
# inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip
# puts inchikey
qr = ClassyFireAPI.get_entity_classification(inchikey,format="sdf")
if qr.include?("The page you were looking for doesn't exist")
@ -503,4 +442,8 @@ module ClassyFireAPI
end
end
end
end
end
if __FILE__ == $0
end

8
lib/node_resource.rb Normal file
View File

@ -0,0 +1,8 @@
require 'active_resource'
require 'rest-client'
class NodeResource < ActiveResource::Base
self.site ='http://classyfire.wishartlab.com'
self.element_name = "tax_node"
has_many :entities, class_name: 'EntityResource'
end