SymPy 1.1 has been released

Have you ever used sympy? AS the authors say: “SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python.”

You can install new release by simply:

pip install -U sympy

It is promised that it will be be soon available also via conda.

What is new (among others)?

1. Many improvements to code generation, including addition of
tensorflow (to lambdify), C++, llvm JIT, and Rust language support, as
well as the beginning of AST classes.

2. Several bug fixes for floating point numbers using higher than the
default precision.

3. Improvements to the group theory module.

4. Implementation of Singularity Functions to solve Beam Bending
problems.

5. Improvements to the mechanics module.

As the main author (Aaron Meurer ) say: “A total of 184 people contributed to this release. Of these, 143 people contributed to SymPy for the first time for this release. ” Maybe you will be next?

Multiple other projects also use SymPy; just to name some, there is Cadabra for (quantum) field theory system, LaTeX Expression project for typesetting of algebraic expressions and yt for analyzing and visualizing volumetric data.

 

Official page of sympy you can find here: http://www.sympy.org/en/index.html

It is also freely available at github: https://github.com/sympy/sympy.github.com

Exact information about the release/authors/deprecations/etc. can be found here: https://github.com/sympy/sympy/wiki/Release-Notes-for-1.1

 

Advertisements

Why use Jupyter Notebook for data analyses?

I think that everyone interested in data science and data analysis somewhere, somehow during their education or internet searches comes across Jupyter Notebook.  Jupyter notebook is an aplication that enables you to create (and share) document that contains code (in various programming languages), explanaitions (text) and visualizations. Jupyter Notebook is super useful when you want to show your workflow and prepare how-to for future analyses for yourself or your team.

I use Jupyter Notebook with Python3 but you can use it with various programming languages if you prefer to. Python has very broad offer of libraries for statistical analysis, data visualizations and machine learning.

With Jupyter Notebook you can show every step of data transformation showing, e.g. pandas’ DataFrames in really nice shape:

Screen Shot 2017-07-01 at 07.53.29

Moreover you can include plots with the code you used to create it so you can easily reproduce it for other data:

Screen Shot 2017-07-01 at 07.51.01

Just to mention, super useful thing in Jupyter Notebook is:

%matplotlib inline

that makes your plots appear as you execute a cell without calling

plt.show()

I hope you see what are indisputable perks of using Jupyter Notebook, I encourage you strongly to try it out.

If you’re into Jupyter Notebook, this year there is a conference in August in New York, called Jupytercon (https://conferences.oreilly.com/jupyter/jup-ny).

There are a lot of interesting projects around Jupyter Notebook, like JupyterHub (https://jupyterhub.readthedocs.io/en/latest/) that allows Jupyter server to be used by multiple users or nteract (https://nteract.io/) that transforms Jupyter Notebooks to desktop application so it’s even easier to use.

Seaborn library for pretty plots

Seaborn is visualization library based on matplotlib (and complementary to matplotlib, you should really understand matplotlib first). It basically makes your work easier and prettier. The library is not really complicated and broad but it makes some thing for you, things that you would have to do in matplotlib on your own.

Seaborn works very well with libraries used in Python for data analysis (pandas, numpy, scipy, statsmodels) and may be used easily in Jupyter notebook for plots imaging. The most frequently mentioned advantage of seaborn are built-in themes. Well… it helps people who don’t know how to combine different colors to make plots aesthetic. Second thing is that functions do really nice plots that try to show something useful even when called with a minimal set of arguments. However, as for matplotlib you have almost endless number of possibilities to adjust your plots.

Additional information about seaborn can be find here: https://seaborn.pydata.org/

Installation is pretty easy:

pip install seaborn

or

conda install seaborn

Additionall info about installation (including development version of seaborn) can be found here: http://seaborn.pydata.org/installing.html

They did really nice job also when comes to documentation and tutorials (e.g. https://seaborn.pydata.org/tutorial.html)

My favorite thing about seaborn? I would say seaborn.distplot function. I usually do two visualizations to look at data before working with it – scatter plot and distribution. Scatter plot is probably easy to obtain in any visualization lib you work with, as is with matplotlib. However to see distribution along with KDE plot, I recommend seaborn function displot.

Here are some examples: https://seaborn.pydata.org/generated/seaborn.distplot.html?highlight=distplot#seaborn.distplot

Basically, all you need to do to have your data in array, e.g. as pandas DataFrame column

import seaborn as sns
ax = sns.distplot(df['column name'])

To try with example data, you can try plotting normally distributed data:

import seaborn as sns, numpy as np
x = np.random.randn(100)
ax = sns.distplot(x)

 

DATA Science in business – perspective from first day employee

This is the one and only opportunity for me to write what was my thoughts about data science after first couple of days in a new office. I decided to start another job, first job in data analysis and first in software house – huge difference from the first day.

First of all I had no idea what anyone was talking about. All those abbreviations and  office slang is a bit overwhelming at first. But you get used to it and understand more and more every day. But after couple of days it is still not enough. But hey! During the first weeks you’re allowed to ask stupid questions, so use it.

Second of all, your chosen technology is not necessary used in the office. Even if you spoke about used technologies during interview and you were asked to implement your chosen technology to your new office, you will have to use also technologies they use. It is not at all a bad thing, it gives you opportunity to expand your knowledge and perspectives. It is easier to understand the data in a way they work with it and after you understand it you can go on with your technologies.

Third thing is the co-operation. You will not be with data alone, others need your results, they (engineers) change the way how data looks like, they want to learn how to do some analyses on their own – strong co-operation in data analysis is crucial.

Forth – you need to understand the goal of your existence in the company. You don’t analyse the data just to analyse it, there is company strategy in it, you have to keep it mind all the time.

Last, but not least, connected to all of the above, company lives its life and what you do today may not be so necessary tomorrow and sometimes you have to deal with unfinished projects. Just go with the flow (and company development).

Python for kids?

Python is a very friendly programming language to start for adults as a very first programming experience. However, can it be used in education of younger? Of course. But I would recommend it as a second step after understanding basic algorithms (e.g. with Scratch or ScratchJr). Python is great to start their programming journey for teens, those who know what sentence structure is and who can do some mathematics.

Why Python is good to start?

  • Comparing to other widely used programming languages, it has quite easy syntax. You can experience it from your first line of clean and working code, so it will encourage you to write more.
  • It is a high level programming language, so you really don’t need too much code to see the effect – also encouraging.
  • There are a lot of information on the Web about Python, how to start with Python, what to do in case of failure – it is very important to have support, feeling that you have someone to turn to for help anytime.
  • If you want to sell something to kids, it must feel interesting to them. Well… you can make simple games with Python (and it’s not very hard), you can quite easily prepare a website and, last but not least, coding on Raspberry Pi may also be an argument.

There are also a couple of books concerning Python for kids. Just to name some:

  1. Python For Kids For Dummies: Brendan Scott
  2. Python for Kids. A Playful Introduction to Programming by Jason R. Briggs
  3. Python Projects for Kids. Jessica Ingrassellino

How Python connects you with biological databases? #1 – Uniprot

In bioinfomatics, the possibility to automatically use information gathered in numerous biological databases is crucial. Some databases are really easy to use, wrappers are great, some have very basic wrappers and some has none. There is a great movement to provide easy access to all biological databases and tools but we have still a lot to do.

One of the first databases I came across during Python programming was Uniprot. Uniprot (http://www.uniprot.org/) is not so easy to use through their page if you don’t really know what are you looking for. It’s common thing for biological data – data is so diverse that it is impossible to avoid redundancy and complexity. However, after some time, it gets easier.

Let’s look on example page of human GAPDH protein (http://www.uniprot.org/uniprot/P04406). You can see that data is categorized and it really makes your life easier. You can look at this page e.g., as xml (so you can extract the part you’re interested in) or text (each line starts with two letter information what is in this line, so it can also be extracted with the use of, e.g. regular expressions). There are multiple different approaches proposed to extract information you need (you have to be careful as some of the solutions may work for Python2 or Python3 only):

  1. requests (example shown here: http://stackoverflow.com/questions/15514614/how-to-use-python-get-results-from-uniprot-automatically)
    import requests
    from StringIO import StringIO  # Python 2
    from io import StringIO  # Python 3
    
    params = {"query": "GO:0070337", "format": "fasta"}
    response = requests.get("http://www.uniprot.org/uniprot/", params)
    
    for record in SeqIO.parse(StringIO(r.text), "fasta"):
        # Do what you need here with your sequences.
  2. uniprot tools (I like this way, connecting it with regular expressions you can extract exact information you need; https://pypi.python.org/pypi/uniprot_tools/0.4.1)
    import uniprot as uni
    print uni.map('P31749', f='ACC', t='P_ENTREZGENEID') # map single id
    print uni.map(['P31749','Q16204'], f='ACC', t='P_ENTREZGENEID') # map list of ids
    print uni.retrieve('P31749')
    print uni.retrieve(['P31749','Q16204'])
  3. swissprot (example shown https://www.biostars.org/p/66904/)
    #!/usr/bin/env python
    """Fetch uniprot entries for given go terms"""
    import sys
    from Bio import SwissProt
    #load go terms
    gos = set(sys.argv[1:])
    sys.stderr.write("Looking for %s GO term(s): %s\n" % (len(gos)," ".join(gos)))
    #parse swisprot dump
    k = 0
    sys.stderr.write("Parsing...\n")
    for i,r in enumerate(SwissProt.parse(sys.stdin)):  
        sys.stderr.write(" %9i\r"%(i+1,))
        #parse cross_references
        for ex_db_data in r.cross_references:
            #print ex_db_data
            extdb,extid = ex_db_data[:2]
            if extdb=="GO" and extid in gos:
              k += 1
              sys.stdout.write( ">%s %s\n%s\n" % (r.accessions[0], extid, r.sequence) )
    sys.stderr.write("Reported %s entries\n" % k)  
  4. bioservices (https://pythonhosted.org/bioservices/references.html#bioservices.uniprot.UniProt) – this is interesting service to look at as they intend to include wrappers to all important biological databases
    from bioservices import UniProt
    u = UniProt(verbose=False)
    u.mapping("ACC", "KEGG_ID", query='P43403')
    defaultdict(<type 'list'>, {'P43403': ['hsa:7535']})
    res = u.search("P43403")
    
    # Returns sequence on the ZAP70_HUMAN accession Id
    sequence = u.search("ZAP70_HUMAN", columns="sequence")
  5. urllib

It is proposed on uniprot website, example:

import urllib,urllib2

url = 'http://www.uniprot.org/uploadlists/'

params = {
'from':'ACC',
'to':'P_REFSEQ_AC',
'format':'tab',
'query':'P13368 P20806 Q9UM73 P97793 Q17192'
}

data = urllib.urlencode(params)
request = urllib2.Request(url, data)
contact = "" # Please set your email address here to help us debug in case of problems.
request.add_header('User-Agent', 'Python %s' % contact)
response = urllib2.urlopen(request)
page = response.read(200000)

 

You check out some general info about providing access to biological databases and tools here:

https://pythonhosted.org/bioservices/

Python possibilities for RNA structure folding

There are quite a lot of different software available for biologists for prediction of RNA secondary or tertiary structure. Here, I won’t discuss different algorithmic approaches and when to use them but I will check which approaches are available easily for Python users to include in their software (of course in specific needs only one software would be suitable and different – e.g. shell – approach would be required to use it automatically). I also won’t discuss software for protein structure folding because it is a whole new subject.

  1. Vienna Package (http://www.tbi.univie.ac.at/RNA/#self_packages) – I guess that this is most popular package used in Python for RNA folding. Information from the site: “RNA secondary structure prediction through energy minimization is the most used function in the package. We provide three kinds of dynamic programming algorithms for structure prediction: the minimum free energy algorithm of (Zuker & Stiegler 1981) which yields a single optimal structure, the partition function algorithm of (McCaskill 1990) which calculates base pair probabilities in the thermodynamic ensemble, and the suboptimal folding algorithm of (Wuchty et.al 1999) which generates all suboptimal structures within a given energy range of the optimal energy. For secondary structure comparison, the package contains several measures of distance (dissimilarities) using either string alignment or tree-editing (Shapiro & Zhang 1990). Finally, we provide an algorithm to design sequences with a predefined structure (inverse folding).”
  2. Multifold (https://pypi.python.org/pypi/multifold) – According to the authors:”MultifFold is a Python based tool package for RNA footprinting data analysis.
    • It accepts RNA footprinting data generated from SHAPE-Seq, PARS and DMS-Seq technologies.
    • It can fold multiple secondary structures for each transcript based on user provideed constraints.
    • It could quantify the abundance of each structure centroid using the RNA footprinting data.
    • It provides a series of commands for users to customize every procedure.
    • It could handle RNA footprinting data generated from gene isoforms or overlapped transcripts.”
  3. Forgi (www.tbi.univie.ac.at/~pkerp/forgi) – it is not for folding exactly but for manipulating folded structures and for this usage it is an excellent tool
  4. Barnacle (https://sourceforge.net/projects/barnacle-rna/) – I think it’s not supported any more.
  5. Frnakenstein (http://www.stats.ox.ac.uk/research/genome/software/frnakenstein) – actually uses Vienna Package

There are also other tools written in Python but not implemented with Python interface. Just to name one:

  1. modeRNA (http://genesilico.pl/moderna/)

Also many short scripts are available at github and private websites but I would be careful with them:

  1. http://philipuren.com/python/RNAFolding.php
  2. https://github.com/xlr8runner/RNA-Folding
  3. https://github.com/cgoliver/Nussinov

If I left something out, please include it in the comment 🙂