Class: MyWorkerManager
- Inherits:
-
ScbiMapreduce::WorkManager
- Object
- ScbiMapreduce::WorkManager
- MyWorkerManager
- Defined in:
- lib/full_lengther_next/classes/my_worker_manager.rb
Class Method Summary collapse
-
.end_work_manager ⇒ Object
close files.
-
.init_work_manager(options, chunk_size = 100) ⇒ Object
open files and prepare global data.
Instance Method Summary collapse
- #error_received(worker_error, obj) ⇒ Object
-
#next_work ⇒ Object
this method is called every time a worker needs a new work Return the work data or nil if no more data is available.
- #too_many_errors_received ⇒ Object
-
#work_received(obj) ⇒ Object
this method is ejecuted each time an obj is finished.
-
#worker_initial_config ⇒ Object
send initial config.
- #write_seq(seq) ⇒ Object
Class Method Details
.end_work_manager ⇒ Object
close files
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 52 def self.end_work_manager # @@fasta_file.close @@annotation_file.close @@alignment_file.close @@prot_file.close @@nts_file.close @@tcode_file.close @@nc_rna_file.close if (!@@options[:chimera].nil?) @@chimera_file.close end # @@error_fasta_file.close # @@error_file.close summary_stats end |
.init_work_manager(options, chunk_size = 100) ⇒ Object
open files and prepare global data
11 12 13 14 15 16 17 18 19 20 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 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 11 def self.init_work_manager(,chunk_size=100) input_file=[:fasta] if !File.exists?('fln_results') Dir.mkdir('fln_results') end file_head = "Query_id\tfasta_length\tSubject_id\tdb_name\tStatus\tt_code\te_value\tp_ident\tprotein_length\ts_length\tWarning_msgs\tframe\tORF_start\tORF_end\ts_start\ts_end\tDescription\tProtein_sequence" @@fasta_file = FastaQualFile.new(input_file,'') @@chunk_size=chunk_size @@options = @@annotation_file = File.open("fln_results/dbannotated.txt", 'w') @@annotation_file.puts file_head @@alignment_file = File.open("fln_results/alignments.txt", 'w') @@prot_file = File.open("fln_results/proteins.fasta", 'w') @@nts_file = File.open("fln_results/nt_seq.txt", 'w') @@tcode_file=File.open("fln_results/new_coding.txt", 'w') @@tcode_file.puts file_head @@nc_rna_file = File.open("fln_results/nc_rnas.txt", 'w') @@nc_rna_file.puts file_head if (![:chimera].nil?) @@chimera_file = File.open("fln_results/chimeric_sequences.txt", 'w') @@chimera_file.puts file_head else if File.exists?("fln_results/chimeric_sequences.txt") File.delete("fln_results/chimeric_sequences.txt") end end # @@error_fasta_file = File.open("fln_results/error_seqs.fasta", 'w') # @@error_file = File.open("fln_results/errors_info.txt", 'w') end |
Instance Method Details
#error_received(worker_error, obj) ⇒ Object
72 73 74 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 72 def error_received(worker_error, obj) puts "Error while processing object #{obj.inspect}\n" + worker_error.original_exception. + ":\n" +worker_error.original_exception.backtrace.join("\n") end |
#next_work ⇒ Object
this method is called every time a worker needs a new work Return the work data or nil if no more data is available
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 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 87 def next_work # seqs=[] # if (@@count % 2==0) # $LOG.info("Processed #{@@count}") # end # prepare work # @@chunk_size.times do n,f,q = @@fasta_file.next_seq if !n.nil? return Sequence.new(n,f,q) else return nil end # end # return work # if !seqs.empty? # return seqs # else # return nil # end end |
#too_many_errors_received ⇒ Object
76 77 78 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 76 def too_many_errors_received $LOG.error "Too many errors: #{@@error_count} errors on #{@@count} executed sequences, exiting before finishing" end |
#work_received(obj) ⇒ Object
this method is ejecuted each time an obj is finished
116 117 118 119 120 121 122 123 124 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 116 def work_received(obj) obj.each do |seq| # puts seq.seq_name write_seq(seq) end end |
#worker_initial_config ⇒ Object
send initial config
81 82 83 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 81 def worker_initial_config return @@options end |
#write_seq(seq) ⇒ Object
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/full_lengther_next/classes/my_worker_manager.rb', line 127 def write_seq(seq) begin # -------------------------------------------------------- Chimeric Seqs if (!@@options[:chimera].nil?) if (q=seq.get_annotations(:chimera).first) @@chimera_file.puts q[:message] # -------------------------------------------------- Complete Seqs elsif (e=seq.get_annotations(:complete).first) @@annotation_file.puts e[:message] if (a=seq.get_annotations(:alignment).first) @@alignment_file.puts a[:message] end if (p=seq.get_annotations(:protein).first) @@prot_file.puts p[:message] end if (n=seq.get_annotations(:nucleotide).first) @@nts_file.puts n[:message] end # --------------------------------------------------- Non Complete Seqs elsif (e=seq.get_annotations(:tmp_annotation).first) @@annotation_file.puts e[:message][0] if (a=seq.get_annotations(:alignment).first) if !a[:message].empty? @@alignment_file.puts a[:message] end end if (p=seq.get_annotations(:protein).first) if !p[:message].empty? @@prot_file.puts p[:message] end end if (n=seq.get_annotations(:nucleotide).first) @@nts_file.puts n[:message] end # ------------------------------------------------- nc RNA elsif (nc=seq.get_annotations(:ncrna).first) @@nc_rna_file.puts nc[:message] # ------------------------------------------------- Test Code elsif (t=seq.get_annotations(:tcode).first) @@tcode_file.puts t[:message] end # --------------------------------------------------------------------------------- # -------------------------------------------------------- without Chimeric Seqs Mode else # ------------------------------------------------- Complete Seqs if (e=seq.get_annotations(:complete).first) @@annotation_file.puts e[:message] if (a=seq.get_annotations(:alignment).first) @@alignment_file.puts a[:message] end if (p=seq.get_annotations(:protein).first) @@prot_file.puts p[:message] end if (n=seq.get_annotations(:nucleotide).first) @@nts_file.puts n[:message] end # ------------------------------------------------- Non Complete Seqs elsif (e=seq.get_annotations(:tmp_annotation).first) @@annotation_file.puts e[:message][0] if (a=seq.get_annotations(:alignment).first) if !a[:message].empty? @@alignment_file.puts a[:message] end end if (p=seq.get_annotations(:protein).first) if !p[:message].empty? @@prot_file.puts p[:message] end end if (n=seq.get_annotations(:nucleotide).first) @@nts_file.puts n[:message] end # ------------------------------------------------- nc RNA elsif (nc=seq.get_annotations(:ncrna).first) @@nc_rna_file.puts nc[:message] # ------------------------------------------------- Test Code elsif (t=seq.get_annotations(:tcode).first) @@tcode_file.puts t[:message] end end # ------------------------------------------------- errors # if e=seq.get_annotations(:error).first # if !e[:message].empty? # @@error_fasta_file.puts ">#{seq.seq_name}\n#{seq.seq_fasta}" # @@error_file.puts e[:message] # end # end rescue puts "Error printing #{seq.seq_name}" end end |