Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Oct 14, 2019
1 parent f8eb5cc commit bd342e5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Mikado/subprograms/util/grep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import functools
from ...parsers import GFF, GTF
from ...subprograms import to_gff
import re


__author__ = 'Luca Venturini'
Expand All @@ -21,6 +22,8 @@ def print_gff_gene(curr_gene, curr_transcripts, args):
:return: None
"""

pat = re.compile("gene")

if curr_gene is not None or len(curr_transcripts) > 0:
starts, ends = [], []
lines = []
Expand All @@ -35,11 +38,17 @@ def print_gff_gene(curr_gene, curr_transcripts, args):
curr_gene.start = min(starts)
if ends and curr_gene is not None:
curr_gene.end = max(ends)
if curr_gene:

if curr_gene and not pat.search(curr_gene.feature) and not lines:
print(curr_gene, file=args.out)
print("###", file=args.out)
return

if lines:
if curr_gene:
print(curr_gene, file=args.out)
print(*lines, sep="\n", file=args.out)
print("###", file=args.out)
print("###", file=args.out)


def verify_storability(record, mrna_ids, gene_ids, args):
Expand Down
41 changes: 41 additions & 0 deletions Mikado/tests/test_system_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,47 @@ def test_v_grep(self):
self.assertEqual(len(found), len(others))
self.assertEqual(found, set(_[0] for _ in others))

@mark.slow
def test_problem_grep(self):
fname = pkg_resources.resource_filename("Mikado.tests", "Chrysemys_picta_bellii_problematic.gff3")
flist = pkg_resources.resource_filename("Mikado.tests", "Chrysemys_picta_bellii_problematic.list.txt")

for flag in ("", "-v"):
with self.subTest(flag=flag):
form = os.path.splitext(fname)[1]
outfile = tempfile.NamedTemporaryFile("wt", suffix=form)
outfile.close()
self.assertFalse(os.path.exists(outfile.name))
if flag:
sys.argv = ["mikado", "util", "grep", flag, flist, fname, outfile.name]
else:
sys.argv = ["mikado", "util", "grep", flist, fname, outfile.name]
print(*sys.argv)
pkg_resources.load_entry_point("Mikado", "console_scripts", "mikado")()
self.assertTrue(os.path.exists(outfile.name))
found = set()

others = ["NC_023890.1:1..16875"]
if flag != "-v":
for line in pkg_resources.resource_stream("Mikado.tests",
"Chrysemys_picta_bellii_problematic.list.txt"):
rec = line.decode().rstrip().split()[0]
print(line, rec)
others.append(rec)

with to_gff(outfile.name, input_format=form[1:]) as stream:
for record in stream:
if record.feature in ("exon", "CDS"):
continue
if record.is_transcript:
found.add(record.transcript)
elif record.feature in ("pseudogene", "region"):
found.add(record.id)

self.assertEqual(len(found), len(others))
self.assertEqual(found, set(others))



if __name__ == "__main__":
unittest.main()

0 comments on commit bd342e5

Please sign in to comment.