Class: FastaFile

Inherits:
Object
  • Object
show all
Defined in:
lib/scbi_fasta/fasta_file.rb

Overview

Author: Almudena Bocinos Rioboo

Use: Deprecated. The class FastaReader has been substituted by FastaQualReader

Reads a fasta file and fires events to process it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ FastaFile

Initialize instance



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scbi_fasta/fasta_file.rb', line 14

def initialize(file_name)
  if File.exist?(file_name)
  @num_seqs = 0

  @file_name = file_name
  @file = File.open(file_name)
else
		raise "File #{file_name} doesn't exists" 
  	
  end
  
end

Instance Attribute Details

#num_seqsObject (readonly)

Returns the value of attribute num_seqs.



10
11
12
# File 'lib/scbi_fasta/fasta_file.rb', line 10

def num_seqs
  @num_seqs
end

Instance Method Details

#closeObject



84
85
86
# File 'lib/scbi_fasta/fasta_file.rb', line 84

def close
	@file.close
end

#eachObject

Scans a file, firing events to process content



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scbi_fasta/fasta_file.rb', line 29

def each
  
  #init variables
  seq_name = '';
  seq_fasta = '';
  seq_found = false;

  
  # for each line of the file
  @file.each do |line|
    
    line.chomp!;
    # if line is name
    if line =~ /^>/
      
      #process previous sequence
      if seq_found
     @num_seqs=@num_seqs+1
        yield(seq_name,seq_fasta);
      end
      
      #get only name

   #get only name
     line.gsub!(/^>\s*/,'');
    
     line =~ /(^[^\s]+)/

     # remove comments
     seq_name = $1

      seq_fasta='';
      seq_found = true;
      
    else

    line.strip! if !line.empty?
	
      #add line to fasta of seq
      seq_fasta+=line;

    seq_fasta.strip! if !seq_fasta.empty?

    end
      
  end

  # when found EOF, process last sequence
  if seq_found
			@num_seqs=@num_seqs+1
    yield(seq_name,seq_fasta);
  end
end

#with_qual?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/scbi_fasta/fasta_file.rb', line 88

def with_qual?
  false
end