test/scout/tsv/test_parser.rb in scout-gear-10.4.0 vs test/scout/tsv/test_parser.rb in scout-gear-10.7.0
- old
+ new
@@ -113,11 +113,26 @@
content.rewind
tsv = TSV.parse(content, :head => 3)
assert_equal 3, tsv.keys.length
end
+ def test_parse_tsv_grep
+ content =<<-EOF
+#: :sep=" "#:type=:double
+#Key ValueA ValueB
+k a|A b|B
+k1 a|A b|B
+k2 a|A b|B
+k3 a|A b|B
+k4 a|A b|B
+ EOF
+ content = StringIO.new content
+ tsv = TSV.parse(content, :tsv_grep => ["k3","k4"])
+ assert_equal %w(k3 k4), tsv.keys.sort
+ end
+
def test_parse_fields
content =<<-EOF
#: :sep=" "#:type=:double
#Key ValueA ValueB
k a|A b|B
@@ -243,8 +258,63 @@
TmpFile.with_file do |db|
content.rewind
data = ScoutCabinet.open db, true, "HDB"
TSV.parse content, sep: " ", header_hash: '', data: data, cast: :to_i, type: :list, serializer: :float_array
assert_equal [1.0, 2.0], data["k"]
+ end
+ end
+
+ def test_merge
+ content =<<-EOF
+#: :type=:double
+#PMID:Sentence number:TF:TG Transcription Factor (Associated Gene Name) Target Gene (Associated Gene Name) Sign Negation PMID
+24265317:3:NR1H3:FASN NR1H3 FASN 24265317
+17522048:0:NR1H3:FASN NR1H3 FASN + 17522048
+19903962:0:NR1H3:FASN NR1H3 FASN 19903962
+19903962:7:NR1H3:FASN NR1H3 FASN 19903962
+22183856:4:NR1H3:FASN NR1H3 FASN 22183856
+22641099:4:NR1H3:FASN NR1H3 FASN + 22641099
+23499676:8:NR1H3:FASN NR1H3 FASN + 23499676
+11790787:5:NR1H3:FASN NR1H3 FASN 11790787
+11790787:7:NR1H3:FASN NR1H3 FASN + 11790787
+11790787:9:NR1H3:FASN NR1H3 FASN + 11790787
+11790787:11:NR1H3:FASN NR1H3 FASN 11790787
+17522048:1:NR1H3:FASN NR1H3 FASN + 17522048
+17522048:3:NR1H3:FASN NR1H3 FASN 17522048
+22160584:1:NR1H3:FASN NR1H3 FASN 22160584
+22160584:5:NR1H3:FASN NR1H3 FASN + 22160584
+22160584:8:NR1H3:FASN NR1H3 FASN + 22160584
+ EOF
+
+ TmpFile.with_file(content) do |filename|
+ tsv = TSV.open(filename, key_field: "Transcription Factor (Associated Gene Name)", fields: ["Target Gene (Associated Gene Name)", "Sign", "PMID"], merge: true, one2one: true, type: :double)
+ assert_equal 16, tsv["NR1H3"]["Sign"].length
+ end
+ end
+
+ def test_load_stream
+ content =<<-EOF
+#Key ValueA ValueB
+k a|A b|B
+k1 a|A b|B
+k2 a|A b|B
+k3 a|A b|B
+k4 a|A b|B
+ EOF
+ content = StringIO.new content.gsub(' ', "\t")
+
+ TmpFile.with_file do |tmp_logfile|
+ old_logfile = Log.logfile
+ Log.logfile(tmp_logfile)
+ TmpFile.with_file do |persistence|
+ data = ScoutCabinet.open persistence, true
+ tsv = Log.with_severity(0) do
+ TSV.parse(content, data: data)
+ end
+ assert_equal %w(b B), tsv["k"]["ValueB"]
+ assert_equal %w(a A), tsv["k4"]["ValueA"]
+ end
+ Log.logfile(old_logfile)
+ assert Open.read(tmp_logfile).include?("directly into")
end
end
end