matr 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/matr +70 -15
- data/lib/matr.rb +20 -18
- data/lib/matr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47333ccd6a3ba0eb865f6840aec2068973e5eef8
|
4
|
+
data.tar.gz: f3d9ac5d78ddb25604fb701dab4b8c0b0aca650b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68b87abc4da6215e12acb57406ce9097fa31b6c96563f289ef939760e5d6fb0eb32d3fd2fed353365f3b963e4823c7c42dcc534fe31b62cddd02c52ae950adf3
|
7
|
+
data.tar.gz: 3a896981433e70be9c4d559c64cea412f224cb582eb573a8a5391b785c1371801b81e6e2d5da87594aa2b3d5f645149c837ba9a14d6fb2c353b4dfdb523dfe8d
|
data/exe/matr
CHANGED
@@ -7,38 +7,93 @@ require "matr"
|
|
7
7
|
require "set"
|
8
8
|
require "trollop"
|
9
9
|
|
10
|
+
mode_info = <<-EOS
|
11
|
+
Modes
|
12
|
+
-----
|
13
|
+
|
14
|
+
- All vs. all non-symmetric (ava): I will make a square matrix
|
15
|
+
that contains all versus all comparisons for each item
|
16
|
+
specified, regardless of the column that the item was in. Any
|
17
|
+
comparisons not specified in the input file will get an 'na'
|
18
|
+
value (or whatever you tell us to replace it with).
|
19
|
+
|
20
|
+
- All vs. all symmetric (ava_symmetric): I will also ensure
|
21
|
+
symmetry by adding a reverse entry for each row (i.e., source -
|
22
|
+
target - score AND target - source - score), even if the reverse
|
23
|
+
entry isn't specified explicitly. If this isn't possible, then
|
24
|
+
I will raise an error.
|
25
|
+
EOS
|
26
|
+
|
10
27
|
opts = Trollop.options do
|
11
28
|
banner <<-EOS
|
12
29
|
|
13
|
-
Take a three-column matrix file and
|
30
|
+
Take a three-column matrix file and do stuff with it.
|
31
|
+
|
14
32
|
|
15
|
-
|
33
|
+
#{mode_info}
|
16
34
|
|
17
35
|
Option details
|
18
36
|
--------------
|
19
37
|
|
20
|
-
|
21
|
-
|
38
|
+
--self-scores: I will add a self score of this value if one is not
|
39
|
+
already specified.
|
22
40
|
|
23
|
-
|
24
|
-
|
41
|
+
--ensure-self-scores: I will ensure all self scores equal the
|
42
|
+
value set in --self-scores even if a self-score is present but
|
43
|
+
set to something else.
|
44
|
+
|
45
|
+
--na-replace <value>: If you pass this flag, I will replace any
|
46
|
+
'na' values with this value.
|
25
47
|
|
26
|
-
- Raise error if a source-target pair is specified twice with a different score
|
27
|
-
- Raise error if source-target and target-source are both specified and they don't match.
|
28
48
|
|
29
49
|
Options:
|
30
50
|
EOS
|
31
51
|
|
32
|
-
opt(:infile,
|
52
|
+
opt(:infile,
|
53
|
+
"Input file",
|
54
|
+
type: :string)
|
55
|
+
|
56
|
+
opt(:mode,
|
57
|
+
"Which mode should I run in?",
|
58
|
+
default: "ava")
|
59
|
+
opt(:print_modes,
|
60
|
+
"Print available modes then exit")
|
61
|
+
|
62
|
+
opt(:na_replace,
|
63
|
+
"Replace any 'na' values with this value",
|
64
|
+
default: 0)
|
65
|
+
|
66
|
+
opt(:self_score,
|
67
|
+
"Score for self connections",
|
68
|
+
default: 100)
|
69
|
+
opt(:ensure_self_scores,
|
70
|
+
"This flag will ensure that self hit scores all match the " \
|
71
|
+
"value of --self-score option")
|
72
|
+
|
73
|
+
opt(:output_style,
|
74
|
+
"Output style [wide,long]",
|
75
|
+
default: "wide")
|
76
|
+
end
|
77
|
+
|
78
|
+
if opts[:print_modes]
|
79
|
+
help = <<-EOS
|
33
80
|
|
34
|
-
|
81
|
+
Available modes: ava, ava_symmetric
|
35
82
|
|
36
|
-
|
83
|
+
#{mode_info}
|
84
|
+
EOS
|
37
85
|
|
38
|
-
|
39
|
-
|
86
|
+
STDERR.puts help
|
87
|
+
exit
|
88
|
+
end
|
40
89
|
|
41
|
-
|
90
|
+
unless opts[:infile_given]
|
91
|
+
abort "FATAL: --infile is a required argument"
|
42
92
|
end
|
43
93
|
|
44
|
-
|
94
|
+
begin
|
95
|
+
Matr.main opts
|
96
|
+
rescue StandardError => err
|
97
|
+
# We only are meant to throw StandardError
|
98
|
+
abort err
|
99
|
+
end
|
data/lib/matr.rb
CHANGED
@@ -8,12 +8,18 @@ module Matr
|
|
8
8
|
def self.main opts
|
9
9
|
|
10
10
|
infile = opts[:infile]
|
11
|
+
mode = self.default_opt opts, :mode, "ava"
|
11
12
|
self_score = self.default_opt opts, :self_score, 100
|
12
|
-
missing_score = self.default_opt opts, :missing_score, 0
|
13
|
-
output_style = self.default_opt opts, :output_style, "wide"
|
14
|
-
ensure_symmetry = true # self.default_opt opts, :ensure_symmetry, true
|
15
13
|
ensure_self_scores = self.default_opt opts, :ensure_self_scores, true
|
16
14
|
|
15
|
+
if opts[:na_replace_given]
|
16
|
+
missing_score = opts[:na_replace]
|
17
|
+
else
|
18
|
+
missing_score = "na"
|
19
|
+
end
|
20
|
+
|
21
|
+
output_style = self.default_opt opts, :output_style, "wide"
|
22
|
+
|
17
23
|
unless File.exist? infile
|
18
24
|
raise StandardError, "FATAL -- infile '#{infile}' does not exist"
|
19
25
|
end
|
@@ -36,20 +42,15 @@ module Matr
|
|
36
42
|
|
37
43
|
all_keys << source << target
|
38
44
|
|
39
|
-
# Fix self score if the option is there.
|
40
|
-
if source == target && ensure_self_scores
|
41
|
-
score = self_score
|
42
|
-
end
|
43
|
-
|
44
45
|
# If you have duplicates with different scores, that's an error: a
|
45
46
|
# => b = 10 and a => b = 20
|
46
47
|
if graph[source].has_key?(target) && graph[source][target] != score
|
47
|
-
raise StandardError, "FATAL -- source--target (#{source}--#{target}) was repeated with a different score"
|
48
|
+
raise StandardError, "FATAL -- source--target (#{source}--#{target}) was repeated with a different score. Old score was #{graph[source][target]}, and the new score was #{score}."
|
48
49
|
end
|
49
50
|
|
50
51
|
graph[source][target] = score
|
51
52
|
|
52
|
-
if
|
53
|
+
if mode == "ava_symmetric"
|
53
54
|
# Since you might have a files that specifies a => b = 10, and b
|
54
55
|
# => a = 10, that would be okay. But if you have a => b = 10, and
|
55
56
|
# b => a = 5, then that would be an error.
|
@@ -59,14 +60,17 @@ module Matr
|
|
59
60
|
|
60
61
|
graph[target][source] = score
|
61
62
|
end
|
63
|
+
end
|
64
|
+
end
|
62
65
|
|
63
|
-
|
64
|
-
unless graph[target].has_key? target
|
65
|
-
graph[target][target] = self_score
|
66
|
-
end
|
66
|
+
all_keys = all_keys.to_a.sort
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
# Zip through and add any self scores that weren't added.
|
69
|
+
all_keys.each do |source|
|
70
|
+
all_keys.each do |target|
|
71
|
+
# With ensure_self_scores, we overwrite the self score even if it was already given. Otherwise, only if it was NOT given.
|
72
|
+
if source == target && (ensure_self_scores || !graph[source][target])
|
73
|
+
graph[source][target] = self_score
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
@@ -80,8 +84,6 @@ module Matr
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
else
|
83
|
-
all_keys = all_keys.sort
|
84
|
-
|
85
87
|
puts ["", all_keys].join "\t"
|
86
88
|
|
87
89
|
all_keys.each do |source|
|
data/lib/matr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|