Below you will find pages that utilize the taxonomy term “python”
Blog
Jupyter / Python Nedir, Nasıl Kurulur?
Jupyter çeşitli programlama dilleri için etkileşimli bir ortam sağlayan yazılımdır. Orijinal olarak IPython (interactive python) adıyla, Python programlama dili için geliştirildi ancak daha sonra kurucuları Jupyter projesini başlatıp IPython’ın birçok tarafını Jupyter’e kaydırdı. IPython, sadece Jupyter’in kerneli olarak devam ediyor.
Jupyter’in özellikleri;
Etkileşimli bir shell sunması, Komut İstemi/Terminal’den jupyter console komutu ile başlatılır ve orijinal Python shell’ine göre otomatik tamamlama gibi kullanıcı dostu özellikleri barındırır. Tarayıcı tabanlı defter (notebook) sunması, Komut İstemi/Terminal’den jupyter notebook komutu ile başlatılır, açılan tarayıcı penceresinden yeni defter oluşturularak çeşitli programlama dillerinde kodlar yazılabilir ve bu kodlar çalıştırılarak çıktıları (metin, grafik, vs) etkileşimli olarak direkt tarayıcıda görüntülenebilir.
Blog
Install Cairo Graphics and PyCairo on Ubuntu 14.04 / Linux Mint 17
Cairo is a 2D graphics library implemented as a library written in the C programming language but if you’d like to use Python programming language, you should also install Python bindings for Cairo.
This guide will go through installation of Cairo Graphics library version 1.14.2 (most recent) and py2cairo Python bindings version 1.10.1 (also most recent).
Install Cairo
It’s very easy with the following repository. Just add it, update your packages and install.
Blog
Install RDKit 2015-03 Build on Ubuntu 14.04 / Linux Mint 17
RDKit is an open source toolkit for cheminformatics. It has many functionalities to work with chemical files.
Follow the below guide to install RDKit 2015-03 build on an Ubuntu 14.04 / Linux Mint 17 computer. Since Ubuntu packages don’t have the latest RDKit for trusty, you have to build RDKit from its source.
Install Dependencies
1sudo apt-get install flex bison build-essential python-numpy cmake python-dev sqlite3 libsqlite3-dev libboost1.54-all-dev Download the Build
Blog
Simple Way of Python's subprocess.Popen with a Timeout Option
subprocess module in Python provides us a variety of methods to start a process from a Python script. We may use these methods to run an external commands / programs, collect their output and manage them. An example use of it might be as following:
1from subprocess import Popen, PIPE 2 3 4p = Popen(['ls', '-l'], stdout=PIPE, stderr=PIPE) 5stdout, stderr = p.communicate() 6print stdout, stderr These lines can be used to run ls -l command in Terminal and collect the output (standard output and standard error) in stdout and stderr variables using communicate method defined in the process.
Blog
ImportError: Reportlab Version 2.1+ is needed
Little bug in xhtml2pdf version 0.0.5. To fix:
$ sudo nano /usr/local/lib/python2.7/dist-packages/xhtml2pdf/util.py Change the following lines:
1if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"): 2 raise ImportError("Reportlab Version 2.1+ is needed!") 3 4REPORTLAB22 = (reportlab.Version[0] == "2" and reportlab.Version[2] >= "2") With these lines:
1if not (reportlab.Version[:3] >= "2.1"): 2 raise ImportError("Reportlab Version 2.1+ is needed!") 3 4REPORTLAB22 = (reportlab.Version[:3] >= "2.1")
Blog
Django Migrations Table Already Exists Fix
Fix this issue by faking the migrations:
python manage.py migrate –fake <appname> Taken from this SO answer
Blog
Mezzanine BS Banners Translation with django-modeltranslation
Mezzanine BS Banners is a nice app for implementing Bootstrap 3 banners/sliders to your Mezzanine projects. The Banners model in BS Banners app has a title and its stacked inline Slides model has title and content for translation.
After [installing and setting up Django/Mezzanine translations]({% post_url 2015-07-01-djangomezzanine-content-translation-for-mezzanine %}):
Create a translation.py inside your Mezzanine project or your custom theme/skin application and copy/paste following lines:
1from modeltranslation.translator import translator 2from mezzanine.core.translation import TranslatedSlugged, TranslatedRichText 3from mezzanine_bsbanners.
Blog
Django/Mezzanine Content Translation for Mezzanine Built-in Applications
As Mezzanine comes with additional Django applications such as pages, galleries and to translate their content, Mezzanine supports django-modeltranslation integration.
Install django-modeltranslation:
pip install django-modeltranslation Add following to the INSTALLED_APPS in settings.py:
1"modeltranslation", And following in settings.py:
1USE_MODELTRANSLATION = True Also, move mezzanine.pages to the top of other Mezzanine apps in INSTALLED_APPS in settings.py like so:
1"mezzanine.pages", 2"mezzanine.boot", 3"mezzanine.conf", 4"mezzanine.core", 5"mezzanine.generic", 6"mezzanine.blog", 7"mezzanine.forms", 8"mezzanine.galleries", 9"mezzanine.twitter", 10"mezzanine.accounts", 11"mezzanine.mobile", Run following to create fields in database tables for translations:
Blog
Setting Up Templates and Python Scripts for Translation
Templates need following template tag:
1{% raw %}{% load i18n %}{% endraw %} Then, wrapping any text with
1{% raw %}{% trans "TEXT" %}{% endraw %} will make it translatable via Rosetta Django application
In Python scripts, you need to import following library:
from django.utils.translation import ugettext_lazy as _ Then wrapping any text with
1_('TEXT') will make it translatable.
Blog
Django Rosetta Translations for Django Applications
Make a directory called locale/ under the application directory:
cd app_name mkdir locale Add the folder in LOCAL_PATHS dictionary in settings.py:
1LOCALE_PATHS = ( 2 os.path.join(PROJECT_ROOT, 'app_name', 'locale/'), 3) Run the following command to create PO translation file for the application:
python ../manage.py makemessages -l tr -e html,py,txt python ../manage.py compilemessages Option -l is for language, it should match your definition in settings.py:
1LANGUAGES = ( 2 ('en' _('English')), 3 ('tr' _('Turkish')), 4 ('it' _('Italian')), 5) Repeat the last step for all languages and the go to Rosetta URL to translate.
Blog
Django Rosetta Installation
Install SciPy:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose Install pymongo and nltk:
sudo pip install pymongo sudo pip install nltk Install Python MySQLdb:
sudo apt-get install python-mysqldb Install Rosetta:
sudo pip install django-rosetta Add following into INSTALLED_APPS in settings.py:
1"rosetta", Add following into urls.py:
url(r’^translations/’, include(‘rosetta.urls’)), To also allow language prefixes , change patters to i18n_patterns in urls.py:
1urlpatterns += i18n_patterns( 2 ... 3)
Blog
Errno 13 Permission denied Django File Uploads
Run following command to give www-data permissions to static folder and all its content:
cd path/to/your/django/project sudo chown -R www-data:www-data static/ Do this in your production server
Blog
Configuring Mezzanine for Apache server & mod_wsgi in AWS
Install [Mezzanine]({% post_url 2015-05-01-how-to-install-mezzanine-on-ubuntulinux-mint %}), [Apache server]({% post_url 2015-05-08-getting-started-with-your-aws-instance-and %}) and mod_wsgi:
sudo apt-get install libapache2-mod-wsgi sudo a2enmod wsgi Set up a MySQL database for your Mezzanine project
Read [my post on how to set up a MySQL database for a Mezzanine project]({% post_url 2015-05-09-how-to-set-up-a-mysql-database-for-a-mezzanine %})
Collect static files:
python manage.py collectstatic Configure your Apache server configuration for the project like following:
WSGIPythonPath /home/ubuntu/www/mezzanine-project <VirtualHost *:80> #ServerName example.com ServerAdmin admin@example.com DocumentRoot /home/ubuntu/www/mezzanine-project WSGIScriptAlias / /home/ubuntu/www/mezzanine-project/wsgi.
Blog
How to Set Up a MySQL Database for a Mezzanine Project
Install MySQL server and python-mysqldb package:
sudo apt-get install mysql-server sudo apt-get install python-mysqldb Run MySQL:
mysql -u root -p Create a database:
mysql> create database mezzanine_project; Confirm it:
mysql> show databases; Exit:
mysql> exit Configure local_settings.py:
cd path/to/your/mezzanine/projectnano local_settings.py Like following:
1DATABASES = { 2 "default": { 3 "ENGINE": "django.db.backends.mysql", 4 "NAME": "mezzanine_project", 5 "USER": "root", 6 "PASSWORD": "123456", 7 "HOST": "", 8 "PORT": "", 9 } 10 } Note: Replace your password
Blog
How to Install Mezzanine on Ubuntu/Linux Mint [Complete Guide]
Mezzanine is a CMS application built on Django web framework. The installation steps are easy but your environment may not just suitable enough for it work without a problem. So, here I’m going to describe complete installation from scratch on a virtual environment.
First of all, install virtualenv:
$ sudo apt-get install python-virtualenv Then, create a virtual environment:
$ virtualenv testenv And, activate it: $ cd testenv $ source bin/activate
Blog
Finding k-cores and Clustering Coefficient Computation with NetworkX
Assume you have a large network and you want to find k-cores of each node and also you want to compute clustering coefficient for each one. Python package NetworkX comes with very nice methods for you to easily do these.
k-core is a maximal subgraph whose nodes are at least k degree [1]. To find k-cores:
Add all edges you have in your network in a NetworkX graph, and use core_number method that gets graph as the single input and returns node – k-core pairs.
Blog
Searching Open Reading Frames (ORF) in DNA sequences - ORF Finder
Open reading frames (ORF) are regions on DNA which are translated into protein. They are in between start and stop codons and they are usually long.
The Python script below searches for ORFs in six frames and returns the longest one. It doesn’t consider start codon as a delimiter and only splits the sequence by stop codons. So the ORF can start with any codon but ends with a stop codon (TAG, TGA, TAA).
Blog
Python: Get Longest String in a List
Here is a quick Python trick you might use in your code.
Assume you have a list of strings and you want to get the longest one in the most efficient way.
1>>>l=["aaa", "bb", "c"] 2>>>longest_string = max(l, key = len) 3>>>longest_string 4'aaa'
Blog
Python: defaultdict(list) Dictionary of Lists
Most of the time, when you need to work on large data, you’ll have to use some dictionaries in Python. Dictionaries of lists are very useful to store large data in very organized way. You can always initiate them by initiating empty lists inside an empty dictionary but when you don’t know how many of them you’ll end up with and if you want an easier option, use defaultdict(list). You just need to import it, first:
Blog
Python: extend() Append Elements of a List to a List
When you append a list to a list by using append() method, you’ll see your list is going to be appended as a list:
1>>>l=["a"] 2>>>l2=["a", "b"] 3>>>l.append(l2) 4>>>l 5['a', ['a', 'b']] If you want to append elements of the list directly without creating nested lists, use extend() method:
1>>>l=["a"] 2>>>l2=["a", "b"] 3>>>l.extend(l2) 4>>>l 5['a', 'a', 'b']
Blog
Salmonella Data Preprocessing for PCSF Algorithm
This post describes data preprocessing in Salmonella project for Prize-Collecting Steiner Forest Problem (PCSF) algorithm.
Salmonella data taken from Table S6 in Phosphoproteomic Analysis of Salmonella-Infected Cells Identifies Key Kinase Regulators and SopB-Dependent Host Phosphorylation Events by Rogers, LD et al. has been converted to tab delimited TXT file from its original XLS file for easy reading in Python.
The data should be separated into time points files (2, 5, 10 and 20 minutes) each of which will contain corresponding phophoproteins and their fold changes.
Blog
How to Install openpyxl on Windows
openpyxl is a Python library to read/write Excel 2007 xlsx/xlsm files. To download and install on Windows:
Download it from Python Packages
Then to install, extract the tar ball you downloaded, open up CMD, navigate to the folder that you extracted and run the following:
C:\Users\Gungor>cd Downloads\openpyxl-2.1.2.tar\dist\openpyxl-2.1.2\openpyxl-2.1.2 C:\Users\Gungor\Downloads\openpyxl-2.1.2.tar\dist\openpyxl-2.1.2\openpyxl-2.1.2>python setup.py install It’s going to install everything and will report any error. If there is nothing that seems like an error. You’re good to go.
Blog
How to Install Numpy Python Package on Windows
Numpy (Numerical Python) is a great Python package that you should definitely make use of if you’re doing scientific computing
Installing it on Windows might be difficult if you don’t know how to do it via command line. There are unofficial Windows binaries for Numpy for Windows 32 and 64 bit which make it super easy to install.
Go to the link below and download the one for your system and Python version:http://www.
Blog
JointSNVMix Installation on Linux Mint 16 Cython, Pysam Included
JointSNVMix is a software package that consists of a number of tools for calling somatic mutations in tumour/normal paired NGS data.
It requires Python (>= 2.7), Cython (>= 0.13) and Pysam (== 0.5.0).
Python must be installed by default ona Linux machine so I will describe the installation of others and JointSNVMix.
Note this guide may become outdated after some time so please make sure before following all.
Install Cython
Blog
Set Up Google Cloud SDK on Windows using Cygwin
Windows isn’t the best environment for software development I believe but if you have to use it there are nice softwares to make it easy for you. Cygwin here will help us to use Google Cloud tools but installation requires certain things that you should be aware of beforehand.
You’ll need
Python latest 2.7.x Google Cloud SDK Cygwin 32-bit (i.e. setup-x86.exe - note only this one works) openssh, curl and latest 2.
Blog
Some String Functions in R, String Manipulation in R
I have programmed with Perl, Python, and PHP before, and string manipulation was more direct and easier in them than in R. But still there are useful functions for string manipulation in R. I’m not an expert in R but I’ve been dealing with it for a while and I’ve learned some good functions for this purpose.
Concatenate strings
Concatenation is done with paste function. It gets concatenated strings as arguments separated bu comma and also separator character(s).
Blog
First Impressions and Thoughts on Rosalind Project
Actually, I signed up Rosalind.info 8 months ago, I didn’t really play around with it. But last week, in a BiGCaT science cafe, after I learnt it, I was more interested than before and I just started solving problems.
In each problem, you have a description about the context and also about the problem. Also, there is a sample input and output. Sometimes there are hints about the solution. What I did was to write a solution that works for the sample and hopefully for the problem.