class Bio::GFF::GFF3::Record
Represents a single line of a GFF3-formatted file. See Bio::GFF::GFF3
for more information.
Public Class Methods
Creates a Bio::GFF::GFF3::Record
object. Is typically not called directly, but is called automatically when creating a Bio::GFF::GFF3
object.
Arguments:
-
str: a tab-delimited line in
GFF3
format
Arguments:
-
seqid: sequence ID (String or nil)
-
source: source (String or nil)
-
feature_type: type of feature (String)
-
start_position: start (Integer)
-
end_position: end (Integer)
-
score: score (Float or nil)
-
strand: strand (String or nil)
-
phase: phase (Integer or nil)
-
attributes: attributes (Array or nil)
Bio::GFF::GFF2::Record::new
# File lib/bio/db/gff.rb 1159 def initialize(*arg) 1160 super(*arg) 1161 end
Parses a GFF3-formatted line and returns a new Bio::GFF::GFF3::Record
object.
# File lib/bio/db/gff.rb 1138 def self.parse(str) 1139 self.new.parse(str) 1140 end
Public Instance Methods
shortcut to the ID attribute
# File lib/bio/db/gff.rb 1112 def id 1113 get_attribute('ID') 1114 end
set ID attribute
# File lib/bio/db/gff.rb 1117 def id=(str) 1118 set_attribute('ID', str) 1119 end
Parses a GFF3-formatted line and stores data from the string. Note that all existing data is wiped out.
Bio::GFF::GFF2::Record::parse
# File lib/bio/db/gff.rb 1165 def parse(string) 1166 super 1167 end
Return the record as a GFF3
compatible string
# File lib/bio/db/gff.rb 1170 def to_s 1171 cmnt = if defined?(@comment) and @comment and 1172 !@comment.to_s.strip.empty? then 1173 @comment.gsub(/[\r\n]+/, ' ') 1174 else 1175 false 1176 end 1177 return "\##{cmnt}\n" if self.comment_only? and cmnt 1178 [ 1179 escape_seqid(column_to_s(@seqname)), 1180 escape(column_to_s(@source)), 1181 escape(column_to_s(@feature)), 1182 escape(column_to_s(@start)), 1183 escape(column_to_s(@end)), 1184 escape(column_to_s(@score)), 1185 escape(column_to_s(@strand)), 1186 escape(column_to_s(@frame)), 1187 attributes_to_s(@attributes) 1188 ].join("\t") + 1189 (cmnt ? "\t\##{cmnt}\n" : "\n") 1190 end
Private Instance Methods
Return the attributes as a string as it appears at the end of a GFF3
line
# File lib/bio/db/gff.rb 1796 def attributes_to_s(attr) 1797 return '.' if !attr or attr.empty? 1798 keys = [] 1799 hash = {} 1800 attr.each do |pair| 1801 key = pair[0] 1802 val = pair[1] 1803 keys.push key unless hash[key] 1804 hash[key] ||= [] 1805 hash[key].push val 1806 end 1807 keys.collect do |key| 1808 values = hash[key] 1809 val = values.collect do |v| 1810 if v.kind_of?(Target) then 1811 v.to_s 1812 else 1813 escape_attribute(v.to_s) 1814 end 1815 end.join(',') 1816 "#{escape_attribute(key)}=#{val}" 1817 end.join(';') 1818 end
# File lib/bio/db/gff.rb 1774 def parse_attributes(string) 1775 return [] if !string or string == '.' 1776 attr_pairs = [] 1777 string.split(';').each do |pair| 1778 key, value = pair.split('=', 2) 1779 key = unescape(key) 1780 values = value.to_s.split(',') 1781 case key 1782 when 'Target' 1783 values.collect! { |v| Target.parse(v) } 1784 when 'Gap' 1785 values.collect! { |v| Gap.parse(v) } 1786 else 1787 values.collect! { |v| unescape(v) } 1788 end 1789 attr_pairs.concat values.collect { |v| [ key, v ] } 1790 end 1791 return attr_pairs 1792 end