bio-faster 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/bio-faster.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bio-faster"
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Francesco Strozzi"]
@@ -75,7 +75,8 @@ Gem::Specification.new do |s|
75
75
  "test/data/formats/solexa_full_range_original_solexa.fastq",
76
76
  "test/data/formats/wrapping_as_illumina.fastq",
77
77
  "test/data/formats/wrapping_as_sanger.fastq",
78
- "test/data/formats/wrapping_as_solexa.fastq"
78
+ "test/data/formats/wrapping_as_solexa.fastq",
79
+ "test/test_stdin.rb"
79
80
  ]
80
81
  s.homepage = "http://github.com/fstrozzi/bioruby-faster"
81
82
  s.licenses = ["MIT"]
data/ext/faster.c CHANGED
@@ -8,7 +8,6 @@
8
8
  #include <stdlib.h>
9
9
 
10
10
  #define _BSIZE 100000
11
-
12
11
  typedef struct {
13
12
  char *id;
14
13
  char *seq;
@@ -67,8 +66,13 @@ int check_header(char *header, char *firstline) {
67
66
  int fastQ_iterator(FastQRecord *seq, int scale_factor) {
68
67
  // initialization of structure elements.
69
68
  char *header = "@"; // FastQ header
70
- if (!seq->stream)
71
- seq->stream = fopen(seq->filename,"r");
69
+ if (!seq->stream) {
70
+ if(strcmp(seq->filename,"stdin") == 0) {
71
+ seq->stream = stdin;
72
+ }
73
+ else
74
+ seq->stream = fopen(seq->filename,"r");
75
+ }
72
76
  if (!seq->line)
73
77
  seq->line = malloc(sizeof (char)* _BSIZE);
74
78
  if (!seq->bad_chars)
@@ -81,6 +85,7 @@ int fastQ_iterator(FastQRecord *seq, int scale_factor) {
81
85
  for (int i = 0; i < 4; i++)
82
86
  {
83
87
  if (fgets(seq->line, _BSIZE, seq->stream) == NULL) {
88
+ fclose(seq->stream);
84
89
  // if either sequence or quality is missing the record is truncated
85
90
  if((seq->seq != NULL && seq->raw_quality == NULL) || (seq->raw_quality != NULL && seq->seq == NULL)) return -2;
86
91
  else return 0;
data/lib/bio/faster.rb CHANGED
@@ -33,7 +33,11 @@ module Bio
33
33
  attach_function :fastQ_iterator, [FastQRecord, :int], :int
34
34
 
35
35
  def each_record
36
- raise ArgumentError, "File #{self.file} does not exist" unless File.exists? self.file
36
+ if self.file == :stdin
37
+ self.file = "stdin"
38
+ elsif !File.exists? self.file
39
+ raise ArgumentError, "File #{self.file} does not exist"
40
+ end
37
41
  record = FastQRecord.new
38
42
  scale_factor = nil
39
43
  case self.encoding
data/spec/parser_spec.rb CHANGED
@@ -42,6 +42,41 @@ describe Bio::Faster do
42
42
 
43
43
  end
44
44
 
45
+ it "can read also gzipped FastQ files" do
46
+ gz_files = Dir.glob(TEST_DATA+"/formats/gzipped/*.fastq.gz").sort
47
+ gz_seq = []
48
+ gz_files.each do |file|
49
+ Bio::Faster.new(file).each_record do |seq|
50
+ gz_seq << seq
51
+ end
52
+ end
53
+ files = Dir.glob(TEST_DATA+"/formats/gzipped/*.fastq").sort
54
+ norm_seq = []
55
+ files.each do |file|
56
+ Bio::Faster.new(file).each_record do |seq|
57
+ norm_seq << seq
58
+ end
59
+ end
60
+ gz_seq.should == norm_seq
61
+ end
62
+
63
+
64
+ it "can read from the standard input" do
65
+ require 'digest/md5'
66
+ file = TEST_DATA+"/formats/illumina_full_range_as_illumina.fastq"
67
+ TEST = File.join(File.dirname(File.dirname(__FILE__)),"test")
68
+ system("cat "+file+" | ruby "+TEST+"/test_stdin.rb > stdin_test.out")
69
+ out = File.open("expected.out","w")
70
+ Bio::Faster.new(file).each_record do |seq|
71
+ out.write seq.to_s+"\n"
72
+ end
73
+ out.close()
74
+ md5_stdin = Digest::MD5.file("stdin_test.out")
75
+ md5_expected = Digest::MD5.file("expected.out")
76
+ md5_stdin.should == md5_expected
77
+ FileUtils.rm "stdin_test.out"
78
+ FileUtils.rm "expected.out"
79
+ end
45
80
 
46
81
  end
47
82
 
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(File.dirname(__FILE__)),"spec","helper")
2
+
3
+ stream = Bio::Faster.new :stdin
4
+ stream.each_record do |seq|
5
+ print seq.to_s+"\n"
6
+ end
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-faster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &2153396520 !ruby/object:Gem::Requirement
16
+ requirement: &2157623240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153396520
24
+ version_requirements: *2157623240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &2153396000 !ruby/object:Gem::Requirement
27
+ requirement: &2157622320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153396000
35
+ version_requirements: *2157622320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2153395420 !ruby/object:Gem::Requirement
38
+ requirement: &2157621820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153395420
46
+ version_requirements: *2157621820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2153394940 !ruby/object:Gem::Requirement
49
+ requirement: &2157621200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153394940
57
+ version_requirements: *2157621200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &2153394460 !ruby/object:Gem::Requirement
60
+ requirement: &2157620460 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153394460
68
+ version_requirements: *2157620460
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bio
71
- requirement: &2153393980 !ruby/object:Gem::Requirement
71
+ requirement: &2157619740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.4.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153393980
79
+ version_requirements: *2157619740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2153409780 !ruby/object:Gem::Requirement
82
+ requirement: &2157619000 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153409780
90
+ version_requirements: *2157619000
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: ffi
93
- requirement: &2153409260 !ruby/object:Gem::Requirement
93
+ requirement: &2157618200 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153409260
101
+ version_requirements: *2157618200
102
102
  description: A fast parser for FastQ files
103
103
  email: francesco.strozzi@gmail.com
104
104
  executables: []
@@ -166,6 +166,7 @@ files:
166
166
  - test/data/formats/wrapping_as_illumina.fastq
167
167
  - test/data/formats/wrapping_as_sanger.fastq
168
168
  - test/data/formats/wrapping_as_solexa.fastq
169
+ - test/test_stdin.rb
169
170
  homepage: http://github.com/fstrozzi/bioruby-faster
170
171
  licenses:
171
172
  - MIT
@@ -181,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  segments:
183
184
  - 0
184
- hash: 4125702484128053207
185
+ hash: -1208999662832865297
185
186
  required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  none: false
187
188
  requirements: