Пример #1
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(mode='w+', 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, bgmodel)
Пример #2
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(mode='w+', 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, bgmodel)
Пример #3
0
 def test_markov_background_1(self):
     """test markov_background() with order 1"""
     background = st.markov_background(["ACCGTATA", "CACAT"], 1)
     self.assertEquals(2, len(background))
     self.assertEquals(4, len(background[0]))
     self.assertEquals(7, len(background[1]))
Пример #4
0
 def test_markov_background_0(self):
     """test markov_background() with order 0"""
     background = st.markov_background(["ACCGTATA", "CACAT"], 0)
     self.assertEquals(1, len(background))
     self.assertEquals(4, len(background[0]))
Пример #5
0
 def test_markov_background_1(self):
     """test markov_background() with order 1"""
     background = st.markov_background(["ACCGTATA", "CACAT"], 1)
     self.assertEquals(2, len(background))
     self.assertEquals(4, len(background[0]))
     self.assertEquals(7, len(background[1]))
Пример #6
0
 def test_markov_background_0(self):
     """test markov_background() with order 0"""
     background = st.markov_background(["ACCGTATA", "CACAT"], 0)
     self.assertEquals(1, len(background))
     self.assertEquals(4, len(background[0]))