Class: ExtractSamples

Inherits:
FastaReader
  • Object
show all
Defined in:
lib/seqtrimnext/utils/extract_samples.rb

Overview

Author

Almudena Bocinos Rioboo

Extract ramdom sequences until “num_seqs”

Inherit

FastaReader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ ExtractSamples

Returns a new instance of ExtractSamples.



12
13
14
15
# File 'lib/seqtrimnext/utils/extract_samples.rb', line 12

def initialize(file_name)
  @num_seqs = 0
  super(file_name)
end

Instance Attribute Details

#num_seqsObject

Returns the value of attribute num_seqs.



11
12
13
# File 'lib/seqtrimnext/utils/extract_samples.rb', line 11

def num_seqs
  @num_seqs
end

Instance Method Details

#on_begin_processObject

override begin processing



18
19
20
21
22
23
# File 'lib/seqtrimnext/utils/extract_samples.rb', line 18

def on_begin_process()
   $LOG.info " Begin Extract Samples"
   @fich = File.open("results/Sample.txt",'w') 
   @max = 1000
   
end

#on_end_processObject

override end processing



47
48
49
50
# File 'lib/seqtrimnext/utils/extract_samples.rb', line 47

def on_end_process()
   $LOG.info "All Samples have been extracted"
   @fich.close
end

#on_process_sequence(seq_name, seq_fasta) ⇒ Object

override processing sequence



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/seqtrimnext/utils/extract_samples.rb', line 26

def on_process_sequence(seq_name,seq_fasta)
    ra_seq = Kernel.rand
   
    if ((@num_seqs < @max) and (ra_seq>0.5)) #if cond is successful then, choose a part from this sequence
      #calculate the part from the sequence
      width = (Kernel.rand * 50 ) + 300
      ra_part1 = Kernel.rand * (seq_fasta.length-width)
      ra_part2 = ra_part1 + width
      sub_seq_fasta = seq_fasta.slice(ra_part1,ra_part2)
      
      @fich.puts "#{seq_name} "
      @fich.puts "#{sub_seq_fasta} "
      @num_seqs += 1
      
    end
    
end