-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenrandomSetAttributes.py
executable file
·86 lines (66 loc) · 2.03 KB
/
genrandomSetAttributes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
##############################################################################
#
# genrandomSetAttributes.py - generate random set attributes
#
# Generates random set attributes in format for EstimNetDirected setAttrFile
#
# File: genrandomSetAttributes.py
# Author: Alex Stivala
# Created: July 2019
#
##############################################################################
"""
Generates random set attributes in format for EstimNetDirected setAttrFile
Usage:
genrandomSetAttributes.py n
n is the size of the sample
Output is to stdout in format to be read by EstimNetDirected in setAttrFile
"""
import sys
import getopt
import random
#-----------------------------------------------------------------------------
#
# Functions
#
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#
# main
#
#-----------------------------------------------------------------------------
def usage(progname):
"""
print usage msg and exit
"""
sys.stderr.write("usage: " + progname + " n\n")
sys.stderr.write(" n is the size of the sample\n");
sys.exit(1)
def main():
"""
See usage message in module header block
"""
try:
opts,args = getopt.getopt(sys.argv[1:], "")
except:
usage(sys.argv[0])
for opt,arg in opts:
usage(sys.argv[0])
if len(args) != 1:
usage(sys.argv[0])
n = int(args[0])
sys.stdout.write("setAttribute1 setAttribute2\n")
for i in xrange(n):
setsizelist = [10, 20]
for i in xrange(len(setsizelist)):
if i > 0:
sys.stdout.write(' ')
randset = random.sample(set(range(setsizelist[i])), random.randint(0, setsizelist[i]))
if len(randset) == 0:
sys.stdout.write('none')
else:
sys.stdout.write(','.join([str(x) for x in randset]))
sys.stdout.write("\n")
if __name__ == "__main__":
main()