Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions tiny/rna/collapser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

import argparse
import builtins
import gzip
import os

from collections import Counter
from functools import partial
from typing import Tuple, Iterable

from tiny.rna.util import gzip_open as gz_f

try:
from _collections import _count_elements # Load Counter's C helper function if it is available
except ImportError:
from collections import _count_elements # Slower mapping[elem] = mapping.get(elem,default_val)+1

# The GZIP read/write interface used by seq_counter() and seq2fasta()
gz_f = partial(gzip.GzipFile, compresslevel=6, fileobj=None, mtime=0)


def get_args() -> 'argparse.NameSpace':
"""Get command line arguments"""
Expand Down
9 changes: 7 additions & 2 deletions tiny/rna/counter/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from tiny.rna.counter.hts_parsing import parse_gff, ReferenceTables
from tiny.rna.counter.features import FeatureSelector
from tiny.rna.util import sorted_natural
from tiny.rna.util import sorted_natural, gzip_open


class ReportFormatter:
Expand Down Expand Up @@ -215,7 +215,12 @@ def chroms_shared_with_genomes(self, genome_fastas):
for fasta in genome_fastas:
if not os.path.isfile(fasta):
continue
with open(fasta, 'rb') as f:
elif fasta.endswith('.gz'):
file_if = gzip_open
else:
file_if = open

with file_if(fasta, 'rb') as f:
for line in f:
if line[0] == ord('>'):
genome_chroms.add(line[1:].strip().decode())
Expand Down
7 changes: 6 additions & 1 deletion tiny/rna/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import functools
import textwrap
import gzip
import time
import os
import re
Expand Down Expand Up @@ -93,4 +94,8 @@ def sorted_natural(lines, reverse=False):

convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [convert(c) for c in re.split(r'(\d+)', key)]
return sorted(lines, key=alphanum_key, reverse=reverse)
return sorted(lines, key=alphanum_key, reverse=reverse)


# File IO interface for reading and writing Gzip files
gzip_open = functools.partial(gzip.GzipFile, compresslevel=6, fileobj=None, mtime=0)