Module: CHASM

Defined in:
lib/rbbt/mutation/chasm.rb

Defined Under Namespace

Classes: NotDone

Constant Summary collapse

URL =
"http://www.cravat.us/ClassifierSelect1"
ASTERISK =
"*"[0]

Class Method Summary collapse

Class Method Details

.chunked_predict(mutations, max = 1000) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rbbt/mutation/chasm.rb', line 49

def self.chunked_predict(mutations, max = 1000)
  flattened_mutations = mutations.collect{|g,list| list = [list] unless Array === list; list.collect{|m| [g,m] } }.flatten(1)
  chunks = flattened_mutations.length.to_f / max
  chunks = chunks.ceil

  Log.debug("Mutation Assessor ran with #{chunks} chunks of #{ max } mutations") if chunks > 1
  num = 1
  Misc.divide(flattened_mutations, chunks).inject(nil) do |acc, list|
    Log.debug("Mutation Assessor ran with #{chunks} chunks: chunk #{num}") if chunks > 1
    unflattened_mutations = {}
    list.each{|g,m| next if g.nil?; unflattened_mutations[g] ||= []; unflattened_mutations[g] << m}
    if acc.nil?
      acc = predict(unflattened_mutations)
    else
      acc = TSV.setup(acc.merge(predict(unflattened_mutations)))
    end
    num += 1
    acc
  end
end

.predict(mutations_by_sample, options = {}) ⇒ Object

Hash of samples pointing to mutations specified in Ensembl Transcript ID



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rbbt/mutation/chasm.rb', line 15

def self.predict(mutations_by_sample, options = {})
  options = Misc.add_defaults options, :chosendb => "CHASM", :emailbox => '[email protected]', :analysistype => 'driver', :inputfile => nil
  mutationbox = []
  i = 1
  mutations_by_sample.each do |sample,mutations|
    mutations.each do |mutation|
      mutationbox << [i, sample].concat(mutation.split(":"))
    end
    i += 1
  end

  options[:mutationbox] = mutationbox.collect{|line| line * "\t"} * "\n"
  post_data = options.collect{|k,v| [k,v] * "="} * "&"

  Log.debug "Querying CHASM for: #{mutationbox.length} mutations in #{mutations_by_sample.length} samples"

  tries = 0
  nocache = false
  begin
    doc = nil
    TmpFile.with_file(post_data) do |post_file|
      Log.medium "Updating cache:" if nocache == :update

      url = URI.parse(URL)
      req = Net::HTTP::Post::Multipart.new url.path, options
      res = Net::HTTP.start(url.host, url.port) do |http|
        http.request(req)
      end
      job_id = JSON.parse(res.body)["jobId"]
      puts job_id
    end
  end
end