Class: MyWorker

Inherits:
ScbiMapreduce::Worker
  • Object
show all
Defined in:
lib/full_lengther_next/classes/my_worker.rb

Instance Method Summary collapse

Instance Method Details

#closing_workerObject



45
46
47
# File 'lib/full_lengther_next/classes/my_worker.rb', line 45

def closing_worker
	 
end

#full_lenghter2(seqs) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
114
115
116
117
118
119
120
121
122
123
124
125
126
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
# File 'lib/full_lengther_next/classes/my_worker.rb', line 64

def full_lenghter2(seqs)
	
	# -------------------------------------------- User database
	# if the user has included his own database in the parameters entry,
	# the location of the database is tested, and blast and the results analysis is done
	
	if (@options[:user_db])
	
		if (@options[:user_db] =~ /\//)
			user_db_name = @options[:user_db].sub(/.+\//,'')
		end
	
		if !File.exists?("#{File.expand_path(@options[:user_db])}.psq")
			puts "user database: #{@options[:user_db]} was not found"
			exit
		end
	
		# do blast
		my_blast = run_blast(seqs, "#{@options[:user_db]}", 'blastx', '1e-6')
		
		# chimera detection
		if (!@options[:chimera].nil?)
			seqs.each_with_index do |seq,i|
				if (!my_blast.querys[i].hits[0].nil?)
					search_chimeras(seq, my_blast.querys[i], @options, user_db_name)
				end
			end
			
			seqs=seqs.select{|s| s.get_annotations(:chimera).empty?}
			my_blast = select_best_blast(my_blast, seqs)
		end
		
		# split and parse blast
		seqs.each_with_index do |seq,i|
			analiza_orf_y_fl(seq, my_blast.querys[i], @options, user_db_name)
		end
		
		new_seqs=seqs.select{|s| (s.get_annotations(:complete).empty? && s.get_annotations(:chimera).empty?)}
		
	else
		new_seqs = seqs
	end

	return if new_seqs.empty?
	
	# -------------------------------------------- UniProt (sp)
	# blast
	sp_path=File.join("sp_#{@options[:tax_group]}","sp_#{@options[:tax_group]}.fasta")
	my_blast = run_blast(new_seqs, sp_path, 'blastx', '1e-6')
	
	# chimera detection
	if (!@options[:chimera].nil?)
		new_seqs.each_with_index do |seq,i|
			if (!my_blast.querys[i].hits[0].nil?)
				search_chimeras(seq, my_blast.querys[i], @options, "sp_#{@options[:tax_group]}")
			end
		end
		new_seqs=seqs.select{|s| s.get_annotations(:chimera).empty?}
		my_blast = select_best_blast(my_blast, new_seqs)
	end
	
	# split and parse blast
	new_seqs.each_with_index do |seq,i|
		analiza_orf_y_fl(seq, my_blast.querys[i], @options, "sp_#{@options[:tax_group]}")
	end
	
	new_seqs=seqs.select{|s| (s.get_annotations(:complete).empty? && s.get_annotations(:chimera).empty?)}
	return if new_seqs.empty?
	
	# -------------------------------------------- UniProt (tr)
	# blast
	tr_path=File.join("tr_#{@options[:tax_group]}","tr_#{@options[:tax_group]}.fasta")
	my_blast = run_blast(new_seqs, tr_path, 'blastx', '1e-6')
	
	# chimera detection
	if (!@options[:chimera].nil?)
		new_seqs.each_with_index do |seq,i|
			if (!my_blast.querys[i].hits[0].nil?)
				search_chimeras(seq, my_blast.querys[i], @options, "tr_#{@options[:tax_group]}")
			end
		end
		new_seqs=new_seqs.select{|s| s.get_annotations(:chimera).empty?}
		my_blast = select_best_blast(my_blast, new_seqs)
	end
	
	# split and parse blast
	new_seqs.each_with_index do |seq,i|
		analiza_orf_y_fl(seq, my_blast.querys[i], @options, "tr_#{@options[:tax_group]}")
	end
	
	# -------------------------------------------- Test Code
	# the sequences without a reliable similarity with an orthologue are processed with Test Code
	testcode_input=seqs.select{|s| (!s.get_annotations(:apply_tcode).empty? && s.get_annotations(:chimera).empty?)}
	return if testcode_input.empty?
	
# active this line to test tcode, and comment all lines above in this function
# testcode_input=seqs

	testcode_input.each do |seq|
		TestCode.new(seq)
	end
	
	# -------------------------------------------- nc RNA
	unknown_seqs=seqs.select{|s| !s.get_annotations(:tcode_unknown).empty?}
	return if unknown_seqs.empty?
	
	# run blastn
	ncrna_path=File.join('nc_rna_db','ncrna_fln_100.fasta')
	my_blast = run_blast(unknown_seqs, ncrna_path, 'blastn', '1e-3')
	
	# split and parse blast
	unknown_seqs.each_with_index do |seq,i|
		find_nc_rna(seq, my_blast.querys[i])
	end
	# ---------------------------------------------------
	
end

#process_object(obj) ⇒ Object



38
39
40
41
42
43
# File 'lib/full_lengther_next/classes/my_worker.rb', line 38

def process_object(obj)

	full_lenghter2(obj)
	return obj
	
end

#receive_initial_config(obj) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/full_lengther_next/classes/my_worker.rb', line 30

def receive_initial_config(obj)
	
	# Reads the parameters
	# $WORKER_LOG.info "Params received: #{obj.to_json}"
	@options = obj
	
end

#run_blast(input, database, blast_type, evalue) ⇒ Object

ejecuta blast utilizando los parametros fichero de entrada, base de datos, fichero de salida y tipo de blast



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/full_lengther_next/classes/my_worker.rb', line 50

def run_blast(input, database, blast_type, evalue)
	
	if (@options[:chimera].nil?)
		blast=BatchBlast.new("-db #{database}",blast_type,"-evalue #{evalue} -max_target_seqs 1")
	else
		blast=BatchBlast.new("-db #{database}",blast_type,"-evalue #{evalue}")
	end
	
	blast_result = blast.do_blast_seqs(input, :xml)
	
	return blast_result
end

#starting_workerObject



22
23
24
25
26
27
28
# File 'lib/full_lengther_next/classes/my_worker.rb', line 22

def starting_worker
	
	# $WORKER_LOG.info "Loading actions"
	rescue Exception => e
	puts (e.message+ e.backtrace.join("\n"))
	
end