Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding/Replacing substrings with annotations in an ASCII file in Python
    primarykey
    data
    text
    <p>I'm having a little coding issue in a bioinformatics project I'm working on. Basically, my task is to extract motif sequences from a database and use the information to annotate a sequence alignment file. The alignment file is plain text, so the annotation will not be anything elaborate, at best simply replacing the extracted sequences with asterisks in the alignment file itself. </p> <p>I have a script which scans the database file, extracts all sequences I need, and writes them to an output file. What I need is, given a query, to read these sequences and match them to their corresponding substrings in the ASCII alignment files. Finally, for every occurrence of a motif sequence (substring of a very large string of characters) I would replace motif sequence XXXXXXX with a sequence of asterisks <strong><em>*</em></strong>. </p> <p>The code I am using goes like this (11SGLOBULIN is the name of the protein entry in the database):</p> <pre><code>motif_file = open('/users/myfolder/final motifs_11SGLOBULIN','r') align_file = open('/Users/myfolder/alignmentfiles/11sglobulin.seqs', 'w+') finalmotifs = motif_file.readlines() seqalign = align_file.readlines() for line in seqalign: if motif[i] in seqalign: # I have stored all motifs in a list called "motif" replace(motif, '*****') </code></pre> <p>But instead of replacing each string with a sequence of asterisks, it deletes the entire file. Can anyone see why this is happening? </p> <p>I suspect that the problem may lie in the fact that my ASCII file is basically just one very long list of amino acids, and Python cannot know how to replace a particular substring hidden within a very long string. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload