parse_fasta 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 889ac551f3260a660a2035614b252f7ddd511551
4
- data.tar.gz: 963cebe7b51e0caaf2327713acc5a0a6d7a34bb4
3
+ metadata.gz: 704dd834a4d948441636422507ca52a9fd44141b
4
+ data.tar.gz: 83d5170a4636337ba9dff578c0de90683f610172
5
5
  SHA512:
6
- metadata.gz: d5f26789225ebc0131680974502f54127240d2db1c9bffb3c577808bf75cf83e09eb7dc1b66fd86be18733b2ea49f4bffd8f51a8111cffeda37ba3e874bc72db
7
- data.tar.gz: cad0979ede863a7e8205b684853533be11e85b8522429e93348eca20ad3c41895148ae42fc854dbd6d87f49f20dfbea5a95c346161790d5c038d1f0366e82a4b
6
+ metadata.gz: ec6f5c7bca2f75e2ec82d18efe31f08e72ca5e3a67f7a7c2c61f5cc5392813396246d601b95c34697dd8a3b133f9655608733ff05e36912f33a6858fe2815c37
7
+ data.tar.gz: ba8e6522891519acf8a22d019500cd4ec46e01fa39b954f52f3b4c2c68586ae6e431a6eb2375799ab52fed0ada667c731be0b34a54ccce732d0f06f1d8dfa7f6
data/README.md CHANGED
@@ -27,7 +27,7 @@ lightweight than BioRuby. And more fun! ;)
27
27
  ## Documentation ##
28
28
 
29
29
  Checkout
30
- [parse_fasta docs](http://rubydoc.info/gems/parse_fasta/1.6.0/frames)
30
+ [parse_fasta docs](http://rubydoc.info/gems/parse_fasta/1.6.2/frames)
31
31
  for the full api documentation.
32
32
 
33
33
  ## Usage ##
@@ -76,6 +76,11 @@ FastqFile instead.
76
76
  Better internal handling of empty sequences -- instead of raising
77
77
  errors, pass empty sequences.
78
78
 
79
+ #### 1.6.2 ####
80
+
81
+ `FastaFile::open` now raises a `ParseFasta::DataFormatError` when passed files
82
+ that don't begin with a `>`.
83
+
79
84
  ### 1.5 ###
80
85
 
81
86
  Now accepts gzipped files. Huzzah!
@@ -22,6 +22,27 @@ require 'zlib'
22
22
  # files are no problem.
23
23
  class FastaFile < File
24
24
 
25
+ # Use it like IO::open
26
+ #
27
+ # @param fname [String] the name of the file to open
28
+ #
29
+ # @return [FastaFile] a FastaFile
30
+ def self.open(fname, *args)
31
+ begin
32
+ handle = Zlib::GzipReader.open(fname)
33
+ rescue Zlib::GzipFile::Error => e
34
+ handle = File.open(fname)
35
+ end
36
+
37
+ unless handle.each_char.peek[0] == '>'
38
+ raise ParseFasta::DataFormatError
39
+ end
40
+
41
+ handle.close
42
+
43
+ super
44
+ end
45
+
25
46
  # Analagous to IO#each_line, #each_record is used to go through a
26
47
  # fasta file record by record. It will accept gzipped files as well.
27
48
  #
@@ -17,5 +17,5 @@
17
17
  # along with parse_fasta. If not, see <http://www.gnu.org/licenses/>.
18
18
 
19
19
  module ParseFasta
20
- VERSION = "1.6.1"
20
+ VERSION = "1.6.2"
21
21
  end
data/lib/parse_fasta.rb CHANGED
@@ -22,3 +22,12 @@ require 'parse_fasta/fastq_file'
22
22
  require 'parse_fasta/seq_file'
23
23
  require 'parse_fasta/sequence'
24
24
  require 'parse_fasta/quality'
25
+
26
+ module ParseFasta
27
+ # Error raised when FASTA file is malformed
28
+ class DataFormatError < IOError
29
+ def message
30
+ "lalala"
31
+ end
32
+ end
33
+ end
@@ -19,6 +19,31 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe FastaFile do
22
+ describe "::open" do
23
+ context "when input is bogus" do
24
+ it "raises a ParseFasta::DataFormatError with message" do
25
+ fname = "#{File.dirname(__FILE__)}/../../test_files/bogus.txt"
26
+
27
+ expect { FastaFile.open(fname).each_record do |h, s|
28
+ puts [h, s].join ' '
29
+ end
30
+ }.to raise_error ParseFasta::DataFormatError
31
+ end
32
+ end
33
+
34
+ let(:fasta) { "#{File.dirname(__FILE__)}/../../test_files/test.fa" }
35
+
36
+ it "takes all the wacky args like IO.open" do
37
+ expect {
38
+ FastaFile.open(fasta, mode: 'r', cr_newline: true)
39
+ }.not_to raise_error
40
+ end
41
+
42
+ it "returns a FastaFile" do
43
+ expect(FastaFile.open(fasta)).to be_a FastaFile
44
+ end
45
+ end
46
+
22
47
  describe "#each_record" do
23
48
  let(:records) { Helpers::RECORDS }
24
49
 
@@ -131,17 +131,17 @@ describe SeqFile do
131
131
  end
132
132
  end
133
133
  end
134
- end
135
134
 
136
- context "when input is bogus" do
137
- it "raises an ArgumentError with message" do
138
- fname = "#{File.dirname(__FILE__)}/../../test_files/bogus.txt"
139
- err_msg = "Input does not look like FASTA or FASTQ"
135
+ context "when input is bogus" do
136
+ it "raises an ArgumentError with message" do
137
+ fname = "#{File.dirname(__FILE__)}/../../test_files/bogus.txt"
138
+ err_msg = "Input does not look like FASTA or FASTQ"
140
139
 
141
- expect { SeqFile.open(fname).each_record do |h, s|
142
- puts [h, s].join ' '
143
- end
144
- }.to raise_error(ArgumentError, err_msg)
140
+ expect { SeqFile.open(fname).each_record do |h, s|
141
+ puts [h, s].join ' '
142
+ end
143
+ }.to raise_error(ArgumentError, err_msg)
144
+ end
145
145
  end
146
146
  end
147
147
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse_fasta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler