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
This is destructive with respect to the input seq arg. Does it need to be?
The constructor takes keyword args.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/parse_fasta/record.rb', line 43 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", "") do_check_fasta_seq = args.fetch :check_fasta_seq, true if fastq? || (!fastq? && !do_check_fasta_seq) @seq = seq else @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.
18 |
# File 'lib/parse_fasta/record.rb', line 18 attr_accessor :header, :id, :seq, :desc, :qual |
#header ⇒ String
Returns the full header of the record without the ‘>’ or ‘@’.
18 19 20 |
# File 'lib/parse_fasta/record.rb', line 18 def header @header end |
#id ⇒ String
Returns the “id” i.e., the first token when split by whitespace.
18 |
# File 'lib/parse_fasta/record.rb', line 18 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.
18 |
# File 'lib/parse_fasta/record.rb', line 18 attr_accessor :header, :id, :seq, :desc, :qual |
#seq ⇒ String
Returns the sequence of the record.
18 |
# File 'lib/parse_fasta/record.rb', line 18 attr_accessor :header, :id, :seq, :desc, :qual |
Instance Method Details
#==(rec) ⇒ Bool
Compare attrs of this rec with another
69 70 71 72 |
# File 'lib/parse_fasta/record.rb', line 69 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.
157 158 159 |
# File 'lib/parse_fasta/record.rb', line 157 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.
110 111 112 |
# File 'lib/parse_fasta/record.rb', line 110 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.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/parse_fasta/record.rb', line 137 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.
89 90 91 92 93 94 95 |
# File 'lib/parse_fasta/record.rb', line 89 def to_s if fastq? to_fastq else to_fasta end end |