• Calculator with letter variables
    4 replies, posted
Me again. I posted a few weeks ago asking for help on a genetics calculator. I've finally had time to sit down and work on it. I have the look of it finalized: [url]http://horse-genetics-info.99k.org/calculator.html[/url] This is done in pure html. The main issue I'm having is that I don't know how to make the calculator actually work using php. My idea is that the user selects all the variables for the sire and dam, then the website generates a list of possible colors based on the parent genetics (if needed, I can whip up a page as an example of what I'm wanting it to look like). I just simply don't know how to do this since I'm new to php and I learn the best by looking at existing code. I've looked around on google and the only calculators I've found are math calculators. Can anyone help me?
When faced with problems like this, it's often best to break it down and decide what needs to be done before starting to code. Basically you have two genotypes (for this example, let's say Aa and aa) that you want to cross. You can code a punnet square in PHP to do this. We start by getting the two parental genotypes, and breaking them into alleles: [php] $paternal_alleles = str_split($paternal_genotype); $maternal_alleles = str_split($maternal_genotype); [/php] Then we use a simple nested for loop to cross each allele. We'll use the $x loop variable for the paternal alleles and $y for the maternal. We create an array from each parental allele and sort it, so that the output always has the dominant allele first (as per convention) [php] $cross = array(); for($x = 0; $x <= 1; $x++) { $cross[$x] = array(); for($y = 0; $y <= 1; $y++) { $a = array($paternal_alleles[$x], $maternal_alleles[$y]); sort($a); $cross[$x][$y] = implode($a); } } [/php] Now $cross is a multidimensional array representing all the possible crosses of two genotypes. I'll leave you to figure out how to use that to accomplish your task.
The punnet square makes a lot of sense. I imagine the more difficult part would be programming the 18 different genes, then again, I might be wrong. Some of the php that you typed makes sense, but most of it doesn't. [url]http://horse-genetics-info.99k.org/results.html[/url] this is what I plan for the results to look like. I just wish the college didn't require three classes before I can take php.
[QUOTE=Raptor_Girl;26020277]The punnet square makes a lot of sense. I imagine the more difficult part would be programming the 18 different genes, then again, I might be wrong. Some of the php that you typed makes sense, but most of it doesn't. [url]http://horse-genetics-info.99k.org/results.html[/url] this is what I plan for the results to look like. I just wish the college didn't require three classes before I can take php.[/QUOTE] The problem with your results page is that it only shows a small sample of the wide variety of combinations of genotypes that the offspring could have.
That page is an example I typed up using HTML. It just shows that one parent was Ee and the other was ee. You'd only have two possible results with that combination. I didn't want to pick two parents with complex genes and have to type out a huge amount of results. I know the genetics, I just don't know the programming.
Sorry, you need to Log In to post a reply to this thread.