class ScanForRestrSite

Public Class Methods

new(sequence,rest) click to toggle source

Creates the structure and start the reading of parameter's file

# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 10
def initialize(sequence,rest)    
  @seq_fasta=sequence 
  @rest=rest      
  puts "#{@seq_fasta}  , #{@rest}"  
  res = execute
  

  res.each do |e| 
      puts "#{e.join(',')}"
  end
  
# selects from res,the max good hit
  puts "--- MAX: --- "
  
  max = res.max{|e1,e2| e1[1]<=> e2[1]}
                    
  puts max.join(' ; ')                    
                                           
# checks if the max one has the size of restriction with a margen error
  margen = (@rest.size <= 4)? 0 : 1;  # <- don't change
  if ((max[1] !=  @rest.size) && (max[1] != @rest.size-margen)) 
    puts "-the max good hit hasn't the size minimum: #{@rest.size} or #{@rest.size-margen} "
    max=[]
  end
  
  
  
  #read_file(path)
end

Public Instance Methods

execute() click to toggle source
# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 42
def execute    
  r=[]
                            #
                            # for (my $p=0; $p < $sL-$srfL; $p++){
                            #     $os = $ns = $xs = 0;
                            #     for ( my $i=0; $i < $srfL; $i++ ) {
                            #         my $c  = substr($s, $i+$p, 1);  # ver si decrementar antes pos
                            #         my $cc = substr($restrSite, $i, 1);
                            #         if ($c eq $cc) {
                            #             ++$os;
                            #         } elsif ($c eq "N"){
                            #             ++$ns;
                            #         } else {
                            #             ++$xs;
                            #         }
                            #     }
                            #     $r[$p] = [$p, $os, $ns, $xs];
                            #         print "$p, $os, $ns, $xs\n";
                            # }
  for p in 0..@seq_fasta.size-@rest.size 
      os = 0; 
      ns = 0; 
      xs = 0;                    
      puts "-------[#{p}]-#{@seq_fasta[p,@seq_fasta.size-p]}  , #{@rest}"  
      
     i=0
    @rest.each_char do |cc|
       c = @seq_fasta[i+p].chr
       puts "(#{c}==#{cc})=>#{c==cc}"
      if (c == cc)
        os += 1
      elsif (c == 'N')
        ns += 1
      else     
        xs += 1
      end
      i+=1     
      
    end
    r[p]=[p,os,ns,xs]
     puts r[p].join(',')
  end     
  return r
end
exists?(param_name) click to toggle source

Returns true if exists the parameter and nil if don't

# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 131
def exists?(param_name)
  return !@h[param_name].nil?
end
get_param(param) click to toggle source

Return the parameter's list in an array

# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 119
def get_param(param)
  #$LOG.debug "Get Param:  #{@h[param]}"
  return @h[param]
end
print_parameters() click to toggle source

Prints the pair name/numeric-value for every parameter

read_file(path_fichero) click to toggle source

Reads param's file

# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 88
def read_file(path_fichero)
  File.open(path_fichero).each_line do |line| 
         
    line.chomp! # delete end of line
    
    if !line.empty?
      if !(line =~ /^#/)   # if line is not a comment
        # extract the parameter's name in params[0] and the parameter's value in params[1]
        params = line.split(/\s*=\s*/)
        
        # storage in the hash the pair key/value, in our case will be name/numeric-value ,
        # that are save in params[0] and params[1],  respectively
        @h[params[0]] = params[1]
        
        $LOG.debug "read: #{params[1]}"
      end # end if comentario
    end #end if line
  end #end each
  $LOG.info "File Params have been readed"

end
set_param(param,value) click to toggle source
# File lib/seqtrimnext/classes/scan_for_restr_site.rb, line 124
def set_param(param,value)
  @h[param] = value
end