#!/usr/bin/env ruby # # An script to compare two 23andme SNP data files. # # Author: Preston Lee # License: Apache 2 # Runtime libraries: require 'erb' # 3rd-party libraries: require 'getopt/long' require 'multimarkdown' # Our libraries: current_dir = File.dirname(File.expand_path(__FILE__)) gem_dir = File.join(current_dir, '..') lib_path = File.join(gem_dir, 'lib') $LOAD_PATH.unshift lib_path require 'youandme' def print_help_and_exit puts "Usage:" puts "\t#{$0} --directory --left <23andme_data_file.txt> --right <23andme_data_file.txt>" puts "\t#{$0} -d -l <23andme_data_file.txt> -r <23andme_data_file.txt>" exit(1) end begin opt = Getopt::Long.getopts( ["--left", "-l", Getopt::REQUIRED], ["--right", "-r", Getopt::REQUIRED], ["--directory", "-d", Getopt::REQUIRED], ["--help", "-h", Getopt::BOOLEAN] ) rescue print_help_and_exit end if(opt['help']) print_help_and_exit end puts "Checking data file existyness..." loader = YouAndMe::RawDataFileLoader.new left_file = opt['left'] right_file = opt['right'] unless(loader.check_file(left_file) and loader.check_file(right_file)) puts "Please specify valid data files!" print_help_and_exit end puts "Parsing data files... (may take a while)" max_rows = 0 left = loader.load_file(left_file, max_rows).sort{|a,b| a[:rsid] <=> b[:rsid]} puts "\tLoaded #{left.length} SNPs from #{left_file}" # y left[0..4] right = loader.load_file(right_file, max_rows).sort{|a,b| a[:rsid] <=> b[:rsid]} puts "\tLoaded #{right.length} SNPs from #{right_file}" processor = YouAndMe::DataProcessor.new(left, right) processor.process(true) puts "Writing reports..." processor.to_multimarkdown(left_file, right_file) path = File.expand_path("#{opt['directory']}") FileUtils.mkdir_p(path) processor.write_multimarkdown(path) processor.write_latex(path) processor.write_html(path) puts "Done!"