Skip to content

Commit 1bfba31

Browse files
committed
Pylint fixes
1 parent cd33e23 commit 1bfba31

File tree

7 files changed

+93
-84
lines changed

7 files changed

+93
-84
lines changed

r2dt.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ def get_ribotyper_output(fasta_input, output_folder, cm_library, skip_ribovore_f
3838
output_folder, os.path.basename(output_folder) + ".ribotyper.long.out"
3939
)
4040
if not os.path.exists(ribotyper_long_out):
41-
cmd = f"ribotyper.pl --skipval -i {cm_library}/modelinfo.txt -f {fasta_input} {output_folder}"
41+
cmd = (
42+
f"ribotyper.pl --skipval -i {cm_library}/modelinfo.txt "
43+
f"-f {fasta_input} {output_folder}"
44+
)
4245
print(cmd)
4346
os.system(cmd)
4447
f_out = os.path.join(output_folder, "hits.txt")
@@ -58,20 +61,9 @@ def get_ribotyper_output(fasta_input, output_folder, cm_library, skip_ribovore_f
5861
return f_out
5962

6063

61-
def symlink_cms(source):
62-
for cm_file in glob.glob(os.path.join(source, "*.cm")):
63-
if "all.cm" not in cm_file:
64-
target = os.path.join(
65-
os.path.abspath(config.CM_LIBRARY), os.path.basename(cm_file)
66-
)
67-
if not os.path.exists(target):
68-
cmd = f"ln -s {os.path.abspath(cm_file)} {target}"
69-
os.system(cmd)
70-
71-
7264
@click.group()
7365
def cli():
74-
pass
66+
"""Required click stub function."""
7567

7668

7769
@cli.command()
@@ -418,9 +410,6 @@ def gtrnadb_setup():
418410

419411

420412
@gtrnadb_group.command("draw")
421-
@click.option(
422-
"--test", default=False, is_flag=True, help="Process only the first 10 sequences"
423-
)
424413
@click.option(
425414
"--domain",
426415
default=False,
@@ -442,7 +431,6 @@ def gtrnadb_draw(
442431
output_folder,
443432
domain="",
444433
isotype="",
445-
test=None,
446434
constraint=None,
447435
exclusion=None,
448436
fold_type=None,
@@ -459,7 +447,6 @@ def gtrnadb_draw(
459447
isotype.capitalize(),
460448
fasta_input,
461449
output_folder,
462-
test,
463450
constraint,
464451
exclusion,
465452
fold_type,
@@ -506,6 +493,7 @@ def rnasep_group():
506493
def rnasep_draw(
507494
fasta_input, output_folder, constraint, exclusion, fold_type, skip_ribovore_filters
508495
):
496+
"""Draw 2D diagrams using RNAse P templates."""
509497
print(shared.get_r2dt_version_header())
510498
os.system(f"mkdir -p {output_folder}")
511499
with open(
@@ -553,6 +541,7 @@ def crw_group():
553541
def rrna_draw(
554542
fasta_input, output_folder, constraint, exclusion, fold_type, skip_ribovore_filters
555543
):
544+
"""Draw 2D diagrams using CRW templates."""
556545
print(shared.get_r2dt_version_header())
557546
os.system(f"mkdir -p {output_folder}")
558547
with open(
@@ -600,6 +589,7 @@ def ribovision_group():
600589
def ribovision_draw_lsu(
601590
fasta_input, output_folder, constraint, exclusion, fold_type, skip_ribovore_filters
602591
):
592+
"""Draw 2D diagrams using LSU templates from RiboVision."""
603593
print(shared.get_r2dt_version_header())
604594
os.system(f"mkdir -p {output_folder}")
605595
with open(
@@ -643,6 +633,7 @@ def ribovision_draw_lsu(
643633
def ribovision_draw_ssu(
644634
fasta_input, output_folder, constraint, exclusion, fold_type, skip_ribovore_filters
645635
):
636+
"""Draw 2D diagrams using SSU templates from RiboVision."""
646637
print(shared.get_r2dt_version_header())
647638
os.system(f"mkdir -p {output_folder}")
648639
with open(
@@ -823,6 +814,7 @@ def force_draw(
823814
exclusion=None,
824815
fold_type=None,
825816
):
817+
"""Draw 2D diagrams using a specified template."""
826818
print(shared.get_r2dt_version_header())
827819
model_type = lm.get_model_type(model_id)
828820
if not model_type:
@@ -890,9 +882,8 @@ def force_draw(
890882
)
891883
elif model_type == "gtrnadb":
892884
domain, isotype = model_id.split("_")
893-
test = False
894885
gtrnadb.visualise(
895-
domain, isotype, fasta_input, output, test, constraint, exclusion, fold_type
886+
domain, isotype, fasta_input, output, constraint, exclusion, fold_type
896887
)
897888
# organise results into folders
898889
organise_results(output, output_folder)

svg2json.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
#!/usr/bin/env python3
22

3+
"""
4+
Copyright [2009-present] EMBL-European Bioinformatics Institute
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
"""
15+
16+
317
import json
418
from xml.dom import minidom
519

@@ -13,7 +27,6 @@
1327
def main(pdb_id, filename, output):
1428
pdb, model, chain = pdb_id.split("_")
1529
doc = minidom.parse(filename)
16-
svg_lines = []
1730

1831
residues = []
1932
prev = None

utils/crw.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
def setup():
22+
"""Setup CRW CM library."""
2223
print("Deleting old CRW library")
2324
os.system(f"rm -Rf {config.CRW_CM_LIBRARY}")
2425
print("Extracting precomputed CRW archive")

utils/generate_cm_library.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
limitations under the License.
1212
"""
1313

14-
1514
import os
16-
import glob
17-
18-
19-
# CRW_FASTA_NO_PSEUDOKNOTS = '/rna/r2dt/data/crw-fasta-no-pseudoknots'
2015

2116

2217
def convert_bpseq_to_fasta(bpseq):
18+
"""Use a Traveler script to convert from BPSEQ to FASTA."""
2319
fasta = bpseq.replace(".bpseq", ".fasta")
2420
if not os.path.exists(fasta):
2521
cmd = f"python /rna/traveler/utils/bpseq2fasta.py -i {bpseq} -o {fasta}"
@@ -28,6 +24,7 @@ def convert_bpseq_to_fasta(bpseq):
2824

2925

3026
def break_pseudoknots(fasta):
27+
"""Remove pseudoknots using RNAStructure."""
3128
fasta_no_knots = fasta.replace("-with-knots.fasta", ".fasta")
3229
if not os.path.exists(fasta_no_knots):
3330
cmd = f"RemovePseudoknots -b {fasta} {fasta_no_knots}"
@@ -36,11 +33,12 @@ def break_pseudoknots(fasta):
3633

3734

3835
def convert_fasta_to_stockholm(fasta):
36+
"""Convert fasta to stockholm."""
3937
stockholm = fasta.replace(".fasta", ".sto")
4038
model_id = os.path.basename(stockholm).replace(".sto", "")
4139
if not os.path.exists(stockholm):
42-
with open(fasta, "r") as f_input:
43-
with open(stockholm, "w") as f_output:
40+
with open(fasta, "r", encoding="utf-8") as f_input:
41+
with open(stockholm, "w", encoding="utf-8") as f_output:
4442
lines = f_input.readlines()
4543
f_output.write("# STOCKHOLM 1.0\n")
4644
f_output.write("\n")
@@ -50,27 +48,33 @@ def convert_fasta_to_stockholm(fasta):
5048
return stockholm
5149

5250

53-
def copy_cm_evalues(cm):
51+
def copy_cm_evalues(cm_filename):
5452
"""
55-
Update covariance files genenrated from CRW covariance models
53+
Update covariance files generated from CRW covariance models
5654
by copying E-values from Rfam CMs.
5755
"""
58-
if not os.path.exists("RF00177.cm"):
59-
cmd = "wget -O RF00177.cm http://rfam.org/family/RF00177/cm"
56+
rfam_acc = "RF00177"
57+
example_cm_filename = os.path.join("temp", f"{rfam_acc}.cm")
58+
if not os.path.exists(example_cm_filename):
59+
cmd = f"wget -O {rfam_acc}.cm http://rfam.org/family/{rfam_acc}/cm"
6060
os.system(cmd)
61-
cmd = "perl /rna/jiffy-infernal-hmmer-scripts/cm-copy-evalue-parameters.pl RF00177.cm {cm}".format(
62-
cm=cm
61+
cmd = (
62+
f"perl /rna/jiffy-infernal-hmmer-scripts/cm-copy-evalue-parameters.pl "
63+
f"{rfam_acc}.cm {cm_filename}"
6364
)
6465
os.system(cmd)
65-
os.system(f"rm {cm}.old")
66+
os.system(f"rm {cm_filename}.old")
6667

6768

6869
def build_cm(stockholm, cm_library):
69-
cm = os.path.join(cm_library, os.path.basename(stockholm).replace(".sto", ".cm"))
70-
if not os.path.exists(cm):
71-
cmd = f"cmbuild {cm} {stockholm}"
70+
"""Build an Infernal covariance model."""
71+
cm_filename = os.path.join(
72+
cm_library, os.path.basename(stockholm).replace(".sto", ".cm")
73+
)
74+
if not os.path.exists(cm_filename):
75+
cmd = f"cmbuild {cm_filename} {stockholm}"
7276
os.system(cmd)
73-
copy_cm_evalues(cm)
77+
copy_cm_evalues(cm_filename)
7478
else:
75-
print(f"CM already exists {cm}")
76-
return cm
79+
print(f"CM already exists {cm_filename}")
80+
return cm_filename

utils/gtrnadb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def skip_trna(entry):
9292

9393

9494
def classify_trna_sequences(fasta_input, output_folder):
95+
"""Run tRNAScan-SE 2.0 and select the matching model."""
9596
if not os.path.exists(output_folder):
9697
os.mkdir(output_folder)
9798
mito_vert = run_trnascan(fasta_input, output_folder, "M")
@@ -151,8 +152,9 @@ def classify_trna_sequences(fasta_input, output_folder):
151152

152153

153154
def visualise(
154-
domain, isotype, fasta_input, output_folder, test, constraint, exclusion, fold_type
155+
domain, isotype, fasta_input, output_folder, constraint, exclusion, fold_type
155156
):
157+
"""A wrapper for visualising multiple tRNA sequences in a FASTA file."""
156158
filename = "headers.txt"
157159
if not os.path.exists(output_folder):
158160
os.makedirs(output_folder)
@@ -165,9 +167,7 @@ def visualise(
165167
os.system(cmd)
166168

167169
with open(filename, "r", encoding="utf-8") as f_headers:
168-
for i, line in enumerate(f_headers):
169-
if test and i > 10:
170-
continue
170+
for _, line in enumerate(f_headers):
171171
seq_id = line.split(" ", 1)[0].replace(">", "").strip()
172172
print(seq_id)
173173
ribovision.visualise(

0 commit comments

Comments
 (0)