Module: MartSearch::ProjectUtils

Includes:
DataSetUtils, ServerViewHelpers, Utils
Included in:
Server
Defined in:
lib/martsearch/project_utils.rb

Overview

Utility module to house all of the data gathering logic for the IKMC project page views.

Author:

Instance Method Summary (collapse)

Methods included from ServerViewHelpers

#content_tag, #partial, #url_for

Methods included from ServerViewHelpers::OrderButtons

#emma_mouse_order_button, #escell_order_button, #mouse_order_button, #vector_order_button

Methods included from ServerViewHelpers::MiscDbLinks

#emma_link_url, #htgt_design_url, #interpro_link_url

Methods included from ServerViewHelpers::GbrowseLinks

#mgi_gbrowse_img

Methods included from ServerViewHelpers::UcscLinks

#ucsc_link_url

Methods included from ServerViewHelpers::EnsemblLinks

#ensembl_link_url_from_coords, #ensembl_link_url_from_exon, #ensembl_link_url_from_gene, #ensembl_link_url_from_transcript, #vega_link_url_from_exon, #vega_link_url_from_gene

Methods included from DataSetUtils

#allele_type, #fix_superscript_text_in_attribute

Methods included from Utils

#build_http_client, #convert_array_to_hash

Instance Method Details

- (Hash) get_ikmc_project_page_data(project_id)

Wrapper function to collate all of the data for a given IKMC project.



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
68
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/martsearch/project_utils.rb', line 21

def get_ikmc_project_page_data( project_id )
  MartSearch::Controller.instance().logger.debug("[MartSearch::ProjectUtils] ::get_ikmc_project_page_data - running get_ikmc_project_page_data( '#{project_id}' )")
  datasources = MartSearch::Controller.instance().datasources
  index       = MartSearch::Controller.instance().index
  data        = { :project_id => project_id.to_s }
  errors      = []

  top_level_data = get_top_level_project_info( datasources, project_id )

  if top_level_data[:data].nil? or top_level_data[:data].empty?
    return { :data => nil }
  else
    data.merge!( top_level_data[:data][0] )
    errors.push( top_level_data[:error] ) unless top_level_data[:error].empty?

    ##
    ## Look for human orthalog's
    ##

    if data[:ensembl_gene_id]
      human_orthalogs = get_human_orthalog( datasources, data[:ensembl_gene_id] )
      data.merge!( human_orthalogs[:data] ) unless human_orthalogs[:data].empty?
      errors.push( human_orthalogs[:error] ) unless human_orthalogs[:error].empty?
    end

    ##
    ## Now search the targ_rep for vectors and es cells
    ##

    vectors_and_cells = get_vectors_and_cells( datasources, project_id )
    data.merge!( vectors_and_cells[:data] )
    errors.push( vectors_and_cells[:error] ) unless vectors_and_cells[:error].empty?

    # Calculate the intended allele type
    allele_design_type = nil
    if !data[:es_cells][:conditional].nil? && !data[:es_cells][:conditional][:cells].empty?
      allele_design_type = data[:es_cells][:conditional][:cells].first[:allele_type]
    elsif !data[:targeting_vectors].nil? && !data[:targeting_vectors].empty?
      allele_design_type = data[:targeting_vectors].first[:design_type]
    elsif !data[:intermediate_vectors].nil? && !data[:intermediate_vectors].empty?
      allele_design_type = data[:intermediate_vectors].first[:design_type]
    end
    data[:allele_design_type] = allele_design_type

    ##
    ## Search Kermits for mice
    ##

    es_cell_names = []
    [ :targeted non-conditional", :conditional ].each do |symbol|
      es_cell_names.push( data[:es_cells][symbol][:cells] ) unless data[:es_cells][symbol].nil?
    end

    es_cell_names.flatten!.map! { |es_cell| es_cell[:name] }
    unless es_cell_names.empty?
      mice = get_mice( datasources, es_cell_names )
      data.merge!( mice[:data] ) unless mice[:data].empty?
      errors.push( mice[:error] ) unless mice[:error].empty?
    end

    ##
    ## Ammend the es cells data to say which cells have been made into a mouse, then sort the cells as
    ## we do in the current code (by mice, followed by qc count).
    ##

    mouse_data = nil
    mouse_data = data[:mice] if data[:mice]

    unless mouse_data.nil?
      mouse_data.each do |mouse|
        [ :targeted non-conditional", :conditional ].each do |symbol|
          unless data[:es_cells][symbol].nil?
            # update the mouse status
            data[:es_cells][symbol][:cells].each do |es_cell|
              if mouse[:escell_clone] == es_cell[:name]
                es_cell.merge!({ "mouse?".to_sym => "yes" })
                mouse.merge!({ :cassette => es_cell[:cassette], :cassette_type => es_cell[:cassette_type] })
              end
            end

            # then sort (by mice > qc_count > name)
            data[:es_cells][symbol][:cells].sort! do |a, b|
              res = b[:mouse?"] <=> a[:mouse?"]
              res = b[:qc_count] <=> a[:qc_count] if res == 0
              res = a[:name]     <=> b[:name]     if res == 0
              res
            end
          end
        end
      end
    end

    ##
    ## Add the mutagenesis predictions and PCR primers
    ##

    unless ['KOMP-Regeneron','mirKO'].include?(data[:ikmc_project])
      mutagenesis_predictions        = get_mutagenesis_predictions( project_id )
      data[:mutagenesis_predictions] = mutagenesis_predictions[:data]
      errors.push( mutagenesis_predictions[:error] ) unless mutagenesis_predictions[:error].empty?
    end

    if ['KOMP-CSD','EUCOMM','mirKO'].include?(data[:ikmc_project])
      pcr_primers                    = get_pcr_primers( project_id, data )
      data[:pcr_primers]             = pcr_primers[:data]
      errors.push( pcr_primers[:error] ) unless pcr_primers[:error].empty?
    end

    ##
    ## Add the conf for the floxed exon display
    ##

    data.merge!( floxed_exon_display_conf( data ) )

    ##
    ## Add the coordinate information
    ##

    search_engine_data = search_engine_data( index, project_id )
    data.merge!( search_engine_data[:data] )  unless search_engine_data[:data].empty?
    errors.push( search_engine_data[:error] ) unless search_engine_data[:error].empty?

    ##
    ## Finally, categorize the stage of the pipeline that we are in
    ##

    data.merge!( get_pipeline_stage( data[:status]) ) if data[:status]
  end

  MartSearch::Controller.instance().logger.debug("[MartSearch::ProjectUtils] ::get_ikmc_project_page_data - running get_ikmc_project_page_data( '#{project_id}' ) - DONE")

  return { :data => data, :errors => errors }
end