Module: Annotations::GO

Defined in:
lib/MARQ/annotations.rb

Defined Under Namespace

Modules: Genecodis

Class Method Summary collapse

Class Method Details

.get_genes(dataset, options = {}) ⇒ Object



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/MARQ/annotations.rb', line 463

def self.get_genes(dataset, options = {})
  fdr, cut_off, folds, do_folds, nth_genes = {
    :fdr => false,
    :cut_off => 0.05,
    :folds => 2.5,
    :do_folds => true,
    :nth_genes => 0,
  }.merge(options).values_at(:fdr, :cut_off, :folds, :do_folds, :nth_genes)

  if nth_genes > 0
    return get_genes_nth(dataset, nth_genes)
  end
  

  path = MARQ.dataset_path(dataset)

  experiments = File.open(path + '.experiments').collect{|l| l.chomp.strip}
  genes       = File.open(path + '.codes').collect{|l| l.chomp.strip}


  experiments_ts   = experiments.select{|exp| exp !~ /\[ratio\]/}
  experiments_fold = experiments.select{|exp| exp =~ /\[ratio\]/}

  experiments_fold = [] if ! do_folds

  values_up = {}
  values_down = {}
  experiments.each{|exp| values_up[exp] = []; values_down[exp] = []}

  File.open(path + '.pvalues').each_with_index{|l, i|
    values = l.chomp.split(/\t/)
    experiments_ts.zip(values).each{|p|
      name = p.first
      value = p.last == "NA" ? 1.0 : p.last.to_f
      values_up[name]     << (value > 0 ? value : 1.0)
      values_down[name]   << (value < 0 ? - value : 1.0)
    }
  }

  File.open(path + '.logratios').each_with_index{|l, i|
    values = l.chomp.split(/\t/)
    experiments.zip(values).each{|p|
      name = p.first
      next unless experiments_fold.include? name
      value = p.last == "NA" ? 0 : p.last.to_f
      values_up[name]     << (p.last > 0 ? value : 0)
      values_down[name]   << (p.last < 0 ? - value : 0)
    }
  }
 
  genes_up = {}
  genes_down = {}

  threshold = cut_off
  values_up.each{|experiment, values|
    genes_up[experiment] = []
    if experiments_ts.include? experiment
      if fdr
        threshold = FDR.step_up(values.sort, cut_off)
        next if threshold == 0.0
      end
      values.each_with_index{|value, i| genes_up[experiment] << genes[i] if value < threshold}
    elsif experiment_fold.include? experiment
      values.each_with_index{|value, i| genes_up[experiment] << genes[i] if value < folds}
    end
  }
  values_down.each{|experiment, values|
    genes_down[experiment] = []
    if experiments_ts.include? experiment
      if fdr
        threshold = FDR.step_up(values.sort, cut_off)
        next if threshold == 0.0
      end
      values.each_with_index{|value, i| genes_down[experiment] << genes[i] if value < threshold}
    elsif experiment_fold.include? experiment
      values.each_with_index{|value, i| genes_down[experiment] << genes[i] if value < folds}
    end
  }


  {:up => genes_up, :down => genes_down}
end

.get_genes_nth(dataset, num_genes) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/MARQ/annotations.rb', line 438

def self.get_genes_nth(dataset, num_genes)
  path = MARQ.dataset_path(dataset)

  experiments = File.open(path + '.experiments').collect{|l| l.chomp.strip}
  genes       = File.open(path + '.codes').collect{|l| l.chomp.strip}
  total_genes = genes.length

  genes_up = {}
  genes_down = {}
  experiments.each{|exp| genes_up[exp] = []; genes_down[exp] = []}

  File.open(path + '.orders').each_with_index{|l, i|
    values = l.chomp.split(/\t/)
    experiments.zip(values).each{|p|
      name = p.first
      value = p.last
      next if p.last == "NA"
      genes_up[name]   <<  genes[i] if value.to_i < num_genes
      genes_down[name] <<  genes[i] if value.to_i > total_genes - num_genes
    }
  }

  {:up => genes_up, :down => genes_down}
end

.get_genes_old(dataset, cut_off = 0.1, fdr = false) ⇒ Object



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/MARQ/annotations.rb', line 546

def self.get_genes_old(dataset, cut_off = 0.1, fdr = false)

  path = MARQ.dataset_path(dataset)

  experiments = File.open(path + '.experiments').collect{|l| l.chomp.strip}.select{|name| !name.match(/\[ratio\]/)}
  genes = File.open(path + '.codes').collect{|l| l.chomp.strip}


  values_up = {}
  values_down = {}
  experiments.each{|exp| values_up[exp] = []; values_down[exp] = []}


  if File.exist?(path + '.pvalues')
    File.open(path + '.pvalues').each_with_index{|l, i|
      values = l.chomp.split(/\t/)
      experiments.zip(values).each{|p|
        value = p.last == "NA" ? 1.0 : p.last.to_f
        values_up[p.first]     << (value > 0 ? value : 1.0)
        values_down[p.first]   << (value < 0 ? - value : 1.0)
      }
    }
  end

  genes_up = {}
  genes_down = {}

  threshold = cut_off
  values_up.each{|experiment, values|
    genes_up[experiment] = []
    if fdr
      threshold = FDR.step_up(values.sort, cut_off)
      next if threshold == 0.0
    end
    values.each_with_index{|value, i| genes_up[experiment] << genes[i] if value < threshold}
  }
  values_down.each{|experiment, values|
    genes_down[experiment] = []
    if fdr
      threshold = FDR.step_up(values.sort, cut_off)
      next if threshold == 0.0
    end
    values.each_with_index{|value, i| genes_down[experiment] << genes[i] if value < threshold}
  }


  {:up => genes_up, :down => genes_down}
end