This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

pandas-charm is a small Python package for getting character matrices (alignments) into and out of pandas. Its purpose is to make pandas interoperable with other scientific packages that can be used for dealing with character matrices, like for example BioPython and Dendropy.

With pandas-charm, it is currently possible to convert between the following objects:

  • BioPython MultipleSeqAlignment <-> pandas DataFrame
  • DendroPy CharacterMatrix <-> pandas DataFrame

The code has been tested with Python 2.7, 3.3, 3.4 and 3.5.

Source repository: https://github.com/jmenglund/pandas-charm


Installation

For most users, the easiest way is probably to install the latest version hosted on PyPI:

$ pip install pandas-charm

The project is hosted at https://github.com/jmenglund/pandas-charm and can also be installed using git:

$ git clone https://github.com/jmenglund/pandas-charm.git
$ cd pandas-charm
$ python setup.py install

You may consider installing pandas-charm and its required Python packages within a virtual environment in order to avoid cluttering your system’s Python path. See for example the environment management system conda or the package virtualenv.

Running tests

Testing is carried out with pytest. Here is an example on how to run the test suite and generating a coverage report:

$ pip install pytest pytest-cov pytest-pep8 dendropy biopython
$ py.test -v --cov-report term-missing --cov pandascharm.py --pep8

Usage

Below are a few examples on how to use pandas-charm. The examples are written with Python 3 code, but pandas-charm should work also with Python 2.7. You need to install BioPython and/or DendroPy manually before you start:

$ pip install biopython
$ pip install dendropy

DendroPy CharacterMatrix to pandas DataFrame

>>> import pandas as pd
>>> import pandascharm as pc
>>> import dendropy
>>> dna_string = '3 5\nt1  TCCAA\nt2  TGCAA\nt3  TG-AA\n'
>>> print(dna_string)
3 5
t1  TCCAA
t2  TGCAA
t3  TG-AA

>>> matrix = dendropy.DnaCharacterMatrix.get_from_string(
...     dna_string, schema='phylip')
>>> df = pc.from_charmatrix(matrix)
>>> df
  t1 t2 t3
0  T  T  T
1  C  G  G
2  C  C  -
3  A  A  A
4  A  A  A

By default, characters are stored as rows and sequences as columns in the DataFrame. If you want rows to hold sequences, just transpose the matrix in pandas:

>>> df.transpose()
    0  1  2  3  4
t1  T  C  C  A  A
t2  T  G  C  A  A
t3  T  G  -  A  A

pandas DataFrame to Dendropy CharacterMatrix

>>> import pandas as pd
>>> import pandascharm as pc
>>> import dendropy
>>> df = pd.DataFrame({
...     't1': ['T', 'C', 'C', 'A', 'A'],
...     't2': ['T', 'G', 'C', 'A', 'A'],
...     't3': ['T', 'G', '-', 'A', 'A']})
>>> df
  t1 t2 t3
0  T  T  T
1  C  G  G
2  C  C  -
3  A  A  A
4  A  A  A

>>> matrix = pc.to_charmatrix(df, data_type='dna')
>>> print(matrix.as_string('phylip'))
3 5
t1  TCCAA
t2  TGCAA
t3  TG-AA

BioPython MultipleSeqAlignment to pandas DataFrame

>>> from io import StringIO
>>> import pandas as pd
>>> import pandascharm as pc
>>> from Bio import AlignIO
>>> dna_string = '3 5\nt1  TCCAA\nt2  TGCAA\nt3  TG-AA\n'
>>> f = StringIO(dna_string)  # make the string a file-like object
>>> alignment = AlignIO.read(f, 'phylip-relaxed')
>>> print(alignment)
SingleLetterAlphabet() alignment with 3 rows and 5 columns
TCCAA t1
TGCAA t2
TG-AA t3
>>> df = pc.from_bioalignment(alignment)
>>> df
  t1 t2 t3
0  T  T  T
1  C  G  G
2  C  C  -
3  A  A  A
4  A  A  A

pandas DataFrame to BioPython MultipleSeqAlignment

>>> import pandas as pd
>>> import pandascharm as pc
>>> import Bio
>>> df = pd.DataFrame({
...     't1': ['T', 'C', 'C', 'A', 'A'],
...     't2': ['T', 'G', 'C', 'A', 'A'],
...     't3': ['T', 'G', '-', 'A', 'A']})
>>> df
  t1 t2 t3
0  T  T  T
1  C  G  G
2  C  C  -
3  A  A  A
4  A  A  A

>>> alignment = pc.to_bioalignment(df, alphabet='generic_dna')
>>> print(alignment)
SingleLetterAlphabet() alignment with 3 rows and 5 columns
TCCAA t1
TGCAA t2
TG-AA t3

The name

pandas-charm got its name from the pandas library plus an acronym for CHARacter Matrix.

License

pandas-charm is distributed under the MIT license.

Citing

If you use results produced with this package in a scientific publication, please just mention the package name in the text and cite the Zenodo DOI of this project:

You can select a citation style from the dropdown menu in the “Cite as” section on the Zenodo page.

Release History

Release History

0.1.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pandas_charm-0.1.2-py2.py3-none-any.whl (8.2 kB) Copy SHA256 Checksum SHA256 any Wheel Aug 8, 2016
pandas-charm-0.1.2.tar.gz (6.8 kB) Copy SHA256 Checksum SHA256 Source Aug 8, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting