parsing a string to an array

Posted by Shork on July 1, 2009, 4:18 p.m.

I am writing a program in python for a genetics professor I had for class. It takes the coordinates of a gene on DNA, and draws an arrow showing the position and direction of the gene on the genome. I thought converting the numbers to an image would be the hard part because it needed scaling and wrapping from one line to the next, but I was wrong.

When I first wrote the program, I simply hardcoded the data used to draw the image. It worked well enough for me, but if I want to make it usable for others, I will need a GUI that takes the numbers from the user and formats it for the image. This is harder. I am trying to convert a string to an array. The string follows this format:

"1-2, 3-4

5-6, 7-8"

and the array should have this format: [[[1, 2], [3,4]], [[5, 6], [7, 8]]]

Of course the numbers could be any number. I have been trying to get this to work for weeks, and I can't get it to parse right. I haven't found any built-in functions for this sort of thing, and I have tried several techniques, such as using nested for loops that search for digits, commas, or hyphens, and tries to build a number and add it to an array, but it just does not work right…

Has anyone done anything similar, or have any suggestions for making it work?

Here is what the final output looks like, in case you're interested. Sorry about screen stretch…

Comments

Shork 15 years, 3 months ago

NOOOOOOOO JPEG IS GUD COMPRESHUN!