Class: Net_parser

Inherits:
Object
  • Object
show all
Defined in:
lib/NetAnalyzer/net_parser.rb

Class Method Summary collapse

Class Method Details

.load(options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/NetAnalyzer/net_parser.rb', line 4

def self.load(options)
	net = nil
	if options[:input_format] == 'pair'
	  net = load_network_by_pairs(options[:input_file], options[:layers], options[:split_char])
	elsif options[:input_format] == 'bin'
	  net = load_network_by_bin_matrix(options[:input_file], options[:node_file], options[:layers])
	elsif options[:input_format] == 'matrix'
	  net = load_network_by_plain_matrix(options[:input_file], options[:node_file], options[:layers], options[:splitChar])
	else
	  raise("ERROR: The format #{options[:input_format]} is not defined")
	end
	return net
end

.load_network_by_bin_matrix(input_file, node_file, layers) ⇒ Object



32
33
34
35
36
37
# File 'lib/NetAnalyzer/net_parser.rb', line 32

def self.load_network_by_bin_matrix(input_file, node_file, layers)
	net = Network.new(layers.map{|layer| layer.first})
	node_names = load_input_list(node_file)
	net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='npy'), node_names, node_names]
	return net
end

.load_network_by_pairs(file, layers, split_character = "\t") ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/NetAnalyzer/net_parser.rb', line 18

def self.load_network_by_pairs(file, layers, split_character="\t")
	net = Network.new(layers.map{|layer| layer.first})
	File.open(file).each do |line|
		line.chomp!
		pair = line.split(split_character)
		node1 = pair[0]
		node2 = pair[1]
		net.add_node(node1, net.set_layer(layers, node1))
		net.add_node(node2, net.set_layer(layers, node2))
		net.add_edge(node1, node2)	
	end
	return net
end

.load_network_by_plain_matrix(input_file, node_file, layers, splitChar = "\t") ⇒ Object



39
40
41
42
43
44
# File 'lib/NetAnalyzer/net_parser.rb', line 39

def self.load_network_by_plain_matrix(input_file, node_file, layers, splitChar="\t")
	net = Network.new(layers.map{|layer| layer.first})
	node_names = load_input_list(node_file)
	net.adjacency_matrices[layers.map{|l| l.first}] = [Numo::NArray.load(input_file, type='txt', splitChar=splitChar), node_names, node_names]
	return net
end