mapp2g 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +8 -0
- data/exe/mapp2g +27 -0
- data/lib/mapp2g/mapper.rb +141 -0
- data/lib/mapp2g/version.rb +5 -0
- data/lib/mapp2g.rb +9 -0
- data/mapp2g.gemspec +39 -0
- data/sig/mapp2g.rbs +4 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76678699954930f428361c012a062316f3b17bb349c44ce6a241749e97f3e056
|
4
|
+
data.tar.gz: 7cb65ee78628d7074cc2b639d24b85ca4c6ba682624b9c834cdd63e936676dfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e796d1e41c7e53b9ffb2550214a2479c654278bd21de549f4d7b94db4f231e5166c46e69f4fc71c9153ca9066395afc9aa60b4229b26515276126634377f89e0
|
7
|
+
data.tar.gz: dd87f0d6934a3a7ec0dec8a63f629d90edcb00c98f2d9ecf701ade80d84d7859ab6bffdd5156054e784d4ba9dd1f790f1c0202bd7810fa1ccf115470616f5155
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Shuji Shigenobu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Mapp2g
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mapp2g`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mapp2g.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/mapp2g
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "mapp2g"
|
4
|
+
require 'bio'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
query = ARGV[0]
|
8
|
+
genome = ARGV[1]
|
9
|
+
outdir = (ARGV[2] || "mapp2g_out_#{$$}")
|
10
|
+
mapp2g_exe = "./mapp2g.rb"
|
11
|
+
|
12
|
+
Dir.mkdir(outdir)
|
13
|
+
|
14
|
+
Bio::FlatFile.open(Bio::FastaFormat, query).each_with_index do |fas, i|
|
15
|
+
tf = Tempfile.new("#{fas.entry_id}")
|
16
|
+
tf.puts fas
|
17
|
+
tf.close
|
18
|
+
id = (i + 1).to_s
|
19
|
+
query_file_path = "#{outdir}/#{id}.fasta"
|
20
|
+
out_file_path = "#{outdir}/#{id}.exonerate.txt"
|
21
|
+
File.open(query_file_path, "w"){|o| o.puts fas}
|
22
|
+
|
23
|
+
mapper = Mapp2g::Mapper.new()
|
24
|
+
res = mapper.run(query_file_path, genome)
|
25
|
+
File.open(out_file_path, "w"){|o| o.puts res}
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Mapp2g
|
4
|
+
|
5
|
+
class Mapper
|
6
|
+
|
7
|
+
EVALUE_DEFAULT = 1.0e-8
|
8
|
+
NCPU_DEFAULT = 4
|
9
|
+
MAX_HSP_INTERVAL = 50000
|
10
|
+
EXTENSION = 50000
|
11
|
+
TMPDIR_DEFAULT = Dir.tmpdir
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
end
|
15
|
+
|
16
|
+
## step 1: tblastn
|
17
|
+
def exec_tblastn_to_know_rough_target_region(query, genome, evalue=EVALUE_DEFAULT, ncpu=NCPU_DEFAULT)
|
18
|
+
cmd = "tblastn -db #{genome} -query #{query} -max_target_seqs 40 -soft_masking yes -seg yes -outfmt 6 -evalue #{evalue} -num_threads #{ncpu} "
|
19
|
+
# puts cmd
|
20
|
+
res = nil
|
21
|
+
IO.popen(cmd){|io| res = io.read}
|
22
|
+
# puts res
|
23
|
+
if res == ""
|
24
|
+
## no hit
|
25
|
+
return nil
|
26
|
+
else
|
27
|
+
lines = []
|
28
|
+
prev_chr = nil
|
29
|
+
res.split(/\n/).each do |l|
|
30
|
+
# p prev_chr
|
31
|
+
a = l.chomp.split(/\t/)
|
32
|
+
unless prev_chr
|
33
|
+
lines << l
|
34
|
+
prev_chr = a[1]
|
35
|
+
else
|
36
|
+
break if a[1] != prev_chr
|
37
|
+
lines << l
|
38
|
+
prev_chr = a[1]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
a = lines.shift.chomp.split(/\t/)
|
43
|
+
left, right = [a[8].to_i, a[9].to_i].sort
|
44
|
+
|
45
|
+
STDERR.puts [left, right].inspect
|
46
|
+
|
47
|
+
lines.each do |l|
|
48
|
+
a = l.chomp.split(/\t/)
|
49
|
+
from, to = [a[8].to_i, a[9].to_i].sort
|
50
|
+
tmpary = [left, right, from, to].sort
|
51
|
+
new_left = tmpary.first
|
52
|
+
new_right = tmpary.last
|
53
|
+
if (new_left - left).abs < MAX_HSP_INTERVAL && (new_right - right).abs < MAX_HSP_INTERVAL
|
54
|
+
right = new_right
|
55
|
+
left = new_left
|
56
|
+
else
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
# p [left, right]
|
61
|
+
|
62
|
+
top_chromosome = res.split(/\n/)[0].split(/\t/)[1]
|
63
|
+
h = {
|
64
|
+
:top_chromosome => top_chromosome,
|
65
|
+
:left => left,
|
66
|
+
:right => right
|
67
|
+
}
|
68
|
+
return h
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
## step 2: get top hit
|
74
|
+
def prepare_rough_target_genomic_region(genome, top_chromosome, left, right)
|
75
|
+
cmd = "blastdbcmd -db #{genome} -entry #{top_chromosome} -outfmt %l "
|
76
|
+
res = nil
|
77
|
+
IO.popen(cmd){|io| res = io.read}
|
78
|
+
seqlength = res.to_i
|
79
|
+
|
80
|
+
left_extract = [(left - EXTENSION), 1].sort.last
|
81
|
+
right_extract = [(right + EXTENSION), seqlength].sort.first
|
82
|
+
|
83
|
+
#p [left_extract, right_extract]
|
84
|
+
|
85
|
+
cmd = "blastdbcmd -db #{genome} -entry #{top_chromosome} -range #{left_extract}-#{right_extract} -outfmt %s"
|
86
|
+
res = nil
|
87
|
+
IO.popen(cmd){|io| res = io.read}
|
88
|
+
seq = res.strip
|
89
|
+
|
90
|
+
seq = "n" * (left_extract - 1) + seq + "n" * (seqlength - right_extract)
|
91
|
+
# [res.size, seq.size, seqlength]
|
92
|
+
raise unless seq.size == seqlength
|
93
|
+
fas = ">#{top_chromosome}\n#{seq}"
|
94
|
+
fas
|
95
|
+
end
|
96
|
+
|
97
|
+
## step 3: run exonerate
|
98
|
+
|
99
|
+
def exec_exonerate(query, target)
|
100
|
+
cmd = "exonerate -q #{query} -t #{target} --model protein2genome --bestn 1 --showquerygff yes --showtargetgff yes --showcigar yes"
|
101
|
+
res = nil
|
102
|
+
IO.popen(cmd){|io| res = io.read}
|
103
|
+
res
|
104
|
+
end
|
105
|
+
|
106
|
+
## standard pipeline from step 1 to 3
|
107
|
+
def run(query, genome)
|
108
|
+
hit = self.exec_tblastn_to_know_rough_target_region(query, genome)
|
109
|
+
if hit
|
110
|
+
top_chromosome = hit[:top_chromosome]
|
111
|
+
left = hit[:left]
|
112
|
+
right = hit[:right]
|
113
|
+
|
114
|
+
target_fasta = prepare_rough_target_genomic_region(genome, top_chromosome, left, right)
|
115
|
+
tf = Tempfile.new("mapp2g-#{Process.pid}")
|
116
|
+
tf.puts(target_fasta)
|
117
|
+
tf.close
|
118
|
+
|
119
|
+
exonerate_result = exec_exonerate(query, tf.path)
|
120
|
+
return exonerate_result
|
121
|
+
|
122
|
+
else
|
123
|
+
return nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
#---
|
132
|
+
if __FILE__ == $0
|
133
|
+
|
134
|
+
mapper = Mapp2g::Mapper.new()
|
135
|
+
|
136
|
+
query = ARGV[0]
|
137
|
+
genome = ARGV[1]
|
138
|
+
res = mapper.run(query, genome)
|
139
|
+
puts res
|
140
|
+
|
141
|
+
end
|
data/lib/mapp2g.rb
ADDED
data/mapp2g.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/mapp2g/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "mapp2g"
|
7
|
+
spec.version = Mapp2g::VERSION
|
8
|
+
spec.authors = ["Shuji Shigenobu"]
|
9
|
+
spec.email = ["sshigenobu@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "mapp2g is the tool to map protein sequences to genome references in a splicing-aware way. "
|
12
|
+
spec.description = "mapp2g is a bioinformatics software, which map and align protein sequences (amino acid sequences) to genome references in a splicing-aware way. mapp2g alignment pipeline employs exonerate and tBLASTn."
|
13
|
+
spec.homepage = "https://github.com/shujishigenobu/mapp2g"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/shujishigenobu/mapp2g"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/shujishigenobu/mapp2g"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, check out our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
data/sig/mapp2g.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mapp2g
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shuji Shigenobu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: mapp2g is a bioinformatics software, which map and align protein sequences
|
14
|
+
(amino acid sequences) to genome references in a splicing-aware way. mapp2g alignment
|
15
|
+
pipeline employs exonerate and tBLASTn.
|
16
|
+
email:
|
17
|
+
- sshigenobu@gmail.com
|
18
|
+
executables:
|
19
|
+
- mapp2g
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".rspec"
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- exe/mapp2g
|
29
|
+
- lib/mapp2g.rb
|
30
|
+
- lib/mapp2g/mapper.rb
|
31
|
+
- lib/mapp2g/version.rb
|
32
|
+
- mapp2g.gemspec
|
33
|
+
- sig/mapp2g.rbs
|
34
|
+
homepage: https://github.com/shujishigenobu/mapp2g
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/shujishigenobu/mapp2g
|
39
|
+
source_code_uri: https://github.com/shujishigenobu/mapp2g
|
40
|
+
changelog_uri: https://github.com/shujishigenobu/mapp2g
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.6.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.2.15
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: mapp2g is the tool to map protein sequences to genome references in a splicing-aware
|
60
|
+
way.
|
61
|
+
test_files: []
|