<div><div>Hello everyone,</div><div><br></div><div>I have written a program, as part of a bioinformatics project, that extracts motif sequences (programmatically just strings of letters) from a database and writes them to a file.</div>
<div>I have written another script to annotate the database file (in plaintext ASCII format) by replacing every match of a motif with a sequence of tildes (~). Primitive I know, but not much more can be done with ASCII files. The code goes as follows: </div>
<div><br></div><div><br></div><div>motif_file = open('myfolder/pythonfiles/final motifs_11SGLOBULIN', 'r') # => final motifs_11sglobulin contains the output of my first program</div><div>align_file = open('myfolder/pythonfiles/11sglobulin.seqs', 'a+') # => 11sglobulin.seqs is the ASCII sequence alignment file which I want to "annotate" (modify) </div>
<div><br></div><div><div>finalmotif_seqs = [] </div><div>finalmotif_length = [] # store length of each motif</div><div>finalmotif_annot = [] </div><div><br></div><div>for line in finalmotifs:</div><div> finalmotif_seqs.append(line)</div>
<div> mot_length = len(line)</div><div> finalmotif_length.append(mot_length)</div><div><br></div><div>for item in finalmotif_length:</div><div> annotation = '~' * item </div><div> finalmotif_annot.append(annotation) </div>
</div><div><br></div><div>finalmotifs = motif_file.readlines()</div><div>seqalign = align_file.readlines() </div></div><div><br></div><div>for line in seqalign: </div><div> for i in len(finalmotif_seqs): # for item in finalmotif_seqs:</div>
<div> for i in len(finalmotif_annot): # for item in finalmotif_annot:</div><div> if finalmotif_seqs[i] in line: # if item in line:</div><div> newline = line.replace(finalmotif_seqs[i], finalmotif_annot[i])</div>
<div> #sys.stdout.write(newline) # => print the lines out on the shell</div><div> align_file.writelines(newline) </div><div><br></div><div>motif_file.close()</div><div>align_file.close()</div>
<div><br></div><div> </div><div>My coding issue is that although the script runs, there is a logic error somewhere in the triple-nested for loop as I when I check my file I'm supposedly modifying there is no change. All three lists are built correctly (I've confirmed this on the Python shell). Any help would be much appreciated! </div>
<div>I am running Python 2.6.5 </div><div><br></div>