Mercurial > repos > rnateam > viennarna_rnaeval
comparison rnafold_SHAPE.py @ 2:f9fdedb38919 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/vienna_rna commit b'bd13ffd1c3e126a6dc59dd3c478347ec1b5824a3\n'
author | rnateam |
---|---|
date | Tue, 16 May 2017 16:28:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:3f9ef14c40de | 2:f9fdedb38919 |
---|---|
1 ### overcoming the problem of SHAPE data working with a single line. | |
2 ### creating multiple multiple files containg SHAPE data for a single sequence and running RNAfold for every | |
3 ### single sequence. | |
4 | |
5 import os | |
6 import sys | |
7 from os import system | |
8 from Bio import SeqIO | |
9 import re | |
10 from subprocess import Popen, PIPE | |
11 | |
12 params_list = sys.argv[1:] | |
13 param_list_no_shape = [s for s in params_list if not "--shape=" in s ] | |
14 shape_file = [s for s in params_list if "--shape=" in s ] | |
15 assert (len(shape_file) == 1) | |
16 | |
17 shape_file = shape_file[0] | |
18 shape_file = shape_file.replace('--shape=', '') | |
19 | |
20 params_no_shape = " ".join(str(x) for x in param_list_no_shape) | |
21 | |
22 pattern = re.compile("^>.*$") | |
23 id_line = "" | |
24 with open(shape_file, 'r') as f: | |
25 content = f.read() | |
26 lines = content.split('\n') | |
27 for line in lines: | |
28 if pattern.match(line): | |
29 id_line = line.split()[0] | |
30 id_line = id_line[1:] | |
31 continue | |
32 else: | |
33 with open(id_line +'.tmp', "a") as clFile: | |
34 clFile.write(line + "\n") | |
35 | |
36 input_file = sys.stdin | |
37 | |
38 for record in SeqIO.parse(input_file, "fasta"): | |
39 seq = ">{}\n{}".format(record.id,record.seq) | |
40 cmd = " RNAfold --shape=" + record.id + '.tmp ' + params_no_shape | |
41 p = Popen(cmd , stdin=PIPE, shell=True, stdout=PIPE, stderr=PIPE) | |
42 out,err = p.communicate(seq.encode()) | |
43 if err: | |
44 raise RuntimeError("Error in calling RNAfold\n{}\n{}\n".format(out, err)) | |
45 print (out.decode('utf-8').strip()) |