lib/seek/parser_mapper.rb
def dortmund_bcat_ko_mapping

      age_regex = /(\d+-?\d*)\s*(day|week|month|year)s?/i
      treatment_substance_regex = /.*\((control|treated)\s?=\s?(.*)\)/i
      treatment_concentration_unit_regex = /(\d*[,\.]?\d*)\s*([\w\s\/]*).*$/
      treatment_protocol_regex = /.*,\s*([\w\s\.]*)$/
      genotype_modification_regex = /(WT|KO)/
      incubation_time_regex = /(\d+\.?\d*)\s+(\w*)s/

      {
          :name => "dortmund_bcat_ko",
          :data_row_offset => 1,

          :samples_mapping => {     # TODO: which fields are really necessary?
              :samples_sheet_name => "BCat KO",

              :add_specimens => true,
              :add_treatments => true,
              :add_samples => true,


              :probing_column => :"specimens.title",


              :"organisms.title" => mapping_entry("FIXED", proc {"Mus musculus"}),

              :"strains.title" => mapping_entry("FIXED", proc {"Wildtype"}),

              :"specimens.sex" => mapping_entry("Gender", proc { |data| data.downcase }),
              :"specimens.title" => mapping_entry("Sample ID"),
              :"specimens.lab_internal_number" => mapping_entry("Sample ID"),
              :"specimens.age" => mapping_entry("Age", proc do |data|
                   if data =~ age_regex
                     $1 ? $1 : ""
                   else
                     ""
                   end
              end),
              :"specimens.age_unit" => mapping_entry("Age", proc do |data|
                  if data =~ age_regex
                    $2 ? $2 : ""
                  else
                    ""
                  end
              end),
              :"specimens.comments" => mapping_entry("FIXED", proc {""}),
              :"specimens.genotype.title" => mapping_entry("FIXED", proc {"Bcat"}),
              :"specimens.genotype.modification" => mapping_entry("Genotype", proc do |data|
                  if data =~ genotype_modification_regex
                    case $1
                      when "KO" then "Knock out"
                      when "WT" then "Wildtype"
                      else "Wildtype"
                    end
                  else
                    "Wildtype"
                  end
              end),

              :"treatment.treatment_protocol" => mapping_entry("Dose/route of adminstration", proc do |data|         # sic!?
                if data =~ treatment_protocol_regex
                  $1 ? $1 : ""
                else
                  ""
                end
              end),
              :"treatment.type" => mapping_entry("FIXED", proc {"concentration"}),
              :"treatment.comments" => mapping_entry("FIXED", proc {""}),
              :"treatment.substance" => mapping_entry("Genotype", proc do |data|
                if data =~ treatment_substance_regex
                  $2 ? $2 : ""
                else
                  ""
                end
              end),
              :"treatment.concentration" => mapping_entry("Dose/route of adminstration", proc do |data|
                if data =~ treatment_concentration_unit_regex
                  $1 ? $1 : nil
                else
                  nil
                end
              end),
              :"treatment.unit" => mapping_entry("Dose/route of adminstration", proc do |data|
                if data =~ treatment_concentration_unit_regex
                  $2 ? $2 : ""
                else
                  ""
                end
              end),
              :"treatment.incubation_time" => mapping_entry("Time point", proc do |data|
                if data =~ incubation_time_regex
                  $1
                else
                  ""
                end
              end),

              :"treatment.incubation_time_unit" => mapping_entry("Time point", proc do |data|
                if data =~ incubation_time_regex
                  $2
                else
                  ""
                end
              end),

              :"samples.comments" => mapping_entry("FIXED", proc {""}),
              :"samples.title" => mapping_entry("Sample ID"),
              :"samples.sample_type" => mapping_entry("FIXED", proc {""}),
              :"samples.donation_date" => mapping_entry("Arrival Date"),
              :"samples.organism_part"  => mapping_entry("FIXED", proc {"organ"}),

              :"tissue_and_cell_types.title" => mapping_entry("FIXED", proc {"Liver"}),

              :"sop.title" => mapping_entry("FIXED", proc {""}),
              :"institution.title" => mapping_entry("FIXED", proc {""})
          },


          :assay_mapping => nil


      }

    end
# mapping for dortmund excel sheets (II)
# example file: BCat KO sample data Dortmund.xls
mapping for dortmund excel sheets (II)
example file: BCat KO sample data Dortmund.xls
mapping for dortmund excel sheets ( II ) example file : BCat KO sample data Dortmund . xls
def dortmund_bcat_ko_mapping
      age_regex = /(\d+-?\d*)\s*(day|week|month|year)s?/i
      treatment_substance_regex = /.*\((control|treated)\s?=\s?(.*)\)/i
      treatment_concentration_unit_regex = /(\d*[,\.]?\d*)\s*([\w\s\/]*).*$/
      treatment_protocol_regex = /.*,\s*([\w\s\.]*)$/
      genotype_modification_regex = /(WT|KO)/
      incubation_time_regex = /(\d+\.?\d*)\s+(\w*)s/
      {
          :name => "dortmund_bcat_ko",
          :data_row_offset => 1,
          :samples_mapping => {     
              :samples_sheet_name => "BCat KO",
              :add_specimens => true,
              :add_treatments => true,
              :add_samples => true,
              :probing_column => :"specimens.title",
              :"organisms.title" => mapping_entry("FIXED", proc {"Mus musculus"}),
              :"strains.title" => mapping_entry("FIXED", proc {"Wildtype"}),
              :"specimens.sex" => mapping_entry("Gender", proc { |data| data.downcase }),
              :"specimens.title" => mapping_entry("Sample ID"),
              :"specimens.lab_internal_number" => mapping_entry("Sample ID"),
              :"specimens.age" => mapping_entry("Age", proc do |data|
                   if data =~ age_regex
                     $1 ? $1 : ""
                   else
                     ""
                   end
              end),
              :"specimens.age_unit" => mapping_entry("Age", proc do |data|
                  if data =~ age_regex
                    $2 ? $2 : ""
                  else
                    ""
                  end
              end),
              :"specimens.comments" => mapping_entry("FIXED", proc {""}),
              :"specimens.genotype.title" => mapping_entry("FIXED", proc {"Bcat"}),
              :"specimens.genotype.modification" => mapping_entry("Genotype", proc do |data|
                  if data =~ genotype_modification_regex
                    case $1
                      when "KO" then "Knock out"
                      when "WT" then "Wildtype"
                      else "Wildtype"
                    end
                  else
                    "Wildtype"
                  end
              end),
              :"treatment.treatment_protocol" => mapping_entry("Dose/route of adminstration", proc do |data|         
                if data =~ treatment_protocol_regex
                  $1 ? $1 : ""
                else
                  ""
                end
              end),
              :"treatment.type" => mapping_entry("FIXED", proc {"concentration"}),
              :"treatment.comments" => mapping_entry("FIXED", proc {""}),
              :"treatment.substance" => mapping_entry("Genotype", proc do |data|
                if data =~ treatment_substance_regex
                  $2 ? $2 : ""
                else
                  ""
                end
              end),
              :"treatment.concentration" => mapping_entry("Dose/route of adminstration", proc do |data|
                if data =~ treatment_concentration_unit_regex
                  $1 ? $1 : nil
                else
                  nil
                end
              end),
              :"treatment.unit" => mapping_entry("Dose/route of adminstration", proc do |data|
                if data =~ treatment_concentration_unit_regex
                  $2 ? $2 : ""
                else
                  ""
                end
              end),
              :"treatment.incubation_time" => mapping_entry("Time point", proc do |data|
                if data =~ incubation_time_regex
                  $1
                else
                  ""
                end
              end),
              :"treatment.incubation_time_unit" => mapping_entry("Time point", proc do |data|
                if data =~ incubation_time_regex
                  $2
                else
                  ""
                end
              end),
              :"samples.comments" => mapping_entry("FIXED", proc {""}),
              :"samples.title" => mapping_entry("Sample ID"),
              :"samples.sample_type" => mapping_entry("FIXED", proc {""}),
              :"samples.donation_date" => mapping_entry("Arrival Date"),
              :"samples.organism_part"  => mapping_entry("FIXED", proc {"organ"}),
              :"tissue_and_cell_types.title" => mapping_entry("FIXED", proc {"Liver"}),
              :"sop.title" => mapping_entry("FIXED", proc {""}),
              :"institution.title" => mapping_entry("FIXED", proc {""})
          },
          :assay_mapping => nil
      }
    end
def dortmund_bcat_ko_mapping age_regex = / ( \d +-? \d *) \s *(day|week|month|year)s? /i treatment_substance_regex = / .* \( (control|treated) \s ?= \s ?(.*) \) /i treatment_concentration_unit_regex = / ( \d *[, \. ]? \d *) \s *([ \w \s \/ ]*).*$ / treatment_protocol_regex = / .*, \s *([ \w \s \. ]*)$ / genotype_modification_regex = / (WT|KO) / incubation_time_regex = / ( \d + \. ? \d *) \s +( \w *)s / { :name => "dortmund_bcat_ko" , :data_row_offset => 1 , :samples_mapping => { :samples_sheet_name => "BCat KO" , :add_specimens => true , :add_treatments => true , :add_samples => true , :probing_column => :" specimens.title " , :" organisms.title " => mapping_entry ( "FIXED" , proc { "Mus musculus" } ) , :" strains.title " => mapping_entry ( "FIXED" , proc { "Wildtype" } ) , :" specimens.sex " => mapping_entry ( "Gender" , proc { | data | data . downcase } ) , :" specimens.title " => mapping_entry ( "Sample ID" ) , :" specimens.lab_internal_number " => mapping_entry ( "Sample ID" ) , :" specimens.age " => mapping_entry ( "Age" , proc do | data | if data =~ age_regex $1 ? $1 : "" else "" end end ) , :" specimens.age_unit " => mapping_entry ( "Age" , proc do | data | if data =~ age_regex $2 ? $2 : "" else "" end end ) , :" specimens.comments " => mapping_entry ( "FIXED" , proc { "" } ) , :" specimens.genotype.title " => mapping_entry ( "FIXED" , proc { "Bcat" } ) , :" specimens.genotype.modification " => mapping_entry ( "Genotype" , proc do | data | if data =~ genotype_modification_regex case $1 when "KO" then "Knock out" when "WT" then "Wildtype" else "Wildtype" end else "Wildtype" end end ) , :" treatment.treatment_protocol " => mapping_entry ( "Dose/route of adminstration" , proc do | data | if data =~ treatment_protocol_regex $1 ? $1 : "" else "" end end ) , :" treatment.type " => mapping_entry ( "FIXED" , proc { "concentration" } ) , :" treatment.comments " => mapping_entry ( "FIXED" , proc { "" } ) , :" treatment.substance " => mapping_entry ( "Genotype" , proc do | data | if data =~ treatment_substance_regex $2 ? $2 : "" else "" end end ) , :" treatment.concentration " => mapping_entry ( "Dose/route of adminstration" , proc do | data | if data =~ treatment_concentration_unit_regex $1 ? $1 : nil else nil end end ) , :" treatment.unit " => mapping_entry ( "Dose/route of adminstration" , proc do | data | if data =~ treatment_concentration_unit_regex $2 ? $2 : "" else "" end end ) , :" treatment.incubation_time " => mapping_entry ( "Time point" , proc do | data | if data =~ incubation_time_regex $1 else "" end end ) , :" treatment.incubation_time_unit " => mapping_entry ( "Time point" , proc do | data | if data =~ incubation_time_regex $2 else "" end end ) , :" samples.comments " => mapping_entry ( "FIXED" , proc { "" } ) , :" samples.title " => mapping_entry ( "Sample ID" ) , :" samples.sample_type " => mapping_entry ( "FIXED" , proc { "" } ) , :" samples.donation_date " => mapping_entry ( "Arrival Date" ) , :" samples.organism_part " => mapping_entry ( "FIXED" , proc { "organ" } ) , :" tissue_and_cell_types.title " => mapping_entry ( "FIXED" , proc { "Liver" } ) , :" sop.title " => mapping_entry ( "FIXED" , proc { "" } ) , :" institution.title " => mapping_entry ( "FIXED" , proc { "" } ) } , :assay_mapping => nil } end
mapping for dortmund excel sheets (II)
example file: BCat KO sample data Dortmund.xls
mapping for dortmund excel sheets ( II ) example file : BCat KO sample data Dortmund . xls
# TODO: which fields are really necessary? # sic!?