dna 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/dna.gemspec +1 -1
- data/lib/dna.rb +12 -0
- data/readme.md +12 -2
- data/spec/data/test.fasta.gz +0 -0
- data/spec/dna_spec.rb +5 -0
- data/spec/spec_helper.rb +2 -1
- metadata +5 -3
data/dna.gemspec
CHANGED
data/lib/dna.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'zlib'
|
2
|
+
|
1
3
|
Dir.glob(File.join(File.dirname(__FILE__), 'parsers', '*.rb')).each { |f| require f }
|
2
4
|
|
3
5
|
##
|
@@ -25,6 +27,16 @@ class Dna
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def detect_format
|
30
|
+
|
31
|
+
# is gzipped?
|
32
|
+
unless @handle.class == Array # for tests mostly...
|
33
|
+
begin
|
34
|
+
@handle = Zlib::GzipReader.new(@handle)
|
35
|
+
rescue
|
36
|
+
@handle.rewind
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
first_line = @handle.first
|
29
41
|
@handle.rewind if @handle.class == File
|
30
42
|
|
data/readme.md
CHANGED
@@ -23,7 +23,7 @@ With Ruby 1.8.7 or better:
|
|
23
23
|
DNA gem has grep-like capabilities. Print records with (Ruby) regexp match in header.
|
24
24
|
|
25
25
|
```
|
26
|
-
$ dna input.fastq "[1-2]"
|
26
|
+
$ dna spec/data/input.fastq "[1-2]"
|
27
27
|
|
28
28
|
@1
|
29
29
|
TGAAACTTATTGATCACCCCGCTTGGCGTTGGGGAGAAATTCAGAAAAGAGTGCTTGATGGGGCGCCACATGCCGTGCAACCCACTCTCTTTCACGCAGCGCGCCCCA
|
@@ -34,7 +34,7 @@ GTCGCGGCTTACCACCCAACGATTTTTTTTAGAGGTGCTGGTTTCA
|
|
34
34
|
+2
|
35
35
|
2550//*-1./4.--/'+.2.,,,,,,,,&(/00.11426554+13
|
36
36
|
|
37
|
-
$
|
37
|
+
$ dna spec/data/test.fasta "\d"
|
38
38
|
|
39
39
|
>1
|
40
40
|
GAGAGATCTCATGACACAGCCGAAG
|
@@ -72,4 +72,14 @@ File.open('sequences.qseq') do |handle|
|
|
72
72
|
records = Dna.new handle
|
73
73
|
puts records.first.inspect
|
74
74
|
end
|
75
|
+
|
76
|
+
# even works on gzipped data
|
77
|
+
|
78
|
+
File.open('sequences.fasta.gz') do |handle|
|
79
|
+
records = Dna.new handle
|
80
|
+
|
81
|
+
records.each do |record|
|
82
|
+
puts record.length
|
83
|
+
end
|
84
|
+
end
|
75
85
|
```
|
Binary file
|
data/spec/dna_spec.rb
CHANGED
@@ -7,11 +7,16 @@ describe Dna do
|
|
7
7
|
let(:fastq) { Dna.new @fastq_file }
|
8
8
|
let(:qseq) { Dna.new @qseq_file }
|
9
9
|
let(:empty) { Dna.new @empty_file }
|
10
|
+
let(:gzipped) { Dna.new @gzip_file }
|
10
11
|
|
11
12
|
it 'doesnt freak out on empty files' do
|
12
13
|
fasta.format == :empty
|
13
14
|
end
|
14
15
|
|
16
|
+
it 'can automatically parse gzipped files' do
|
17
|
+
gzipped.format.should == :fasta
|
18
|
+
end
|
19
|
+
|
15
20
|
it 'can auto-detect fasta format' do
|
16
21
|
fasta.format.should == :fasta
|
17
22
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Austin G. Davis-Richardson
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- readme.md
|
40
40
|
- spec/data/empty.txt
|
41
41
|
- spec/data/test.fasta
|
42
|
+
- spec/data/test.fasta.gz
|
42
43
|
- spec/data/test.fastq
|
43
44
|
- spec/data/test.qseq
|
44
45
|
- spec/dna_spec.rb
|
@@ -80,6 +81,7 @@ summary: DNA sequence parser
|
|
80
81
|
test_files:
|
81
82
|
- spec/data/empty.txt
|
82
83
|
- spec/data/test.fasta
|
84
|
+
- spec/data/test.fasta.gz
|
83
85
|
- spec/data/test.fastq
|
84
86
|
- spec/data/test.qseq
|
85
87
|
- spec/dna_spec.rb
|