module SNPSandGO

Constants

URL

Public Class Methods

add_predictions(tsv) click to toggle source
# File lib/rbbt/mutation/snps_and_go.rb, line 22
def self.add_predictions(tsv)
  raise "Input not TSV" unless TSV === tsv

  uniprot_field = tsv.identify_field "UniProt/SwissProt Accession" 
  raise "Field 'UniProt/SwissProt Accession' Not in TSV" if uniprot_field.nil?

  protein_field = tsv.identify_field "Protein Mutation" 
  raise "Field 'Protein Mutation' Not in TSV" if protein_field.nil?


  if tsv.type == :double
    tsv.add_field "SNPs&GO:Prediction" do |key,values|
      uniprots = if uniprot_field === :key
                   [key]
                 else
                   values[uniprot_field] || []
                 end

      mutations = values[protein_field]

      uniprots.zip(mutations).collect{|uniprot,mutation| 
        case
        when mutation.nil?
          "No Prediction" 
        when mutation[0] == mutation[-1]
          "Neutral"
        when (uniprot.nil? or uniprot.empty?)
          "No Prediction" 
        else
          begin
            SNPSandGO.predict(uniprot, mutation).first
          rescue
            "No Prediction"
          end
        end
      }
    end
  else
    tsv.add_field "SNPs&GO:Prediction" do |key,values|
      uniprot = if uniprot_field === :key
                   key
                 else
                   values[uniprot_field]
                 end

      next if uniprot.nil? or uniprot.empty?
      
      mutation = values[protein_field]
      case
      when mutation.nil?
        "No Prediction" 
      when mutation[0] == mutation[-1]
        "Neutral"
      when (uniprot.nil? or uniprot.empty?)
        "No Prediction" 
      else
        begin
          SNPSandGO.predict(uniprot, mutation).first
        rescue
          "No Prediction"
        end
      end
    end
  end

  tsv
end
parse_mutation(mutation) click to toggle source
# File lib/rbbt/mutation/snps_and_go.rb, line 6
def self.parse_mutation(mutation)
  mutation.match(/([A-Z])(\d+)([A-Z])/i).values_at 1,2,3
end
predict(accession, mutation) click to toggle source
# File lib/rbbt/mutation/snps_and_go.rb, line 10
def self.predict(accession, mutation)
  reference, pos, substitution = parse_mutation(mutation)

  url = URL.sub(/#ACCESSION#/,accession).sub(/#POSITION#/, pos).sub(/#REFERENCE#/,reference).sub(/#SUBSTITUTION#/,substitution)

  res = Open.read(url)

  raise "Error in prediction: #{$1}" if res =~ /ERROR: (.*)/

  res.match(/Position\s+WT\s+NEW\s+Effect\s+RI\n\s+\d+\s+[A-Z]\s+[A-Z]\s+(\w+)\s+(\d+)/).values_at 1,2
end