Skip to content

Commit

Permalink
rna_pdb_tools.py --get-ss causes NameError. fix #146
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagnus committed Jan 11, 2024
1 parent 4c9d62b commit fb041ae
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 9 deletions.
126 changes: 126 additions & 0 deletions rna_tools/output/secondary_structures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
input/1xjr.pdb
>1xjr nts=47 [whole]
gGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))
>1xjr-A #1 nts=47 0.27(3.09) [chain] RNA
gGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))

input/1xjr_A1-4.pdb
>1xjr_A1-4 nts=4 [whole]
GGAG
....
>1xjr_A1-4-A #1 nts=4 2.61(0.09) [chain] RNA
GGAG
....

input/1xjr_A3-4.pdb
>1xjr_A3-4 nts=2 [whole]
AG
..
>1xjr_A3-4-A #1 nts=2 [chain] RNA
AG
..

input/1xjr_A5-10.pdb
>1xjr_A5-10 nts=6 [whole]
UUCACC
......
>1xjr_A5-10-A #1 nts=6 2.73(0.10) [chain] RNA
UUCACC
......

input/1xjr_C10-11.pdb
>1xjr_C10-11 nts=2 [whole]
AG
..
>1xjr_C10-11-C #1 nts=2 [chain] RNA
AG
..

input/1xjr_GTP.pdb
>1xjr_GTP nts=1 [whole]
g
.
>1xjr_GTP-A #1 nts=1 [chain] RNA
g
.

input/1xjr_ba.pdb
>1xjr_ba nts=47 [whole]
gGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))
>1xjr_ba-1-A #1 nts=47 0.27(3.09) [chain] RNA
gGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))

input/1xjr_clx_charmm.pdb
>1xjr_clx_charmm nts=46 [whole]
GAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
.(((((((...((((.((((.....))..))..))).).)))))))
>1xjr_clx_charmm-A #1 nts=46 0.27(3.12) [chain] RNA
GAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
.(((((((...((((.((((.....))..))..))).).)))))))

input/1xjr_missing_atom.pdb
>1xjr_missing_atom nts=3 [whole]
gGA
...
>1xjr_missing_atom-A #1 nts=3 2.98(0.03) [chain] RNA
gGA
...

input/1xjr_no_op3.pdb
>1xjr_no_op3 nts=2 [whole]
g&A
.&.
>1xjr_no_op3-A #1 nts=1 [chain] RNA
g
.
>1xjr_no_op3-B #2 nts=1 [chain] RNA
A
.

input/1xjr_no_op3_simrna_ready.pdb
>1xjr_no_op3_simrna_ready nts=2 [whole]
G&A
.&.
>1xjr_no_op3_simrna_ready-A #1 nts=1 [chain] RNA
G
.
>1xjr_no_op3_simrna_ready-B #2 nts=1 [chain] RNA
A
.

input/1xjr_onlyGTP.pdb
>1xjr_onlyGTP nts=1 [whole]
g
.
>1xjr_onlyGTP-A #1 nts=1 [chain] RNA
g
.

input/1xjr_onlyGTP_X.pdb
>1xjr_onlyGTP_X nts=1 [whole]
G
.
>1xjr_onlyGTP_X-A #1 nts=1 [chain] RNA
G
.

input/1xjr_rpr.pdb
>1xjr_rpr nts=47 [whole]
GGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))
>1xjr_rpr-A #1 nts=47 0.27(3.09) [chain] RNA
GGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))

input/1xjr_std.pdb
>1xjr_std nts=47 [whole]
GGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))
>1xjr_std-A #1 nts=47 0.27(3.09) [chain] RNA
GGAGUUCACCGAGGCCACGCGGAGUACGAUCGAGGGUACAGUGAAUU
..(((((((...((((.((((.....))..))..))).).)))))))

30 changes: 21 additions & 9 deletions rna_tools/tools/rna_x3dna/rna_x3dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def get_parser():
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-c', '--compact', action='store_true')
parser.add_argument('--rerun', action='store_true')
parser.add_argument('-x', '--rerun', action='store_true')
parser.add_argument('-s', '--show', action='store_true', help="show results")
parser.add_argument('--pymol', action='store_true', help='get resi to color code puckers in PyMOL')
parser.add_argument('-l', '--show-log', action='store_true', help="show full log")
parser.add_argument('-v', '--verbose', action='store_true', help="show full log")
Expand Down Expand Up @@ -112,7 +113,7 @@ def get_modifications(self):
text += l.replace('uncommon residue ', '') + '\n'
return text.strip()

def run_x3dna(self, show_log=False):
def run_x3dna(self, show_log=False, verbose=False):
"""
"""
cmd = X3DNA + ' -i=' + self.curr_fn
Expand All @@ -122,7 +123,7 @@ def run_x3dna(self, show_log=False):
outerr = str(out.stderr.read().decode())

f = open('py3dna.log', 'w')
if args.verbose: print(f'cmd: {cmd}')
if verbose: print(f'cmd: {cmd}')
f.write(cmd + '\n' + stdout)

if show_log:
Expand Down Expand Up @@ -182,13 +183,18 @@ def get_seq(self):
Somehow 1bzt_1 x3dna UCAGACUUUUAAPCUGA, what is P?
P -> u
"""
return self.report.split('\n')[-2].replace('P', 'u').replace('I', 'a')

def get_secstruc(self):
"""Get secondary structure.
"""
return self.report.split('\n')[-1]
hits = re.search("as a whole and per chain.*?\n(?P<ss>.+?)\n\*", self.report, re.DOTALL|re.MULTILINE)
if hits:
return hits.group('ss')
else:
self.report.split('\n')[-1] # tofix

def get_torsions(self, outfn) -> str:
"""Get torsion angles into 'torsion.csv' file::
Expand Down Expand Up @@ -246,6 +252,11 @@ def get_torsions(self, outfn) -> str:
nangles = re.sub(r'---', 'nan', nangles, 0, re.MULTILINE)
with open(outfn, 'w') as f:
f.write(nangles.strip())

if args.show:
import pandas as pd
df = pd.read_csv(outfn)
print(df)
return nangles.strip()

# name
Expand Down Expand Up @@ -275,12 +286,13 @@ def get_torsions(self, outfn) -> str:
outfn = os.path.basename(f.replace('.pdb', '')) + '-torsion-paired.csv'
if not args.rerun:
if os.path.isfile(outfn):
print(f'skip: {f}, use --rerun to run analysis again')
continue
p = x3DNA(f, args.show_log)
#s = p.get_seq()
#print(s)
#s = p.get_secstruc()
#print(s)
p = x3DNA(f, args.show_log, args.verbose)
s = p.get_seq()
print(s)
s = p.get_secstruc()
print(s)
s = p.get_torsions(outfn)
if args.verbose: print(s)
p.clean_up(args.verbose)

0 comments on commit fb041ae

Please sign in to comment.