Class: Bio::DB::Polymarker
- Inherits:
-
Object
- Object
- Bio::DB::Polymarker
- Defined in:
- lib/bio-polymarker_db_batch/polymarker_db_batch.rb
Instance Method Summary collapse
- #each_running ⇒ Object
- #each_snp_in_file(file_id) ⇒ Object
- #each_to_run ⇒ Object
- #execute_polymarker(snp_file) ⇒ Object
-
#initialize(props) ⇒ Polymarker
constructor
A new instance of Polymarker.
- #mysql_version ⇒ Object
- #review_running_status(file_id, filename) ⇒ Object
- #send_email(to, opts = {}) ⇒ Object
- #update_status(snp_file_id, new_status) ⇒ Object
- #write_output_file_and_execute(file_id, filename) ⇒ Object
Constructor Details
#initialize(props) ⇒ Polymarker
Returns a new instance of Polymarker.
5 6 7 8 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 5 def initialize( props) @properties =Hash[*File.read(props).split(/[=\n]+/)] puts @properties.inspect end |
Instance Method Details
#each_running ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 25 def each_running query="SELECT snp_file_id, filename FROM snp_file WHERE status NOT IN ('NEW', 'DONE', 'LOADED');" ret = 0 if block_given? ret = execute_query(query){|row| yield row } else ret = execute_query(query) end ret end |
#each_snp_in_file(file_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 36 def each_snp_in_file(file_id) query="SELECT name, chromosome, sequence FROM snp, snp_file_snp WHERE snp_file_snp.snpList_snpId = snp.snpId AND snp_file_snp.snp_file_snp_file_id = '#{file_id}';" ret = 0 puts query if block_given? ret = execute_query(query){|row| yield row } else ret = execute_query(query) end ret end |
#each_to_run ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 14 def each_to_run query="SELECT snp_file_id, filename FROM snp_file WHERE status = 'NEW';" ret = 0 if block_given? ret = execute_query(query){|row| yield row } else ret = execute_query(query) end ret end |
#execute_polymarker(snp_file) ⇒ Object
61 62 63 64 65 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 61 def execute_polymarker(snp_file) cmd="#{@properties['wrapper_prefix'] } polymarker.rb -m #{snp_file} -o #{snp_file}_out -c #{@properties['path_to_chromosomes']} #{@properties['wrapper_suffix'] }" #polymarker.rb -m 1_GWAS_SNPs.csv -o 1_test -c /Users/ramirezr/Documents/TGAC/references/Triticum_aestivum.IWGSP1.21.dna_rm.genome.fa execute_command(cmd) end |
#mysql_version ⇒ Object
10 11 12 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 10 def mysql_version con.get_server_info end |
#review_running_status(file_id, filename) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 93 def review_running_status(file_id, filename) out_folder=@properties["execution_path"]+"/#{file_id}_#{filename}_out" started=File.exist?(out_folder) done=false if started lines = IO.readlines("#{out_folder}/status.txt") # puts lines.inspect done = lines.last.split(",").include?("DONE\n") if lines.size > 1 end if done exons_filename="#{out_folder}/exons_genes_and_contigs.fa" output_primers="#{out_folder}/primers.csv" read_file_to_snp_file("mask_fasta", file_id, exons_filename ) read_file_to_snp_file("polymarker_output", file_id, output_primers ) update_status(file_id, "DONE") elsif started update_status(file_id, "RUNNING") end end |
#send_email(to, opts = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 74 def send_email(to,opts={}) opts[:server] ||= 'localhost' opts[:from] ||= '[email protected]' opts[:from_alias] ||= 'Example Emailer' opts[:subject] ||= "You need to see this" opts[:body] ||= "Important stuff!" msg = <<END_OF_MESSAGE From: #{opts[:from_alias]} <#{opts[:from]}> To: <#{to}> Subject: #{opts[:subject]} #{opts[:body]} END_OF_MESSAGE Net::SMTP.start(opts[:server]) do |smtp| smtp. msg, opts[:from], to end end |
#update_status(snp_file_id, new_status) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 67 def update_status(snp_file_id, new_status) raise "Invalid status #{new_status}" unless ["NEW", "SUBMITTED", "RUNNING", "DONE", "ERROR"].include?(new_status) pst = con.prepare "UPDATE snp_file SET status = ? WHERE snp_file_id = ?" pst.execute new_status, snp_file_id con.commit end |
#write_output_file_and_execute(file_id, filename) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bio-polymarker_db_batch/polymarker_db_batch.rb', line 48 def write_output_file_and_execute(file_id, filename) path =@properties["execution_path"]+"/#{file_id}_#{filename}" puts "Writting: #{path}" f=File.open(path, "w") each_snp_in_file(file_id) do |row| f.puts(row.join(",")) end execute_polymarker(path) update_status(file_id, "SUBMITTED") f.close end |