<html><head></head><body><div class="yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:10px;"><div dir="ltr" data-setdir="false">Dear all,</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Currently there are four classes in Biopython that model an array where the letters can be used as indices:<br></div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Bio.Align.substitution_matrices: <span>Array class </span><br></div><div dir="ltr" data-setdir="false"><span>Bio.Align.AlignInfo: <span>PSSM class</span><br></span></div><div dir="ltr" data-setdir="false"><span><span>Bio.Phylo.TreeConstruction: <span><span>_Matrix class</span></span><br></span></span></div><div dir="ltr" data-setdir="false"><span><span><span>Bio.motifs.matrix: <span><span><span><span>GenericPositionMatrix</span></span></span></span><br></span></span></span></div><div dir="ltr" data-setdir="false"><span><span><span><br></span></span></span></div><div dir="ltr" data-setdir="false"><span><span><span>(and the FreqTable class in </span></span></span>Bio.SubsMat.FreqTable is similar).<br></div><div dir="ltr" data-setdir="false"><span><span></span></span><div><br></div><span><span></span></span></div><div dir="ltr" data-setdir="false"><span><span><span>For example, the Array class in <span>Bio.Align.substitution_matrices allows you to do things like</span></span></span></span></div><div dir="ltr" data-setdir="false"><span><span><span><div dir="ltr" data-setdir="false"><div>>>> from Bio.Align.substitution_matrices import Array</div>>>> a = Array("ACGT", dims=2)<br><div dir="ltr" data-setdir="false"><div>>>> a<br>Array([[0., 0., 0., 0.],<br> [0., 0., 0., 0.],<br> [0., 0., 0., 0.],<br> [0., 0., 0., 0.]],<br> alphabet='ACGT')<br><br></div><div dir="ltr" data-setdir="false">>>> a['C','A'] = 6</div><div dir="ltr" data-setdir="false"><div dir="ltr" data-setdir="false">>>> a<br>Array([[0., 0., 0., 0.],<br> [6., 0., 0., 0.],<br> [0., 0., 0., 0.],<br> [0., 0., 0., 0.]],<br> alphabet='ACGT')<br><div dir="ltr" data-setdir="false">>>> sum(a['C'])<br>6.0<br>>>> a[3,'G'] = 1 <div dir="ltr" data-setdir="false">>>> a['A',:] = 4<br>>>> a<br>Array([[4., 4., 4., 4.],<br> [6., 0., 0., 0.],<br> [0., 0., 0., 0.],<br><div> [0., 0., 1., 0.]],</div><div> alphabet='ACGT')</div><div dir="ltr" data-setdir="false"><div>>>> sum(a[:, 'A'])<br>10.0</div><div dir="ltr" data-setdir="false">>>> <div dir="ltr" data-setdir="false"><div><span><span><span><span>>>> from numpy import sin</span></span></span></span></div><div><span><span><span><span></span></span></span></span>>>> sin(a)</div> <div>Array([[-0.7568025 , -0.7568025 , -0.7568025 , -0.7568025 ],<br> [-0.2794155 , 0. , 0. , 0. ],<br> [ 0. , 0. , 0. , 0. ],<br> [ 0. , 0. , 0.84147098, 0. ]],<br> alphabet='ACGT')<br><br></div><br></div><div><br></div></div></div><div dir="ltr" data-setdir="false">This class was implemented as a subclass of a numpy array. This has the big advantage that the array acts as a numpy array (e.g. you can apply numpy functions to it and get back an array of the same class, as in the example above), but unfortunately subclassing numpy arrays is not easy (see the code in Bio.Align.substitution_matrices).</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Would it then make sense to make this class available as a general-purpose array class where strings can be used as indices?</div><div dir="ltr" data-setdir="false">For example, inside a new Bio.math module.<br></div><div dir="ltr" data-setdir="false">Other modules in Biopython could then either make use of this class directly, or subclass it if needed.</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Thanks,</div><div dir="ltr" data-setdir="false">-Michiel<br></div></div></div></div></div></div></div></span></span></span><span><span><span></span></span></span></div><div dir="ltr" data-setdir="false"><br></div></div></body></html>