Skip to content

Commit

Permalink
Fix and test #197 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Jul 19, 2019
1 parent 6ba21cb commit 3ee0794
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Mikado/subprograms/util/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def launch(args):
current = None
if parser.__annot_type__ == "gtf":
out_format = "gff3"
elif parser.__annot_type__ in ("bed12", "gff3"):
elif parser.__annot_type__ in ("bed12", "gff3", "bam"):
out_format = "gtf"
else:
raise TypeError("Invalid annotation type: {}".format(parser.__annot_type__))
Expand All @@ -41,7 +41,19 @@ def launch(args):
for line in parser:
if line.header is True:
continue
if isinstance(line, BED12) or (line.is_exon is False and line.gene is None):
if parser.__annot_type__ == "bam":
# BAM file. We need to do things a little bit differently
if line.is_unmapped is True:
continue

mock_gene_counter += 1
gene = "gene_{mock_gene_counter}".format(**locals())
transcript = Transcript(line)
transcript.parent = gene
print(Gene(transcript).format(out_format, transcriptomic=args.transcriptomic), file=args.out)
continue

elif isinstance(line, BED12) or (line.is_exon is False and line.gene is None):
mock_gene_counter += 1
gene = "gene_{mock_gene_counter}".format(**locals())
line.parent = gene
Expand Down Expand Up @@ -71,6 +83,7 @@ def launch(args):
current.add(Transcript(line))
elif line.is_exon is True:
current.add_exon(line)

if current is not None:
print(current.format(out_format, transcriptomic=args.transcriptomic), file=args.out)

Expand Down
Binary file added Mikado/tests/test_mRNA.bam
Binary file not shown.
18 changes: 18 additions & 0 deletions Mikado/tests/test_system_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
import pysam


class ConvertCheck(unittest.TestCase):

@mark.slow
def test_convert_from_bam(self):

bam_inp = pkg_resources.resource_filename("Mikado.tests", "test_mRNA.bam")
for outp in ("gff3", "gtf", "bed12"):
with self.subTest(outp=outp):
outfile = tempfile.NamedTemporaryFile(mode="wt")
outfile.close()
sys.argv = ["", "util", "convert", "-of", outp, bam_inp, outfile.name]
# with self.assertRaises(SystemExit):
pkg_resources.load_entry_point("Mikado", "console_scripts", "mikado")()
self.assertGreater(os.stat(outfile.name).st_size, 0)
lines = [_ for _ in open(outfile.name)]
assert any(["TraesCS2B02G055500.1" in line for line in lines])


# @mark.slow
class PrepareCheck(unittest.TestCase):

Expand Down

0 comments on commit 3ee0794

Please sign in to comment.