bio-faidx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c78d17dec354ee49f73fcf3b9ad112b4f2eb29d
4
+ data.tar.gz: 131d2aceda2d2be6df0686fb525b9883c97643ae
5
+ SHA512:
6
+ metadata.gz: 92a83e738d87455b096a3e537878ea2fb864211cf5d19730145fe665c1abf88d9576f42bd9328122e430069cbed5699240c4e04f9c35431a0693058953a6d63e
7
+ data.tar.gz: c1bbf2b36f518fab44ee32c6a80974e59352a8cc96902dd4678c443cb90efd32143e9e40af1a9ee5769c35589cb7a45731e2ed90d95dfcc6332155d320d1de66
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+
7
+ # - rbx-19mode
8
+ # - 1.8.7
9
+ # - jruby-18mode # JRuby in 1.8 mode
10
+ # - rbx-18mode
11
+
12
+ # uncomment this line if your project needs to run something other than `rake`:
13
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "simplecov", ">= 0"
12
+ gem "jeweler", "~> 2.0.1", :git => "https://github.com/technicalpickles/jeweler.git"
13
+ gem "bundler", ">= 1.0.21"
14
+ gem "bio", ">= 1.4.2"
15
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 homonecloco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # bio-faidx
2
+
3
+ [![Build Status](https://secure.travis-ci.org/homonecloco/bioruby-faidx.png)](http://travis-ci.org/homonecloco/bioruby-faidx)
4
+
5
+ API to work with the fai format produced to samtools. Useful if you don't want to rely on all the samtools component.
6
+ Can query sequences from the fasta file. At the minute, it uses bio-samtools, but the idea is to make this self-sufficient.
7
+
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ gem install bio-faidx
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ require 'bio-faidx'
19
+ ```
20
+
21
+ The API doc is online. For more code examples see the test files in
22
+ the source tree.
23
+
24
+ ## Project home page
25
+
26
+ Information on the source tree, documentation, examples, issues and
27
+ how to contribute, see
28
+
29
+ http://github.com/homonecloco/bioruby-faidx
30
+
31
+ The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
32
+
33
+ ## Cite
34
+
35
+ If you use this software, please cite one of
36
+
37
+ * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
38
+ * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
39
+
40
+ ## Biogems.info
41
+
42
+ This Biogem is published at (http://biogems.info/index.html#bio-faidx)
43
+
44
+ ## Copyright
45
+
46
+ Copyright (c) 2014 homonecloco. See LICENSE.txt for further details.
47
+
@@ -0,0 +1,48 @@
1
+ = bio-faidx
2
+
3
+ {<img
4
+ src="https://secure.travis-ci.org/homonecloco/bioruby-faidx.png"
5
+ />}[http://travis-ci.org/#!/homonecloco/bioruby-faidx]
6
+
7
+ Full description goes here
8
+
9
+ Note: this software is under active development!
10
+
11
+ == Installation
12
+
13
+ gem install bio-faidx
14
+
15
+ == Usage
16
+
17
+ == Developers
18
+
19
+ To use the library
20
+
21
+ require 'bio-faidx'
22
+
23
+ The API doc is online. For more code examples see also the test files in
24
+ the source tree.
25
+
26
+ == Project home page
27
+
28
+ Information on the source tree, documentation, issues and how to contribute, see
29
+
30
+ http://github.com/homonecloco/bioruby-faidx
31
+
32
+ The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
33
+
34
+ == Cite
35
+
36
+ If you use this software, please cite one of
37
+
38
+ * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
39
+ * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
40
+
41
+ == Biogems.info
42
+
43
+ This Biogem is published at http://biogems.info/index.html#bio-faidx
44
+
45
+ == Copyright
46
+
47
+ Copyright (c) 2014 homonecloco. See LICENSE.txt for further details.
48
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "bio-faidx"
18
+ gem.homepage = "http://github.com/homonecloco/bioruby-faidx"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Tools to work with fasta files, indexed with samtools}
21
+ gem.description = %Q{ools to work with fasta files, indexed with samtools. The initial releases depend on bio-samtools, but that will change}
22
+ gem.email = "ricardo.ramirez-gonzalez@tgac.ac.uk"
23
+ gem.authors = ["homonecloco"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "bio-faidx #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,12 @@
1
+ # Please require your code below, respecting the naming conventions in the
2
+ # bioruby directory tree.
3
+ #
4
+ # For example, say you have a plugin named bio-plugin, the only uncommented
5
+ # line in this file would be
6
+ #
7
+ # require 'bio/bio-plugin/plugin'
8
+ #
9
+ # In this file only require other files. Avoid other source code.
10
+
11
+ require 'bio-faidx/faidx.rb'
12
+
@@ -0,0 +1,174 @@
1
+ require 'csv'
2
+ require 'bio-samtools'
3
+
4
+
5
+ class Bio::DB::Faidx
6
+
7
+ class Entry
8
+ attr_accessor :name, :length, :offset, :linebases, :linewidth
9
+ end
10
+ def initialize(opts)
11
+ @cache = false
12
+ @cache = opts[:cache] if opts[:cache]
13
+ @filename = opts[:filename]
14
+ @inited = false
15
+ end
16
+
17
+ def init_cache
18
+ @inited = true
19
+ @entries = Hash.new
20
+ @entries_order = Array.new
21
+ read_entries do |e|
22
+ @entries[e.name] = e
23
+ @entries_order << e.name
24
+ end
25
+ end
26
+
27
+ def entries
28
+ init_cache unless @inited
29
+ @entries
30
+ end
31
+
32
+ def [](entry)
33
+ init_cache unless @inited
34
+ @entries[entry]
35
+ end
36
+
37
+
38
+ def entries_order
39
+ init_cache unless @inited
40
+ return @entries_order
41
+ end
42
+
43
+ def read_entries
44
+ CSV.foreach(@filename, :col_sep => "\t", :skip_lines=>/^#/, :skip_blanks=>true) do |row|
45
+ fasta_entry = Bio::DB::Faidx::Entry.new
46
+ [:name, :length, :offset, :linebases, :linewidth].each_with_index do |sym, i|
47
+ answer = row[i]
48
+ answer = answer.to_i if [:length, :offset, :linebases, :linewidth].include?(sym)
49
+ fasta_entry.send("#{sym}=".to_sym, answer)
50
+ yield fasta_entry
51
+ end
52
+ end
53
+
54
+ def each_entry
55
+ unless @cache
56
+ read_entries { |e| yield e }
57
+ else
58
+ entries_order.each { |e| yield @entries[e] }
59
+ end
60
+ end
61
+ end
62
+
63
+
64
+ class Bio::DB::Fasta::Region
65
+ def overlaps (other)
66
+ return false if other.entry != @entry
67
+ return true if other.start >= @start and other.start <= @end
68
+ return true if other.end >= @start and other.end <= @end
69
+ return false
70
+ end
71
+
72
+ def subset (other)
73
+ return false if other.entry != @entry
74
+ return true if other.start >= @start and other.end <= @end
75
+ end
76
+
77
+ def joinRegion (other)
78
+ return nil unless self.overlaps(other)
79
+ out = self.clone
80
+ out.start = other.start if other.start < out.start
81
+ out.end = other.end if other.end > out.end
82
+ return out
83
+ end
84
+
85
+ def overlap_in_set(set)
86
+ overlap_set = Set.new
87
+ set.each do |e|
88
+ overlap_set << e if self.overlaps(e)
89
+ end
90
+ overlap_set
91
+ end
92
+ end
93
+ #class Faidx
94
+ class Entry
95
+ attr_accessor :name, :length, :offset, :linebases, :linewidth
96
+ end
97
+ def initialize(opts)
98
+ @cache = false
99
+ @cache = opts[:cache] if opts[:cache]
100
+ @filename = opts[:filename]
101
+ @inited = false
102
+ end
103
+
104
+ def init_cache
105
+ @inited = true
106
+ @entries = Hash.new
107
+ @entries_order = Array.new
108
+ read_entries do |e|
109
+ @entries[e.name] = e
110
+ @entries_order << e.name
111
+ end
112
+ end
113
+
114
+ def entries
115
+ init_cache unless @inited
116
+ @entries
117
+
118
+ end
119
+
120
+ def entries_order
121
+ init_cache unless @inited
122
+ return @entries_order
123
+ end
124
+
125
+ def read_entries
126
+ CSV.foreach(@filename, :col_sep => "\t", :skip_lines=>/^#/, :skip_blanks=>true) do |row|
127
+ fasta_entry = Bio::DB::Faidx::Entry.new
128
+ [:name, :length, :offset, :linebases, :linewidth].each_with_index do |sym, i|
129
+ answer = row[i]
130
+ answer = answer.to_i if [:length, :offset, :linebases, :linewidth].include?(sym)
131
+ fasta_entry.send("#{sym}=".to_sym, answer)
132
+ yield fasta_entry
133
+ end
134
+ end
135
+
136
+ def each_entry
137
+ unless @cache
138
+ read_entries { |e| yield e }
139
+ else
140
+ entries_order.each { |e| yield @entries[e] }
141
+ end
142
+ end
143
+ end
144
+ end
145
+
146
+ class Bio::DB::Fasta::Region
147
+ def overlaps (other)
148
+ return false if other.entry != @entry
149
+ return true if other.start >= @start and other.start <= @end
150
+ return true if other.end >= @start and other.end <= @end
151
+ return false
152
+ end
153
+
154
+ def subset (other)
155
+ return false if other.entry != @entry
156
+ return true if other.start >= @start and other.end <= @end
157
+ end
158
+
159
+ def joinRegion (other)
160
+ return nil unless self.overlaps(other)
161
+ out = self.clone
162
+ out.start = other.start if other.start < out.start
163
+ out.end = other.end if other.end > out.end
164
+ return out
165
+ end
166
+
167
+ def overlap_in_set(set)
168
+ overlap_set = Set.new
169
+ set.each do |e|
170
+ overlap_set << e if self.overlaps(e)
171
+ end
172
+ overlap_set
173
+ end
174
+ end
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'bio-faidx'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBioFaidx < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bio-faidx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - homonecloco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.21
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.21
83
+ - !ruby/object:Gem::Dependency
84
+ name: bio
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.4.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.4.2
97
+ description: ools to work with fasta files, indexed with samtools. The initial releases
98
+ depend on bio-samtools, but that will change
99
+ email: ricardo.ramirez-gonzalez@tgac.ac.uk
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.md
105
+ - README.rdoc
106
+ files:
107
+ - ".document"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - lib/bio-faidx.rb
116
+ - lib/bio-faidx/faidx.rb
117
+ - test/helper.rb
118
+ - test/test_bio-faidx.rb
119
+ homepage: http://github.com/homonecloco/bioruby-faidx
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Tools to work with fasta files, indexed with samtools
143
+ test_files: []