matr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4260569f27f8c3961c355967e92e2ba32b704597
4
- data.tar.gz: 3f90f0b7d05e58cecb17a66cb572d351b5035774
3
+ metadata.gz: 0aefd54bc8a7c57da41e3843bbc8cd9e29885457
4
+ data.tar.gz: 3f6a1f167731135a93423bcb076a99259a22a5de
5
5
  SHA512:
6
- metadata.gz: eb9fee9fe9f643cb2006c8bf606cc0b2f56adbf037da552e460a77709bedbd6578ebfb580544ecb041aafd981b310f656cb9bbbd6799f66c40e8a88133562600
7
- data.tar.gz: fde9a31b9a0188e2b394a55c161a3ee8e62c87c3b1c4cd37fb36103a13ed1ef3e6a4b67dc70f6fdb1062de71d476e1a342fca96da5c945921d14254d9ed27199
6
+ metadata.gz: 47c0ca490761b79d628b72ba7ae805450844da7ec550284207fe4cea78e497cf239f71faf9ee5de070b319e9137bd869997c3776bd3d764db0ecf5a01f722326
7
+ data.tar.gz: 0baeb31d028459fba8ab48a409e3f5666c1c3d4449504b92e32d233b5291acf3288801404d628d36acedccc4657cdebb1a3cbf4000a608bec0d74d7bcfa074ea
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ matr (0.0.1)
5
+ trollop (~> 2.1, >= 2.1.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.0)
25
+ trollop (2.1.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ matr!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.4
data/README.md CHANGED
@@ -16,10 +16,6 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install matr
18
18
 
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
19
  ## Development
24
20
 
25
21
  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.
data/exe/matr ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("PIPE", "EXIT")
4
+
5
+ require "set"
6
+ require "trollop"
7
+
8
+ opts = Trollop.options do
9
+ banner <<-EOS
10
+
11
+ Take a three-column matrix file and ensure that it is symmetric for input into R.
12
+
13
+ Options:
14
+ EOS
15
+
16
+ opt(:infile, "Input file", type: :string)
17
+
18
+ opt(:self_score, "Score for self connections", default: 100)
19
+ opt(:missing_score, "Score for missing connections", default: 0)
20
+ opt(:output_style, "Output style [wide,long]", default: "wide")
21
+ end
22
+
23
+ infile = opts[:infile]
24
+ self_score = opts[:self_score]
25
+ missing_score = opts[:missing_score]
26
+ output_style = opts[:output_style]
27
+
28
+ unless File.exist? infile
29
+ abort "FATAL -- infile '#{infile}' does not exist"
30
+ end
31
+
32
+ unless output_style == "wide" || output_style == "long"
33
+ abort "FATAL -- output style must be either wide or long"
34
+ end
35
+
36
+ graph = Hash.new { |ht, k| ht[k] = Hash.new }
37
+ all_keys = Set.new
38
+ header = nil
39
+
40
+ File.open(infile, "rt").each_line.with_index do |line, idx|
41
+ line.chomp!
42
+
43
+ if idx.zero?
44
+ header = line
45
+ else
46
+ source, target, score = line.split "\t"
47
+
48
+ all_keys << source << target
49
+
50
+ # If you have duplicates with different scores, that's an error: a
51
+ # => b = 10 and a => b = 20
52
+ if graph[source].has_key?(target) && graph[source][target] != score
53
+ abort "source--target (#{source}--#{target}) was repeated with a different score"
54
+ end
55
+
56
+ graph[source][target] = score
57
+
58
+ # Since you might have a files that specifies a => b = 10, and b
59
+ # => a = 10, that would be okay. But if you have a => b = 10, and
60
+ # b => a = 5, then that would be an error.
61
+ if graph[target].has_key?(source) && graph[target][source] != score
62
+ abort "target--source (#{target}--#{source}) is specified seperately from source--target (#{source}--#{target}), BUT there scores do not match. This means your matrix is NOT symmetric."
63
+
64
+ end
65
+
66
+ graph[target][source] = score
67
+
68
+ unless graph[target].has_key? target
69
+ graph[target][target] = self_score
70
+ end
71
+
72
+ unless graph[source].has_key? source
73
+ graph[source][source] = self_score
74
+ end
75
+ end
76
+ end
77
+
78
+ if output_style == "long"
79
+ puts header
80
+
81
+ all_keys.each do |source|
82
+ all_keys.each do |target|
83
+ puts [source, target, graph[source][target] || missing_score].join "\t"
84
+ end
85
+ end
86
+ else
87
+ all_keys = all_keys.sort
88
+
89
+ puts ["", all_keys].join "\t"
90
+
91
+ all_keys.each do |source|
92
+ row = all_keys.map do |target|
93
+ graph[source][target] || missing_score
94
+ end
95
+
96
+ puts [source, row].join "\t"
97
+ end
98
+ end
data/lib/matr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Matr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/matr.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
+ spec.add_runtime_dependency "trollop", "~> 2.1", ">= 2.1.3"
26
+
25
27
  spec.add_development_dependency "bundler", "~> 1.16"
26
28
  spec.add_development_dependency "rake", "~> 10.0"
27
29
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Moore
@@ -10,6 +10,26 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2018-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.1.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.1.3
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +75,8 @@ dependencies:
55
75
  description: Deal text file matrices.
56
76
  email:
57
77
  - moorer@udel.edu
58
- executables: []
78
+ executables:
79
+ - matr
59
80
  extensions: []
60
81
  extra_rdoc_files: []
61
82
  files:
@@ -64,11 +85,13 @@ files:
64
85
  - ".travis.yml"
65
86
  - CODE_OF_CONDUCT.md
66
87
  - Gemfile
88
+ - Gemfile.lock
67
89
  - LICENSE.txt
68
90
  - README.md
69
91
  - Rakefile
70
92
  - bin/console
71
93
  - bin/setup
94
+ - exe/matr
72
95
  - lib/matr.rb
73
96
  - lib/matr/version.rb
74
97
  - matr.gemspec