#! /usr/bin/env python # samplingMethods.py # P.Clote # Wrapper for RNAsubopt -p to sample # secondary structures and return list of sampled structures. import sys,os def printList(L): for x in L: print x ######## Sampling methods #################################### def RNAsubopt(rna,n): L = [] #list of sec str sampled D = {} # dictionary to allow easy removal of duplicates cmd = 'echo %s | RNAsubopt -p %d' % (rna,n) file = os.popen(cmd) line = file.readline() while line: secstr = line.strip() D[secstr] = 1 line = file.readline() file.close() L = D.keys() return L ######## end of Sampling methods #################################### def main(rna,numSamples): L = RNAsubopt(rna,numSamples) print rna printList(L) if __name__ == '__main__': if len(sys.argv) < 2: print "Usage: %s rna [numSamples]" % sys.argv[0] sys.exit(1) rna = sys.argv[1].strip() if len(sys.argv)>2: numSamples = int(sys.argv[2]) else: numSamples = 10 main(rna,numSamples)