Module: TransFIC
- Defined in:
- lib/rbbt/mutation/transFIC.rb
Defined Under Namespace
Classes: NotDone
Constant Summary collapse
- URL =
"http://bg.upf.edu/transfic/taskService"
- ASTERISK =
"*"[0]
Class Method Summary collapse
- .chunked_predict(mutations, max = 1000) ⇒ Object
-
.predict(mutations) ⇒ Object
mutations is a hash of genes in Uniprot protein accession pointing to lists of aminoacid substitutions.
Class Method Details
.chunked_predict(mutations, max = 1000) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rbbt/mutation/transFIC.rb', line 69 def self.chunked_predict(mutations, max = 1000) chunks = mutations.length.to_f / max chunks = chunks.ceil Log.debug("TransFIC ran with #{chunks} chunks of #{ max } mutations") if chunks > 1 num = 1 Misc.divide(mutations, chunks).inject(nil) do |acc, list| Log.debug("TransFIC ran with #{chunks} chunks: chunk #{num}") if chunks > 1 begin result = predict(list) rescue if list.length > 2 Log.debug("Error predicting in transFIC. Divinding list of size #{list.length}") result = chunked_predict(list, list.length / 2) else Log.debug("Error predicting in transFIC. Single error detected") next end end if acc.nil? acc = result else acc = TSV.setup(acc.merge(result)) end num += 1 acc end end |
.predict(mutations) ⇒ Object
mutations is a hash of genes in Uniprot protein accession pointing to lists of aminoacid substitutions
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rbbt/mutation/transFIC.rb', line 18 def self.predict(mutations) = {} ensp2uni = Organism.identifiers("Hsa").index :target => "UniProt/SwissProt ID", :fields => "Ensembl Protein ID", :persist => true searchText = mutations.collect{|mutation| protein, change = mutation.split(":"); next if ensp2uni[protein].nil?; [ensp2uni[protein], change] * "\t"}.compact.uniq * "\n" Log.debug "Querying TransFIC for: #{mutations.length} mutations" TmpFile.with_file(searchText) do |file| test_url = CMD.cmd("curl -X PUT -T '#{ file }' '#{ URL }'").read result = nil begin Misc.insist(5) do result = CMD.cmd("curl -X GET '#{ test_url }'").read raise result.split("\n").select{|line| line =~ /Error/}.first if result =~ /Error/ while result =~ /executing/ sleep 10 result = CMD.cmd("curl -X GET '#{ test_url }'").read end raise result.split("\n").select{|line| line =~ /Error/}.first if result =~ /Error/ end rescue if $!. =~ /validating/ Log.debug(Open.read(file)) end raise $! end Log.medium("TransFIC DONE") tsv = TSV.setup({}, :key_field => "Protein Mutation", :fields => %w(siftTransfic siftTransficLabel pph2Transfic pph2TransficLabel maTransfic maTransficLabel), :type => :list) result.split("\n").each do |line| next if line[0] == "#"[0] id, hgnc, hgncdesc, transcript, ensp, sw, protein_position, amino_acids, sift, polyphen, mass, siftTransfic, siftTransficLabel, pph2Transfic, pph2TransficLabel, maTransfic, maTransficLabel = line.split("\t") change = [amino_acids.split("/").first, protein_position, amino_acids.split("/").last] * "" mutation = [ensp,change] * ":" tsv[mutation] = [siftTransfic, siftTransficLabel, pph2Transfic, pph2TransficLabel, maTransfic, maTransficLabel] end tsv.select(mutations) end end |