seqtrimnext 2.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/Manifest.txt +114 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +159 -0
- data/Rakefile +38 -0
- data/bin/create_graphs.rb +46 -0
- data/bin/extract_seqs.rb +45 -0
- data/bin/extract_seqs_from_fasta.rb +56 -0
- data/bin/extract_seqs_from_fastq.rb +45 -0
- data/bin/fasta2fastq.rb +38 -0
- data/bin/fastq2fasta.rb +35 -0
- data/bin/gen_qual.rb +46 -0
- data/bin/get_seq.rb +46 -0
- data/bin/group_by_range.rb +17 -0
- data/bin/join_ilumina_paired.rb +130 -0
- data/bin/parse_amplicons.rb +95 -0
- data/bin/parse_json_results.rb +66 -0
- data/bin/parse_params.rb +82 -0
- data/bin/resume_clusters.rb +48 -0
- data/bin/resume_rejected.sh +9 -0
- data/bin/reverse_paired.rb +49 -0
- data/bin/seqtrimnext +368 -0
- data/bin/split_fastq.rb +42 -0
- data/bin/split_ilumina_paired.rb +65 -0
- data/bin/split_paired.rb +70 -0
- data/lib/seqtrimnext/actions/action_ab_adapter.rb +32 -0
- data/lib/seqtrimnext/actions/action_ab_far_adapter.rb +32 -0
- data/lib/seqtrimnext/actions/action_ab_left_adapter.rb +32 -0
- data/lib/seqtrimnext/actions/action_empty_insert.rb +22 -0
- data/lib/seqtrimnext/actions/action_ignore_repeated.rb +24 -0
- data/lib/seqtrimnext/actions/action_indetermination.rb +30 -0
- data/lib/seqtrimnext/actions/action_induced_low_complexity.rb +29 -0
- data/lib/seqtrimnext/actions/action_insert.rb +32 -0
- data/lib/seqtrimnext/actions/action_is_contaminated.rb +30 -0
- data/lib/seqtrimnext/actions/action_key.rb +30 -0
- data/lib/seqtrimnext/actions/action_left_adapter.rb +32 -0
- data/lib/seqtrimnext/actions/action_left_primer.rb +17 -0
- data/lib/seqtrimnext/actions/action_linker.rb +30 -0
- data/lib/seqtrimnext/actions/action_low_complexity.rb +30 -0
- data/lib/seqtrimnext/actions/action_low_high_size.rb +31 -0
- data/lib/seqtrimnext/actions/action_low_quality.rb +33 -0
- data/lib/seqtrimnext/actions/action_mid.rb +30 -0
- data/lib/seqtrimnext/actions/action_multiple_linker.rb +29 -0
- data/lib/seqtrimnext/actions/action_paired_reads.rb +28 -0
- data/lib/seqtrimnext/actions/action_poly_a.rb +29 -0
- data/lib/seqtrimnext/actions/action_poly_t.rb +29 -0
- data/lib/seqtrimnext/actions/action_rem_adit_artifacts.rb +32 -0
- data/lib/seqtrimnext/actions/action_right_adapter.rb +29 -0
- data/lib/seqtrimnext/actions/action_right_primer.rb +25 -0
- data/lib/seqtrimnext/actions/action_short_insert.rb +32 -0
- data/lib/seqtrimnext/actions/action_unexpected_poly_t.rb +29 -0
- data/lib/seqtrimnext/actions/action_unexpected_vector.rb +31 -0
- data/lib/seqtrimnext/actions/action_vectors.rb +31 -0
- data/lib/seqtrimnext/actions/seqtrim_action.rb +136 -0
- data/lib/seqtrimnext/classes/action_manager.rb +47 -0
- data/lib/seqtrimnext/classes/em_classes/seqtrim_work_manager.rb +335 -0
- data/lib/seqtrimnext/classes/em_classes/seqtrim_worker.rb +290 -0
- data/lib/seqtrimnext/classes/extract_stats.rb +255 -0
- data/lib/seqtrimnext/classes/gnu_plot_graph.rb +140 -0
- data/lib/seqtrimnext/classes/graph_stats.rb +74 -0
- data/lib/seqtrimnext/classes/install_database.rb +43 -0
- data/lib/seqtrimnext/classes/install_requirements.rb +123 -0
- data/lib/seqtrimnext/classes/list_db.rb +49 -0
- data/lib/seqtrimnext/classes/make_blast_db.rb +113 -0
- data/lib/seqtrimnext/classes/one_blast.rb +41 -0
- data/lib/seqtrimnext/classes/params.rb +387 -0
- data/lib/seqtrimnext/classes/piro.rb +78 -0
- data/lib/seqtrimnext/classes/plugin_manager.rb +153 -0
- data/lib/seqtrimnext/classes/scan_for_restr_site.rb +138 -0
- data/lib/seqtrimnext/classes/scbi_stats.rb +68 -0
- data/lib/seqtrimnext/classes/seqtrim.rb +317 -0
- data/lib/seqtrimnext/classes/sequence.rb +55 -0
- data/lib/seqtrimnext/classes/sequence_group.rb +72 -0
- data/lib/seqtrimnext/classes/sequence_with_action.rb +503 -0
- data/lib/seqtrimnext/plugins/plugin.rb +267 -0
- data/lib/seqtrimnext/plugins/plugin_ab_adapters.rb +189 -0
- data/lib/seqtrimnext/plugins/plugin_adapters.rb +165 -0
- data/lib/seqtrimnext/plugins/plugin_amplicons.rb +221 -0
- data/lib/seqtrimnext/plugins/plugin_contaminants.rb +209 -0
- data/lib/seqtrimnext/plugins/plugin_extract_inserts.rb +438 -0
- data/lib/seqtrimnext/plugins/plugin_find_poly_at.rb +393 -0
- data/lib/seqtrimnext/plugins/plugin_ignore_repeated.rb +101 -0
- data/lib/seqtrimnext/plugins/plugin_indeterminations.rb +199 -0
- data/lib/seqtrimnext/plugins/plugin_key.rb +70 -0
- data/lib/seqtrimnext/plugins/plugin_linker.rb +232 -0
- data/lib/seqtrimnext/plugins/plugin_low_complexity.rb +98 -0
- data/lib/seqtrimnext/plugins/plugin_low_high_size.rb +74 -0
- data/lib/seqtrimnext/plugins/plugin_low_quality.rb +394 -0
- data/lib/seqtrimnext/plugins/plugin_mids.rb +231 -0
- data/lib/seqtrimnext/plugins/plugin_rem_adit_artifacts.rb +246 -0
- data/lib/seqtrimnext/plugins/plugin_short_insert.rb +244 -0
- data/lib/seqtrimnext/plugins/plugin_vectors.rb +191 -0
- data/lib/seqtrimnext/templates/amplicons.txt +16 -0
- data/lib/seqtrimnext/templates/genomics_454.txt +5 -0
- data/lib/seqtrimnext/templates/genomics_454_with_paired.txt +5 -0
- data/lib/seqtrimnext/templates/low_quality.txt +5 -0
- data/lib/seqtrimnext/templates/low_quality_and_low_complexity.txt +5 -0
- data/lib/seqtrimnext/templates/transcriptomics_454.txt +8 -0
- data/lib/seqtrimnext/templates/transcriptomics_plants.txt +8 -0
- data/lib/seqtrimnext/utils/extract_samples.rb +52 -0
- data/lib/seqtrimnext/utils/fasta2xml.rb +69 -0
- data/lib/seqtrimnext/utils/global_match.rb +65 -0
- data/lib/seqtrimnext/utils/hash_stats.rb +29 -0
- data/lib/seqtrimnext/utils/json_utils.rb +50 -0
- data/lib/seqtrimnext/utils/load_fasta_names_in_hash.rb +37 -0
- data/lib/seqtrimnext/utils/load_qual_in_hash.rb +37 -0
- data/lib/seqtrimnext/utils/recover_mid.rb +95 -0
- data/lib/seqtrimnext/utils/string_utils.rb +56 -0
- data/lib/seqtrimnext.rb +37 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_seqtrimnext.rb +11 -0
- metadata +318 -0
|
@@ -0,0 +1,503 @@
|
|
|
1
|
+
|
|
2
|
+
require "action_manager.rb"
|
|
3
|
+
require "sequence"
|
|
4
|
+
require 'term/ansicolor'
|
|
5
|
+
include Term::ANSIColor
|
|
6
|
+
|
|
7
|
+
######################################
|
|
8
|
+
# Author:: Almudena Bocinos Rioboo
|
|
9
|
+
# This class create the structure to storage the actions associated to a sequence.
|
|
10
|
+
# It allows to add action, and to write at file the actions for every sequence
|
|
11
|
+
# Inherit:: Sequence
|
|
12
|
+
######################################
|
|
13
|
+
|
|
14
|
+
class SequenceWithAction < Sequence
|
|
15
|
+
SHOW_QUAL = false
|
|
16
|
+
SHOW_FINAL_INSERTS=true
|
|
17
|
+
attr_accessor :actions,:seq_fasta_orig, :seq_qual_orig ,:insert_start , :insert_end, :stats , :insert_start_last , :insert_end_last
|
|
18
|
+
|
|
19
|
+
# Creates an instance with the structure to storage the actions associated to a sequence
|
|
20
|
+
def initialize(seq_name,seq_fasta,seq_qual, seq_comment = '')
|
|
21
|
+
super
|
|
22
|
+
#Tried
|
|
23
|
+
#if @ns_present then $LOG.debug "The sequence #{seq_name} has N's" else $LOG.debug "The sequence #{seq_name} hasn't N's" end
|
|
24
|
+
#if @xs_present then $LOG.debug "The sequence #{seq_name} has X's" else $LOG.debug "The sequence #{seq_name} hasn't X's" end
|
|
25
|
+
@actions = []
|
|
26
|
+
@seq_fasta_orig = seq_fasta
|
|
27
|
+
@seq_fasta = seq_fasta
|
|
28
|
+
|
|
29
|
+
@seq_qual_orig = seq_qual
|
|
30
|
+
@seq_qual = seq_qual
|
|
31
|
+
|
|
32
|
+
@insert_start = 0
|
|
33
|
+
@insert_end = seq_fasta.length-1
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
#@seq_qual = seq_qual
|
|
37
|
+
|
|
38
|
+
@stats={}
|
|
39
|
+
|
|
40
|
+
@file_tags=[]
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# add a file tag to sequence
|
|
45
|
+
def add_file_tag(tag_level, tag_value, tag_type)
|
|
46
|
+
@file_tags<< {:level => tag_level, :name => tag_value, :type=> tag_type}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# join file tags into a path
|
|
50
|
+
def get_file_tag_path
|
|
51
|
+
levels=@file_tags.map{|e| e[:level]}.uniq
|
|
52
|
+
|
|
53
|
+
dirpath = []
|
|
54
|
+
levels.sort.each do |level|
|
|
55
|
+
# select names from all that are not files
|
|
56
|
+
level_path = @file_tags.select{|e| ((e[:level]==level) && (e[:type]!=:file))}.map{|tag| tag[:name]}
|
|
57
|
+
dirpath << level_path.join('_') if !level_path.empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
filepath = []
|
|
61
|
+
levels.sort.each do |level|
|
|
62
|
+
# select names from all that are not files
|
|
63
|
+
level_path = @file_tags.select{|e| ((e[:level]==level) && (e[:type]!=:dir))}.map{|tag| tag[:name]}
|
|
64
|
+
filepath << level_path.join('_') if !level_path.empty?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
filename=filepath.join('_')
|
|
69
|
+
dirname=File.join(dirpath)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# puts "#{dirname}, #{filename}"
|
|
73
|
+
|
|
74
|
+
return [dirname,filename]
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Adds a new action to the sequence
|
|
79
|
+
def add_action(a)
|
|
80
|
+
$LOG.info("Adding action #{a.type} to #{seq_name}")
|
|
81
|
+
|
|
82
|
+
@actions.push a
|
|
83
|
+
|
|
84
|
+
a.apply_to(self)
|
|
85
|
+
|
|
86
|
+
return a
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Adds a new action to the sequence
|
|
91
|
+
def new_action(start_pos,end_pos,action_type)
|
|
92
|
+
|
|
93
|
+
a = ActionManager.new_action(start_pos,end_pos,action_type)
|
|
94
|
+
|
|
95
|
+
return a
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# def left_action(seq_fasta,start_pos,end_pos)
|
|
101
|
+
# return ((start_pos - 0 ) < (seq_fasta.length - end_pos))
|
|
102
|
+
# end
|
|
103
|
+
#
|
|
104
|
+
# def right_action(seq_fasta,start_pos,end_pos)
|
|
105
|
+
# return !left_action(seq_fasta,start_pos,end_pos)
|
|
106
|
+
# end
|
|
107
|
+
|
|
108
|
+
# Adds a set of actions to the sequence, update the positon of the cut sequence. #
|
|
109
|
+
# Version with the parameters left_action and rigth action #
|
|
110
|
+
|
|
111
|
+
# TODO - Nuevo algoritmo de corte de seqs.
|
|
112
|
+
# 1 - Ordenar seqs con cut=true en izq y der y por posición de ends o begs
|
|
113
|
+
# 2 - Obtener izq.ends.max y der.begs.min
|
|
114
|
+
# 3 - El corte lo definen esos min y max
|
|
115
|
+
|
|
116
|
+
def add_actions(actions)
|
|
117
|
+
|
|
118
|
+
if !actions.empty?
|
|
119
|
+
start_pos=0
|
|
120
|
+
end_pos = 0
|
|
121
|
+
cut = false
|
|
122
|
+
|
|
123
|
+
max_end_pos = 0
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
p_beg = @insert_start
|
|
128
|
+
p_end = @seq_fasta.length-1+@insert_start
|
|
129
|
+
# p_end = @seq_fasta.length-1
|
|
130
|
+
# puts "ADDING ACTIONS"
|
|
131
|
+
# puts "=" * 50
|
|
132
|
+
# puts 'actions ' + actions.inspect
|
|
133
|
+
# para cada accion ordenada por start_pos
|
|
134
|
+
actions.sort{|e,f| e.start_pos<=>f.start_pos}.each do |action|
|
|
135
|
+
# puts ' current ' + action.inspect
|
|
136
|
+
# puts " UUUUUUUUUU1 "
|
|
137
|
+
# puts "vect in pos #{action.start_pos} #{action.end_pos}" if (action.type=='ActionVectors')
|
|
138
|
+
# puts " UUUUUUUUUU2 "
|
|
139
|
+
|
|
140
|
+
# puts "ADD ACTION:",action.to_json
|
|
141
|
+
|
|
142
|
+
# añadir el inicio del inserto si es necesario
|
|
143
|
+
if action.start_pos !=0 or action.end_pos != 0
|
|
144
|
+
action.start_pos+=@insert_start
|
|
145
|
+
action.end_pos+=@insert_start
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# guardar accion
|
|
149
|
+
a = add_action(action)
|
|
150
|
+
|
|
151
|
+
start_pos= a.start_pos
|
|
152
|
+
end_pos=a.end_pos
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# si hay que cortar y es accion izquierda
|
|
156
|
+
# if (a.cut && ( left_action(@seq_fasta,start_pos-p_beg,end_pos) || # action is left in insert
|
|
157
|
+
if (a.cut && a.left_action?(@seq_fasta.length))
|
|
158
|
+
# if (a.cut && ( a.left_action==true ||
|
|
159
|
+
# ( a.right_action==false && (left_action(@seq_fasta,start_pos-p_beg,end_pos-p_beg) || # action is left in insert
|
|
160
|
+
# (start_pos==p_beg)) ))) # action is right in insert but it's continous to the before action
|
|
161
|
+
#
|
|
162
|
+
# puts "in seq w action left act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
163
|
+
# puts "Cut left: #{a.inspect}"
|
|
164
|
+
if (end_pos+1) > p_beg
|
|
165
|
+
p_beg=end_pos+1
|
|
166
|
+
end
|
|
167
|
+
a.left_action=true
|
|
168
|
+
cut=true
|
|
169
|
+
# puts "in seq w action left act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
170
|
+
|
|
171
|
+
# elsif (a.cut && right_action(@seq_fasta,start_pos-p_beg,end_pos)) # action is rigth in insert
|
|
172
|
+
elsif (a.cut && a.right_action?(@seq_fasta.length))
|
|
173
|
+
# puts "Cut right: #{a.inspect}"
|
|
174
|
+
# elsif (a.cut && (a.right_action==true || right_action(@seq_fasta,start_pos-p_beg,end_pos-p_beg))) # action is rigth in insert
|
|
175
|
+
# puts "in seq w action right act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
176
|
+
if (start_pos-1) < p_end
|
|
177
|
+
p_end = start_pos-1
|
|
178
|
+
end
|
|
179
|
+
a.right_action=true
|
|
180
|
+
cut=true
|
|
181
|
+
# puts "in seq w action right act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
182
|
+
elsif !a.cut
|
|
183
|
+
# puts "NO cut action"
|
|
184
|
+
if a.right_action?(@seq_fasta.length)
|
|
185
|
+
a.right_action=true
|
|
186
|
+
else
|
|
187
|
+
a.left_action = true
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# puts "p_beg: #{p_beg} , p_end: #{p_end}"
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
if cut then
|
|
198
|
+
|
|
199
|
+
@seq_fasta = @seq_fasta_orig[p_beg..p_end]
|
|
200
|
+
# puts @seq_fasta
|
|
201
|
+
@seq_qual = @seq_qual_orig[p_beg..p_end] if !@seq_qual_orig.nil?
|
|
202
|
+
|
|
203
|
+
# puts "in seq w action1 #{@insert_start} #{@insert_end}"
|
|
204
|
+
@insert_start = p_beg
|
|
205
|
+
size_cut_right = @insert_end - p_end
|
|
206
|
+
@insert_end -= size_cut_right
|
|
207
|
+
# puts "in seq w action2 #{@insert_start} #{@insert_end}"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# Adds a set of actions to the sequence, update the positon of the cut sequence. #
|
|
216
|
+
# Version without the parameters left_action and rigth action #
|
|
217
|
+
|
|
218
|
+
def add_actions_no_left_rigth_parameters(actions)
|
|
219
|
+
|
|
220
|
+
if !actions.empty?
|
|
221
|
+
start_pos=0
|
|
222
|
+
end_pos = 0
|
|
223
|
+
cut = false
|
|
224
|
+
|
|
225
|
+
max_end_pos = 0
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
p_beg = @insert_start
|
|
230
|
+
p_end = @seq_fasta.length-1+@insert_start
|
|
231
|
+
# p_end = @seq_fasta.length-1
|
|
232
|
+
|
|
233
|
+
# puts 'actions ' + actions.inspect
|
|
234
|
+
# para cada accion ordenada por start_pos
|
|
235
|
+
actions.sort!{|e,f| e.start_pos<=>f.start_pos}.each do |action|
|
|
236
|
+
# puts ' current ' + action.inspect
|
|
237
|
+
# puts " UUUUUUUUUU1 "
|
|
238
|
+
# puts "vect in pos #{action.start_pos} #{action.end_pos}" if (action.type=='ActionVectors')
|
|
239
|
+
# puts " UUUUUUUUUU2 "
|
|
240
|
+
|
|
241
|
+
# puts "ADD ACTION:",action.to_json
|
|
242
|
+
|
|
243
|
+
# añadir el inicio del inserto si es necesario
|
|
244
|
+
if action.start_pos !=0 or action.end_pos != 0
|
|
245
|
+
action.start_pos+=@insert_start
|
|
246
|
+
action.end_pos+=@insert_start
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# guardar accion
|
|
250
|
+
a = add_action(action)
|
|
251
|
+
|
|
252
|
+
start_pos= a.start_pos
|
|
253
|
+
end_pos=a.end_pos
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# si hay que cortar y es accion izquierda
|
|
257
|
+
# if (a.cut && ( left_action(@seq_fasta,start_pos-p_beg,end_pos) || # action is left in insert
|
|
258
|
+
if (a.cut && ( left_action(@seq_fasta,start_pos-p_beg,end_pos-p_beg) || # action is left in insert
|
|
259
|
+
(start_pos==p_beg)) ) # action is right in insert but it's continous to the before action
|
|
260
|
+
|
|
261
|
+
puts "in seq w action left act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
262
|
+
|
|
263
|
+
p_beg=end_pos+1
|
|
264
|
+
cut=true
|
|
265
|
+
a.left_action=true
|
|
266
|
+
# puts "in seq w action left act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
267
|
+
|
|
268
|
+
# elsif (a.cut && right_action(@seq_fasta,start_pos-p_beg,end_pos)) # action is rigth in insert
|
|
269
|
+
elsif (a.cut && right_action(@seq_fasta,start_pos-p_beg,end_pos-p_beg)) # action is rigth in insert
|
|
270
|
+
puts "in seq w action right act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
271
|
+
p_end = start_pos-1
|
|
272
|
+
a.right_action=true
|
|
273
|
+
cut=true
|
|
274
|
+
# puts "in seq w action right act #{start_pos} #{end_pos} pbeg #{p_beg} p_end #{p_end}"
|
|
275
|
+
elsif !a.cut
|
|
276
|
+
puts "NO cut action"
|
|
277
|
+
if right_action(@seq_fasta,start_pos-p_beg,end_pos-p_beg)
|
|
278
|
+
a.right_action=true
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
if cut then
|
|
289
|
+
|
|
290
|
+
@seq_fasta = @seq_fasta_orig[p_beg..p_end]
|
|
291
|
+
@seq_qual = @seq_qual_orig[p_beg..p_end] if !@seq_qual_orig.nil?
|
|
292
|
+
|
|
293
|
+
# puts "in seq w action1 #{@insert_start} #{@insert_end}"
|
|
294
|
+
@insert_start = p_beg
|
|
295
|
+
size_cut_right = @insert_end - p_end
|
|
296
|
+
@insert_end -= size_cut_right
|
|
297
|
+
# puts "in seq w action2 #{@insert_start} #{@insert_end}"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
# check if range defined by q_beg and q_end is inside some action of the type indicated by action_type
|
|
306
|
+
def range_inside_action_type?(q_beg,q_end,action_type)
|
|
307
|
+
res = false
|
|
308
|
+
|
|
309
|
+
action_list = get_actions(action_type)
|
|
310
|
+
|
|
311
|
+
action_list.each do |action|
|
|
312
|
+
|
|
313
|
+
if action.contains_action?(q_beg+@insert_start,q_end+@insert_start,10)
|
|
314
|
+
res = true
|
|
315
|
+
break
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
return res
|
|
320
|
+
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
# Prints a sequence with its actions to a file
|
|
326
|
+
def to_text
|
|
327
|
+
|
|
328
|
+
output_res=[]
|
|
329
|
+
|
|
330
|
+
if @seq_rejected
|
|
331
|
+
output_res<< " Sequence #{seq_name} had the next actions: ".bold.underline + " REJECTED: #{@seq_rejected_by_message}".red
|
|
332
|
+
# puts @seq_name.bold + bold + ' REJECTED BECAUSE ' +@seq_rejected_by_message.bold if @seq_rejected
|
|
333
|
+
else
|
|
334
|
+
output_res<< " Sequence #{seq_name} had the next actions: ".bold.underline
|
|
335
|
+
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
n=1
|
|
339
|
+
withMessage = ["ActionIsContaminated","ActionVectors","ActionBadAdapter","ActionLeftAdapter","ActionRightAdapter"]
|
|
340
|
+
color = red
|
|
341
|
+
|
|
342
|
+
@actions.sort!{|e,f| e.start_pos<=>f.start_pos}.each do |a|
|
|
343
|
+
a_type=a.action_type
|
|
344
|
+
color = a.apply_decoration(" EXAMPLE ")
|
|
345
|
+
color2 =a.apply_decoration(" #{a_type.center(8)} ")
|
|
346
|
+
|
|
347
|
+
reversed_str = ''
|
|
348
|
+
|
|
349
|
+
if a.reversed
|
|
350
|
+
reversed_str = " REVERSED ".bold
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
output_res<< " [#{n}] ".bold + color2+ " #{a.title} ".ljust(24).reset + " [ " + " #{a.start_pos+1}".center(6) + " , " + "#{a.end_pos+1}".center(6) + " ]" + clear.to_s + "#{a.message}".rjust(a.message.size+8) + reversed_str
|
|
354
|
+
|
|
355
|
+
n +=1
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
pos = 0
|
|
359
|
+
res = ''
|
|
360
|
+
|
|
361
|
+
@seq_fasta_orig.each_char do |c|
|
|
362
|
+
|
|
363
|
+
@actions.each do |a|
|
|
364
|
+
c= a.decorate(c,pos)
|
|
365
|
+
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
res += c
|
|
369
|
+
|
|
370
|
+
pos += 1
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
output_res<< res
|
|
374
|
+
|
|
375
|
+
if SHOW_QUAL and @seq_qual_orig
|
|
376
|
+
res = ''
|
|
377
|
+
pos=0
|
|
378
|
+
output_res<< ''
|
|
379
|
+
@seq_fasta_orig.each_char do |c2|
|
|
380
|
+
c=@seq_qual_orig[pos].to_s+' '
|
|
381
|
+
@actions.each do |a|
|
|
382
|
+
c= a.decorate(c,pos)
|
|
383
|
+
|
|
384
|
+
end
|
|
385
|
+
res += c
|
|
386
|
+
pos += 1
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
output_res<< res
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
if SHOW_FINAL_INSERTS
|
|
393
|
+
output_res<< "INSERT ==>"+get_inserts.join("\nINSERT ==>")
|
|
394
|
+
output_res<< "="*80
|
|
395
|
+
end
|
|
396
|
+
# puts @seq_name.bold + bold + ' rejected because ' +@seq_rejected_by_message.bold if @seq_rejected
|
|
397
|
+
|
|
398
|
+
return output_res
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
def to_text_seq_fasta
|
|
402
|
+
return " "*@insert_start +@seq_fasta
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
# Saves a sequence with its actions to a file
|
|
406
|
+
def save_to_file
|
|
407
|
+
File.open("results/#{seq_name}"+".txt", 'w') { |file|
|
|
408
|
+
|
|
409
|
+
n=1
|
|
410
|
+
|
|
411
|
+
@actions.each do |a|
|
|
412
|
+
file.puts a.description
|
|
413
|
+
n +=1
|
|
414
|
+
end
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def action_right(a,p_beg,p_end)
|
|
420
|
+
|
|
421
|
+
# $LOG.debug " is right action" if ((a.start_pos-p_beg)>(p_end-a.end_pos-1))
|
|
422
|
+
# $LOG.debug " is left action " if !((a.start_pos-p_beg)>(p_end-a.end_pos-1))
|
|
423
|
+
return ((a.start_pos-p_beg)>(p_end-a.end_pos-1))
|
|
424
|
+
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
# def is_first_action(p_beg,p_end,seq_end)
|
|
429
|
+
# return ((p_beg==0) && (p_end==seq_end))
|
|
430
|
+
# end
|
|
431
|
+
|
|
432
|
+
#Receive a type of action. Be carefull, type is not a string .
|
|
433
|
+
#Return an array of actions of this type
|
|
434
|
+
def get_actions(type=nil)
|
|
435
|
+
res = []
|
|
436
|
+
|
|
437
|
+
@actions.each do |a|
|
|
438
|
+
if a.is_a?(type) or type.nil?
|
|
439
|
+
res.push a
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
return res
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def get_inserts
|
|
450
|
+
|
|
451
|
+
inserts = get_actions(ActionInsert)
|
|
452
|
+
|
|
453
|
+
res =[]
|
|
454
|
+
inserts.each do |insert|
|
|
455
|
+
res.push @seq_fasta_orig[insert.start_pos..insert.end_pos]
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
return res
|
|
459
|
+
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
def get_qual_inserts
|
|
463
|
+
|
|
464
|
+
inserts = get_actions(ActionInsert)
|
|
465
|
+
|
|
466
|
+
res =[]
|
|
467
|
+
|
|
468
|
+
if @seq_qual_orig
|
|
469
|
+
inserts.each do |insert|
|
|
470
|
+
res.push @seq_qual_orig[insert.start_pos..insert.end_pos]
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
return res
|
|
475
|
+
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
def insert_bounds
|
|
479
|
+
return [@insert_start,@insert_end]
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
def to_json
|
|
483
|
+
s={}
|
|
484
|
+
s[:seq_name]=@seq_name
|
|
485
|
+
s[:seq_fasta]=@seq_fasta_orig
|
|
486
|
+
s[:seq_qual]=''
|
|
487
|
+
if @seq_qual_orig
|
|
488
|
+
s[:seq_qual]=@seq_qual_orig.join(' ')
|
|
489
|
+
end
|
|
490
|
+
s[:rejected]=@rejected
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
s[:fasta_inserts]= get_inserts
|
|
494
|
+
s[:qual_inserts]=get_qual_inserts.map { |e| e.join(' ') }
|
|
495
|
+
s[:actions]=[]
|
|
496
|
+
|
|
497
|
+
@actions.each { |a| s[:actions].push a.to_hash }
|
|
498
|
+
# puts "YAML",s.to_yaml
|
|
499
|
+
return JSON.pretty_generate(s)
|
|
500
|
+
end
|
|
501
|
+
# private :to_text
|
|
502
|
+
|
|
503
|
+
end
|