<div dir="ltr">Hello everyone,<div><br></div><div> I have multiple fasta sequences that have been aligned and cut to the same length. I want to go through each nucleotide position one at a time to see if it is the same for all of the sequences. I have written a script that can do one nucleotide position at a time but I can't figure out how to get it to loop through the entire length of the sequence.</div><div><br></div><div><div>name = "test.fas"</div><div>handle = open(name, 'r')</div><div>conout = open("consensus.txt", 'a')</div><div><br></div><div>val = []</div><div>from Bio import SeqIO</div><div>pos = 45 #test position</div><div>seqlength = 1542</div><div><br></div><div>for seq_record in SeqIO.parse(handle, "fasta"): #parses fasta file</div><div># seqlength = len(seq_record.seq)</div><div> val.append(seq_record.seq[pos]) #creates dictionary with key = sequence#, value = nucleotide at position (pos)</div><div>length = len(val) #determines the total number of key/value pairs</div><div><br></div><div>y=0</div><div>z=1</div><div><br></div><div>for x in val: #parses through position values</div><div> if val[y] == val[z]: #checks to see if adjacent values are equal</div><div># print val[z]</div><div> z=z+1</div><div> if z == length: #if all values are the same, writes value (nucleotide) to file</div><div> print "position " + str(pos+1) + " equals " + val[y]</div><div> conout.write(val[y])</div><div> break</div><div> else: #if all values are not the same, writes newline to file</div><div> print "position " + str(pos+1) + " does not have a common nucleotide"</div><div> conout.write('\n')</div><div> break </div></div><div><br></div><div> The way I have written the script, if all of the nucleotides in the same position are the same it will write the nucleotide to a file. If they are not it will write a newline. What I want is for the script to go through the length of the DNA sequence (1542 bp) and write this information to a text file so that I will end up with essentially all of the consensus sequences that I can then check for potential primer locations.<br></div><div><br></div><div>When I try to put in a for or while loop I end up getting the first nucleotide repeated for each position. I think I just need to clear/reset the val dictionary after each run but it doesn't seem to work.</div><div><br></div><div> Any help would be greatly appreciated.</div><div><br></div><div> Damian<br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div><font face="arial, helvetica, sans-serif" size="2">Damian Menning, Ph.D.</font></div><div><font face="arial, helvetica, sans-serif" size="2"><br></font></div><div><font face="arial, helvetica, sans-serif" size="2">"There are two types of academics. Those who use the Oxford comma, those who don't and those who should."</font></div><div><font face="arial, helvetica, sans-serif" size="2"><br></font></div><div><font face="arial, helvetica, sans-serif" size="2">Standard comma - You know Bob, Sue and Greg? They came to my house.</font></div><div><font face="arial, helvetica, sans-serif" size="2">Oxford comma - </font><span style="font-family:arial,helvetica,sans-serif;font-size:small">You know Bob, Sue, and Greg? They came to my house.</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:small">Walken Comma - </span><span style="font-family:arial,helvetica,sans-serif;font-size:small">You know, Bob, Sue, and Greg? They came, to my house.</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:small">Shatner comma - </span><span style="font-family:arial,helvetica,sans-serif;font-size:small">You, know, Bob, Sue, and Greg? They, came, to my house.</span></div></div></div></div></div></div></div></div></div></div></div></div>
</div></div>