The first game based on a gene regulation network ! (and it’s boring !)

Do you know the Wikigame ? It is an online game whose goal is to go from one article of Wikipedia to another by only clicking on the hypertext links of the articles (actually quite a lot of fun 🙂 ). In my previous post I showed how to use Python to explore E. coli’s network of gene interactions. Now, why not transpose the Wikigame to this network ? Here is how I would do it :

  1. Get the network
  2. Take its main connected component.
  3. Choose two genes of this component randomly
  4. Compute the shortest path between the two components
  5. Set the maximum number of moves allowed to two times the length of the shortest time
  6. Lead the player through the network, proposing at each nodes to go to any of its neighbors.
  7. End the game if the player reached its goal or if the moves limit has been reached

And here is the code :

import random

def iGame(geneNetwork):
	""" A game in the spirit of the wikiGame : the computer decides of
		two random genes and you must find a way from one to the other
		in a maximum of ten moves. """

	nb_allowed_moves = 10

	# SELECT THE BIGGEST CONNECTED COMPONENT OF THE NETWORK

	undirected_net = geneNetwork.to_undirected()
	component_nodes = nx.connected_components(undirected_net)[0]
	component = geneNetwork.subgraph(component_nodes)

	# SELECT TWO RANDOM GENES INSIDE THIS COMPONENT

	start,goal = random.sample(component,2)

	# COMPUTE THE SHORTEST PATH

	shortest_path = nx.shortest_path(undirected_net,start,goal)
	nb_allowed_moves = 2*len(shortest_path)

	# A RECURSIVE FUNCTION DEFINING THE RULES

	def recursive(gene, countDown):
		""" A recursive function to explore E. coli's network from
			gene to gene """

		if gene == goal:

			print "You win ! Congratulations !"

		elif countDown == 0 :

			print "So sorry, no moves left ! You lose !"

		else :

			regulators = component.predecessors(gene)
			regulated =  component.successors(gene)

			print '\n -- Goal : %s . %d moves left'%(goal,countDown)
			print 'Genes regulating %s : '%(gene), " ".join(regulators)
			print 'Genes regulated by %s : '%(gene), " ".join(regulated)

			playerChoice = ''

			while not playerChoice in ( regulators + regulated ):

				playerChoice = raw_input('Where to move next ?')

			recursive(playerChoice, countDown-1)

	# START THE GAME

	print "\n Welcome to the iGAME, You are a level 1 raider"
	print "located on the gene %s. Your quest, would you choose"%(start)
	print "to accept it, is to reach the gene %s in less"%(goal)
	print "than %d moves. Good luck !"%(nb_allowed_moves)

	recursive(start,nb_allowed_moves)

	# END THE GAME

	print "The shortest path was : "
	print " ".join(shortest_path)

This game ( that I called iGame as a reference to the iGEM competition) is certainly one of the dullest, unfunniest games I ever coded. It’s main drawback is that, without any background information, it comes to a random walk with no visibility in a maze with hundreds of bag-ends. Maybe it would be more fun if it could be played directly on the RegulonDB webpages, which give detailled descriptions on the role and location of each gene. At which case it would be one of the nerdiest games on the internet !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s