Пример #1
0
    def test_rnaalifold_output(self):
        """Test for rnaalifold format parser"""
        #Test empty lines
        self.assertEqual(MinimalRnaalifoldParser(''), [])

        #Test one structure
        obs = MinimalRnaalifoldParser(self.rnaalifold_out)
        self.assertEqual(obs, self.rnaalifold_exp)

        #Test two structures
        obs_2 = MinimalRnaalifoldParser(self.rnaalifold_out_2)
        self.assertEqual(obs_2, self.rnaalifold_exp_2)
Пример #2
0
def get_constrained_fold(sequence, constraint_string, params=None):
    """Returns secondary structure from RNAfold with constraints.
    
        - sequence: RNA sequence object or string.
        - constraint_string: RNAfold folding constraint string.
        - params: dict of additional RNAfold parameters.
    """
    #Check that sequence and constraint string exist.
    if not sequence:
        raise ValueError, 'No sequence found!'
    elif not constraint_string:
        raise ValueError, 'No constraint string found!'
    
    sequence = str(sequence) 
    #Check that sequence and constraint_string are equal length.
    if len(sequence) != len(constraint_string):
        raise ValueError, 'Sequence and constraint string are not same length!'
    app = RNAfold(params=params)
    #Turn on constrained folding.
    app.Parameters['-C'].on()
    
    res = app([sequence,constraint_string])
    #Parse out seq, struct string and energy.
    seq, struct, energy = MinimalRnaalifoldParser(res['StdOut'].readlines())[0]
    #Clean up after application.
    res.cleanUp()
    
    return seq, struct, energy
Пример #3
0
def rnaalifold_from_alignment(aln, moltype=RNA, params=None):
    """Returns seq, pairs, folding energy for alignment.
    """
    #Create Alignment object.  Object will handle if seqs are unaligned.
    aln = Alignment(aln, MolType=RNA)
    int_map, int_keys = aln.getIntMap()

    app = RNAalifold(WorkingDir='/tmp',\
        InputHandler='_input_as_multiline_string',params=params)
    res = app(clustal_from_alignment(int_map))

    #seq,pairs,energy = rnaalifold_parser(res['StdOut'].readlines())
    pairs_list = MinimalRnaalifoldParser(res['StdOut'].readlines())

    res.cleanUp()
    return pairs_list
Пример #4
0
def get_secondary_structure(sequence, params=None):
    """Returns secondary structure from RNAfold.
    
        - sequence: RNA sequence object or string.
        - params: dict of additional RNAfold parameters.
    """
    #Check that sequence and constraint string exist.
    if not sequence:
        raise ValueError, 'No sequence found!'
    
    sequence = str(sequence) 

    app = RNAfold(params=params)
    
    res = app([sequence])
    
    #Parse out seq, struct string and energy.
    seq, struct, energy = MinimalRnaalifoldParser(res['StdOut'].readlines())[0]
    #Clean up after application.
    res.cleanUp()
    
    return seq, struct, energy