Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed output formatting
  • Loading branch information
Moria committed Sep 28, 2015
1 parent dac8c99 commit 3d91614
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
35 changes: 26 additions & 9 deletions center_string.py
Expand Up @@ -39,36 +39,49 @@ OUTPUT
import os
import sys

# I need to symlink my Anaconda install with this :/
sys.path.append('/usr/local/lib/python2.7/dist-packages')
import cplex


# Absolutepath to inputs, outputs
# Absolute path to inputs, outputs
path_to_inputs = '/home/moria/Projects/Bioinformatics/CenterStringLP/Inputs/'
path_to_outputs = '/home/moria/Projects/Bioinformatics/CenterStringLP/Outputs/'

# Master bases
bases = ['A','C','T','G']

# For each input file...
for fn in os.listdir(path_to_inputs):

# Split filename into prefix, suffix
pre,suff = fn.split('.')

# Reset line counter
# Reset line counter, init array S to store sequences
line_num = 0
S = []
S = []

# Open the files
f_in = open(path_to_inputs+fn, 'r')
f_out = open(path_to_outputs+pre+'.lp', 'w')

# For each line in the input file...
for line in f_in:

# If line num is 0, grab n,m else put stripped sequence into S
if line_num == 0:
# get number of strings, length of strings
m,n = line.split(' ')
m = int(m)
n = int(n)
line_num += 1
else:
S.append(str(line))
S.append(str(line.strip()))
line_num += 1

# Write LP

# We want to minimize d subject to constraints
f_out.write('Minimize\n')
f_out.write(' obj: d\n')
f_out.write('Subject To\n')
Expand All @@ -77,8 +90,9 @@ for fn in os.listdir(path_to_inputs):

# For each sequence in S
for s in S:

# Write first part - c#:
equation = ' '
s = s.strip()
equation += 'c' + str(count) + ': '
count += 1

Expand All @@ -87,15 +101,17 @@ for fn in os.listdir(path_to_inputs):
equation += ' - ' + str(v) + str(i)
equation += ' - d <= - ' + str(n) + '\n'
f_out.write(equation)


# All Xi's must add up to 1
for number in range(n):
constraint = ' c' + str(count) + ': '
count += 1
for letter in bases:
constraint += ' + ' + letter + str(number)
constraint += ' = 1\n'

f_out.write(constraint)

# No bounds, just binary numbers
f_out.write('Bounds\n')
f_out.write('Binaries\n')
for number in range(n):
Expand All @@ -116,9 +132,10 @@ for fn in os.listdir(path_to_inputs):
lp_problem.solve()

soln = ''
# If Xi = 1, append it to the solution as this is the center string in element i
for number in range(n):
for letter in bases:
if lp_problem.solution.get_values(letter+str(number)) == 1:
soln += letter
print "Center string is: " + soln + "\n"
print "d is " + str(lp_problem.solution.get_values('d')) + "\n"
print "\n\nCenter string is: " + soln + "\n"
print "d is " + str(lp_problem.solution.get_values('d')) + "\n\n\n\n###################"
26 changes: 23 additions & 3 deletions output.txt
Expand Up @@ -38,10 +38,15 @@ Parallel b&c, 2 threads:
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.01 sec. (6.49 ticks)


Center string is: CGAAGACTATAAATAGCGAGGCCTTAAAGAACTTCCAATGTTCTAGAACCTATGCTTGAGCTGACACTACGGCATCGATTTTCTAATGCTCCGACCCATC

d is 59.0



###################
Solving input3.lp

Found incumbent of value 25.000000 after 0.00 sec. (0.01 ticks)
Expand Down Expand Up @@ -86,10 +91,15 @@ Parallel b&c, 2 threads:
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.00 sec. (0.71 ticks)


Center string is: CAGAGGTAAAAGAAAGGGGGACAAT

d is 3.0



###################
Solving input1.lp

Found incumbent of value 5.000000 after 0.00 sec. (0.00 ticks)
Expand Down Expand Up @@ -124,20 +134,25 @@ Root relaxation solution time = 0.00 sec. (0.02 ticks)
0 0 2.5000 2 4.0000 2.5000 6 37.50%
* 0+ 0 3.0000 2.5000 6 16.67%
0 0 cutoff 3.0000 3.0000 6 0.00%
Elapsed time = 0.03 sec. (0.17 ticks, tree = 0.00 MB, solutions = 3)
Elapsed time = 0.00 sec. (0.17 ticks, tree = 0.00 MB, solutions = 3)

Root node processing (before b&c):
Real time = 0.03 sec. (0.17 ticks)
Real time = 0.00 sec. (0.17 ticks)
Parallel b&c, 2 threads:
Real time = 0.00 sec. (0.00 ticks)
Sync time (average) = 0.00 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.03 sec. (0.17 ticks)
Total (root+branch&cut) = 0.00 sec. (0.17 ticks)


Center string is: AAACC

d is 3.0



###################
Solving input2.lp

Found incumbent of value 10.000000 after 0.00 sec. (0.01 ticks)
Expand Down Expand Up @@ -183,7 +198,12 @@ Parallel b&c, 2 threads:
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 0.00 sec. (0.71 ticks)


Center string is: ACAAACCCCC

d is 6.0



###################

0 comments on commit 3d91614

Please sign in to comment.