Class: PluginAdaptersOld

Inherits:
Plugin
  • Object
show all
Defined in:
lib/seqtrimnext/plugins_old/plugin_adapters_old.rb

Overview

Author: Almudena Bocinos Rioboo

Defines the main methods that are necessary to execute PluginAdapters

Inherit: Plugin

Instance Attribute Summary

Attributes inherited from Plugin

#stats

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#add_plugin_stats, #add_stats, #add_text_stats, auto_setup, #can_execute?, check_param, #execute, get_graph_filename, get_graph_title, graph_ignored?, ignored_graphs, #initialize, #merge_hits, #overlapX?, plot_setup, valid_graphs

Constructor Details

This class inherits a constructor from Plugin

Class Method Details

.check_params(params) ⇒ Object

Returns an array with the errors due to parameters are missing



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/seqtrimnext/plugins_old/plugin_adapters_old.rb', line 137

def self.check_params(params)
  errors=[]
  
  comment='Blast E-value used as cut-off when searching for adapters or primers'
  default_value = 1e-6
params.check_param(errors,'blast_evalue_adapters','Float',default_value,comment)

comment='Minimum required identity (%) for a reliable adapter'
default_value = 95
params.check_param(errors,'blast_percent_adapters','Integer',default_value,comment)
  
  comment='Path for adapter database'
default_value = File.join($FORMATTED_DB_PATH,'adapters.fasta')
params.check_param(errors,'adapters_db','DB',default_value,comment)		
  
  return errors
end

Instance Method Details

#cut_by_right(adapter, seq) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/seqtrimnext/plugins_old/plugin_adapters_old.rb', line 36

def cut_by_right(adapter,seq)
  
  left_size = adapter.q_beg-seq.insert_start+1
  right_size = seq.insert_end-adapter.q_end+1
  left_size=0 if (left_size<0)
  right_size=0 if (right_size<0) 
  
  return (left_size>(right_size/2).to_i)
  
end

#do_blasts(seqs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/seqtrimnext/plugins_old/plugin_adapters_old.rb', line 47

def do_blasts(seqs)
   # find MIDS  with less results than max_target_seqs value 
   blast=BatchBlast.new("-db #{@params.get_param('adapters_db')}",'blastn'," -task blastn-short -evalue #{@params.get_param('blast_evalue_adapters')} -perc_identity #{@params.get_param('blast_percent_adapters')}")  
   $LOG.debug('BLAST:'+blast.get_blast_cmd)

   fastas=[]
   
   seqs.each do |seq|
    fastas.push ">"+seq.seq_name
    fastas.push seq.seq_fasta
   end
   
   # fastas=fastas.join("\n")
   
   blast_table_results = blast.do_blast(fastas)
   
   # puts blast_table_results.inspect
  
   return blast_table_results
end

#exec_seq(seq, blast_query) ⇒ Object



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
# File 'lib/seqtrimnext/plugins_old/plugin_adapters_old.rb', line 69

def exec_seq(seq,blast_query)
 if blast_query.query_id != seq.seq_name
   raise "Blast and seq names does not match, blast:#{blast_query.query_id} sn:#{seq.seq_name}"
 end
 
  $LOG.debug "[#{self.class.to_s}, seq: #{seq.seq_name}]: looking for adapters into the sequence" 

      
  # blast=BatchBlast.new("-db #{File.join($FORMATTED_DB_PATH,'adapters.fasta')}",'blastn'," -task blastn-short -evalue #{@params.get_param('blast_evalue_adapters')} -perc_identity #{@params.get_param('blast_percent_adapters')}")  
  
  # blast with only one sequence, no with many sequences from a database
  #---------------------------------------------------------------------
  
  # blast_table_results = blast.do_blast(seq.seq_fasta)             #rise seq to adapterss  executing over blast
  
  #blast_table_results = BlastTableResult.new(res) 
  
  # blast_table_results.inspect         
  
  adapters=[]
  # blast_table_results.querys.each do |query|     # first round to save adapters without overlap
    merge_hits(blast_query,adapters)
  # end

  begin 
    adapters2=adapters                            # second round to save adapters without overlap
    adapters = []
    merge_hits(adapters2,adapters)
  end until (adapters2.count == adapters.count) 

  actions=[] 
  adapter_size=0
  # @stats['adapter_size']={}
  adapters.each do |ad|                           # adds the correspondent action to the sequence  
     
     type = get_type_adapter(ad.q_beg,ad.q_end,seq)
     a = seq.new_action(ad.q_beg,ad.q_end,type) 
     # puts " state left_action #{a.left_action} right_action #{a.right_action}"
       

     adapter_size=ad.q_end-ad.q_beg+1 
     
     if cut_by_right(ad,seq)
      
      # puts "action right end1 #{seq.insert_end}"
      
      a.right_action=true    #mark rigth action to get the left insert
    else 
        
      # puts " cut1 by left #{seq.insert_start} ad #{ad.q_beg+seq.insert_start} #{ad.q_end+seq.insert_start}"
               
      a.left_action = true   #mark left action to get the right insert        
      
    end 
    
    a.message = ad.subject_id 
    a.reversed = ad.reversed 
    actions.push a 
    
    # @stats[:adapter_size]={adapter_size => 1} 
    add_stats('adapter_size',adapter_size)  
      
  end 
  seq.add_actions(actions)
  #    
end

#get_type_adapter(p_start, p_end, seq) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/seqtrimnext/plugins_old/plugin_adapters_old.rb', line 12

def get_type_adapter(p_start,p_end,seq)
     #if q_beg is nearer the left, add adapter action by the left,
     #if q_end esta is nearer the right , add adapter action by  the right
     #NOTE: If the adapter is very near from left and rigth,
     #then the sequence isn't valid, because almost sequence is adapter.
     
     
     v1= p_end.to_i
     v2= p_start.to_i   
     
      # puts " startadapter #{v2} endadapter #{v1} insert_start #{seq.insert_start}  insert_end #{seq.insert_end}"
     
      # puts " #{v2+seq.insert_start} <? #{seq.seq_fasta.length - v1 - 1 + seq.seq_fasta_orig.length - seq.insert_end-1}"
     if (v2+seq.insert_start  < (seq.seq_fasta.length - v1 - 1+ seq.seq_fasta_orig.length - seq.insert_end-1)) #IF THE NEAREST ONE IS THE LEFT
       type = "ActionLeftAdapter"          
       
     else
        type = "ActionRightAdapter"
       
     end
     return type
end