diff --git a/.yardoc/checksums b/.yardoc/checksums index 733e89f..d62f6d6 100644 --- a/.yardoc/checksums +++ b/.yardoc/checksums @@ -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 diff --git a/.yardoc/object_types b/.yardoc/object_types index 467fb84..9fb0174 100644 Binary files a/.yardoc/object_types and b/.yardoc/object_types differ diff --git a/.yardoc/objects/root.dat b/.yardoc/objects/root.dat index 45e47d8..768a41c 100644 Binary files a/.yardoc/objects/root.dat and b/.yardoc/objects/root.dat differ diff --git a/Gemfile b/Gemfile index e212456..a43f9f6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,7 @@ source "https://rubygems.org" +#ruby-2.3.0-dev gem 'rest-client' -gem 'yard' \ No newline at end of file +gem 'yard' +gem 'activeresource' +gem 'openbabel' diff --git a/Gemfile.lock b/Gemfile.lock index f77ad1b..5cabbb6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/doc/ClassyFireAPI.html b/doc/ClassyFireAPI.html index 5ba7df4..c3b7959 100644 --- a/doc/ClassyFireAPI.html +++ b/doc/ClassyFireAPI.html @@ -84,7 +84,18 @@
+

Overview

+
+ +

require 'node_resource.rb'

+ +
+
+
+ + +

Constant Summary

@@ -114,6 +125,30 @@
  • + + (Text) get_chemont_node(chemontid) + + + + + + + + + + + + + +
    +

    Return data for the TaxNode with ID chemontid.

    +
    + +
  • + + +
  • + + + (Text) get_entity_classification(inchikey, format = "json") @@ -129,7 +164,7 @@
    -

    Retrieves the classification results for a given entity.

    +

    Retrieves the classification results for a given chemical entity.

  • @@ -336,7 +371,7 @@ of a given size.

  • - + (Object) submit_query_input_in_chunks(input_file, slice_length, start, type = 'STRUCTURE') + + (Object) submit_query_input_in_chunks(input_file, slice_length = 1000, start = 1, type = 'STRUCTURE') @@ -355,31 +390,6 @@ of a given size.

    a given size.

    -
  • - - -
  • - - - + (Object) submit_random_subset_of_query_input_in_chunks(tab_separated_input_file, size, type = 'STRUCTURE') - - - - - - - - - - - - - -
    -

    Takes a tab-separated file and submit randomly selected structures in bulks -of a given size.

    -
    -
  • @@ -393,9 +403,9 @@ of a given size.

    -

    +

    - + (Text) get_entity_classification(inchikey, format = "json") + + (Text) get_chemont_node(chemontid) @@ -404,7 +414,9 @@ of a given size.

    -

    Retrieves the classification results for a given entity.

    +

    Return data for the TaxNode with ID chemontid.

    + +

    Use JSON.parse to get a the json object.

    @@ -415,7 +427,7 @@ of a given size.

  • - inchikey + chemontid (String) @@ -424,25 +436,125 @@ of a given size.

    -

    the InChIKey of the entity.

    +

    the ChemOnt ID of the entity.

    +
    + +
  • + + + +

    Returns:

    +
      + +
    • + + + (Text) + + + + — +
      +

      A text displaying the classification results for the entity in the +specified format.

      +
      + +
    • + +
    + +
    + + + + +
    +
    +
    +
    +63
    +64
    +65
    +66
    +67
    +68
    +69
    +70
    +71
    +72
    +73
    +74
    +75
    +76
    +
    +
    # File 'lib/classyfire_api.rb', line 63
    +
    +def ClassyFireAPI.get_chemont_node(chemontid)
    +  chemont_id = chemontid.to_s.gsub("CHEMONTID:","C")
    +  begin
    +    RestClient.get "#{URL}/tax_nodes/#{chemont_id}.json", :accept => :json
    +  rescue RestClient::ResourceNotFound => e
    +    e.response
    +  rescue  RestClient::InternalServerError => e
    +    e.response
    +  rescue RestClient::GatewayTimeout => e
    +    e.response
    +  rescue RestClient::RequestTimeout => e
    +    e.response
    +  end
    +end
    +
    +
    + +
    +

    + + + (Text) get_entity_classification(inchikey, format = "json") + + + + + +

    +
    + +

    Retrieves the classification results for a given chemical entity.

    + + +
    +
    +
    +

    Parameters:

    +
      + +
    • + + the + + + + + + + — +
      +

      InChIKey [String] of the entity

    • - format + The - (String) + - (defaults to: "json") - —
      -

      the format of the query, 'text' (either JSON, CSV, or SDF)

      +

      format [String] the format of the query (Only JSON)

    • @@ -475,29 +587,29 @@ specified format.

       
       
      -62
      -63
      -64
      -65
      -66
      -67
      -68
      -69
      -70
      -71
      -72
      -73
      -74
      -75
      -76
      -77
      -78
      -79
      -80
      -81
      +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 -
      # File 'lib/classyfire_api.rb', line 62
      +      
      # File 'lib/classyfire_api.rb', line 105
       
       def ClassyFireAPI.get_entity_classification(inchikey,format="json")
         inchikey_id = inchikey.to_s.gsub('InChIKey=','')
      @@ -608,7 +720,6 @@ specified format.

       
       
      -37
       38
       39
       40
      @@ -626,10 +737,11 @@ specified format.

      52 53 54 -55
      +55 +56
      -
      # File 'lib/classyfire_api.rb', line 37
      +      
      # File 'lib/classyfire_api.rb', line 38
       
       def ClassyFireAPI.get_query(query_id,format="json")
         begin
      @@ -669,6 +781,8 @@ specified format.

      Retrieves the classification results for a given sequence.

      +

      Use JSON.parse to get a the json object.

      +
    @@ -678,17 +792,16 @@ specified format.

  • - the + fingerprint - + (String)
    -

    fingerprint [String] the fingerprint (generated from the sequence using -Digest::MD5).

    +

    the fingerprint (generated from the sequence using Digest::MD5).

  • @@ -725,7 +838,7 @@ Digest::MD5).

    -

    A text file displaying the classification results for the entity in the +

    A text displaying the classification results for the entity in the specified format.

    @@ -739,6 +852,10 @@ specified format.

     
     
    +84
    +85
    +86
    +87
     88
     89
     90
    @@ -749,14 +866,10 @@ specified format.

    95 96 97 -98 -99 -100 -101 -102
    +98 -
    # File 'lib/classyfire_api.rb', line 88
    +      
    # File 'lib/classyfire_api.rb', line 84
     
     def ClassyFireAPI.get_sequence_classification(fingerprint,format="json")
       begin
    @@ -842,17 +955,17 @@ specified format.

     
     
    -129
     130
     131
     132
     133
     134
     135
    -136
    +136 +137
    -
    # File 'lib/classyfire_api.rb', line 129
    +      
    # File 'lib/classyfire_api.rb', line 130
     
     def ClassyFireAPI.query_status(query_id)
       begin
    @@ -932,72 +1045,71 @@ retrieve the strutcure's classification from ClassyFire.

     
     
    +256
    +257
    +258
    +259
    +260
    +261
    +262
    +263
    +264
    +265
    +266
    +267
    +268
    +269
    +270
    +271
    +272
    +273
    +274
    +275
    +276
    +277
    +278
    +279
    +280
    +281
    +282
    +283
    +284
    +285
    +286
    +287
    +288
    +289
    +290
    +291
    +292
    +293
    +294
    +295
    +296
    +297
    +298
    +299
    +300
    +301
    +302
    +303
    +304
    +305
    +306
    +307
    +308
    +309
    +310
     311
     312
     313
     314
     315
     316
    -317
    -318
    -319
    -320
    -321
    -322
    -323
    -324
    -325
    -326
    -327
    -328
    -329
    -330
    -331
    -332
    -333
    -334
    -335
    -336
    -337
    -338
    -339
    -340
    -341
    -342
    -343
    -344
    -345
    -346
    -347
    -348
    -349
    -350
    -351
    -352
    -353
    -354
    -355
    -356
    -357
    -358
    -359
    -360
    -361
    -362
    -363
    -364
    -365
    -366
    -367
    -368
    -369
    -370
    -371
    -372
    -373
    +317
    -
    # File 'lib/classyfire_api.rb', line 311
    +      
    # File 'lib/classyfire_api.rb', line 256
     
     def ClassyFireAPI.retrieve_classification(input,output)
       absolute_path = File.expand_path(input)
    @@ -1058,7 +1170,6 @@ retrieve the strutcure's classification from ClassyFire.

    e.message end end - res += "]}" f_output.print res end
    @@ -1133,63 +1244,63 @@ format.

     
     
    -380
    -381
    -382
    -383
    -384
    -385
    -386
    -387
    -388
    -389
    -390
    -391
    -392
    -393
    -394
    -395
    -396
    -397
    -398
    -399
    -400
    -401
    -402
    -403
    -404
    -405
    -406
    -407
    -408
    -409
    -410
    -411
    -412
    -413
    -414
    -415
    -416
    -417
    -418
    -419
    -420
    -421
    -422
    -423
    -424
    -425
    -426
    -427
    -428
    -429
    -430
    -431
    -432
    -433
    +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377
    -
    # File 'lib/classyfire_api.rb', line 380
    +      
    # File 'lib/classyfire_api.rb', line 324
     
     def ClassyFireAPI.retrieve_entities_json(input,output)
       absolute_path = File.expand_path(input)
    @@ -1216,7 +1327,7 @@ format.

    puts i # puts "#{key} :: #{h[key]}" begin - inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip + inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0] # puts inchikey qr = JSON.parse(ClassyFireAPI.get_entity_classification(inchikey,format="json")) qr['identifier'] = key @@ -1231,7 +1342,7 @@ format.

    key = h.keys[-1] # puts "#{key} :: #{h[key]}" begin - inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip + inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0] # puts inchikey qr = JSON.parse(ClassyFireAPI.get_entity_classification(inchikey,format="json")) qr['identifier'] = key @@ -1316,69 +1427,67 @@ format.

     
     
    +386
    +387
    +388
    +389
    +390
    +391
    +392
    +393
    +394
    +395
    +396
    +397
    +398
    +399
    +400
    +401
    +402
    +403
    +404
    +405
    +406
    +407
    +408
    +409
    +410
    +411
    +412
    +413
    +414
    +415
    +416
    +417
    +418
    +419
    +420
    +421
    +422
    +423
    +424
    +425
    +426
    +427
    +428
    +429
    +430
    +431
    +432
    +433
    +434
    +435
    +436
    +437
    +438
    +439
    +440
    +441
     442
    -443
    -444
    -445
    -446
    -447
    -448
    -449
    -450
    -451
    -452
    -453
    -454
    -455
    -456
    -457
    -458
    -459
    -460
    -461
    -462
    -463
    -464
    -465
    -466
    -467
    -468
    -469
    -470
    -471
    -472
    -473
    -474
    -475
    -476
    -477
    -478
    -479
    -480
    -481
    -482
    -483
    -484
    -485
    -486
    -487
    -488
    -489
    -490
    -491
    -492
    -493
    -494
    -495
    -496
    -497
    -498
    -499
    -500
    -501
    +443
    -
    # File 'lib/classyfire_api.rb', line 442
    +      
    # File 'lib/classyfire_api.rb', line 386
     
     def ClassyFireAPI.retrieve_entities_sdf(input,output)
       absolute_path = File.expand_path(input)
    @@ -1400,7 +1509,7 @@ format.

    puts i # puts "#{key} :: #{h[key]}" begin - inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip + inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0] # puts inchikey qr = ClassyFireAPI.get_entity_classification(inchikey,format="sdf") if qr.include?("The page you were looking for doesn't exist") @@ -1419,9 +1528,8 @@ format.

    i += 1 end key = h.keys[-1] - # puts "#{key} :: #{h[key]}" - begin - inchikey = %x(/Applications/ChemAxon/JChem/bin/molconvert inchikey -s "#{h[key]}").strip + begin + inchikey = %x(obabel -:"#{h[key]}" -oinchikey).strip.split("\t")[0] # puts inchikey qr = ClassyFireAPI.get_entity_classification(inchikey,format="sdf") if qr.include?("The page you were looking for doesn't exist") @@ -1438,8 +1546,7 @@ format.

    e.message end end - # f_output.print res -end
    +end
    @@ -1509,19 +1616,19 @@ slice_length [Integer] The maximum number of entries for each query input
     
     
    -229
    -230
    -231
    -232
    -233
    -234
    -235
    -236
    -237
    -238
    +239 +240 +241 +242 +243 +244 +245 +246 +247 +248
    -
    # File 'lib/classyfire_api.rb', line 229
    +      
    # File 'lib/classyfire_api.rb', line 239
     
     def ClassyFireAPI.submit_queries_from_directory(folder,slice_length,type="STRUCTURE")
       if File.directory?(folder)
    @@ -1552,7 +1659,7 @@ slice_length [Integer] The maximum number of entries for each query input
         
     

    Submits a ClassyFire query in a JSON format.

    -

    if there is an error.

    +

    if there is an error. Use JSON.parse to get a the json object.

    @@ -1638,7 +1745,6 @@ slice_length [Integer] The maximum number of entries for each query input
     
     
    -14
     15
     16
     17
    @@ -1653,10 +1759,11 @@ slice_length [Integer] The maximum number of entries for each query input
     26
     27
     28
    -29
    +29 +30
    -
    # File 'lib/classyfire_api.rb', line 14
    +      
    # File 'lib/classyfire_api.rb', line 15
     
     def ClassyFireAPI.submit_query(label,input, type='STRUCTURE')
       begin
    @@ -1682,7 +1789,7 @@ slice_length [Integer] The maximum number of entries for each query input
           

    - + (Object) submit_query_input_in_chunks(input_file, slice_length, start, type = 'STRUCTURE') + + (Object) submit_query_input_in_chunks(input_file, slice_length = 1000, start = 1, type = 'STRUCTURE') @@ -1740,7 +1847,6 @@ framgments from the index 'start'.

     
     
    -151
     152
     153
     154
    @@ -1803,49 +1909,68 @@ framgments from the index 'start'.

    211 212 213 -214
    +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224

    -
    # File 'lib/classyfire_api.rb', line 151
    +      
    # File 'lib/classyfire_api.rb', line 152
     
    -def ClassyFireAPI.submit_query_input_in_chunks(input_file,slice_length, start, type='STRUCTURE')
    +def ClassyFireAPI.submit_query_input_in_chunks(input_file,slice_length=1000, start=1, type='STRUCTURE')
       @start_time = Time.now
       absolute_path = File.expand_path(input_file)
       f             = File.open(absolute_path, 'r')
       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[0]}\t#{sline[1]}"
    +    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 = 120
    -  initial_nr_of_jobs = 60
    +  # 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}"
    +
    +    title = File.basename(absolute_path).split(".")[0] + "_yannick" + "_part_#{i}"
     
         if i <= subdivised_groups.length
    -      begin
    -        puts "submitting #{title}"
    +      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)
    -        query_ids << JSON.parse(q)['id']
    -      rescue Exception => e  
    -        puts e.message  
    -        puts e.backtrace.inspect
    -      end
    -      i = i + 1
    +        # puts q
    +        query_ids << JSON.parse(q)['id']
    +      # rescue Exception => e  
    +        # puts e.message  
    +        # puts e.backtrace.inspect
    +      # end
    +      i = i + 1
    +    else
    +      break
         end
       end
     
    @@ -1853,9 +1978,9 @@ framgments from the index 'start'.

    sleep(sleeping_time) puts "Waking up at #{Time.now - @start_time}" - while i < subdivised_groups.length + 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 @@ -1875,210 +2000,6 @@ framgments from the index 'start'.

    - - -
    -

    - - + (Object) submit_random_subset_of_query_input_in_chunks(tab_separated_input_file, size, type = 'STRUCTURE') - - - - - -

    -
    - -

    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. is fragmented into n part of #slice_length entries each).

    - - -
    -
    -
    -

    Parameters:

    -
      - -
    • - - tab_separated_input_file - - - (Text) - - - - — -
      -

      The path to the input file.

      -
      - -
    • - -
    • - - size - - - (Integer) - - - - — -
      -

      The maximum number of entries for each query input (the whole file

      -
      - -
    • - -
    • - - type - - - (String) - - - (defaults to: 'STRUCTURE') - - - — -
      -

      The query_type, 'STRUCTURE' (default) or 'IUPAC_NAME' or -'FASTA'.

      -
      - -
    • - -
    - - -
    - - - - -
    -
    -
    -
    -254
    -255
    -256
    -257
    -258
    -259
    -260
    -261
    -262
    -263
    -264
    -265
    -266
    -267
    -268
    -269
    -270
    -271
    -272
    -273
    -274
    -275
    -276
    -277
    -278
    -279
    -280
    -281
    -282
    -283
    -284
    -285
    -286
    -287
    -288
    -289
    -290
    -291
    -292
    -293
    -294
    -295
    -296
    -297
    -298
    -299
    -300
    -301
    -302
    -303
    -304
    -
    -
    # File 'lib/classyfire_api.rb', line 254
    -
    -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
    -
    @@ -2086,9 +2007,9 @@ text. is fragmented into n part of #slice_length entries each).

    diff --git a/doc/EntityResource.html b/doc/EntityResource.html index a5202f3..4ee04f2 100644 --- a/doc/EntityResource.html +++ b/doc/EntityResource.html @@ -114,9 +114,9 @@ diff --git a/doc/NodeResource.html b/doc/NodeResource.html new file mode 100644 index 0000000..6b53e22 --- /dev/null +++ b/doc/NodeResource.html @@ -0,0 +1,123 @@ + + + + + + Class: NodeResource + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

    Class: NodeResource + + + +

    + +
    + +
    Inherits:
    +
    + ActiveResource::Base + +
      +
    • Object
    • + + + + + +
    + show all + +
    + + + + + + + + + +
    Defined in:
    +
    lib/node_resource.rb
    + +
    +
    + + + + + + + + + + + +
    + + + + + \ No newline at end of file diff --git a/doc/QueryResource.html b/doc/QueryResource.html index 6538bb0..d18afef 100644 --- a/doc/QueryResource.html +++ b/doc/QueryResource.html @@ -183,9 +183,9 @@ diff --git a/doc/SequenceResource.html b/doc/SequenceResource.html index c1c1a8e..85f2f64 100644 --- a/doc/SequenceResource.html +++ b/doc/SequenceResource.html @@ -114,9 +114,9 @@ diff --git a/doc/_index.html b/doc/_index.html index 64f3f27..83cb277 100644 --- a/doc/_index.html +++ b/doc/_index.html @@ -106,6 +106,19 @@ + + +
    • Q
      • @@ -140,9 +153,9 @@ diff --git a/doc/class_list.html b/doc/class_list.html index f7d10fd..335b2b6 100644 --- a/doc/class_list.html +++ b/doc/class_list.html @@ -50,7 +50,7 @@ diff --git a/doc/file.README.html b/doc/file.README.html index c669d32..745a073 100644 --- a/doc/file.README.html +++ b/doc/file.README.html @@ -236,9 +236,9 @@ XML format.

        diff --git a/doc/index.html b/doc/index.html index c669d32..78ac5a8 100644 --- a/doc/index.html +++ b/doc/index.html @@ -236,9 +236,9 @@ XML format.

        diff --git a/doc/method_list.html b/doc/method_list.html index 8a94711..b3ba1fa 100644 --- a/doc/method_list.html +++ b/doc/method_list.html @@ -52,67 +52,67 @@
      • + get_chemont_node + ClassyFireAPI +
      • + + +
      • get_entity_classification ClassyFireAPI
      • -
      • +
      • get_query ClassyFireAPI
      • -
      • +
      • get_sequence_classification ClassyFireAPI
      • -
      • +
      • query_status ClassyFireAPI
      • -
      • +
      • retrieve_classification ClassyFireAPI
      • -
      • +
      • retrieve_entities_json ClassyFireAPI
      • -
      • +
      • retrieve_entities_sdf ClassyFireAPI
      • -
      • +
      • submit_queries_from_directory ClassyFireAPI
      • -
      • +
      • submit_query ClassyFireAPI
      • -
      • - submit_query_input_in_chunks - ClassyFireAPI -
      • - -
      • - submit_random_subset_of_query_input_in_chunks + submit_query_input_in_chunks ClassyFireAPI
      • diff --git a/doc/top-level-namespace.html b/doc/top-level-namespace.html index 5468c69..74fd85a 100644 --- a/doc/top-level-namespace.html +++ b/doc/top-level-namespace.html @@ -89,7 +89,7 @@ - Classes: EntityResource, QueryResource, SequenceResource + Classes: EntityResource, NodeResource, QueryResource, SequenceResource

        @@ -105,9 +105,9 @@ diff --git a/lib/classyfire_api.rb b/lib/classyfire_api.rb index 6c86705..b24f8ae 100644 --- a/lib/classyfire_api.rb +++ b/lib/classyfire_api.rb @@ -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< 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 \ No newline at end of file +end + +if __FILE__ == $0 + +end diff --git a/lib/node_resource.rb b/lib/node_resource.rb new file mode 100644 index 0000000..1d7915c --- /dev/null +++ b/lib/node_resource.rb @@ -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 \ No newline at end of file