Skip to content

Commit aa47879

Browse files
committed
Formatting
1 parent be653aa commit aa47879

18 files changed

Lines changed: 723 additions & 739 deletions

notebooks/Plotting_ribotricer_profile.ipynb

Lines changed: 671 additions & 667 deletions
Large diffs are not rendered by default.

ribotricer/bam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for spliting bam file"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith

ribotricer/cli.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""Command line interface for ribotricer
2-
"""
1+
"""Command line interface for ribotricer"""
2+
33
# Part of ribotricer software
44
#
55
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith
@@ -238,9 +238,7 @@ def detect_orfs_cmd(
238238
sys.exit("Error: psite_offsets only allowed when read_lengths is provided")
239239
if read_lengths is not None and psite_offsets is not None:
240240
try:
241-
psite_offsets = [
242-
int(x.strip()) for x in psite_offsets.strip().split(",")
243-
]
241+
psite_offsets = [int(x.strip()) for x in psite_offsets.strip().split(",")]
244242
except Exception:
245243
sys.exit("Error: cannot convert psite_offsets into integers")
246244
if len(read_lengths) != len(psite_offsets):

ribotricer/common.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for common usage"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith
@@ -78,9 +79,7 @@ def merge_intervals(intervals):
7879
intervals[i].end,
7980
intervals[i].strand,
8081
)
81-
while (
82-
i + 1 < len(intervals) and intervals[i + 1].start <= to_merge.end
83-
):
82+
while i + 1 < len(intervals) and intervals[i + 1].start <= to_merge.end:
8483
to_merge.end = max(to_merge.end, intervals[i + 1].end)
8584
i += 1
8685
merged_intervals.append(to_merge)
@@ -128,7 +127,6 @@ def collapse_coverage_to_codon(coverage):
128127
Coverage collapsed to codon level
129128
"""
130129
codon_coverage = [
131-
sum(coverage[current: current + 3])
132-
for current in range(0, len(coverage), 3)
130+
sum(coverage[current : current + 3]) for current in range(0, len(coverage), 3)
133131
]
134132
return codon_coverage

ribotricer/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants used in ribotricer"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith

ribotricer/count_orfs.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for translating ORF detection"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith
@@ -21,9 +22,7 @@
2122
import pandas as pd
2223

2324

24-
def count_orfs(
25-
ribotricer_index, detected_orfs, features, outfile, report_all=False
26-
):
25+
def count_orfs(ribotricer_index, detected_orfs, features, outfile, report_all=False):
2726
"""
2827
Parameters
2928
----------
@@ -59,11 +58,7 @@ def count_orfs(
5958
# do not output 'nontranslating' events unless report_all is set
6059
if status != "nontranslating" or report_all:
6160
intervals = orf_index[oid].intervals
62-
coor = [
63-
x
64-
for iv in intervals
65-
for x in range(iv.start, iv.end + 1)
66-
]
61+
coor = [x for iv in intervals for x in range(iv.start, iv.end + 1)]
6762
if strand == "-":
6863
coor = coor[::-1]
6964
profile_stripped = profile.strip()[1:-1].split(", ")
@@ -111,9 +106,7 @@ def count_orfs_codon(
111106
if True, all coverages will be exported
112107
"""
113108
orf_index = {}
114-
fasta_df = pd.read_csv(ribotricer_index_fasta, sep="\t").set_index(
115-
"ORF_ID"
116-
)
109+
fasta_df = pd.read_csv(ribotricer_index_fasta, sep="\t").set_index("ORF_ID")
117110
read_counts = defaultdict(dict)
118111
with open(ribotricer_index, "r") as fin:
119112
# Skip header
@@ -134,15 +127,9 @@ def count_orfs_codon(
134127
# do not output 'nontranslating' events unless report_all is set
135128
if status != "nontranslating" or report_all:
136129
intervals = orf_index[oid].intervals
137-
coor = [
138-
x
139-
for iv in intervals
140-
for x in range(iv.start, iv.end + 1)
141-
]
130+
coor = [x for iv in intervals for x in range(iv.start, iv.end + 1)]
142131
codon_coor = [
143-
x
144-
for iv in intervals
145-
for x in range(iv.start, iv.end + 1, 3)
132+
x for iv in intervals for x in range(iv.start, iv.end + 1, 3)
146133
]
147134
if strand == "-":
148135
coor = coor[::-1]
@@ -207,16 +194,12 @@ def count_orfs_codon(
207194
fout_df["per_codon_enrichment(total/n_occur)"] = (
208195
fout_df["total_codon_coverage"] / fout_df["codon_occurences"]
209196
)
210-
fout_df[
211-
"-log10_relative_enrichment(per_codon/total_gene_coverage)"
212-
] = -np.log10(
197+
fout_df["-log10_relative_enrichment(per_codon/total_gene_coverage)"] = -np.log10(
213198
fout_df["per_codon_enrichment(total/n_occur)"]
214199
/ fout_df.groupby("gene_id")["total_codon_coverage"].transform("sum")
215200
)
216201
# Overwrite
217-
fout_df.to_csv(
218-
"{}_genewise.tsv".format(prefix), sep="\t", index=False, header=True
219-
)
202+
fout_df.to_csv("{}_genewise.tsv".format(prefix), sep="\t", index=False, header=True)
220203
# Remove infs
221204
fout_df = fout_df.replace([np.inf, -np.inf], np.nan)
222205
fout_df = fout_df.dropna()

ribotricer/detect_orfs.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for translating ORF detection"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith
@@ -174,10 +175,7 @@ def orf_coverage(orf, alignments, offset_5p=0, offset_3p=0):
174175
except KeyError:
175176
coverage.append(0)
176177
else:
177-
if (
178-
strand in alignments
179-
and (chrom, pos) in alignments[strand]
180-
):
178+
if strand in alignments and (chrom, pos) in alignments[strand]:
181179
coverage.append(alignments[strand][(chrom, pos)])
182180
else:
183181
coverage.append(0)
@@ -269,9 +267,7 @@ def export_orf_coverages(
269267
valid_codons_ratio = valid_codons / n_codons
270268
# total reads in the ORF divided by the length
271269
orf_density = np.sum(codon_coverage) / n_codons
272-
codon_coverage_exceeds_min = (
273-
codon_coverage >= min_reads_per_codon
274-
)
270+
codon_coverage_exceeds_min = codon_coverage >= min_reads_per_codon
275271
status = (
276272
"translating"
277273
if (
@@ -327,9 +323,7 @@ def export_wig(merged_alignments, prefix):
327323
if chrom != cur_chrom:
328324
cur_chrom = chrom
329325
to_write += "variableStep chrom={}\n".format(chrom)
330-
to_write += "{}\t{}\n".format(
331-
pos, merged_alignments[strand][(chrom, pos)]
332-
)
326+
to_write += "{}\t{}\n".format(pos, merged_alignments[strand][(chrom, pos)])
333327
if strand == "+":
334328
fname = "{}_pos.wig".format(prefix)
335329
else:
@@ -387,11 +381,7 @@ def detect_orfs(
387381

388382
# parse the index file
389383
now = datetime.datetime.now()
390-
print(
391-
now.strftime(
392-
"%b %d %H:%M:%S ... started parsing ribotricer index file"
393-
)
394-
)
384+
print(now.strftime("%b %d %H:%M:%S ... started parsing ribotricer index file"))
395385
annotated, refseq = parse_ribotricer_index(ribotricer_index)
396386

397387
# create directory
@@ -412,9 +402,7 @@ def detect_orfs(
412402
# split bam file into strand and read length
413403
now = datetime.datetime.now()
414404
print(now.strftime("%b %d %H:%M:%S ... started reading bam file"))
415-
alignments, read_length_counts = split_bam(
416-
bam, protocol, prefix, read_lengths
417-
)
405+
alignments, read_length_counts = split_bam(bam, protocol, prefix, read_lengths)
418406

419407
# plot read length distribution
420408
now = datetime.datetime.now()

ribotricer/fasta.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""process fasta files"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith

ribotricer/gtf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities for reading GTF file"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith

ribotricer/infer_protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""infer experimental protocol"""
2+
23
# Part of ribotricer software
34
#
45
# Copyright (C) 2020 Saket Choudhary, Wenzheng Li, and Andrew D Smith

0 commit comments

Comments
 (0)