join_count_files 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/join_count_files.rb +86 -0
  3. metadata +50 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70cd5605437dea753ba0883494a083e52b4fadd0944b824ad9ec98e8c32d6bbd
4
+ data.tar.gz: 58e1df54960004daa3226d477b689e8a443383ab520c02302012fc6665a0c6e5
5
+ SHA512:
6
+ metadata.gz: 357aef087b26c874d099ee9af88180490d3641e51e4b4cdc09270b448305982a1d567a1a2dd4ae6086e65e542c98810bb3c63cfa6d146949f9fca57b4d08ff5f
7
+ data.tar.gz: 79b2d63ca3b5431cb14c4eaab518f83a0edd8dc58b5ddf4608156f352f36fbe14f8c45a71d21302842bb3b1afe5d31cf5f0d1ad5febff1b0c1cc3f7e01ec3e3d
@@ -0,0 +1,86 @@
1
+ # JOIN COUNTS FROM MULTIPLE FILES (JOINCOUNTFILES)
2
+
3
+ ##############################################################
4
+ # MIT License
5
+
6
+ # Copyright (c) [2020] [ZACHARY L. DWIGHT]
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ # of this software and associated documentation files (the "Software"), to deal
10
+ # in the Software without restriction, including without limitation the rights
11
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ # copies of the Software, and to permit persons to whom the Software is
13
+ # furnished to do so, subject to the following conditions:
14
+
15
+ # The above copyright notice and this permission notice shall be included in all
16
+ # copies or substantial portions of the Software.
17
+
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ # SOFTWARE.
25
+ ##############################################################
26
+ #
27
+ #
28
+ # Use for merging comma delimited files of sums or totals
29
+ # First column is unique ID or name or label
30
+ # Second column is number
31
+
32
+ # Example...
33
+ # Sem1-Points.txt
34
+ # Jack, 56
35
+ # Jill, 100
36
+
37
+ # Sem2-Points.txt
38
+ # Jack, 80
39
+ # Jill, 99
40
+
41
+ # puts JOINCOUNTFILES::MergeCounts.buildfile('Sem1-Points.txt','Sem2-Points.txt','asc','MergedFile.txt')
42
+
43
+ # MergedFile.txt
44
+ # Jack, 136
45
+ # Jill, 199
46
+
47
+ module JOINCOUNTFILES
48
+ class MergeCounts
49
+ def self.buildfile(majorFile,minorFile,sort,outputfile)
50
+
51
+ mers1 = Hash.new()
52
+ mers2 = Hash.new()
53
+ comboHash = Hash.new()
54
+
55
+ File.foreach(majorFile) {|x|
56
+ xarr = x.split(",")
57
+ mers1.store(xarr[0],xarr[1].to_i)
58
+ }
59
+
60
+ File.foreach(minorFile) {|y|
61
+ yarr = y.split(",")
62
+ mers2.store(yarr[0],yarr[1].to_i)
63
+ }
64
+
65
+ comboHash = mers1.merge(mers2){|key, oldval, newval| newval + oldval}
66
+
67
+ if(sort == 'asc')
68
+ open(outputfile, 'w') { |f|
69
+ comboHash.sort{|a,b| a[1]<=>b[1]}.each { |elem|
70
+ f.puts "#{elem[0]},#{elem[1]}"
71
+ }
72
+ }
73
+ end
74
+ if(sort == 'desc')
75
+ open(outputfile, 'w') { |f|
76
+ comboHash.sort{|a,b| b[1]<=>a[1]}.each { |elem|
77
+ f.puts "#{elem[0]},#{elem[1]}"
78
+ }
79
+ }
80
+ end
81
+ return 0
82
+ end
83
+
84
+ end
85
+ end
86
+
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: join_count_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Zachary L. Dwight
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby Gem used for consolidating files with a unique identifier (such
14
+ as genetic sequence) and their associated value, count, or sum in asc or desc order. We've
15
+ used it for sequencing and genomic searches for assay development in molecular diagnostics
16
+ to consolidate distributed processes and pipelines. Also helpful for bioinformatics
17
+ and NLP applications to summarize occurences of frequency.
18
+ email: zach.dwight@path.utah.edu
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/join_count_files.rb
24
+ homepage: https://dna-utah.org
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Join two files with unique counts into a single file with sum by ascending
48
+ or descending order. Primarily used for genomic sequencing & searches, bioinformatics,
49
+ and NLP pipelines to quickly consolidate files.
50
+ test_files: []