Esempio n. 1
0
 def test_order2string(self):
     self.assertEquals("1st", util.order2string(1))
     self.assertEquals("2nd", util.order2string(2))
     self.assertEquals("3rd", util.order2string(3))
     self.assertEquals("4th", util.order2string(4))
     self.assertEquals("11th", util.order2string(11))
     self.assertEquals("12th", util.order2string(12))
     self.assertEquals("21st", util.order2string(21))
     self.assertEquals("22nd", util.order2string(22))
     self.assertEquals("23rd", util.order2string(23))
Esempio n. 2
0
def make_background_file(bgseqs, use_revcomp, bgorder=3):
    """create a meme background file and returns its name"""
    def make_seqs(seqs):
        """prepare the input sequences for feeding into meme.
        This means only taking the unique sequences and their reverse
        complement if desired"""
        meme_input_seqs = []
        for locseq in seqs.values():
            seq = locseq[1]
            util.add_if_unique(meme_input_seqs, seq)
            if use_revcomp:
                util.add_if_unique(meme_input_seqs, st.revcomp(seq))
        return meme_input_seqs

    filename = None
    bgmodel = st.markov_background(make_seqs(bgseqs), bgorder)
    with tempfile.NamedTemporaryFile(prefix='memebg',
                                     delete=False) as outfile:
        filename = outfile.name
        #logging.info("make background file '%s'", filename)
        outfile.write("# %s order Markov background model\n" %
                      util.order2string(len(bgmodel) - 1))
        for order_row in bgmodel:
            for seq, frequency in order_row.items():
                outfile.write('%s %10s\n' %
                              (seq, str(round(frequency, 8))))
    return filename
Esempio n. 3
0
def make_background_file(bgseqs, use_revcomp, bgorder):
    """create a meme background file and returns its name and the model itself as
    a tuple"""
    def make_seqs(seqs):
        """prepare the input sequences for feeding into meme.
        This means only taking the unique sequences and their reverse
        complement if desired"""
        meme_input_seqs = []
        for locseq in seqs.values():
            seq = locseq[1]
            if seq not in meme_input_seqs:
                meme_input_seqs.append(seq)
            if use_revcomp:
                revseq = st.revcomp(seq)
                if revseq not in meme_input_seqs:
                    meme_input_seqs.append(revseq)
        return meme_input_seqs

    filename = None
    bgmodel = st.markov_background(make_seqs(bgseqs), bgorder)
    with tempfile.NamedTemporaryFile(prefix='memebg', delete=False) as outfile:
        filename = outfile.name
        #logging.info("make background file '%s'", filename)
        outfile.write("# %s order Markov background model\n" %
                      util.order2string(len(bgmodel) - 1))
        for order_row in bgmodel:
            for seq, frequency in order_row.iteritems():
                outfile.write('%s %10s\n' % (seq, str(round(frequency, 8))))
    return (filename, bgmodel)
Esempio n. 4
0
def make_background_file_FS(bgseqs, use_revcomp, filename, alphabet, alphabet_replacement, temp = True):
    """create a meme background file and returns its name"""
    logging.info("\x1b[31mmeme:\t\x1b[0mgenerating Seq background model")
    
    def make_seqs(seqs):
        """prepare the input sequences for feeding into meme.
        This means only taking the unique sequences and their reverse
        complement if desired"""
        meme_input_seqs = []
        for locseq in seqs.values():
            seq = locseq[1]
            util.add_if_unique(meme_input_seqs, seq)
            if use_revcomp:
                util.add_if_unique(meme_input_seqs, st.revcomp(seq))
        bigstring = "  ".join(meme_input_seqs)
        return bigstring

    bgmodel = st.markov_background_FS(make_seqs(bgseqs), 3, alphabet, alphabet_replacement)
    logging.info("\x1b[31mmeme:\t\x1b[0mMarkov model built")

    if temp == False:
        outfile = open(filename, "w")
    else:
        filename = None
        outfile = tempfile.NamedTemporaryFile(prefix='memebg',
                                         delete=False)
        filename = outfile.name

    
    logging.info("\x1b[31mmeme:\t\x1b[0mmake background file '%s'", filename)
    outfile.write("# %s order Markov background model\n" %
                  util.order2string(len(bgmodel) - 1))
    for order_row in bgmodel:
        for seq, frequency in order_row.items():
            outfile.write('%s %10s\n' %
                          (seq, str(round(frequency, 8))))
    if temp == False: outfile.close()
    logging.info("\x1b[31mmeme:\t\x1b[0mdone generating background Seqs")
    return filename