资源简介
Python RWR,可重启的随机游走源代码,可重启的随机游走源代码
代码片段和文件信息
“““
Main script for running tissue-specific graph walk experiments to convergence.
“““
import sys
import argparse
from walker import Walker
def generate_seed_list(seed_file):
“““ Read seed file into a list. “““
seed_list = []
try:
fp = open(seed_file “r“)
except IOError:
sys.exit(“Error opening file {}“.format(seed_file))
for line in fp.readlines():
info = line.rstrip().split()
if len(info) > 1:
seed_list.append(info[1])
else:
seed_list.append(info[0])
fp.close()
return seed_list
def get_node_list(node_file):
node_list = []
try:
fp = open(node_file ‘r‘)
except IOError:
sys.exit(‘Could not open file: {}‘.format(node_file))
# read the first (i.e. largest) connected component
cur_line = fp.readline()
while cur_line and not cur_line.isspace():
if cur_line:
node_list.append(cur_line.rstrip())
cur_line = fp.readline()
fp.close()
return node_list
def main(argv):
# set up argument parsing
parser = argparse.ArgumentParser()
parser.add_argument(‘input_graph‘ help=‘Original graph input file in\
edge list format‘)
parser.add_argument(‘seed‘ help=‘Seed file to pull start nodes from‘)
parser.add_argument(‘-e‘ ‘--restart_prob‘ type=float default=0.7
help=‘Res
评论
共有 条评论