Skip to content

Commit

Permalink
Merged in networkx_breaking_change (pull request #8)
Browse files Browse the repository at this point in the history
generate seeds for PRNG in advance
  • Loading branch information
mdml committed Aug 24, 2015
2 parents 8aabebd + 0734b93 commit 6861258
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions comet/permute.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ def permute_mutation_data(G, genes, patients, seed, Q=100):
H.add_edges_from([ (genes[u], patients[v]) for u, v in zip(*np.where(B == 1)) ])
else:
H = G.copy()
random.seed(seed)
bipartite_double_edge_swap(H, genes, patients, nswap=Q * len( G.edges() ))
return graph_to_mutation_data(H, genes, patients)
12 changes: 6 additions & 6 deletions run_comet_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ def runComet(cometArgs):
return RC.run( RC.get_parser().parse_args(cometArgs) )

def run( args ):
# Seed Python PRNG and generate seeds for each permutation
random.seed(args.seed)
seeds = random.sample(xrange(2**31-1), args.num_permutations)

# Load mutation data using Multi-Dendrix and output as a temporary file
mutations = C.load_mutation_data(args.mutation_matrix, args.patient_file,
args.gene_file, args.min_freq)
Expand Down Expand Up @@ -102,13 +98,17 @@ def run( args ):
else:
directory = tempfile.mkdtemp(dir=".", prefix=".tmp")

for i in range(args.num_permutations):
# Generate random seeds for each permutation
random.seed(args.seed)
seeds = [ random.randint(0, 2**31-1) for _ in range(args.num_permutations) ]

for i, seed in enumerate(seeds):
# Print simple progress bar
sys.stdout.write("* Running CoMEt on permuted matrices... {}/{}\r".format(i+1, args.num_permutations))
sys.stdout.flush()

# Create a permuted dataset and save it a temporary file
mutations = C.permute_mutation_data(G, genes, patients, seeds[i], args.Q)
mutations = C.permute_mutation_data(G, genes, patients, seed, args.Q)
_, _, _, _, geneToCases, patientToGenes = mutations
adj_list = [ p + "\t" + "\t".join( sorted(patientToGenes[p]) ) for p in patients ]

Expand Down

0 comments on commit 6861258

Please sign in to comment.