def test_interval_metadata_to_gff3(self): with io.StringIO() as fh: _interval_metadata_to_gff3(self.imd1, fh, seq_id='Chromosome') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [i for i in fh.getvalue().splitlines() if not i.startswith('#')] with open(self.single_fp) as f: exp = [i.rstrip() for i in f.readlines() if not i.startswith('#')] self.assertEqual(obs, exp)
def test_interval_metadata_to_gff3(self): with io.StringIO() as fh: _interval_metadata_to_gff3(self.imd1, fh, seq_id='Chromosome') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [ i for i in fh.getvalue().splitlines() if not i.startswith('#') ] with open(self.single_fp) as f: exp = [i.rstrip() for i in f.readlines() if not i.startswith('#')] self.assertEqual(obs, exp)
def test_interval_metadata_to_gff3_missing_field(self): exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=gene00001;Name=EDEN' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={ 'type': 'gene', 'ID': 'gene00001', 'Name': 'EDEN'}) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [i for i in fh.getvalue().splitlines() if not i.startswith('#')] self.assertEqual([exp], obs)
def test_interval_metadata_to_gff3_escape(self): # test escape of reserved char in GFF3 exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=a%3B%3D%26%2Cb' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={'type': 'gene', 'ID': 'a;=&,b'}) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [ i for i in fh.getvalue().splitlines() if not i.startswith('#') ] self.assertEqual([exp], obs)
def test_interval_metadata_to_gff3_multiple_values(self): # test multiple values of db_xref are correctly serialized exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tDbxref=GO:000152,GO:001234' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={ 'type': 'gene', 'db_xref': ['GO:000152', 'GO:001234']}) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [i for i in fh.getvalue().splitlines() if not i.startswith('#')] self.assertEqual([exp], obs)
def test_interval_metadata_to_gff3_escape(self): # test escape of reserved char in GFF3 exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=a%3B%3D%26%2Cb' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={ 'type': 'gene', 'ID': 'a;=&,b'}) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [i for i in fh.getvalue().splitlines() if not i.startswith('#')] self.assertEqual([exp], obs)
def test_roundtrip_interval_metadata(self): '''''' with io.StringIO() as fh: _interval_metadata_to_gff3(_gff3_to_interval_metadata( self.single_fp, seq_id='Chromosome'), fh, seq_id='Chromosome') obs = [ i for i in fh.getvalue().splitlines() if not i.startswith('#') ] with open(self.single_fp) as f: exp = [i.rstrip() for i in f.readlines() if not i.startswith('#')] self.assertEqual(obs, exp)
def test_roundtrip_interval_metadata(self): '''''' with io.StringIO() as fh: _interval_metadata_to_gff3( _gff3_to_interval_metadata( self.single_fp, seq_id='Chromosome'), fh, seq_id='Chromosome') obs = [i for i in fh.getvalue().splitlines() if not i.startswith('#')] with open(self.single_fp) as f: exp = [i.rstrip() for i in f.readlines() if not i.startswith('#')] self.assertEqual(obs, exp)
def test_interval_metadata_to_gff3_multiple_values(self): # test multiple values of db_xref are correctly serialized exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tDbxref=GO:000152,GO:001234' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={ 'type': 'gene', 'db_xref': ['GO:000152', 'GO:001234'] }) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [ i for i in fh.getvalue().splitlines() if not i.startswith('#') ] self.assertEqual([exp], obs)
def test_interval_metadata_to_gff3_missing_field(self): exp = 'ctg123\t.\tgene\t1\t9\t.\t.\t.\tID=gene00001;Name=EDEN' imd = IntervalMetadata(9) imd.add([(0, 9)], metadata={ 'type': 'gene', 'ID': 'gene00001', 'Name': 'EDEN' }) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='ctg123') # only compare the uncommented lines because the comments are not # stored in IntervalMetadata obs = [ i for i in fh.getvalue().splitlines() if not i.startswith('#') ] self.assertEqual([exp], obs)
def test_interval_metadata_to_gff3_empty(self): imd = IntervalMetadata(None) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='foo') obs = fh.getvalue() self.assertEqual(obs, '##gff-version 3\n')
def test_interval_metadata_to_gff3_empty(self): imd = IntervalMetadata(None) with io.StringIO() as fh: _interval_metadata_to_gff3(imd, fh, seq_id='foo') obs = fh.getvalue() self.assertEqual(obs, '##gff-version 3\n')