def Writeproba(dir, Matrixproba, constraintes, rna): FF.CreateFold(Matrixproba) for file in constraintes: PSPath = dir + "/" + file + "_dp.ps" bpm = loadDotPlotPS(PSPath, "RNAfold") dp = DotPlot(rna, bpm) with open(Matrixproba + file.split('.')[0] + ".proba", "w") as o: for (i, j) in bpm.keys(): o.write("%i\t%i\t%.6f\n" % (i, j, bpm[(i, j)])) o.close()
def StructSampling(Pathconstraints, InputAlignment, numberofsruct, Tmpr, Extension, m, b): print InputAlignment dir = 'OutputSamples' + str(numberofsruct) FF.CreateFold(dir) for Path in Pathconstraints: for filename in FF.GetListFile(Path, Extension): print "filename", filename Input = Path + "/" + filename output = dir + '/' + os.path.splitext(filename)[0] #Command = 'RNAsubopt -p ' + str(numberofsruct) + ' -s -T ' + str(Tmpr)+ ' --maxBPspan '+ str(3*444/2) Command = 'RNAsubopt -p ' + str(numberofsruct) + ' -s -T ' + str( Tmpr) if Path == conf.PathConstrainteFile: Command += ' -C --enforceConstraint' if Path == conf.PathConstrainteFileShape: ShapeFile = conf.PathConstrainteFileShape + "/" + os.path.splitext( filename)[0] + 'Shape.txt' #Command += ' --shape ' + ShapeFile + ' shapeMethod=Z '+ 'shapeConversion= M' # by default the shapeMethod=D (Deigan et al 2009), where the method Z is from Zarringhalm et al 2012 #Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm3.48b-1.35"' # DMS new param #Command += ' --shape ' + ShapeFile #" defaults #Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm3.4794b-1.1598"' # for CMCT #print Command Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm' + str( m) + 'b' + str(b) + '"' subprocess.call(Command, stdin=open(Input, 'r'), stdout=open(output, 'wb'), shell=True) #because the version 2.3 of rnaeval does not consider the rna, second line should be removed lines = [] with open(output, 'r') as f: lines = f.readlines() with open(output, 'w') as f: f.writelines(lines[:1] + lines[2:]) for filename in FF.GetListFile(InputAlignment, '.aln'): Input = InputAlignment + "/" + filename print InputAlignment, Input Output = 'Sample' + os.path.splitext(filename)[0] #For the sampling from MSA alifold Command = 'RNAalifold -r -d2 --noLP --aln --stochBT ' + str( numberofsruct) subprocess.call(Command, stdin=open(Input, 'r'), stdout=open(Output, 'wb'), shell=True) Adjust_structure(Output, dir, os.path.splitext(filename)[0]) return dir
def StructSampling(Pathconstraints, Conditions, numberStructures, T, m, b, defaultFasta): conf = loadConfig() dir = os.path.join(conf.OutputFolder, "tmp", 'OutputSamples' + str(numberStructures)) FF.CreateFold(dir) thermoMsgShown = False for filename in Conditions: lines = [] header = [] progress.StartTask("Processing %s"%(filename)) while len(lines) - NUM_HEADER_LINES < numberStructures: # If alternative sequence file found in constraints folder, use it rather than default Input = defaultFasta for p in Pathconstraints: tmpInput = os.path.join(p, filename + '.' + IPANEMAP.FASTA_EXTENSION) if os.path.isfile(tmpInput): Input = tmpInput output = os.path.join(dir, filename) Command = 'RNAsubopt -p ' + str(numberStructures) + ' -s -T ' + str(T) (hasHardConstraints, hasSoftConstraints) = (False, False) hardConstraintFile = os.path.join(conf.PathConstraintsFile, filename + '.txt') if os.path.isfile(hardConstraintFile): Command += ' -C --enforceConstraint ' hasHardConstraints = True Input = hardConstraintFile ShapeFile = os.path.join(conf.PathConstraintsFileShape, filename + '.txt') if os.path.isfile(ShapeFile): Command += ' --shape ' + ShapeFile + ' --shapeMethod="Dm' + str(m) + 'b' + str(b) + '"' hasSoftConstraints = True if not (hasHardConstraints or hasSoftConstraints or thermoMsgShown): progress.Print("Warning: Did not find suitable constraint file for this condition, using purely thermodynamic sampling") thermoMsgShown = True subprocess.call(Command, stdin=open(Input, 'r'), stdout=open(output, 'wb'), stderr=open(os.devnull, 'w'), shell=True) with open(output, 'r') as f: nlines = f.readlines() header = nlines[:NUM_HEADER_LINES] lines += nlines[NUM_HEADER_LINES:] with open(output, 'w') as f: f.writelines(header+lines[:numberStructures]) progress.EndTask() return dir
def StructSampling(Pathconstraints, numberofsruct, Tmpr, Extension): dir = 'OutputSamples' + str(numberofsruct) FF.CreateFold(dir) for Path in Pathconstraints: for filename in FF.GetListFile(Path, Extension): Input = Path + "/" + filename output = dir + '/' + os.path.splitext(filename)[0] Command = 'RNAsubopt --noLP -p ' + str( numberofsruct) + ' -s -T ' + str(Tmpr) if Path == conf.PathConstrainteFile: Command += ' -C' if Path == conf.PathConstrainteFileShape: ShapeFile = conf.PathConstrainteFileShape + "/" + os.path.splitext( filename)[0] + 'Shape.txt' Command += ' --shape ' + ShapeFile subprocess.call(Command, stdin=open(Input, 'r'), stdout=open(output, 'wb'), shell=True) return dir
def DotplotRnaFold(dir, PathConstrainteFile, PathConstrainteFileShape): FF.CreateFold(dir) for filename in FF.GetListFile(PathConstrainteFile, '.fa'): name = os.path.splitext(filename)[0] Input = PathConstrainteFile + "/" + filename output = dir + '/' + name #print "command is", 'RNAfold -p -d2 -C --enforceConstraint <'+Input+ '>'+ output os.system('RNAfold --noLP -p -d2 -C --enforceConstraint <' + Input + '>' + output) #Sp.call("RNAfold -p -d2 -C ", stdin=Input, stdout=output, shell=True) # redirect files to the specific folder dir shutil.move(name + '_dp.ps', dir + "/" + name + '_dp.ps') shutil.move(name + '_ss.ps', dir + "/" + name + '_ss.ps') for filename in FF.GetListFile(PathConstrainteFileShape, '.fa'): name = os.path.splitext(filename)[0] Input = PathConstrainteFileShape + "/" + filename ShapeFile = PathConstrainteFileShape + "/" + name + 'Shape.txt' output = dir + '/' + name os.system('RNAfold -p -d2 -C ' + '<' + Input + ' --shape ' + ShapeFile + '>' + output) shutil.move(name + '_dp.ps', dir + "/" + name + '_dp.ps') shutil.move(name + '_ss.ps', dir + "/" + name + '_ss.ps')
import FileFunctions as FF import Sampling as SP import StructureFunctions as SF import StructureFunctions as SF import VisualizationTools as VT import ClustersTrait as CT import Optimize_clustering as OC from Progress import progress FASTA_EXTENSION = "fa" if __name__ == "__main__": conf = loadConfig() # Create folders FF.CreateFold(conf.OutputFolder) FF.CreateFold(os.path.join(conf.OutputFolder, "tmp")) FF.CreateFold(os.path.join(conf.OutputFolder, "tmp", conf.PickledData)) # Redirects all the print to the output Log file sys.stdout = Logger(os.path.join(conf.OutputFolder, conf.OutputLogfile)) # ******************************** Generate sample try: rna = os.path.split(conf.RNA)[-1] RNAName = rna[:-(len(FASTA_EXTENSION) + 1)] progress.StartTask("Processing RNA %s" % (RNAName)) if not os.path.isfile(conf.RNA): raise FF.IPANEMAPError("Input file '%s' not found" % (conf.RNA))