<html>
<head>
<title>M150 TMA 5 : Programming : Task 5 - Displaying a Gene</title>
<script language="Javascript" type="text/javascript">
//YOU DO NOT NEED TO MODIFY THIS FUNCTION
function getCodonArray (baseString)
{
var codonLength = 3;
var codonArray = new Array();
var baseArray;
baseArray = baseString.split('');
var loopCount = 0;
while (baseArray.length >= codonLength)
{
codonArray[loopCount] = baseArray.slice(0, codonLength);
baseArray = baseArray.slice(codonLength, baseArray.length);
loopCount = loopCount + 1;
}
return codonArray;
}
//YOU DO NOT NEED TO MODIFY THIS FUNCTION
function findStartCodon(baseString)
{
var startSearchIndex = 0;
var startCodonAt = -1;
var codons = getCodonArray(baseString);
codons = codons.slice(startSearchIndex, codons.length);
var codonFound = false;
var loopCount = 0;
while ((codonFound == false)&&(loopCount + 1 <= codons.length))
{
if (codons[loopCount].join('') == 'ATG')
{
startCodonAt = loopCount;
codonFound = true;
}
else
{
loopCount = loopCount + 1;
}
}
return startCodonAt;
}
function findStopCodon(baseString)
{
var startSearchIndex = 0;
var stopCodonAt = -1;
var codons = getCodonArray(baseString);
codons = codons.slice(startSearchIndex, codons.length);
var codonFound = false;
var loopCount = 0;
while ((codonFound == false) && (loopCount + 1 <= codons.length))
{
if (codons[loopCount].join('') == 'TGA' || codons[loopCount].join('') == 'TAA' || codons[loopCount].join('') == 'TAG' )
{
stopCodonAt = loopCount;
codonFound = true;
}
else
{
loopCount = loopCount + 1;
}
}
return stopCodonAt;
}
// YOU MUST COMPLETE THIS FUNCTION FOR THIS PART OF THE TMA
function displayGene()
{
var startPosition = this.document.testForm.sequenceString.value;
var startCodon = findStartCodon(startPosition);
var stopPosition = this.document.testForm.sequenceString.value;
var stopCodon = findStopCodon(stopPosition);
window.alert(startCodon + ' ' + stopCodon)
}
</script>
</head>
<body>
<!--
YOU DO NOT NEED TO MODIFY ANY OF THE HTML BELOW
-->
<strong>A program to display information about a gene.<br></strong>
<form action="" method="post" name="testForm">
<p>
Input sequence:
</p>
<p>
<input name="sequenceString" type="text" size="150" maxlength="150">
</p>
<p>
First gene:
</p>
<p>
<input name="geneString" type="text" size="150" maxlength="150">
</p>
<input name="resetButton" type="reset" value="Clear Form">
<input name="submitButton" type="button" value="Display the Gene!" onclick="displayGene();">
</form>
</body>
</html>
For the course what i need to do is take a gene string find the start gene and stop gene then display the gene. The problem i am having is that in the example gene string i have to use the first stop gene is before the start gene.
This is the gene string i have to use.
AATGGATCGTAGACTATGCCTGTGTACCGATCCGCGTCTAGGAGGCCCCGCCGACTGGCTCTACTCCGCTTCGGGCGATAATGG
I have written two functions to find the stop and start genes and need to write the displayGene() function to display it. The problem i have is that i need the display gene to find the first instance of a stop gene after the start thus ignoring the one that appears before it in the string above.
The closest i think i have been was by copying the findStopCodon() and putting it in the displayGene() function and amending this line
{
var startSearchIndex = 0;
var stopCodonAt = -1;
to this
{
var startSearchIndex = findStartCodon(baseString);
var stopCodonAt = -1;
I cannot change any of the functions other than displayGene()
Hope someone can help with this it is really doing my head in

New Topic/Question
This topic is locked



MultiQuote





|