lib/bio/db/fasta.rb in bio-1.4.3.0001 vs lib/bio/db/fasta.rb in bio-1.5.0
- old
+ new
@@ -66,10 +66,11 @@
# ==== Methods related to the name of the sequence
#
# A larger range of methods for dealing with Fasta definition lines can be found in FastaDefline, accessed through the FastaFormat#identifiers method.
#
# f.entry_id #=> "gi|398365175"
+ # f.first_name #=> "gi|398365175|ref|NP_009718.3|"
# f.definition #=> "gi|398365175|ref|NP_009718.3| Cdc28p [Saccharomyces cerevisiae S288c]"
# f.identifiers #=> Bio::FastaDefline instance
# f.accession #=> "NP_009718"
# f.accessions #=> ["NP_009718"]
# f.acc_version #=> "NP_009718.3"
@@ -88,10 +89,11 @@
# === A less structured fasta entry
#
# f.entry #=> ">abc 123 456\nASDF"
#
# f.entry_id #=> "abc"
+ # f.first_name #=> "abc"
# f.definition #=> "abc 123 456"
# f.comment #=> nil
# f.accession #=> nil
# f.accessions #=> []
# f.acc_version #=> nil
@@ -279,9 +281,24 @@
end
# Returns locus.
def locus
identifiers.locus
+ end
+
+ # Returns the first name (word) of the definition line - everything
+ # before the first whitespace.
+ #
+ # >abc def #=> 'abc'
+ # >gi|398365175|ref|NP_009718.3| Cdc28p [Saccharomyces cerevisiae S288c] #=> 'gi|398365175|ref|NP_009718.3|'
+ # >abc #=> 'abc'
+ def first_name
+ index = definition.index(/\s/)
+ if index.nil?
+ return @definition
+ else
+ return @definition[0...index]
+ end
end
end #class FastaFormat
end #module Bio