Skip to main content
`Ctrl`+`K`

# skbio.alignment.TabularMSA.sort

TabularMSA.sort(level=None, ascending=True)

  Sort sequences by index label in-place.

  Parameters:
    level int or object, optional

      Index level to sort on when index is a `pd.MultiIndex`. Does nothing otherwise.

    ascending: bool, optional

      If `False`, sort in descending (i.e., reverse) order.

  See also

  `index`
  `reassign_index`
  `pandas.Series.sort_index`

  Notes

  This is a passthrough to `pd.Series.sort_index` internally.

  Examples

  Create a `TabularMSA` object with sequence identifiers as index labels:

      >>> from skbio import DNA, TabularMSA
      >>> seqs = [DNA('ACG', metadata={'id': 'c'}),
      ...         DNA('AC-', metadata={'id': 'b'}),
      ...         DNA('AC-', metadata={'id': 'a'})]
      >>> msa = TabularMSA(seqs, minter='id')
      >>> msa
      TabularMSA[DNA]
      ---------------------
      Stats:
          sequence count: 3
          position count: 3
      ---------------------
      ACG
      AC-
      AC-
      >>> msa.index
      Index(['c', 'b', 'a'], dtype='object')

  Sort the sequences in alphabetical order by index label:

      >>> msa.sort()
      >>> msa
      TabularMSA[DNA]
      ---------------------
      Stats:
          sequence count: 3
          position count: 3
      ---------------------
      AC-
      AC-
      ACG
      >>> msa.index
      Index(['a', 'b', 'c'], dtype='object')

  Note that since the sort is in-place, the `TabularMSA` object is modified (a new object is not returned).