def fold(self, shmiR, prefix=None): task_id = self.request.id if prefix is not None: task_id = "{}/{}".format(prefix, task_id) pdf, ss = execute( task_id, shmiR, to_zip=False ) with mfold_path(task_id) as tmp_dirname: zip_file(self.request.id, [pdf, ss], tmp_dirname) return { 'path_id': task_id, 'ss': ss, }
def fold_and_score( self, seq1, seq2, frame_tuple, original, score_fun, args_fun, prefix=None ): """Function for scoring and folding sequnces. Args: seq1(str): First RNA sequence. seq2(str): Second RNA sequence. frame_tuple(tuple): Tuple with frame and inserts. orginal(Backbone): orginal Backbone model. score_fun(function): Scoring function. args_fun(tuple): Arguments for scoring function. Kwargs: prefix(str): prefix for mfold path (default None) Returns: tuple with score, sh-miR, name of Backbone, task id and sequences. """ if prefix: path_id = "%s/%s" % (prefix, self.request.id) else: path_id = self.request.id frame, insert1, insert2 = frame_tuple mfold_data = execute_mfold( path_id, frame.template(insert1, insert2), zip_file=False ) pdf, ss = mfold_data score = score_fun(frame_tuple, original, ss, *args_fun) with mfold_path(path_id) as tmp_dirname: zipped_mfold(self.request.id, [pdf, ss], tmp_dirname) return [ score, frame.template(insert1, insert2), frame.name, path_id, (seq1, seq2), ]
def execute(directory, sequence, to_zip=True): """Function which executes mfold Args: directory: directory in which mfold is executed & output files are stored sequence(str): sequence to be folded via mfold to_zip(bool): tells if files should be zipped (default: True) Returns: Path of foleded files """ with mfold_path(directory) as tmp_dirname: with open('sequence', "w") as f: f.write(sequence) pid = os.fork() if pid == 0: os.execl(MFOLD_PATH, 'mfold', 'SEQ=sequence') process_id, status = os.waitpid(pid, 0) # Status in 0 - 255 status = (status & 0xff00) >> 8 if status == 0: result = map( lambda mfold_path: os.path.join( tmp_dirname, mfold_path.format('sequence') ), ["{}_1.pdf", "{}_1.ss"] ) if to_zip: result = zip_file(directory, result, tmp_dirname) if status != 0: remove_error_folding(directory) raise NoResultError("No foldings for %s" % sequence) return result
def execute_mfold(path_id, sequence, zip_file=True): """Function which executes mfold Args: path_id: path where is mfold sequence(str): sequence to be folded via mfold zip_file(bool): tells if files should be zipped (default: True) Returns: Path of foleded files """ with mfold_path(path_id) as tmp_dirname: with open('sequence', "w") as f: f.write(sequence) pid = fork() if pid == 0: execl(MFOLD_PATH, 'mfold', 'SEQ=sequence') process_id, status = waitpid(pid, 0) # Status in 0 - 255 status = (status & 0xff00) >> 8 if status == 0: result = map( lambda mfold_path: path.join( tmp_dirname, mfold_path.format('sequence') ), ["{}_1.pdf", "{}_1.ss"] ) if zip_file: result = zipped_mfold(path_id, result, tmp_dirname) if status != 0: remove_error_folding(path_id) raise NoResultError("No foldings for %s" % sequence) return result
def execute_mfold(path_id, sequence, zip_file=True): """Function which executes mfold Args: path_id: path where is mfold sequence(str): sequence to be folded via mfold zip_file(bool): tells if files should be zipped (default: True) Returns: Path of foleded files """ with mfold_path(path_id) as tmp_dirname: with open('sequence', "w") as f: f.write(sequence) pid = fork() if pid == 0: execl(MFOLD_PATH, 'mfold', 'SEQ=sequence') process_id, status = waitpid(pid, 0) # Status in 0 - 255 status = (status & 0xff00) >> 8 if status == 0: result = map( lambda mfold_path: path.join(tmp_dirname, mfold_path.format('sequence')), ["{}_1.pdf", "{}_1.ss"]) if zip_file: result = zipped_mfold(path_id, result, tmp_dirname) if status != 0: remove_error_folding(path_id) raise NoResultError("No foldings for %s" % sequence) return result