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 +4 -4
- data/README.md +6 -1
- data/lib/parse_fasta/fasta_file.rb +21 -0
- data/lib/parse_fasta/version.rb +1 -1
- data/lib/parse_fasta.rb +9 -0
- data/spec/lib/fasta_file_spec.rb +25 -0
- data/spec/lib/seq_file_spec.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 704dd834a4d948441636422507ca52a9fd44141b
|
4
|
+
data.tar.gz: 83d5170a4636337ba9dff578c0de90683f610172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
#
|
data/lib/parse_fasta/version.rb
CHANGED
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
|
data/spec/lib/fasta_file_spec.rb
CHANGED
@@ -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
|
|
data/spec/lib/seq_file_spec.rb
CHANGED
@@ -131,17 +131,17 @@ describe SeqFile do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
|
-
end
|
135
134
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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.
|
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
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|