<s> import copy <EOL> import unittest <EOL> import functools <EOL> import itertools <EOL> import types <EOL> import numpy as np <EOL> import numpy . testing as npt <EOL> import pandas as pd <EOL> import scipy . stats <EOL> from skbio import Sequence , DNA , RNA , Protein , TabularMSA <EOL> from skbio . sequence import GrammaredSequence <EOL> from skbio . util . _decorator import classproperty , overrides <EOL> from skbio . util . _testing import ReallyEqualMixin <EOL> from skbio . metadata . _testing import ( MetadataMixinTests , <EOL> PositionalMetadataMixinTests ) <EOL> from skbio . util . _testing import ( assert_index_equal , <EOL> assert_data_frame_almost_equal ) <EOL> class TabularMSASubclass ( TabularMSA ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class TestTabularMSAMetadata ( unittest . TestCase , ReallyEqualMixin , <EOL> MetadataMixinTests ) : <EOL> def setUp ( self ) : <EOL> self . _metadata_constructor_ = functools . partial ( TabularMSA , [ ] ) <EOL> class TestTabularMSAPositionalMetadata ( unittest . TestCase , ReallyEqualMixin , <EOL> PositionalMetadataMixinTests ) : <EOL> def setUp ( self ) : <EOL> def factory ( axis_len , positional_metadata = None ) : <EOL> return TabularMSA ( [ DNA ( '<STR_LIT:A>' * axis_len ) ] , <EOL> positional_metadata = positional_metadata ) <EOL> self . _positional_metadata_constructor_ = factory <EOL> class TestTabularMSA ( unittest . TestCase , ReallyEqualMixin ) : <EOL> def test_from_dict_empty ( self ) : <EOL> self . assertEqual ( TabularMSA . from_dict ( { } ) , TabularMSA ( [ ] , index = [ ] ) ) <EOL> def test_from_dict_single_sequence ( self ) : <EOL> self . assertEqual ( TabularMSA . from_dict ( { '<STR_LIT:foo>' : DNA ( '<STR_LIT>' ) } ) , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) ) <EOL> def test_from_dict_multiple_sequences ( self ) : <EOL> msa = TabularMSA . from_dict ( <EOL> { <NUM_LIT:1> : DNA ( '<STR_LIT>' ) , <NUM_LIT:2> : DNA ( '<STR_LIT>' ) , <NUM_LIT:3> : DNA ( '<STR_LIT>' ) } ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> def test_from_dict_invalid_input ( self ) : <EOL> with self . assertRaisesRegex ( <EOL> ValueError , '<STR_LIT>' ) : <EOL> TabularMSA . from_dict ( { '<STR_LIT:a>' : DNA ( '<STR_LIT>' ) , '<STR_LIT:b>' : DNA ( '<STR_LIT>' ) } ) <EOL> def test_constructor_invalid_dtype ( self ) : <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ Sequence ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ <NUM_LIT> , DNA ( '<STR_LIT>' ) ] ) <EOL> def test_constructor_not_monomorphic ( self ) : <EOL> with self . assertRaisesRegex ( TypeError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ Protein ( '<STR_LIT>' ) , Protein ( '<STR_LIT>' ) , <NUM_LIT> , Protein ( '<STR_LIT>' ) ] ) <EOL> def test_constructor_unequal_length ( self ) : <EOL> with self . assertRaisesRegex ( <EOL> ValueError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ Protein ( '<STR_LIT>' ) , Protein ( '<STR_LIT:P>' ) ] ) <EOL> with self . assertRaisesRegex ( <EOL> ValueError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ Protein ( '<STR_LIT>' ) , Protein ( '<STR_LIT>' ) , Protein ( '<STR_LIT:A>' ) ] ) <EOL> def test_constructor_non_iterable ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> TabularMSA ( <NUM_LIT> ) <EOL> def test_constructor_non_unique_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:1> ] ) <EOL> assert_index_equal ( msa . index , pd . Int64Index ( [ <NUM_LIT:1> , <NUM_LIT:1> ] ) ) <EOL> def test_constructor_minter_and_index_both_provided ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = str , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> def test_constructor_index_length_mismatch_iterable ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = iter ( [ ] ) ) <EOL> def test_constructor_index_length_mismatch_index_object ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , <EOL> '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = pd . Index ( [ ] ) ) <EOL> def test_constructor_empty_no_index ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> self . assertIsNone ( msa . dtype ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ] ) ) <EOL> with self . assertRaises ( StopIteration ) : <EOL> next ( iter ( msa ) ) <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> msa = TabularMSA ( seqs ) <EOL> self . assertIs ( msa . dtype , DNA ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> assert_index_equal ( msa . index , pd . Int64Index ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( list ( msa ) , seqs ) <EOL> def test_constructor_empty_with_labels ( self ) : <EOL> msa = TabularMSA ( [ ] , minter = lambda x : x ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ] ) ) <EOL> msa = TabularMSA ( [ ] , index = iter ( [ ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT> } ) ] , minter = '<STR_LIT:id>' ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = iter ( [ <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> def test_constructor_non_empty_no_labels_provided ( self ) : <EOL> seqs = [ DNA ( '<STR_LIT>' ) ] <EOL> msa = TabularMSA ( seqs ) <EOL> self . assertIs ( msa . dtype , DNA ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:1> , <NUM_LIT:3> ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( list ( msa ) , seqs ) <EOL> seqs = [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:C>' ) , DNA ( '<STR_LIT>' ) ] <EOL> msa = TabularMSA ( seqs ) <EOL> self . assertIs ( msa . dtype , DNA ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:3> , <NUM_LIT:1> ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> self . assertEqual ( list ( msa ) , seqs ) <EOL> def test_constructor_non_empty_with_labels_provided ( self ) : <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> msa = TabularMSA ( seqs , minter = str ) <EOL> self . assertIs ( msa . dtype , DNA ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( list ( msa ) , seqs ) <EOL> msa = TabularMSA ( seqs , index = iter ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> def test_constructor_works_with_iterator ( self ) : <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> msa = TabularMSA ( iter ( seqs ) , minter = str ) <EOL> self . assertIs ( msa . dtype , DNA ) <EOL> self . assertEqual ( msa . shape , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( list ( msa ) , seqs ) <EOL> def test_constructor_with_multiindex_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_constructor_with_multiindex_minter ( self ) : <EOL> def multiindex_minter ( seq ) : <EOL> if str ( seq ) == '<STR_LIT>' : <EOL> return ( '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> else : <EOL> return ( '<STR_LIT:bar>' , <NUM_LIT> ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = multiindex_minter ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_copy_constructor_without_metadata ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> copy = TabularMSA ( msa ) <EOL> self . assertEqual ( msa , copy ) <EOL> self . assertIsNot ( msa , copy ) <EOL> def test_copy_constructor_with_metadata ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> ) } , <EOL> index = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> copy = TabularMSA ( msa ) <EOL> self . assertEqual ( msa , copy ) <EOL> self . assertIsNot ( msa , copy ) <EOL> self . assertIsNot ( msa . metadata , copy . metadata ) <EOL> self . assertIsNot ( msa . positional_metadata , copy . positional_metadata ) <EOL> self . assertIsNot ( msa . index , copy . index ) <EOL> def test_copy_constructor_state_override_with_minter ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> ) } , <EOL> index = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> copy = TabularMSA ( msa , metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> , <NUM_LIT:8> ) } , <EOL> minter = str ) <EOL> self . assertNotEqual ( msa , copy ) <EOL> self . assertEqual ( <EOL> copy , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> , <NUM_LIT:8> ) } , <EOL> minter = str ) ) <EOL> def test_copy_constructor_state_override_with_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> ) } , <EOL> index = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> copy = TabularMSA ( msa , metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> , <NUM_LIT:8> ) } , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> self . assertNotEqual ( msa , copy ) <EOL> self . assertEqual ( <EOL> copy , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> metadata = { '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:bar>' : range ( <NUM_LIT:4> , <NUM_LIT:8> ) } , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) <EOL> def test_dtype ( self ) : <EOL> self . assertIsNone ( TabularMSA ( [ ] ) . dtype ) <EOL> self . assertIs ( TabularMSA ( [ Protein ( '<STR_LIT>' ) ] ) . dtype , Protein ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> TabularMSA ( [ ] ) . dtype = DNA <EOL> with self . assertRaises ( AttributeError ) : <EOL> del TabularMSA ( [ ] ) . dtype <EOL> def test_shape ( self ) : <EOL> shape = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) . shape <EOL> self . assertEqual ( shape , ( <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( shape . sequence , shape [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( shape . position , shape [ <NUM_LIT:1> ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> shape [ <NUM_LIT:0> ] = <NUM_LIT:3> <EOL> with self . assertRaises ( AttributeError ) : <EOL> TabularMSA ( [ ] ) . shape = ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> with self . assertRaises ( AttributeError ) : <EOL> del TabularMSA ( [ ] ) . shape <EOL> def test_index_getter ( self ) : <EOL> index = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = str ) . index <EOL> self . assertIsInstance ( index , pd . Index ) <EOL> assert_index_equal ( index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> with self . assertRaises ( TypeError ) : <EOL> index [ <NUM_LIT:1> ] = '<STR_LIT>' <EOL> assert_index_equal ( index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> def test_index_mixed_type ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ '<STR_LIT:abc>' , '<STR_LIT:d>' , <NUM_LIT> ] ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT:abc>' , '<STR_LIT:d>' , <NUM_LIT> ] ) ) <EOL> def test_index_setter_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . index = iter ( [ ] ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ] ) ) <EOL> def test_index_setter_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa . index = range ( <NUM_LIT:3> ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> msa . index = range ( <NUM_LIT:3> , <NUM_LIT:6> ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> def test_index_setter_length_mismatch ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = str ) <EOL> index = pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_index_equal ( msa . index , index ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . index = iter ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert_index_equal ( msa . index , index ) <EOL> def test_index_setter_non_unique_index ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , minter = str ) <EOL> msa . index = [ '<STR_LIT:1>' , '<STR_LIT:1>' ] <EOL> self . assertEqual ( msa , TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , <EOL> index = [ '<STR_LIT:1>' , '<STR_LIT:1>' ] ) ) <EOL> def test_index_setter_tuples ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> msa . index = [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( <EOL> msa . index , <EOL> pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] , tupleize_cols = True ) ) <EOL> def test_index_deleter ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , minter = str ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> del msa . index <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> def test_bool ( self ) : <EOL> self . assertFalse ( TabularMSA ( [ ] ) ) <EOL> self . assertFalse ( TabularMSA ( [ RNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertFalse ( <EOL> TabularMSA ( [ RNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> RNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:2> } ) ] , minter = '<STR_LIT:id>' ) ) <EOL> self . assertTrue ( TabularMSA ( [ RNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertTrue ( TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT:..>' ) ] ) ) <EOL> self . assertTrue ( TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_len ( self ) : <EOL> self . assertEqual ( len ( TabularMSA ( [ ] ) ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) , <NUM_LIT:3> ) <EOL> def test_iter ( self ) : <EOL> with self . assertRaises ( StopIteration ) : <EOL> next ( iter ( TabularMSA ( [ ] ) ) ) <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( list ( iter ( TabularMSA ( seqs ) ) ) , seqs ) <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( list ( iter ( TabularMSA ( seqs ) ) ) , seqs ) <EOL> def test_reversed ( self ) : <EOL> with self . assertRaises ( StopIteration ) : <EOL> next ( reversed ( TabularMSA ( [ ] ) ) ) <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT> } ) ] <EOL> self . assertEqual ( list ( reversed ( TabularMSA ( seqs ) ) ) , seqs [ : : - <NUM_LIT:1> ] ) <EOL> seqs = [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] <EOL> self . assertEqual ( list ( reversed ( TabularMSA ( seqs ) ) ) , seqs [ : : - <NUM_LIT:1> ] ) <EOL> def test_eq_and_ne ( self ) : <EOL> components = [ <EOL> ( [ ] , { } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) ] , { } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : lambda x : str ( x ) + '<STR_LIT>' } ) , <EOL> ( [ RNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT> } ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : str } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , <EOL> { '<STR_LIT>' : lambda x : '<STR_LIT>' if '<STR_LIT>' in x else '<STR_LIT>' } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : { '<STR_LIT:foo>' : <NUM_LIT> } } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : { '<STR_LIT:foo>' : <NUM_LIT> } } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , { '<STR_LIT>' : { '<STR_LIT:foo>' : <NUM_LIT> , '<STR_LIT:bar>' : <NUM_LIT> } } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , <EOL> { '<STR_LIT>' : { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> ] } } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , <EOL> { '<STR_LIT>' : { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> ] } } ) , <EOL> ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , <EOL> { '<STR_LIT>' : { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> ] , '<STR_LIT:bar>' : [ <NUM_LIT> , <NUM_LIT> ] } } ) , <EOL> ] <EOL> for seqs , kwargs in components : <EOL> obj = TabularMSA ( seqs , ** kwargs ) <EOL> self . assertReallyEqual ( obj , obj ) <EOL> self . assertReallyEqual ( obj , TabularMSA ( seqs , ** kwargs ) ) <EOL> self . assertReallyEqual ( obj , TabularMSASubclass ( seqs , ** kwargs ) ) <EOL> for ( seqs1 , kwargs1 ) , ( seqs2 , kwargs2 ) in itertools . combinations ( components , <NUM_LIT:2> ) : <EOL> obj1 = TabularMSA ( seqs1 , ** kwargs1 ) <EOL> obj2 = TabularMSA ( seqs2 , ** kwargs2 ) <EOL> self . assertReallyNotEqual ( obj1 , obj2 ) <EOL> self . assertReallyNotEqual ( obj1 , <EOL> TabularMSASubclass ( seqs2 , ** kwargs2 ) ) <EOL> msa = TabularMSA ( [ ] ) <EOL> self . assertReallyNotEqual ( msa , <NUM_LIT> ) <EOL> self . assertReallyNotEqual ( msa , [ ] ) <EOL> self . assertReallyNotEqual ( msa , { } ) <EOL> self . assertReallyNotEqual ( msa , '<STR_LIT>' ) <EOL> def test_eq_constructed_from_different_iterables_compare_equal ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa2 = TabularMSA ( ( DNA ( '<STR_LIT>' ) , ) ) <EOL> self . assertReallyEqual ( msa1 , msa2 ) <EOL> def test_eq_ignores_minter_str_and_lambda ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) ] , minter = '<STR_LIT:id>' ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) ] , <EOL> minter = lambda x : x . metadata [ '<STR_LIT:id>' ] ) <EOL> self . assertReallyEqual ( msa1 , msa2 ) <EOL> def test_eq_minter_and_index ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) ] , index = [ '<STR_LIT:a>' ] ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) ] , minter = '<STR_LIT:id>' ) <EOL> self . assertReallyEqual ( msa1 , msa2 ) <EOL> def test_reassign_index_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . reassign_index ( ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> assert_index_equal ( msa . index , pd . Int64Index ( [ ] ) ) <EOL> msa . reassign_index ( minter = str ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] , minter = str ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa . reassign_index ( ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> ] ) ) <EOL> msa . reassign_index ( minter = str ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , minter = str ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' ] ) ) <EOL> def test_reassign_index_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:2> } ) ] , minter = str ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> msa . reassign_index ( minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:2> } ) ] , minter = '<STR_LIT:id>' ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> msa . reassign_index ( mapping = { <NUM_LIT:1> : <NUM_LIT:5> } ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:1> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:2> } ) ] , index = [ <NUM_LIT:5> , <NUM_LIT:2> ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:5> , <NUM_LIT:2> ] ) ) <EOL> msa . reassign_index ( ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> def test_reassign_index_minter_and_mapping_both_provided ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = str ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . reassign_index ( minter = str , mapping = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> def test_reassign_index_with_mapping_dict_empty ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> msa . reassign_index ( mapping = { } ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> def test_reassign_index_with_mapping_dict_subset ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> mapping = { <NUM_LIT:0.5> : "<STR_LIT:a>" , <NUM_LIT> : "<STR_LIT:c>" } <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> msa . reassign_index ( mapping = mapping ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ '<STR_LIT:a>' , <NUM_LIT> , '<STR_LIT:c>' ] ) ) <EOL> def test_reassign_index_with_mapping_dict_superset ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> mapping = { <NUM_LIT:0.5> : "<STR_LIT:a>" , <NUM_LIT> : "<STR_LIT:b>" , <NUM_LIT> : "<STR_LIT:c>" , <NUM_LIT> : "<STR_LIT:d>" } <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> msa . reassign_index ( mapping = mapping ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) ) <EOL> def test_reassign_index_with_mapping_callable ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> msa . reassign_index ( mapping = str ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] ) ) <EOL> def test_reassign_index_non_unique_existing_index ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> mapping = { <NUM_LIT:0.5> : "<STR_LIT:a>" , <NUM_LIT> : "<STR_LIT:b>" , <NUM_LIT> : "<STR_LIT:c>" , <NUM_LIT> : "<STR_LIT:d>" } <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT:0.5> , <NUM_LIT:0.5> ] ) <EOL> msa . reassign_index ( mapping = mapping ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) ) <EOL> def test_reassign_index_non_unique_new_index ( self ) : <EOL> seqs = [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT:C>" ) , DNA ( "<STR_LIT>" ) ] <EOL> mapping = { <NUM_LIT:0.5> : "<STR_LIT:a>" , <NUM_LIT> : "<STR_LIT:a>" , <NUM_LIT> : "<STR_LIT:a>" } <EOL> msa = TabularMSA ( seqs , index = [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> msa . reassign_index ( mapping = mapping ) <EOL> self . assertEqual ( msa , TabularMSA ( seqs , index = [ '<STR_LIT:a>' , '<STR_LIT:a>' , '<STR_LIT:a>' ] ) ) <EOL> def test_reassign_index_to_multiindex_with_minter ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> def multiindex_minter ( seq ) : <EOL> if str ( seq ) == '<STR_LIT>' : <EOL> return ( '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> else : <EOL> return ( '<STR_LIT:bar>' , <NUM_LIT> ) <EOL> msa . reassign_index ( minter = multiindex_minter ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_reassign_index_to_multiindex_with_mapping ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> mapping = { <NUM_LIT:0> : ( '<STR_LIT:foo>' , <NUM_LIT> ) , <NUM_LIT:1> : ( '<STR_LIT:bar>' , <NUM_LIT> ) } <EOL> msa . reassign_index ( mapping = mapping ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_sort_on_unorderable_msa_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ <NUM_LIT> , <NUM_LIT> , '<STR_LIT:foo>' ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ <NUM_LIT> , <NUM_LIT> , '<STR_LIT:foo>' ] ) ) <EOL> def test_sort_empty_on_msa_index ( self ) : <EOL> msa = TabularMSA ( [ ] , index = [ ] ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] , index = [ ] ) ) <EOL> msa = TabularMSA ( [ ] , index = [ ] ) <EOL> msa . sort ( ascending = False ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] , index = [ ] ) ) <EOL> def test_sort_single_sequence_on_msa_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT> ] ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT> ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT> ] ) <EOL> msa . sort ( ascending = False ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT> ] ) ) <EOL> def test_sort_multiple_sequences_on_msa_index ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:z>' , '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> msa . sort ( ascending = True ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:z>' ] ) ) <EOL> msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:z>' , '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> msa . sort ( ascending = False ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:z>' , '<STR_LIT:b>' , '<STR_LIT:a>' ] ) ) <EOL> def test_sort_on_labels_with_some_repeats ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:8> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:0> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) ] , minter = '<STR_LIT:id>' ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:0> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:8> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT:10> } ) ] , minter = '<STR_LIT:id>' ) ) <EOL> def test_sort_on_key_with_all_repeats ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) ] , minter = str ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) ] , minter = str ) ) <EOL> def test_sort_already_sorted ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> msa . sort ( ascending = False ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) ) <EOL> def test_sort_reverse_sorted ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:T>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:A>' ) ] , index = [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:T>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:T>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:A>' ) ] , index = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> msa . sort ( ascending = False ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:T>' ) ] , index = [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) ) <EOL> def test_sort_multiindex ( self ) : <EOL> multiindex = [ ( <NUM_LIT:2> , '<STR_LIT:a>' ) , ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:3> , '<STR_LIT:b>' ) ] <EOL> sortedindex = [ ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:2> , '<STR_LIT:a>' ) , ( <NUM_LIT:3> , '<STR_LIT:b>' ) ] <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:C>' ) , DNA ( '<STR_LIT>' ) ] , index = multiindex ) <EOL> msa . sort ( ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT:C>' ) , DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = sortedindex ) ) <EOL> def test_sort_multiindex_with_level ( self ) : <EOL> multiindex = [ ( <NUM_LIT:2> , '<STR_LIT:a>' ) , ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:3> , '<STR_LIT:b>' ) ] <EOL> first_sorted = [ ( <NUM_LIT:1> , '<STR_LIT:c>' ) , ( <NUM_LIT:2> , '<STR_LIT:a>' ) , ( <NUM_LIT:3> , '<STR_LIT:b>' ) ] <EOL> second_sorted = [ ( <NUM_LIT:2> , '<STR_LIT:a>' ) , ( <NUM_LIT:3> , '<STR_LIT:b>' ) , ( <NUM_LIT:1> , '<STR_LIT:c>' ) ] <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:C>' ) , DNA ( '<STR_LIT>' ) ] , index = multiindex ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> msa . sort ( level = <NUM_LIT:0> ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT:C>' ) , DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = first_sorted ) ) <EOL> msa . sort ( level = <NUM_LIT:1> ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:C>' ) ] , <EOL> index = second_sorted ) ) <EOL> def test_to_dict_falsey_msa ( self ) : <EOL> self . assertEqual ( TabularMSA ( [ ] ) . to_dict ( ) , { } ) <EOL> self . assertEqual ( TabularMSA ( [ RNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) . to_dict ( ) , <EOL> { '<STR_LIT:foo>' : RNA ( '<STR_LIT>' ) } ) <EOL> def test_to_dict_non_empty ( self ) : <EOL> seqs = [ Protein ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : <NUM_LIT> } ) , <EOL> Protein ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : - <NUM_LIT> } ) ] <EOL> msa = TabularMSA ( seqs , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( msa . to_dict ( ) , { <NUM_LIT> : seqs [ <NUM_LIT:0> ] , - <NUM_LIT> : seqs [ <NUM_LIT:1> ] } ) <EOL> def test_to_dict_duplicate_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT:A>" ) , DNA ( "<STR_LIT>" ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:0> ] ) <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> msa . to_dict ( ) <EOL> self . assertIn ( "<STR_LIT>" , str ( cm . exception ) ) <EOL> def test_from_dict_to_dict_roundtrip ( self ) : <EOL> d = { } <EOL> self . assertEqual ( TabularMSA . from_dict ( d ) . to_dict ( ) , d ) <EOL> d1 = { '<STR_LIT:a>' : DNA ( '<STR_LIT>' ) , <NUM_LIT> : DNA ( '<STR_LIT>' ) } <EOL> d2 = TabularMSA . from_dict ( d1 ) . to_dict ( ) <EOL> self . assertEqual ( d2 , d1 ) <EOL> self . assertIs ( d1 [ '<STR_LIT:a>' ] , d2 [ '<STR_LIT:a>' ] ) <EOL> self . assertIs ( d1 [ <NUM_LIT> ] , d2 [ <NUM_LIT> ] ) <EOL> class TestContains ( unittest . TestCase ) : <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] , index = [ ] ) <EOL> self . assertFalse ( '<STR_LIT>' in msa ) <EOL> self . assertFalse ( '<STR_LIT:foo>' in msa ) <EOL> def test_with_str_labels ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> self . assertTrue ( '<STR_LIT:foo>' in msa ) <EOL> self . assertTrue ( '<STR_LIT:bar>' in msa ) <EOL> self . assertFalse ( '<STR_LIT>' in msa ) <EOL> self . assertFalse ( <NUM_LIT:0> in msa ) <EOL> def test_with_int_labels ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT> , - <NUM_LIT:1> ] ) <EOL> self . assertTrue ( <NUM_LIT> in msa ) <EOL> self . assertTrue ( - <NUM_LIT:1> in msa ) <EOL> self . assertFalse ( <NUM_LIT:0> in msa ) <EOL> self . assertFalse ( '<STR_LIT:foo>' in msa ) <EOL> class TestCopy ( unittest . TestCase ) : <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa_copy = copy . copy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . _seqs , msa_copy . _seqs ) <EOL> def test_with_sequences ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa_copy = copy . copy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . _seqs , msa_copy . _seqs ) <EOL> self . assertIsNot ( msa [ <NUM_LIT:0> ] , msa_copy [ <NUM_LIT:0> ] ) <EOL> self . assertIsNot ( msa [ <NUM_LIT:1> ] , msa_copy [ <NUM_LIT:1> ] ) <EOL> msa_copy . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> msa_copy . _seqs [ <NUM_LIT:0> ] . metadata [ '<STR_LIT:bar>' ] = <NUM_LIT> <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> msa_copy . _seqs [ <NUM_LIT:0> ] . metadata [ '<STR_LIT:foo>' ] . append ( <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_with_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> msa_copy = copy . copy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . index , msa_copy . index ) <EOL> msa_copy . index = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert_index_equal ( msa_copy . index , pd . Index ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> class TestDeepCopy ( unittest . TestCase ) : <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa_copy = copy . deepcopy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . _seqs , msa_copy . _seqs ) <EOL> def test_with_sequences ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa_copy = copy . deepcopy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . _seqs , msa_copy . _seqs ) <EOL> self . assertIsNot ( msa [ <NUM_LIT:0> ] , msa_copy [ <NUM_LIT:0> ] ) <EOL> self . assertIsNot ( msa [ <NUM_LIT:1> ] , msa_copy [ <NUM_LIT:1> ] ) <EOL> msa_copy . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> msa_copy . _seqs [ <NUM_LIT:0> ] . metadata [ '<STR_LIT:bar>' ] = <NUM_LIT> <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> msa_copy . _seqs [ <NUM_LIT:0> ] . metadata [ '<STR_LIT:foo>' ] . append ( <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> ] } ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_with_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> msa_copy = copy . deepcopy ( msa ) <EOL> self . assertEqual ( msa , msa_copy ) <EOL> self . assertIsNot ( msa , msa_copy ) <EOL> self . assertIsNot ( msa . index , msa_copy . index ) <EOL> msa_copy . index = [ <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> assert_index_equal ( msa_copy . index , pd . Index ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> class SharedIndexTests : <EOL> def get ( self , obj , indexable ) : <EOL> raise NotImplementedError ( ) <EOL> def test_tuple_too_big ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> self . get ( TabularMSA ( [ ] ) , ( None , None , None ) ) <EOL> def test_empty_msa_slice ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> new = self . get ( msa , slice ( None , None ) ) <EOL> self . assertIsNot ( msa , new ) <EOL> self . assertEqual ( msa , new ) <EOL> def test_msa_slice_all_first_axis ( self ) : <EOL> msa = TabularMSA ( [ RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } ) , <EOL> RNA ( "<STR_LIT>" , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } ) ] , <EOL> metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] } ) <EOL> new_slice = self . get ( msa , slice ( None ) ) <EOL> new_ellipsis = self . get ( msa , Ellipsis ) <EOL> self . assertIsNot ( msa , new_slice ) <EOL> for s1 , s2 in zip ( msa , new_slice ) : <EOL> self . assertIsNot ( s1 , s2 ) <EOL> self . assertEqual ( msa , new_slice ) <EOL> self . assertIsNot ( msa , new_ellipsis ) <EOL> for s1 , s2 in zip ( msa , new_ellipsis ) : <EOL> self . assertIsNot ( s1 , s2 ) <EOL> self . assertEqual ( msa , new_ellipsis ) <EOL> def test_msa_slice_all_both_axes ( self ) : <EOL> msa = TabularMSA ( [ RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } ) , <EOL> RNA ( "<STR_LIT>" , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } ) ] , <EOL> metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] } ) <EOL> new_slice = self . get ( msa , ( slice ( None ) , slice ( None ) ) ) <EOL> new_ellipsis = self . get ( msa , ( Ellipsis , Ellipsis ) ) <EOL> self . assertIsNot ( msa , new_slice ) <EOL> for s1 , s2 in zip ( msa , new_slice ) : <EOL> self . assertIsNot ( s1 , s2 ) <EOL> self . assertEqual ( msa , new_slice ) <EOL> self . assertIsNot ( msa , new_ellipsis ) <EOL> for s1 , s2 in zip ( msa , new_ellipsis ) : <EOL> self . assertIsNot ( s1 , s2 ) <EOL> self . assertEqual ( msa , new_ellipsis ) <EOL> def test_bool_index_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } ) <EOL> b = DNA ( "<STR_LIT>" , positional_metadata = { <NUM_LIT:1> : [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] } ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } , <EOL> index = [ True , False , True ] ) <EOL> new = self . get ( msa , [ True , True , False ] ) <EOL> self . assertEqual ( new , TabularMSA ( [ a , b ] , metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } , <EOL> index = [ True , False ] ) ) <EOL> def test_bool_index_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } ) <EOL> b = DNA ( "<STR_LIT>" , positional_metadata = { <NUM_LIT:1> : [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] } ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } , <EOL> index = [ True , False , True ] ) <EOL> new = self . get ( msa , ( Ellipsis , [ True , True , False ] ) ) <EOL> self . assertEqual ( new , TabularMSA ( [ a [ <NUM_LIT:0> , <NUM_LIT:1> ] , b [ <NUM_LIT:0> , <NUM_LIT:1> ] , c [ <NUM_LIT:0> , <NUM_LIT:1> ] ] , <EOL> metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> ] } , <EOL> index = [ True , False , True ] ) ) <EOL> def test_bool_index_both_axes ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } ) <EOL> b = DNA ( "<STR_LIT>" , positional_metadata = { <NUM_LIT:1> : [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] } ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } , <EOL> index = [ True , False , True ] ) <EOL> new = self . get ( msa , ( [ False , True , True ] , [ True , True , False ] ) ) <EOL> self . assertEqual ( new , TabularMSA ( [ b [ <NUM_LIT:0> , <NUM_LIT:1> ] , c [ <NUM_LIT:0> , <NUM_LIT:1> ] ] , <EOL> metadata = { <NUM_LIT:0> : '<STR_LIT:x>' } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> ] } , <EOL> index = [ False , True ] ) ) <EOL> def test_bool_index_too_big ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] , <EOL> index = [ False , True , False ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ False , False , False , False ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ True , True , True , True ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , [ True , False , True , False , True ] ) ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( [ True , False , True , False ] , <EOL> [ True , False , True , False , False ] ) ) <EOL> def test_bool_index_too_small ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] , <EOL> index = [ False , True , False ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ False ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ True ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , [ True ] ) ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( [ True , False ] , [ True , False , True , False ] ) ) <EOL> def test_bad_scalar ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] ) <EOL> with self . assertRaises ( ( KeyError , TypeError ) ) : <EOL> self . get ( msa , "<STR_LIT:foo>" ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , "<STR_LIT:foo>" ) ) <EOL> def test_bad_fancy_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] ) <EOL> with self . assertRaises ( ( KeyError , TypeError ) ) : <EOL> self . get ( msa , [ <NUM_LIT:0> , "<STR_LIT:foo>" ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , [ <NUM_LIT:0> , "<STR_LIT:foo>" ] ) ) <EOL> def test_asburd_slice ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] ) <EOL> with self . assertRaises ( TypeError ) : <EOL> self . get ( msa , { set ( <NUM_LIT:1> ) : <NUM_LIT:0> } ) <EOL> class SharedPropertyIndexTests ( SharedIndexTests ) : <EOL> def setUp ( self ) : <EOL> self . combo_msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , <EOL> positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , <EOL> positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , <EOL> positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { <NUM_LIT:4> : <NUM_LIT:4> } , <EOL> positional_metadata = { <NUM_LIT:4> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] } ) <EOL> ] , index = list ( '<STR_LIT>' ) , metadata = { '<STR_LIT:x>' : '<STR_LIT:x>' } , <EOL> positional_metadata = { '<STR_LIT:y>' : [ <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] } ) <EOL> """<STR_LIT>""" <EOL> self . combo_first_axis = [ <EOL> ( [ ] , [ ] ) , <EOL> ( slice ( <NUM_LIT:0> , <NUM_LIT:0> ) , [ ] ) , <EOL> ( Ellipsis , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( slice ( None ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( slice ( <NUM_LIT:0> , <NUM_LIT> ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> ( - <NUM_LIT:4> , <NUM_LIT:1> ) , <EOL> ( [ <NUM_LIT:0> ] , [ <NUM_LIT:0> ] ) , <EOL> ( [ <NUM_LIT:2> ] , [ <NUM_LIT:2> ] ) , <EOL> ( slice ( <NUM_LIT:1> , <NUM_LIT:3> ) , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> ( slice ( <NUM_LIT:3> , <NUM_LIT:0> , - <NUM_LIT:1> ) , [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) , <EOL> ( [ - <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ] ) , <EOL> ( [ - <NUM_LIT:4> , - <NUM_LIT:3> , - <NUM_LIT:2> , - <NUM_LIT:1> ] , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( np . array ( [ - <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:1> ] ) , [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> ] ) , <EOL> ( [ True , True , False , False , True ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ] ) , <EOL> ( np . array ( [ True , True , False , True , False ] ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> ] ) , <EOL> ( range ( <NUM_LIT:3> ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> ( [ slice ( <NUM_LIT:0> , <NUM_LIT:2> ) , slice ( <NUM_LIT:3> , <NUM_LIT:4> ) , <NUM_LIT:4> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> ] <EOL> self . combo_second_axis = self . combo_first_axis <EOL> def test_combo_single_axis_natural ( self ) : <EOL> for idx , exp in self . combo_first_axis : <EOL> self . assertEqual ( self . get ( self . combo_msa , idx ) , <EOL> self . combo_msa . iloc [ exp ] , <EOL> msg = "<STR_LIT>" % ( idx , exp ) ) <EOL> def test_combo_first_axis_only ( self ) : <EOL> for idx , exp in self . combo_first_axis : <EOL> self . assertEqual ( self . get ( self . combo_msa , idx , axis = <NUM_LIT:0> ) , <EOL> self . combo_msa . iloc [ exp , ... ] , <EOL> msg = "<STR_LIT>" % ( idx , exp ) ) <EOL> def test_combo_second_axis_only ( self ) : <EOL> for idx , exp in self . combo_second_axis : <EOL> self . assertEqual ( self . get ( self . combo_msa , idx , axis = <NUM_LIT:1> ) , <EOL> self . combo_msa . iloc [ ... , exp ] , <EOL> msg = "<STR_LIT>" % ( idx , exp ) ) <EOL> def test_combo_both_axes ( self ) : <EOL> for idx1 , exp1 in self . combo_first_axis : <EOL> for idx2 , exp2 in self . combo_second_axis : <EOL> self . assertEqual ( self . get ( self . combo_msa , ( idx1 , idx2 ) ) , <EOL> self . combo_msa . iloc [ exp1 , exp2 ] , <EOL> msg = ( "<STR_LIT>" <EOL> % ( ( idx1 , idx2 ) , exp1 , exp2 ) ) ) <EOL> class TestLoc ( SharedPropertyIndexTests , unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> SharedPropertyIndexTests . setUp ( self ) <EOL> self . combo_first_axis = [ <EOL> ( [ ] , [ ] ) , <EOL> ( slice ( '<STR_LIT:X>' , "<STR_LIT>" ) , [ ] ) , <EOL> ( '<STR_LIT:A>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT:E>' , <NUM_LIT:4> ) , <EOL> ( [ '<STR_LIT:B>' ] , [ <NUM_LIT:1> ] ) , <EOL> ( np . asarray ( [ '<STR_LIT:B>' ] ) , [ <NUM_LIT:1> ] ) , <EOL> ( slice ( '<STR_LIT:A>' , '<STR_LIT:C>' , <NUM_LIT:2> ) , [ <NUM_LIT:0> , <NUM_LIT:2> ] ) , <EOL> ( slice ( '<STR_LIT:C>' , '<STR_LIT:A>' , - <NUM_LIT:2> ) , [ <NUM_LIT:2> , <NUM_LIT:0> ] ) , <EOL> ( slice ( '<STR_LIT:A>' , '<STR_LIT:B>' ) , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) , <EOL> ( slice ( None ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( slice ( '<STR_LIT:A>' , None ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( slice ( None , '<STR_LIT:C>' ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> ( Ellipsis , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( self . combo_msa . index , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> ( [ '<STR_LIT:B>' , '<STR_LIT:A>' , '<STR_LIT:A>' , '<STR_LIT:C>' ] , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ] ) , <EOL> ( np . asarray ( [ '<STR_LIT:B>' , '<STR_LIT:A>' , '<STR_LIT:A>' , '<STR_LIT:C>' ] ) , [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ] ) , <EOL> ( [ True , False , True , True , False ] , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> ( np . asarray ( [ True , False , True , True , False ] ) , [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , <EOL> ] <EOL> def test_forced_axis_returns_copy ( self ) : <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] ) <EOL> self . assertIsNot ( msa . loc ( axis = <NUM_LIT:1> ) , msa . loc ) <EOL> def test_forced_axis_no_mutate ( self ) : <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] ) <EOL> self . assertEqual ( msa . loc ( axis = <NUM_LIT:1> ) [ <NUM_LIT:0> ] , Sequence ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( msa . loc [ <NUM_LIT:0> ] , Protein ( "<STR_LIT>" ) ) <EOL> self . assertIsNone ( msa . loc . _axis ) <EOL> def get ( self , obj , indexable , axis = None ) : <EOL> if axis is None : <EOL> return obj . loc [ indexable ] <EOL> else : <EOL> return obj . loc ( axis = axis ) [ indexable ] <EOL> def test_complex_single_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" ) <EOL> b = DNA ( "<STR_LIT>" ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) <EOL> self . assertIs ( a , self . get ( msa , ( ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ) ) ) <EOL> self . assertIs ( b , self . get ( msa , ( ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ) ) ) <EOL> self . assertIs ( c , self . get ( msa , ( ( '<STR_LIT:b>' , <NUM_LIT:0> ) , ) ) ) <EOL> def test_partial_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" ) <EOL> b = DNA ( "<STR_LIT>" ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) <EOL> exp_a = TabularMSA ( [ a , b ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> exp_b = TabularMSA ( [ c ] , index = [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( self . get ( msa , '<STR_LIT:a>' ) , exp_a ) <EOL> self . assertEqual ( self . get ( msa , '<STR_LIT:b>' ) , exp_b ) <EOL> def test_label_not_exists ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) ] , index = [ '<STR_LIT:foo>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> self . get ( msa , '<STR_LIT:bar>' ) <EOL> def test_duplicate_index_nonscalar_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( self . get ( msa , <NUM_LIT:0> ) , <EOL> TabularMSA ( [ a , b ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:0> ] ) ) <EOL> def test_duplicate_index_scalar_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( self . get ( msa , <NUM_LIT:1> ) , c ) <EOL> def test_multiindex_complex ( self ) : <EOL> a = DNA ( "<STR_LIT>" ) <EOL> b = DNA ( "<STR_LIT>" ) <EOL> c = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b , c ] , index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) <EOL> exp = TabularMSA ( [ a , c ] , index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) <EOL> self . assertEqual ( self . get ( msa , [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> ) ] ) , exp ) <EOL> def test_fancy_index_missing_label ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) ] , index = [ '<STR_LIT:foo>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> self . get ( msa , [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> self . get ( msa , [ '<STR_LIT:bar>' ] ) <EOL> def test_multiindex_fancy_indexing_incomplete_label ( self ) : <EOL> a = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:c>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] } , <EOL> index = [ ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , '<STR_LIT:y>' , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT:b>' , '<STR_LIT:x>' , <NUM_LIT:0> ) ] ) <EOL> self . assertEqual ( self . get ( msa , ( ( '<STR_LIT:a>' , '<STR_LIT:x>' ) , Ellipsis ) ) , <EOL> TabularMSA ( [ a , b ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:c>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , <EOL> '<STR_LIT:d>' ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> def test_multiindex_complicated_axis ( self ) : <EOL> a = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:c>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] } , <EOL> index = [ ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , '<STR_LIT:y>' , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT:b>' , '<STR_LIT:x>' , <NUM_LIT:0> ) ] ) <EOL> self . assertEqual ( self . get ( msa , ( ( [ False , True , False , True ] , <EOL> '<STR_LIT:x>' , <NUM_LIT:0> ) , Ellipsis ) ) , <EOL> TabularMSA ( [ d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:c>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , <EOL> '<STR_LIT:d>' ] } , <EOL> index = [ ( '<STR_LIT:b>' , '<STR_LIT:x>' , <NUM_LIT:0> ) ] ) ) <EOL> def test_multiindex_complicated_axis_empty_selection ( self ) : <EOL> a = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = RNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:c>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] } , <EOL> index = [ ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:0> ) , ( '<STR_LIT:a>' , '<STR_LIT:x>' , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , '<STR_LIT:y>' , <NUM_LIT:2> ) , <EOL> ( '<STR_LIT:b>' , '<STR_LIT:x>' , <NUM_LIT:0> ) ] ) <EOL> self . assertEqual ( self . get ( msa , ( ( [ False , True , False , True ] , <EOL> '<STR_LIT:x>' , <NUM_LIT:2> ) , Ellipsis ) ) , <EOL> TabularMSA ( [ ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = None , <EOL> index = [ ] ) ) <EOL> def test_bool_index_scalar_bool_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ False , True , False , False ] ) <EOL> self . assertEqual ( self . get ( msa , True ) , b ) <EOL> def test_bool_index_nonscalar_bool_label ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> d = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ False , True , False , True ] ) <EOL> self . assertEqual ( self . get ( msa , True ) , <EOL> TabularMSA ( [ b , d ] , metadata = { '<STR_LIT:x>' : '<STR_LIT:y>' } , <EOL> positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ True , True ] ) ) <EOL> def test_unhashable_index_first_axis ( self ) : <EOL> s = slice ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] , <EOL> index = [ s , slice ( <NUM_LIT:1> , <NUM_LIT:2> ) , slice ( <NUM_LIT:2> , <NUM_LIT:3> ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , Ellipsis , axis = <NUM_LIT:0> ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , s , axis = <NUM_LIT:0> ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , <NUM_LIT:0> , axis = <NUM_LIT:0> ) <EOL> def test_unhashable_index_second_axis ( self ) : <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] , <EOL> index = [ slice ( <NUM_LIT:0> , <NUM_LIT:1> ) , slice ( <NUM_LIT:1> , <NUM_LIT:2> ) , slice ( <NUM_LIT:2> , <NUM_LIT:3> ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , Ellipsis , axis = <NUM_LIT:1> ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , [ <NUM_LIT:0> , <NUM_LIT:1> ] , axis = <NUM_LIT:1> ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , <NUM_LIT:0> , axis = <NUM_LIT:1> ) <EOL> def test_unhashable_index_both_axes ( self ) : <EOL> s = [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> msa = TabularMSA ( [ RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) ] , <EOL> index = [ s , [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , ( Ellipsis , Ellipsis ) ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , ( s , <NUM_LIT:0> ) ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , ( '<STR_LIT:x>' , <NUM_LIT:10> ) ) <EOL> def test_categorical_index_scalar_label ( self ) : <EOL> msa = TabularMSA ( [ RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) ] , <EOL> index = pd . CategoricalIndex ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) ) <EOL> self . assertEqual ( self . get ( msa , '<STR_LIT:a>' ) , RNA ( "<STR_LIT>" ) ) <EOL> def test_categorical_index_nonscalar_label ( self ) : <EOL> msa = TabularMSA ( [ RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) ] , <EOL> index = pd . CategoricalIndex ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) ) <EOL> self . assertEqual ( self . get ( msa , '<STR_LIT:b>' ) , <EOL> TabularMSA ( [ RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) ] , <EOL> index = pd . CategoricalIndex ( <EOL> [ '<STR_LIT:b>' , '<STR_LIT:b>' ] , categories = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> ) ) <EOL> def test_float_index_out_of_order_slice ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] , <EOL> index = [ <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> self . get ( msa , slice ( <NUM_LIT:0.1> , <NUM_LIT> ) ) <EOL> msa . sort ( ) <EOL> result = self . get ( msa , slice ( <NUM_LIT:0.1> , <NUM_LIT> ) ) <EOL> self . assertEqual ( result , TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) , <EOL> DNA ( "<STR_LIT>" ) ] , <EOL> index = [ <NUM_LIT:0.1> , <NUM_LIT> , <NUM_LIT> ] ) ) <EOL> def test_nonscalar_fancy_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> , <NUM_LIT:1> ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , <EOL> '<STR_LIT>' ) : <EOL> self . get ( msa , [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> def test_missing_first_nonscalar_fancy_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> , <NUM_LIT:1> ) ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> self . get ( msa , [ '<STR_LIT:x>' , '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> def test_tuple_fancy_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ ( '<STR_LIT:a>' , <NUM_LIT:0> , <NUM_LIT:1> ) , ( '<STR_LIT:a>' , <NUM_LIT:1> , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> , <NUM_LIT:1> ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , ( ( ( '<STR_LIT:a>' , <NUM_LIT:0> , <NUM_LIT:1> ) , ( '<STR_LIT:b>' , <NUM_LIT:0> , <NUM_LIT:1> ) ) , Ellipsis ) ) <EOL> def test_non_multiindex_tuple ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> self . get ( msa , ( ( <NUM_LIT:0> , <NUM_LIT:1> ) , Ellipsis ) ) <EOL> def test_assertion_exists_for_future_failure_of_get_sequence_loc ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaises ( AssertionError ) : <EOL> msa . _get_sequence_loc_ ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> class TestILoc ( SharedPropertyIndexTests , unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> SharedPropertyIndexTests . setUp ( self ) <EOL> self . combo_first_axis = self . combo_second_axis <EOL> def test_forced_axis_returns_copy ( self ) : <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] ) <EOL> self . assertIsNot ( msa . iloc ( axis = <NUM_LIT:1> ) , msa . iloc ) <EOL> def test_forced_axis_no_mutate ( self ) : <EOL> msa = TabularMSA ( [ Protein ( "<STR_LIT>" ) , Protein ( "<STR_LIT>" ) ] ) <EOL> self . assertEqual ( msa . iloc ( axis = <NUM_LIT:1> ) [ <NUM_LIT:0> ] , Sequence ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( msa . iloc [ <NUM_LIT:0> ] , Protein ( "<STR_LIT>" ) ) <EOL> self . assertIsNone ( msa . iloc . _axis ) <EOL> def get ( self , obj , indexable , axis = None ) : <EOL> if axis is None : <EOL> return obj . iloc [ indexable ] <EOL> else : <EOL> return obj . iloc ( axis = axis ) [ indexable ] <EOL> def test_entire_fancy_first_axis ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , <EOL> positional_metadata = { '<STR_LIT:a>' : [ <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT:4> ] } ) , <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , <EOL> positional_metadata = { '<STR_LIT:b>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> ] , metadata = { '<STR_LIT:c>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> new_np_simple = self . get ( msa , np . arange ( <NUM_LIT:2> ) ) <EOL> new_list_simple = self . get ( msa , [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> new_list_backwards = self . get ( msa , [ - <NUM_LIT:2> , - <NUM_LIT:1> ] ) <EOL> self . assertIsNot ( msa , new_np_simple ) <EOL> self . assertEqual ( msa , new_np_simple ) <EOL> self . assertIsNot ( msa , new_list_simple ) <EOL> self . assertEqual ( msa , new_list_simple ) <EOL> self . assertIsNot ( msa , new_list_backwards ) <EOL> self . assertEqual ( msa , new_list_backwards ) <EOL> def test_fancy_entire_second_axis ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , <EOL> positional_metadata = { '<STR_LIT:a>' : [ <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT:4> ] } ) , <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , <EOL> positional_metadata = { '<STR_LIT:b>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> ] , metadata = { '<STR_LIT:c>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> new_np_simple = self . get ( msa , ( Ellipsis , np . arange ( <NUM_LIT:4> ) ) ) <EOL> new_list_simple = self . get ( msa , ( Ellipsis , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> new_list_backwards = self . get ( msa , ( Ellipsis , [ - <NUM_LIT:4> , - <NUM_LIT:3> , - <NUM_LIT:2> , - <NUM_LIT:1> ] ) ) <EOL> self . assertIsNot ( msa , new_np_simple ) <EOL> self . assertEqual ( msa , new_np_simple ) <EOL> self . assertIsNot ( msa , new_list_simple ) <EOL> self . assertEqual ( msa , new_list_simple ) <EOL> self . assertIsNot ( msa , new_list_backwards ) <EOL> self . assertEqual ( msa , new_list_backwards ) <EOL> def test_fancy_entire_both_axes ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , <EOL> positional_metadata = { '<STR_LIT:a>' : [ <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT:4> ] } ) , <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , <EOL> positional_metadata = { '<STR_LIT:b>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> ] , metadata = { '<STR_LIT:c>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> new_np_simple = self . get ( msa , ( np . arange ( <NUM_LIT:2> ) , np . arange ( <NUM_LIT:4> ) ) ) <EOL> new_list_simple = self . get ( msa , ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) <EOL> new_list_backwards = self . get ( msa , ( [ - <NUM_LIT:2> , - <NUM_LIT:1> ] , [ - <NUM_LIT:4> , - <NUM_LIT:3> , - <NUM_LIT:2> , - <NUM_LIT:1> ] ) ) <EOL> self . assertIsNot ( msa , new_np_simple ) <EOL> self . assertEqual ( msa , new_np_simple ) <EOL> self . assertIsNot ( msa , new_list_simple ) <EOL> self . assertEqual ( msa , new_list_simple ) <EOL> self . assertIsNot ( msa , new_list_backwards ) <EOL> self . assertEqual ( msa , new_list_backwards ) <EOL> def test_fancy_out_of_bound ( self ) : <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) , ( Ellipsis , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_fancy_empty_both_axis ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:x>' : <NUM_LIT:1> } ) , <EOL> DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:y>' : <NUM_LIT:2> } ) ] , index = list ( "<STR_LIT>" ) ) <EOL> new_np_simple = self . get ( msa , ( np . arange ( <NUM_LIT:0> ) , np . arange ( <NUM_LIT:0> ) ) ) <EOL> new_list_simple = self . get ( msa , ( [ ] , [ ] ) ) <EOL> self . assertEqual ( TabularMSA ( [ ] ) , new_np_simple ) <EOL> self . assertEqual ( TabularMSA ( [ ] ) , new_list_simple ) <EOL> def test_fancy_standard_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , [ <NUM_LIT:0> , <NUM_LIT:2> ] ) , <EOL> TabularMSA ( [ a , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:2> ] ) ) <EOL> def test_fancy_standard_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( Ellipsis , [ <NUM_LIT:0> , <NUM_LIT:2> ] ) ) , <EOL> TabularMSA ( [ a [ <NUM_LIT:0> , <NUM_LIT:2> ] , b [ <NUM_LIT:0> , <NUM_LIT:2> ] , c [ <NUM_LIT:0> , <NUM_LIT:2> ] ] , <EOL> metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:3> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_fancy_standard_both_axes ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( [ <NUM_LIT:0> , <NUM_LIT:2> ] , [ <NUM_LIT:0> , <NUM_LIT:2> ] ) ) , <EOL> TabularMSA ( [ a [ <NUM_LIT:0> , <NUM_LIT:2> ] , c [ <NUM_LIT:0> , <NUM_LIT:2> ] ] , <EOL> metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:3> ] } , <EOL> index = [ <NUM_LIT:0> , <NUM_LIT:2> ] ) ) <EOL> def test_fancy_empty_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , [ ] ) , <EOL> TabularMSA ( [ ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } ) ) <EOL> def test_fancy_empty_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( Ellipsis , [ ] ) ) , <EOL> TabularMSA ( [ a [ <NUM_LIT:0> : <NUM_LIT:0> ] , b [ <NUM_LIT:0> : <NUM_LIT:0> ] , c [ <NUM_LIT:0> : <NUM_LIT:0> ] ] , <EOL> metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : np . array ( <EOL> [ ] , dtype = int ) } ) ) <EOL> def test_fancy_empty_both_axes ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( [ ] , [ ] ) ) , <EOL> TabularMSA ( [ ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } ) ) <EOL> def test_fancy_out_of_bounds_first_axis ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ <NUM_LIT:10> ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ] ) <EOL> def test_fancy_out_of_bounds_second_axis ( self ) : <EOL> msa = TabularMSA ( [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , [ <NUM_LIT:10> ] ) ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ] ) ) <EOL> def test_get_scalar_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , positional_metadata = { '<STR_LIT:y>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b ] ) <EOL> new0 = self . get ( msa , <NUM_LIT:0> ) <EOL> new1 = self . get ( msa , <NUM_LIT:1> ) <EOL> self . assertEqual ( new0 , a ) <EOL> self . assertEqual ( new1 , b ) <EOL> def test_get_scalar_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , positional_metadata = { '<STR_LIT:y>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b ] , positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> new0 = self . get ( msa , ( Ellipsis , <NUM_LIT:0> ) ) <EOL> new1 = self . get ( msa , ( Ellipsis , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( new0 , <EOL> Sequence ( "<STR_LIT>" , metadata = { '<STR_LIT:z>' : <NUM_LIT:5> } , <EOL> positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:1> , np . nan ] , <EOL> '<STR_LIT:y>' : [ np . nan , <NUM_LIT:3> ] } ) ) <EOL> self . assertEqual ( new1 , <EOL> Sequence ( "<STR_LIT>" , metadata = { '<STR_LIT:z>' : <NUM_LIT:6> } , <EOL> positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:2> , np . nan ] , <EOL> '<STR_LIT:y>' : [ np . nan , <NUM_LIT:4> ] } ) ) <EOL> def test_scalar_sliced_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( <NUM_LIT:1> , [ <NUM_LIT:1> , <NUM_LIT:3> ] ) ) , <EOL> DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , <EOL> positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:2> , <NUM_LIT:4> ] } ) ) <EOL> def test_scalar_sliced_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:0> : <NUM_LIT:0> } , positional_metadata = { <NUM_LIT:0> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:1> : <NUM_LIT:1> } , positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> c = DNA ( "<STR_LIT>" , metadata = { <NUM_LIT:2> : <NUM_LIT:2> } , positional_metadata = { <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b , c ] , metadata = { <NUM_LIT:3> : <NUM_LIT:3> } , <EOL> positional_metadata = { <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . assertEqual ( self . get ( msa , ( [ <NUM_LIT:1> , <NUM_LIT:2> ] , <NUM_LIT:3> ) ) , <EOL> Sequence ( "<STR_LIT>" , metadata = { <NUM_LIT:3> : <NUM_LIT:4> } , <EOL> positional_metadata = { <NUM_LIT:1> : [ <NUM_LIT:4> , np . nan ] , <EOL> <NUM_LIT:2> : [ np . nan , <NUM_LIT:4> ] } ) ) <EOL> def test_get_scalar_out_of_bound_first_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , positional_metadata = { '<STR_LIT:y>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b ] , positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , <NUM_LIT:3> ) <EOL> def test_get_scalar_out_of_bound_second_axis ( self ) : <EOL> a = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:a>' : '<STR_LIT:foo>' } , positional_metadata = { '<STR_LIT:x>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> b = DNA ( "<STR_LIT>" , metadata = { '<STR_LIT:b>' : '<STR_LIT:bar>' } , positional_metadata = { '<STR_LIT:y>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> msa = TabularMSA ( [ a , b ] , positional_metadata = { '<STR_LIT:z>' : [ <NUM_LIT:5> , <NUM_LIT:6> ] } ) <EOL> with self . assertRaises ( IndexError ) : <EOL> self . get ( msa , ( Ellipsis , <NUM_LIT:3> ) ) <EOL> class TestGetItem ( SharedIndexTests , unittest . TestCase ) : <EOL> def get ( self , obj , indexable ) : <EOL> return obj [ indexable ] <EOL> def test_uses_iloc_not_loc ( self ) : <EOL> a = DNA ( "<STR_LIT>" ) <EOL> b = DNA ( "<STR_LIT>" ) <EOL> msa = TabularMSA ( [ a , b ] , index = [ <NUM_LIT:1> , <NUM_LIT:0> ] ) <EOL> self . assertIs ( msa [ <NUM_LIT:0> ] , a ) <EOL> self . assertIs ( msa [ <NUM_LIT:1> ] , b ) <EOL> class TestConstructor ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . seqs = [ DNA ( "<STR_LIT>" ) , DNA ( "<STR_LIT>" ) ] <EOL> self . m = { '<STR_LIT:x>' : '<STR_LIT:y>' , <NUM_LIT:0> : <NUM_LIT:1> } <EOL> self . pm = pd . DataFrame ( { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> self . index = pd . Index ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> self . msa = TabularMSA ( self . seqs , metadata = self . m , <EOL> positional_metadata = self . pm , index = self . index ) <EOL> def test_no_override ( self ) : <EOL> result = self . msa . _constructor_ ( ) <EOL> self . assertEqual ( self . msa , result ) <EOL> for seq1 , seq2 in zip ( result , self . msa ) : <EOL> self . assertIsNot ( seq1 , seq2 ) <EOL> self . assertIsNot ( result . metadata , self . msa . metadata ) <EOL> self . assertIsNot ( result . positional_metadata , <EOL> self . msa . positional_metadata ) <EOL> def test_sequence_override_same_seqs ( self ) : <EOL> result = self . msa . _constructor_ ( sequences = self . seqs ) <EOL> self . assertEqual ( self . msa , result ) <EOL> for seq1 , seq2 in zip ( result , self . msa ) : <EOL> self . assertIsNot ( seq1 , seq2 ) <EOL> self . assertIsNot ( result . metadata , self . msa . metadata ) <EOL> self . assertIsNot ( result . positional_metadata , <EOL> self . msa . positional_metadata ) <EOL> def test_sequence_override ( self ) : <EOL> seqs = [ RNA ( "<STR_LIT>" ) , RNA ( "<STR_LIT>" ) ] <EOL> result = self . msa . _constructor_ ( sequences = seqs ) <EOL> self . assertNotEqual ( result , self . msa ) <EOL> self . assertEqual ( list ( result ) , seqs ) <EOL> assert_index_equal ( result . index , self . index ) <EOL> self . assertEqual ( result . metadata , self . m ) <EOL> assert_data_frame_almost_equal ( result . positional_metadata , self . pm ) <EOL> def test_no_override_no_md ( self ) : <EOL> msa = TabularMSA ( self . seqs , index = self . index ) <EOL> self . assertEqual ( msa , msa . _constructor_ ( ) ) <EOL> def test_metadata_override ( self ) : <EOL> new_md = { '<STR_LIT:foo>' : { '<STR_LIT:x>' : <NUM_LIT:0> } } <EOL> result = self . msa . _constructor_ ( metadata = new_md ) <EOL> self . assertNotEqual ( result , self . msa ) <EOL> self . assertEqual ( list ( result ) , self . seqs ) <EOL> assert_index_equal ( result . index , self . index ) <EOL> self . assertEqual ( result . metadata , new_md ) <EOL> assert_data_frame_almost_equal ( result . positional_metadata , self . pm ) <EOL> def test_positional_metadata_override ( self ) : <EOL> new_pm = pd . DataFrame ( { '<STR_LIT:x>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> result = self . msa . _constructor_ ( positional_metadata = new_pm ) <EOL> self . assertNotEqual ( result , self . msa ) <EOL> self . assertEqual ( list ( result ) , self . seqs ) <EOL> assert_index_equal ( result . index , self . index ) <EOL> self . assertEqual ( result . metadata , self . m ) <EOL> assert_data_frame_almost_equal ( result . positional_metadata , new_pm ) <EOL> def test_index_override ( self ) : <EOL> new_index = pd . Index ( [ ( '<STR_LIT:a>' , <NUM_LIT:0> ) , ( '<STR_LIT:b>' , <NUM_LIT:1> ) ] ) <EOL> result = self . msa . _constructor_ ( index = new_index ) <EOL> self . assertNotEqual ( result , self . msa ) <EOL> self . assertEqual ( list ( result ) , self . seqs ) <EOL> assert_index_equal ( result . index , new_index ) <EOL> self . assertEqual ( result . metadata , self . m ) <EOL> assert_data_frame_almost_equal ( result . positional_metadata , self . pm ) <EOL> class TestAppend ( unittest . TestCase ) : <EOL> def test_to_empty_msa ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_to_empty_with_minter ( self ) : <EOL> msa = TabularMSA ( [ ] , minter = str ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_to_empty_msa_with_index ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) , index = '<STR_LIT:a>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' ] ) ) <EOL> def test_to_empty_msa_invalid_dtype ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . append ( Sequence ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_to_empty_msa_invalid_minter ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> msa . append ( DNA ( '<STR_LIT>' ) , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_to_non_empty_msa_invalid_minter ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> msa . append ( DNA ( '<STR_LIT>' ) , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) ) <EOL> def test_wrong_dtype_rna ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . append ( RNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_wrong_dtype_float ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . append ( <NUM_LIT> ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_wrong_length ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( <EOL> ValueError , '<STR_LIT>' ) : <EOL> msa . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_with_minter_metadata_key ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) ] , <EOL> minter = '<STR_LIT:id>' ) <EOL> msa . append ( DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) ] , minter = '<STR_LIT:id>' ) ) <EOL> def test_with_minter_callable ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) ] , <EOL> minter = '<STR_LIT:id>' ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) , minter = str ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT>' ] ) ) <EOL> def test_with_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) , index = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:foo>' ] ) ) <EOL> def test_no_index_no_minter ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_no_index_no_minter_msa_has_non_default_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> msa . append ( DNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) <EOL> def test_with_index_type_change ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:.>' ) ] ) <EOL> msa . append ( DNA ( '<STR_LIT:C>' ) , index = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:.>' ) , DNA ( '<STR_LIT:C>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:foo>' ] ) ) <EOL> def test_with_index_and_minter ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> msa . append ( DNA ( '<STR_LIT>' ) , index = '<STR_LIT>' , minter = str ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_multiple_appends_to_empty_msa_with_default_labels ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . append ( RNA ( '<STR_LIT>' ) ) <EOL> msa . append ( RNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_multiple_appends_to_non_empty_msa_with_default_labels ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> msa . append ( RNA ( '<STR_LIT>' ) ) <EOL> msa . append ( RNA ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_with_multiindex_index ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) , index = ( '<STR_LIT:foo>' , <NUM_LIT> ) ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) ] ) ) <EOL> def test_with_multiindex_minter ( self ) : <EOL> def multiindex_minter ( seq ) : <EOL> return ( '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . append ( DNA ( '<STR_LIT>' ) , minter = multiindex_minter ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) ] ) ) <EOL> class TestExtend ( unittest . TestCase ) : <EOL> def test_empty_to_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_empty_to_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_single_sequence ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_multiple_sequences ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_from_iterable ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( iter ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_from_tabular_msa_default_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_from_tabular_msa_non_default_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . extend ( TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) <EOL> def test_from_tabular_msa_with_index ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> msa1 . extend ( msa2 , index = msa2 . index ) <EOL> self . assertEqual ( <EOL> msa1 , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_minter_and_index ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ ] ) . extend ( [ DNA ( '<STR_LIT>' ) ] , minter = str , index = [ '<STR_LIT:foo>' ] ) <EOL> def test_no_minter_no_index_to_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_no_minter_no_index_to_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_no_minter_no_index_msa_has_non_default_labels ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:1> ] ) ) <EOL> def test_invalid_dtype ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . extend ( [ Sequence ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_invalid_minter ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:foo>' } ) , <EOL> DNA ( '<STR_LIT>' ) ] , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' ] ) ) <EOL> def test_mismatched_dtype ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_wrong_dtype_float ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , <NUM_LIT> ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_wrong_length ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( <EOL> ValueError , '<STR_LIT>' ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_sequences_index_length_mismatch ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( ValueError , <EOL> '<STR_LIT>' ) : <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ ] ) ) <EOL> def test_with_minter_metadata_key ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) ] , <EOL> minter = '<STR_LIT:id>' ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:d>' } ) ] , minter = '<STR_LIT:id>' ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:d>' } ) ] , minter = '<STR_LIT:id>' ) ) <EOL> def test_with_minter_callable ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT:C>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) ] , <EOL> minter = '<STR_LIT:id>' ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:T>' ) ] , minter = str ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT:A>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT:C>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT:T>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT>' , '<STR_LIT:T>' ] ) ) <EOL> def test_with_index ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:..>' ) ] , index = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:..>' ) ] , <EOL> index = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> def test_with_index_type_change ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:.>' ) ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT:C>' ) ] , index = [ '<STR_LIT:foo>' ] ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , DNA ( '<STR_LIT:.>' ) , DNA ( '<STR_LIT:C>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:foo>' ] ) ) <EOL> def test_multiple_extends_to_empty_msa_with_default_labels ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ RNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( msa , TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_multiple_extends_to_non_empty_msa_with_default_labels ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ RNA ( '<STR_LIT>' ) , RNA ( '<STR_LIT>' ) ] ) <EOL> msa . extend ( [ RNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_with_multiindex_index ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_with_multiindex_minter ( self ) : <EOL> def multiindex_minter ( seq ) : <EOL> if str ( seq ) == '<STR_LIT>' : <EOL> return ( '<STR_LIT:foo>' , <NUM_LIT> ) <EOL> else : <EOL> return ( '<STR_LIT:bar>' , <NUM_LIT> ) <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , minter = multiindex_minter ) <EOL> self . assertIsInstance ( msa . index , pd . MultiIndex ) <EOL> assert_index_equal ( msa . index , pd . Index ( [ ( '<STR_LIT:foo>' , <NUM_LIT> ) , ( '<STR_LIT:bar>' , <NUM_LIT> ) ] ) ) <EOL> def test_with_index_object ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , <EOL> index = pd . Index ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) ) <EOL> def test_extending_on_empty_with_positional_metadata ( self ) : <EOL> msa = TabularMSA ( [ ] , positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> msa . extend ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( <EOL> msa , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) ) <EOL> class TestJoin ( unittest . TestCase ) : <EOL> def test_invalid_how ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ ] ) . join ( TabularMSA ( [ ] ) , how = '<STR_LIT>' ) <EOL> def test_invalid_other_type ( self ) : <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ ] ) . join ( DNA ( '<STR_LIT>' ) ) <EOL> def test_dtype_mismatch ( self ) : <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) . join ( TabularMSA ( [ RNA ( '<STR_LIT>' ) ] ) ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) . join ( TabularMSA ( [ ] ) ) <EOL> with self . assertRaisesRegex ( TypeError , '<STR_LIT>' ) : <EOL> TabularMSA ( [ ] ) . join ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_duplicate_index_labels ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , <EOL> "<STR_LIT>" ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:0> ] ) . join ( <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:..>' ) ] ) ) <EOL> with self . assertRaisesRegex ( ValueError , <EOL> "<STR_LIT>" ) : <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) . join ( <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT:..>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:0> ] ) ) <EOL> def test_no_metadata ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_ignores_metadata ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:a>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:b>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:c>' } ) ] , <EOL> metadata = { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:d>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:e>' } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT:f>' } ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> metadata = { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) ) <EOL> def test_outer_join_on_per_sequence_positional_metadata ( self ) : <EOL> msa1 = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:1>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT:foo>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:2>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] , '<STR_LIT:foo>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' ] } ) ] ) <EOL> msa2 = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:3>' : [ <NUM_LIT:5> , <NUM_LIT:6> ] , '<STR_LIT:foo>' : [ '<STR_LIT:e>' , '<STR_LIT:f>' ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:4>' : [ <NUM_LIT:7> , <NUM_LIT:8> ] , '<STR_LIT:foo>' : [ '<STR_LIT:g>' , '<STR_LIT:h>' ] } ) ] ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' , <EOL> positional_metadata = { '<STR_LIT:1>' : [ <NUM_LIT:1> , <NUM_LIT:2> , np . nan , np . nan ] , <EOL> '<STR_LIT:3>' : [ np . nan , np . nan , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> '<STR_LIT:foo>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:e>' , '<STR_LIT:f>' ] } ) , <EOL> DNA ( '<STR_LIT>' , <EOL> positional_metadata = { '<STR_LIT:2>' : [ <NUM_LIT:3> , <NUM_LIT:4> , np . nan , np . nan ] , <EOL> '<STR_LIT:4>' : [ np . nan , np . nan , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> '<STR_LIT:foo>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:g>' , '<STR_LIT:h>' ] } ) ] ) ) <EOL> def test_no_sequences ( self ) : <EOL> msa1 = TabularMSA ( [ ] , positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> msa2 = TabularMSA ( [ ] , positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( joined , TabularMSA ( [ ] ) ) <EOL> def test_no_positions ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:1>' : [ ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:2>' : [ ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:3>' : [ ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:4>' : [ ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:1>' : [ ] , '<STR_LIT:3>' : [ ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:2>' : [ ] , '<STR_LIT:4>' : [ ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ ] } ) ) <EOL> def test_one_with_positions_one_without_positions ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT:A>' , positional_metadata = { '<STR_LIT:1>' : [ '<STR_LIT:a>' ] } ) , <EOL> DNA ( '<STR_LIT:C>' , positional_metadata = { '<STR_LIT:2>' : [ '<STR_LIT:b>' ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ '<STR_LIT:bar>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:3>' : [ ] } ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:4>' : [ ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ ] } ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT:A>' , positional_metadata = { '<STR_LIT:1>' : [ '<STR_LIT:a>' ] , <EOL> '<STR_LIT:3>' : [ np . nan ] } ) , <EOL> DNA ( '<STR_LIT:C>' , positional_metadata = { '<STR_LIT:2>' : [ '<STR_LIT:b>' ] , <EOL> '<STR_LIT:4>' : [ np . nan ] } ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ '<STR_LIT:bar>' ] } ) ) <EOL> def test_how_strict ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' ] } ) <EOL> joined = msa1 . join ( msa2 ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' ] } ) ) <EOL> def test_how_strict_failure_index_mismatch ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa1 . join ( msa2 ) <EOL> def test_how_strict_failure_positional_metadata_mismatch ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> with self . assertRaisesRegex ( ValueError , <EOL> '<STR_LIT>' ) : <EOL> msa1 . join ( msa2 ) <EOL> def test_how_inner ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT:..>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] } ) ) <EOL> def test_how_inner_no_positional_metadata_overlap ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:b>' , '<STR_LIT:a>' ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] , <EOL> positional_metadata = { '<STR_LIT:bar>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) ) <EOL> def test_how_inner_no_index_overlap_with_positional_metadata_overlap ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ '<STR_LIT:a>' , '<STR_LIT:b>' ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT>' ) <EOL> self . assertEqual ( joined , TabularMSA ( [ ] ) ) <EOL> def test_how_outer ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = range ( - <NUM_LIT:1> , <NUM_LIT:4> ) , <EOL> positional_metadata = { <EOL> '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , np . nan , np . nan , np . nan ] , <EOL> '<STR_LIT>' : [ np . nan , np . nan , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] } ) ) <EOL> def test_how_left ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT:left>' ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { <EOL> '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , np . nan , np . nan , np . nan ] } ) ) <EOL> def test_how_right ( self ) : <EOL> msa1 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] } ) <EOL> msa2 = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] } ) <EOL> joined = msa1 . join ( msa2 , how = '<STR_LIT:right>' ) <EOL> self . assertEqual ( <EOL> joined , <EOL> TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , index = [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ] , <EOL> positional_metadata = { <EOL> '<STR_LIT:foo>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> '<STR_LIT>' : [ np . nan , np . nan , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] } ) ) <EOL> class TestIterPositions ( unittest . TestCase ) : <EOL> def test_method_return_type ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> obs = msa . iter_positions ( ) <EOL> self . assertIsInstance ( obs , types . GeneratorType ) <EOL> def test_position_type ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> first_position = next ( msa . iter_positions ( ) ) <EOL> self . assertIs ( type ( first_position ) , Sequence ) <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> obs = list ( msa . iter_positions ( ) ) <EOL> self . assertEqual ( obs , [ ] ) <EOL> def test_no_sequences_reverse ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> obs = list ( msa . iter_positions ( reverse = True ) ) <EOL> self . assertEqual ( obs , [ ] ) <EOL> def test_no_positions ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> obs = list ( msa . iter_positions ( ) ) <EOL> self . assertEqual ( obs , [ ] ) <EOL> def test_no_positions_reverse ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> obs = list ( msa . iter_positions ( reverse = True ) ) <EOL> self . assertEqual ( obs , [ ] ) <EOL> def test_single_position ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) ] ) <EOL> obs = list ( msa . iter_positions ( ) ) <EOL> self . assertEqual ( obs , [ Sequence ( '<STR_LIT:A>' ) ] ) <EOL> def test_single_position_reverse ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT:T>' ) ] ) <EOL> obs = list ( msa . iter_positions ( reverse = True ) ) <EOL> self . assertEqual ( obs , [ Sequence ( '<STR_LIT>' ) ] ) <EOL> def test_multiple_positions ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> obs = list ( msa . iter_positions ( ) ) <EOL> self . assertEqual ( obs , <EOL> [ Sequence ( '<STR_LIT>' ) , Sequence ( '<STR_LIT>' ) , Sequence ( '<STR_LIT>' ) , <EOL> Sequence ( '<STR_LIT>' ) ] ) <EOL> def test_multiple_positions_reverse ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> obs = list ( msa . iter_positions ( reverse = True ) ) <EOL> self . assertEqual ( obs , <EOL> [ Sequence ( '<STR_LIT>' ) , Sequence ( '<STR_LIT>' ) ] ) <EOL> def test_with_positional_metadata ( self ) : <EOL> msa_positional_metadata = { '<STR_LIT>' : [ <NUM_LIT:0.5> , <NUM_LIT> ] , '<STR_LIT:foo>' : [ <NUM_LIT:9> , <NUM_LIT> ] } <EOL> seqs = [ <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> ] } ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:foo>' : [ - <NUM_LIT:1> , - <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ) ] <EOL> msa = TabularMSA ( seqs , positional_metadata = msa_positional_metadata ) <EOL> obs = list ( msa . iter_positions ( ) ) <EOL> self . assertEqual ( <EOL> obs , <EOL> [ Sequence ( '<STR_LIT>' , metadata = { '<STR_LIT>' : <NUM_LIT:0.5> , '<STR_LIT:foo>' : <NUM_LIT:9> } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , np . nan , - <NUM_LIT:1> ] , <EOL> '<STR_LIT:bar>' : [ np . nan , np . nan , '<STR_LIT>' ] } ) , <EOL> Sequence ( '<STR_LIT>' , metadata = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , np . nan , - <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ np . nan , np . nan , '<STR_LIT>' ] } ) ] ) <EOL> def test_with_positional_metadata_reverse ( self ) : <EOL> msa_positional_metadata = { '<STR_LIT>' : [ <NUM_LIT:0.5> , <NUM_LIT> ] , '<STR_LIT:foo>' : [ <NUM_LIT:9> , <NUM_LIT> ] } <EOL> seqs = [ <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> ] } ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:foo>' : [ - <NUM_LIT:1> , - <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ) ] <EOL> msa = TabularMSA ( seqs , positional_metadata = msa_positional_metadata ) <EOL> obs = list ( msa . iter_positions ( reverse = True ) ) <EOL> self . assertEqual ( <EOL> obs , <EOL> [ Sequence ( '<STR_LIT>' , metadata = { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT:foo>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , np . nan , - <NUM_LIT:2> ] , <EOL> '<STR_LIT:bar>' : [ np . nan , np . nan , '<STR_LIT>' ] } ) , <EOL> Sequence ( '<STR_LIT>' , metadata = { '<STR_LIT>' : <NUM_LIT:0.5> , '<STR_LIT:foo>' : <NUM_LIT:9> } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , np . nan , - <NUM_LIT:1> ] , <EOL> '<STR_LIT:bar>' : [ np . nan , np . nan , '<STR_LIT>' ] } ) ] ) <EOL> class TestConsensus ( unittest . TestCase ) : <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , Sequence ( '<STR_LIT>' ) ) <EOL> def test_no_positions ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , DNA ( '<STR_LIT>' ) ) <EOL> def test_single_sequence ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , DNA ( '<STR_LIT>' ) ) <EOL> def test_multiple_sequences ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , DNA ( '<STR_LIT>' ) ) <EOL> def test_ties ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertTrue ( cons in [ DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) , DNA ( '<STR_LIT>' ) ] ) <EOL> def test_ties_with_gaps ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:->' ) , <EOL> DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:T>' ) , <EOL> DNA ( '<STR_LIT:T>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertTrue ( cons in [ DNA ( '<STR_LIT:T>' ) , DNA ( '<STR_LIT:->' ) ] ) <EOL> def test_default_gap_char ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:.>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , DNA ( '<STR_LIT:->' ) ) <EOL> def test_different_dtype ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , RNA ( '<STR_LIT>' ) ) <EOL> def test_with_positional_metadata ( self ) : <EOL> seqs = [ <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT>' : range ( <NUM_LIT:0> , <NUM_LIT:3> ) } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT>' : range ( <NUM_LIT:3> , <NUM_LIT:6> ) } ) , <EOL> DNA ( '<STR_LIT>' , metadata = { '<STR_LIT:id>' : '<STR_LIT>' } , <EOL> positional_metadata = { '<STR_LIT>' : range ( <NUM_LIT:6> , <NUM_LIT:9> ) } ) <EOL> ] <EOL> msa = TabularMSA ( seqs , metadata = { '<STR_LIT>' : <NUM_LIT> } , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] } ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( <EOL> cons , <EOL> DNA ( '<STR_LIT>' , positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] } ) ) <EOL> def test_mixed_gap_characters_as_majority ( self ) : <EOL> seqs = [ <EOL> DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:->' ) , <EOL> DNA ( '<STR_LIT:->' ) <EOL> ] <EOL> msa = TabularMSA ( seqs ) <EOL> cons = msa . consensus ( ) <EOL> self . assertEqual ( cons , DNA ( '<STR_LIT:->' ) ) <EOL> class TestConservation ( unittest . TestCase ) : <EOL> def test_no_sequences ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> cons = msa . conservation ( ) <EOL> npt . assert_array_equal ( cons , np . array ( [ ] ) ) <EOL> def test_shannon_entropy_dna ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:A>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT:C>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] , <EOL> base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_shannon_entropy_rna ( self ) : <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT:A>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT:A>' ) , <EOL> RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT:C>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] , <EOL> base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ RNA ( '<STR_LIT>' ) , <EOL> RNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_shannon_entropy_protein ( self ) : <EOL> msa = TabularMSA ( [ Protein ( '<STR_LIT:A>' ) , <EOL> Protein ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:20> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ Protein ( '<STR_LIT:A>' ) , <EOL> Protein ( '<STR_LIT>' ) , <EOL> Protein ( '<STR_LIT:C>' ) , <EOL> Protein ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT> ] , <EOL> base = <NUM_LIT:20> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ Protein ( '<STR_LIT>' ) , <EOL> Protein ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:20> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:20> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:20> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ Protein ( '<STR_LIT>' ) , <EOL> Protein ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:20> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:20> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:20> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:20> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_degenerate_mode_nan ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT>' ) <EOL> expected = np . array ( [ np . nan , <EOL> np . nan , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_degenerate_mode_error ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' ) <EOL> def test_error_on_degenerate_w_nan_on_gap ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> def test_column_with_degen_and_gap ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:N>' ) , <EOL> DNA ( '<STR_LIT:->' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( actual , np . array ( [ np . nan ] ) ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT:ignore>' ) <EOL> npt . assert_array_equal ( actual , np . array ( [ np . nan ] ) ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( actual , np . array ( [ np . nan ] ) ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT:error>' ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' , <EOL> gap_mode = '<STR_LIT:error>' ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> degenerate_mode = '<STR_LIT:error>' , <EOL> gap_mode = '<STR_LIT:ignore>' ) <EOL> def test_gap_mode_nan ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> expected = np . array ( [ np . nan , <EOL> np . nan , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> np . nan ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_gap_mode_include ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:5> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:5> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:5> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:5> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_gap_mode_include_gaps_treated_as_single_char ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:->' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:5> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_gap_mode_ignore ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT:ignore>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> actual = msa . conservation ( metric = '<STR_LIT>' , <EOL> gap_mode = '<STR_LIT:ignore>' ) <EOL> expected = np . array ( [ <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:1.0> ] , base = <NUM_LIT:4> ) , <EOL> <NUM_LIT:1.> - scipy . stats . entropy ( [ <NUM_LIT:0.5> , <NUM_LIT:0.5> ] , base = <NUM_LIT:4> ) ] ) <EOL> npt . assert_array_equal ( actual , expected ) <EOL> def test_gap_mode_error ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> gap_mode = "<STR_LIT:error>" ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> gap_mode = "<STR_LIT:error>" ) <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> self . assertRaises ( ValueError , msa . conservation , <EOL> metric = '<STR_LIT>' , <EOL> gap_mode = "<STR_LIT:error>" ) <EOL> def test_bad_metric ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( metric = '<STR_LIT>' ) <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( metric = '<STR_LIT>' ) <EOL> def test_bad_gap_mode ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( gap_mode = '<STR_LIT>' ) <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( gap_mode = '<STR_LIT>' ) <EOL> def test_bad_degenerate_mode ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( degenerate_mode = '<STR_LIT>' ) <EOL> msa = TabularMSA ( [ ] ) <EOL> with self . assertRaisesRegex ( ValueError , '<STR_LIT>' ) : <EOL> msa . conservation ( degenerate_mode = '<STR_LIT>' ) <EOL> class TestGapFrequencies ( unittest . TestCase ) : <EOL> def test_default_behavior ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:2> ] ) , freqs ) <EOL> def test_invalid_axis_str ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> TabularMSA ( [ ] ) . gap_frequencies ( axis = '<STR_LIT:foo>' ) <EOL> def test_invalid_axis_int ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> TabularMSA ( [ ] ) . gap_frequencies ( axis = <NUM_LIT:2> ) <EOL> def test_position_axis_str_and_int_equivalent ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> str_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> int_freqs = msa . gap_frequencies ( axis = <NUM_LIT:1> ) <EOL> npt . assert_array_equal ( str_freqs , int_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ] ) , str_freqs ) <EOL> def test_sequence_axis_str_and_int_equivalent ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> str_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> int_freqs = msa . gap_frequencies ( axis = <NUM_LIT:0> ) <EOL> npt . assert_array_equal ( str_freqs , int_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ] ) , str_freqs ) <EOL> def test_correct_dtype_absolute_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , freqs ) <EOL> self . assertEqual ( int , freqs . dtype ) <EOL> def test_correct_dtype_relative_empty ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , freqs ) <EOL> self . assertEqual ( float , freqs . dtype ) <EOL> def test_correct_dtype_absolute_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> ] ) , freqs ) <EOL> self . assertEqual ( int , freqs . dtype ) <EOL> def test_correct_dtype_relative_non_empty ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] ) , freqs ) <EOL> self . assertEqual ( float , freqs . dtype ) <EOL> def test_no_sequences_absolute ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , pos_freqs ) <EOL> def test_no_sequences_relative ( self ) : <EOL> msa = TabularMSA ( [ ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , pos_freqs ) <EOL> def test_no_positions_absolute ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> ] ) , pos_freqs ) <EOL> def test_no_positions_relative ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ np . nan ] ) , pos_freqs ) <EOL> def test_single_sequence_absolute ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> ] ) , pos_freqs ) <EOL> def test_single_sequence_relative ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1.0> , <NUM_LIT:0.0> ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0.5> ] ) , pos_freqs ) <EOL> def test_single_position_absolute ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:T>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:0> ] ) , pos_freqs ) <EOL> def test_single_position_relative ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT:.>' ) , <EOL> DNA ( '<STR_LIT:T>' ) ] ) <EOL> seq_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> pos_freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0.5> ] ) , seq_freqs ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1.0> , <NUM_LIT:0.0> ] ) , pos_freqs ) <EOL> def test_position_axis_absolute ( self ) : <EOL> msa = TabularMSA ( [ <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:4> ] ) , freqs ) <EOL> def test_position_axis_relative ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0.0> , <NUM_LIT:0.5> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ] ) , freqs ) <EOL> def test_sequence_axis_absolute ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> ] ) , freqs ) <EOL> def test_sequence_axis_relative ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0.0> , <NUM_LIT:2> / <NUM_LIT:3> , <NUM_LIT:1> / <NUM_LIT:3> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ] ) , freqs ) <EOL> def test_relative_frequencies_precise ( self ) : <EOL> class CustomSequence ( GrammaredSequence ) : <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def gap_chars ( cls ) : <EOL> return set ( '<STR_LIT>' ) <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def default_gap_char ( cls ) : <EOL> return '<STR_LIT:0>' <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def definite_chars ( cls ) : <EOL> return set ( '<STR_LIT>' ) <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def degenerate_map ( cls ) : <EOL> return { } <EOL> msa = TabularMSA ( [ CustomSequence ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' , relative = True ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:1.0> ] ) , freqs ) <EOL> def test_custom_gap_characters ( self ) : <EOL> class CustomSequence ( GrammaredSequence ) : <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def gap_chars ( cls ) : <EOL> return set ( '<STR_LIT>' ) <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def default_gap_char ( cls ) : <EOL> return '<STR_LIT:#>' <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def definite_chars ( cls ) : <EOL> return set ( '<STR_LIT>' ) <EOL> @ classproperty <EOL> @ overrides ( GrammaredSequence ) <EOL> def degenerate_map ( cls ) : <EOL> return { '<STR_LIT:D>' : '<STR_LIT>' } <EOL> msa = TabularMSA ( [ CustomSequence ( '<STR_LIT>' ) , <EOL> CustomSequence ( '<STR_LIT>' ) , <EOL> CustomSequence ( '<STR_LIT>' ) , <EOL> CustomSequence ( '<STR_LIT>' ) , <EOL> CustomSequence ( '<STR_LIT>' ) ] ) <EOL> freqs = msa . gap_frequencies ( axis = '<STR_LIT>' ) <EOL> npt . assert_array_equal ( np . array ( [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:4> ] ) , freqs ) <EOL> class TestGetPosition ( unittest . TestCase ) : <EOL> def test_without_positional_metadata ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] ) <EOL> position = msa . _get_position_ ( <NUM_LIT:1> ) <EOL> self . assertEqual ( position , Sequence ( '<STR_LIT>' ) ) <EOL> def test_with_positional_metadata ( self ) : <EOL> msa = TabularMSA ( [ DNA ( '<STR_LIT>' ) , <EOL> DNA ( '<STR_LIT>' ) ] , <EOL> positional_metadata = { '<STR_LIT:foo>' : [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> '<STR_LIT:bar>' : [ '<STR_LIT:abc>' , '<STR_LIT>' , '<STR_LIT>' ] } ) <EOL> position = msa . _get_position_ ( <NUM_LIT:1> ) <EOL> self . assertEqual ( position , <EOL> Sequence ( '<STR_LIT>' , metadata = { '<STR_LIT:foo>' : <NUM_LIT> , '<STR_LIT:bar>' : '<STR_LIT>' } ) ) <EOL> class TestIsSequenceAxis ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . msa = TabularMSA ( [ ] ) <EOL> def test_invalid_str ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> self . msa . _is_sequence_axis ( '<STR_LIT:foo>' ) <EOL> def test_invalid_int ( self ) : <EOL> with self . assertRaisesRegex ( ValueError , "<STR_LIT>" ) : <EOL> self . msa . _is_sequence_axis ( <NUM_LIT:2> ) <EOL> def test_positive_str ( self ) : <EOL> self . assertTrue ( self . msa . _is_sequence_axis ( '<STR_LIT>' ) ) <EOL> def test_positive_int ( self ) : <EOL> self . assertTrue ( self . msa . _is_sequence_axis ( <NUM_LIT:0> ) ) <EOL> def test_negative_str ( self ) : <EOL> self . assertFalse ( self . msa . _is_sequence_axis ( '<STR_LIT>' ) ) <EOL> def test_negative_int ( self ) : <EOL> self . assertFalse ( self . msa . _is_sequence_axis ( <NUM_LIT:1> ) ) <EOL> class TestRepr ( unittest . TestCase ) : <EOL> def test_repr ( self ) : <EOL> self . assertEqual ( repr ( TabularMSA ( [ ] ) ) , str ( TabularMSA ( [ ] ) ) ) <EOL> self . assertEqual ( repr ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) , <EOL> str ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) ) <EOL> self . assertEqual ( repr ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) , <EOL> str ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) ) <EOL> self . assertEqual ( repr ( TabularMSA ( [ DNA ( '<STR_LIT>' * <NUM_LIT> ) for x in range ( <NUM_LIT:10> ) ] ) ) , <EOL> str ( TabularMSA ( [ DNA ( '<STR_LIT>' * <NUM_LIT> ) for x in range ( <NUM_LIT:10> ) ] ) ) ) <EOL> obs = repr ( TabularMSA ( [ ] ) ) <EOL> self . assertEqual ( obs . count ( '<STR_LIT:\n>' ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( obs . startswith ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> obs = repr ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertEqual ( obs . count ( '<STR_LIT:\n>' ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( obs . startswith ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> obs = repr ( TabularMSA ( [ DNA ( '<STR_LIT>' ) ] ) ) <EOL> self . assertEqual ( obs . count ( '<STR_LIT:\n>' ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( obs . startswith ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertTrue ( obs . endswith ( '<STR_LIT>' ) ) <EOL> obs = repr ( TabularMSA ( [ DNA ( '<STR_LIT:A>' * <NUM_LIT> ) for x in range ( <NUM_LIT:6> ) ] ) ) <EOL> self . assertEqual ( obs . count ( '<STR_LIT:\n>' ) , <NUM_LIT:10> ) <EOL> self . assertTrue ( obs . startswith ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertTrue ( obs . endswith ( '<STR_LIT>' ) ) <EOL> obs = repr ( TabularMSA ( [ DNA ( '<STR_LIT:A>' * <NUM_LIT> ) ] ) ) <EOL> self . assertEqual ( obs . count ( '<STR_LIT:\n>' ) , <NUM_LIT:6> ) <EOL> self . assertTrue ( obs . startswith ( '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertIn ( '<STR_LIT>' , obs ) <EOL> self . assertTrue ( obs . endswith ( '<STR_LIT>' + '<STR_LIT:A>' * <NUM_LIT> ) ) <EOL> class TabularMSAReprDoctests : <EOL> r"""<STR_LIT>""" <EOL> pass <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
