Mercurial > repos > vimalkumarvelayudhan > riboplot
comparison tests/test_plot.py @ 0:ca58e9466cbf
First commit
author | Vimalkumar Velayudhan <vimal@biotechcoder.com> |
---|---|
date | Mon, 29 Jun 2015 16:38:36 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ca58e9466cbf |
---|---|
1 import os | |
2 import logging | |
3 import unittest | |
4 | |
5 from riboplot import core, config, plot | |
6 | |
7 # use testing configuration | |
8 CONFIG = plot.CONFIG = config.TestingConfig() | |
9 logging.disable(logging.CRITICAL) | |
10 | |
11 RIBO_FILE = os.path.join(CONFIG.DATA_DIR, '5hRPFsorted.bam') | |
12 RNA_FILE = os.path.join(CONFIG.DATA_DIR, '5hmRNAsorted.bam') | |
13 TRANSCRIPT_NAME = 'gi|148357119|ref|NM_001098396.1|' | |
14 TRANSCRIPTOME_FASTA = os.path.join(CONFIG.DATA_DIR, 'zebrafish.fna') | |
15 TRANSCRIPTOME_FASTA_MINUS1 = os.path.join(CONFIG.DATA_DIR, 'zebrafish_minus1.fna') | |
16 | |
17 class RNACountsTestCase(unittest.TestCase): | |
18 | |
19 def test_get_rna_counts(self): | |
20 """Test get RNA counts for transcript from RNA-Seq BAM file""" | |
21 counts = plot.get_rna_counts(rna_file=RNA_FILE, transcript_name=TRANSCRIPT_NAME) | |
22 self.assertIsInstance(counts, dict) | |
23 self.assertTrue(len(counts) > 0) | |
24 | |
25 def test_missing_rna_file(self): | |
26 """Exit with error if RNA BAM file does not exist. """ | |
27 self.assertRaises(OSError, plot.get_rna_counts, rna_file='{}.absent'.format(RNA_FILE), | |
28 transcript_name=TRANSCRIPT_NAME) | |
29 | |
30 def test_missing_bedtools(self): | |
31 """Exit with error if bedtools is missing.""" | |
32 # reset env temporarily | |
33 paths = os.environ['PATH'] | |
34 os.environ['PATH'] = '' | |
35 self.assertRaises(OSError, plot.get_rna_counts, rna_file=RNA_FILE, | |
36 transcript_name=TRANSCRIPT_NAME) | |
37 os.environ['PATH'] = paths | |
38 | |
39 | |
40 class PlotTestCase(unittest.TestCase): | |
41 | |
42 def test_get_codon_positions(self): | |
43 """Test get codon positions. """ | |
44 # input is the sequence obtained from get_transcript so no new lines. | |
45 fasta = ('AACCGGAGCACCCAGAGAAAACCCACGCAAACGCAGGGAGAATTTGCAAACTCCACACA' | |
46 'GAAATGCCAGCTGATCCAGCCGAGCCTCGAGTCAGCATCCTTGCTTGTTGGATGCCTGA' | |
47 'TTGCAGTTCAACTCCAAACTCAGTTGGACCAGCTGATCAGTG') | |
48 codon_positions = plot.get_start_stops(fasta) | |
49 expected = {1: {'starts': [], 'stops': []}, | |
50 2: {'starts': [], 'stops': [71, 116, 152]}, | |
51 3: {'starts': [63, 111], 'stops': []}} | |
52 self.assertEqual(codon_positions, expected) |