Class: ParseFasta::Record
- Inherits:
-
Object
- Object
- ParseFasta::Record
- Defined in:
- lib/parse_fasta/record.rb
Instance Attribute Summary collapse
-
#desc ⇒ String or Nil
If the record is from a fastA file, it is nil; else, the description line of the fastQ record.
-
#header ⇒ String
The full header of the record without the ‘>’ or ‘@’.
-
#id ⇒ String
The “id” i.e., the first token when split by whitespace.
-
#qual ⇒ String or Nil
If the record is from a fastA file, it is nil; else, the quality string of the fastQ record.
-
#seq ⇒ String
The sequence of the record.
Instance Method Summary collapse
-
#==(rec) ⇒ Bool
Compare attrs of this rec with another.
-
#fastq? ⇒ Bool
Returns true if record is a fastQ record.
-
#initialize(args = {}) ⇒ Record
constructor
The constructor takes keyword args.
-
#to_fasta ⇒ String
Returns a fastA record ready to print.
-
#to_fastq(opts = {}) ⇒ String
Returns a fastA record ready to print.
-
#to_s ⇒ String
Return a fastA or fastQ record ready to print.
Constructor Details
#initialize(args = {}) ⇒ Record
The constructor takes keyword args.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/parse_fasta/record.rb', line 52 def initialize args = {} @header = args.fetch :header @id = @header.split(" ")[0] @desc = args.fetch :desc, nil @qual = args.fetch :qual, nil @qual.tr!(" \t\n\r", "") if @qual seq = args.fetch(:seq) seq.tr!(" \t\n\r", "") if fastq? # is fastQ @seq = seq else # is fastA @seq = check_fasta_seq(seq) end end |
Instance Attribute Details
#desc ⇒ String or Nil
Returns if the record is from a fastA file, it is nil; else, the description line of the fastQ record.
36 |
# File 'lib/parse_fasta/record.rb', line 36 attr_accessor :header, :id, :seq, :desc, :qual |
#header ⇒ String
Returns the full header of the record without the ‘>’ or ‘@’.
36 37 38 |
# File 'lib/parse_fasta/record.rb', line 36 def header @header end |
#id ⇒ String
Returns the “id” i.e., the first token when split by whitespace.
36 |
# File 'lib/parse_fasta/record.rb', line 36 attr_accessor :header, :id, :seq, :desc, :qual |
#qual ⇒ String or Nil
Returns if the record is from a fastA file, it is nil; else, the quality string of the fastQ record.
36 |
# File 'lib/parse_fasta/record.rb', line 36 attr_accessor :header, :id, :seq, :desc, :qual |
#seq ⇒ String
Returns the sequence of the record.
36 |
# File 'lib/parse_fasta/record.rb', line 36 attr_accessor :header, :id, :seq, :desc, :qual |
Instance Method Details
#==(rec) ⇒ Bool
Compare attrs of this rec with another
76 77 78 79 |
# File 'lib/parse_fasta/record.rb', line 76 def == rec self.header == rec.header && self.seq == rec.seq && self.desc == rec.desc && self.qual == rec.qual end |
#fastq? ⇒ Bool
Returns true if record is a fastQ record.
This method returns true if the fastq instance method is set.
164 165 166 |
# File 'lib/parse_fasta/record.rb', line 164 def fastq? true if @qual end |
#to_fasta ⇒ String
Returns a fastA record ready to print.
If the record is fastQ like, the desc and qual are dropped.
117 118 119 |
# File 'lib/parse_fasta/record.rb', line 117 def to_fasta ">#{header}\n#{seq}" end |
#to_fastq(opts = {}) ⇒ String
Returns a fastA record ready to print.
If the record is fastA like, the desc and qual can be specified.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/parse_fasta/record.rb', line 144 def to_fastq opts = {} if fastq? "@#{@header}\n#{@seq}\n+#{@desc}\n#{qual}" else qual = opts.fetch :qual, "I" check_qual qual desc = opts.fetch :desc, "" qual_str = make_qual_str qual "@#{@header}\n#{@seq}\n+#{desc}\n#{qual_str}" end end |
#to_s ⇒ String
Return a fastA or fastQ record ready to print.
If the Record is fastQ like then it returns a fastQ record string. If the record is fastA like, then it returns a fastA record string.
96 97 98 99 100 101 102 |
# File 'lib/parse_fasta/record.rb', line 96 def to_s if fastq? to_fastq else to_fasta end end |