#!/usr/bin/env python # coding: utf-8 # In[3]: def cycleToChromosome(nodes): """ Input: A sequence Nodes of integers between 1 and 2n. Output: The chromosome Chromosome containing n synteny blocks resulting from applying CycleToChromosome to Nodes.""" chromosome = [] for j in range(len(nodes)/2): if nodes[2*j] < nodes[2*j + 1]: chromosome.append(nodes[2*j + 1]/2) else: chromosome.append(-nodes[2*j]/2) return chromosome # In[4]: nodes = [1, 2, 4, 3, 6, 5, 7, 8] cycleToChromosome(nodes) # In[13]: f = open('input/rosalind_ba6g.txt') nodes = map(int, f.read().strip().lstrip('(').rstrip(')').split()) ans = cycleToChromosome(nodes) output = '('+' '.join([['', '+'][value > 0] + str(value) for value in ans])+')' print(output) # In[ ]: