As far as I know, TargetP is still (17 years after its original publication!) the best software for predicting subcellular localization for plant proteins, and also the location of truncation sites.
Without any modifications, targetp works well with small (by modern standards) queries, of less than 2,000 sequences at a time. But becomes glitchy when running with larger queries, such as the 30k-100k genes that are typical from a plant transcriptome assembly.
To adapt TargetP for larger queries, I wrote a Python script that acts as a wrapper around TargetP, called targetp_all.py. The script works by separating the input into smaller subsets of sequences and running those, and combining the output.
Interface is the same as the original program but with a few additional options. The output is somewhat simplified to be in tab-separated format.
It would also be nice to be able to parallelize the execution of TargetP to run on multiple cores at once, but I haven't attempted this yet. I believe that there will be complications involving conflicting temporary files, that may require careful modification of the original source code.
Source code follows. BioPython is a dependency.
Showing posts with label python. Show all posts
Showing posts with label python. Show all posts
Thursday, August 17, 2017
targetP wrapper for large queries
Thursday, October 13, 2016
rendering zdock server results using python and UCSF Chimera
Problem:
I was interested in learning where the protein-protein interaction sites were on a particular protein (the receptor). I had pdb files for that protein, and for three proteins that it is known to bind to (the ligands). There are specific amino-acids of interest on the receptor protein, where there is variability among different species. For every combination of receptor and ligand, I want to perform a prediction of where the proteins interact, and then generate an image where the variable amino-acids are highlighted.
I was interested in learning where the protein-protein interaction sites were on a particular protein (the receptor). I had pdb files for that protein, and for three proteins that it is known to bind to (the ligands). There are specific amino-acids of interest on the receptor protein, where there is variability among different species. For every combination of receptor and ligand, I want to perform a prediction of where the proteins interact, and then generate an image where the variable amino-acids are highlighted.
Sunday, July 3, 2016
Random discrete distributions (decks) in game development
Randomness plays an important role in many games. Enemies appear randomly, or events occur at randomly spaced intervals. A relatively easy way to think of random events in a game is as a deck of note cards. The probability of a particular word being drawn is a function of the
number of cards in the deck with that word on them, and the total number of cards in the deck.
This approach is called a discrete distribution.
In the case of circle the aardvark, I used a discrete distribution to determine whether an aardvark or an enemy spawned, and how long each character should remain on the screen before timing out and going away.
The game is written in Monkey X, but the code in this post is in Python.
You can find the Monkey X version here.
Read on for details
This approach is called a discrete distribution.
In the case of circle the aardvark, I used a discrete distribution to determine whether an aardvark or an enemy spawned, and how long each character should remain on the screen before timing out and going away.
The game is written in Monkey X, but the code in this post is in Python.
You can find the Monkey X version here.
Read on for details
Thursday, December 10, 2015
Extracting gene ontology categories using python pandas and rdflib
I've got a table I exported from Blast2GO, which associates transcript IDs with GO term IDs (an "annot" file in Blast2GO terminology). I want to separate the GO IDs by category: biological_process, cellular_component, or molecular_function. (Note: in this example I use rdflib, a faster way to do the same thing would be to use the more specialized goatools, which is probably the best GO library for python. I used rdflib because I wanted practice SPARQL)
Monday, April 13, 2015
MGR CMS: a simple Django-based content management system for genomic data
MGR-CMS (Mint Genomics Resource) is a content management system for
genomic and transcriptomic data. The code for MGR-CMS can be found Here. As implied by the name, it was
originally built to house data for mint plants, but it can be easily
adapted for data from other organisms. I made MGR because I couldn't
figure out how to get Tripal to behave
how I wanted it to. I later found out that was my fault, not Tripal's
fault, so if you want a more or less feature complete genomics content
management system, look there. If you want a simple system written in
Python (Django), or you have the misfortune of having a Windows server
(as I do), then MGR might be just the thing for you (but it still might
be worth your while to shoot the Tripal people an e-mail, just to make
sure it really can't handle your situation).
Labels:
biology,
django,
programming,
python,
web design
Monday, April 6, 2015
evaluating boolean gene-reaction associations and assigning expression levels to reactions in stoichiometric models
Problem: You've got a stoichometric model, and an RNAseq dataset, and you want to use the transcriptome data to determine which reactions in the model are likely to be active, and at what level.
Solution: Use pandas to read the model and the RNAseq data. Use a pyparsing grammar to parse the boolean gene-reaction association expressions.Write a function calculate a reaction expression level based on the parsed gene-reaction association expression, and the RNAseq data. Write a new model file with a column for gene expression.
Read on for details....
Solution: Use pandas to read the model and the RNAseq data. Use a pyparsing grammar to parse the boolean gene-reaction association expressions.Write a function calculate a reaction expression level based on the parsed gene-reaction association expression, and the RNAseq data. Write a new model file with a column for gene expression.
Read on for details....
Monday, February 16, 2015
Comparing data from open natural products chemical spectral databases
I recently wrote a review article called "Open-access metabolomics databases for natural product research: present capabilities and future potential", for the journal Frontiers in Bioengineering and Biotechnology, section Bioinformatics and Computational Biology (link).
Part of the review involved evaluating the contents of In this post, this post consists of the notes I took when generating those comparisons. The code I used is available from my Bitbucket account (I apologize for the poor organization and near-lack of documentation), some of the scripts depend on srj_chembiolib, and/or Pandas. InChI normalization relies on ChemAxon molconvert.
Factors to compare: how many unique compounds are present in the database, how many structures have the various kinds of associated analytical spectra, what compound classes are represented.
Part of the review involved evaluating the contents of In this post, this post consists of the notes I took when generating those comparisons. The code I used is available from my Bitbucket account (I apologize for the poor organization and near-lack of documentation), some of the scripts depend on srj_chembiolib, and/or Pandas. InChI normalization relies on ChemAxon molconvert.
Factors to compare: how many unique compounds are present in the database, how many structures have the various kinds of associated analytical spectra, what compound classes are represented.
Labels:
biology,
chemistry,
lab notebook,
programming,
python
Wednesday, August 13, 2014
Chemspider python scripting
In the past, I've shown how to script Chemdraw and ChemAxon for the purposes of converting chemical information among different file formats. In this post I'll show how to achieve (vaguely) similar results using the ChemSpider web API. ChemSpider is nice because (unlike SciFinder) it is free, they don't mind if you reuse their data, and they don't mind if you access their website with scripts. Using ChemSpider has the advantage that it is a huge database and provides cross-references to other databases, it has images, mol files, and lots of other data about each compound.
Tuesday, July 29, 2014
Using SwissProt and ExPASy ENZYME to generate putative EC annotations for sequence data
There was a question on Biostars about how to make EC assignments based on sequence. I gave one of the answers, suggesting a few possible solutions. One of my solutions was to Blast against ExPASy ENZYME and base the annotations on the best hit from there. In this post I explain how to do that, and supply the necessary Python code.
[Note: PRIAM is another tool that assigns EC numbers to sequences based on the data in the ENZYME database. Instead of individual blast hits, it uses profiles built from multiple sequence alignments of peptides known to catalyze a given reaction. It's also a lot quicker to use than the method outlined here, so it's probably worth checking out first]
[Note: PRIAM is another tool that assigns EC numbers to sequences based on the data in the ENZYME database. Instead of individual blast hits, it uses profiles built from multiple sequence alignments of peptides known to catalyze a given reaction. It's also a lot quicker to use than the method outlined here, so it's probably worth checking out first]
Sunday, July 27, 2014
srj_chembiolib a set of scripts for doing Bioinformaticky type stuff
This post is to announce srj_chembiolib which in an uncreatively named set of scripts I've written to perform various bioinformatics (and hopefully eventually some cheminformatic) tasks that would otherwise be a pain in the rear to accomplish. Most of the scripts work both as libraries that can be imported into other scripts, and as stand alone command line scripts. Some depend on external libraries such as BioPython. Documentation is mostly found in block comments at the top of the script files. Where possible, for example with the scripts that manipulate fasta files, I've tried to make it so that multiple programs can be chained together with pipes on the command line to accomplish more complex tasks. I hope they're useful for someone.
Here's an overview of some (but not all!) of the scripts in the package:
blast_xml_to_outfmt6.py: Converts Blast+ xml output to '-outfmt 6' style output (a tab separated form). Allows for some additional features not available in the standard outfmt 6, such as printing a line for query sequences that had no hits.
subset_fasta.py: Give it a fasta file and a list of strings, and it will give you a fasta file containing only those sequences whose names contain something from the list of strings as a substring.
extract_massbank.py: A class to read and store data from MassBank format text files, such as those used by MassBank, ReSpect, and Spektraris (my favorite database...).
extract_top_blast_hits.py: Reads a blast xml file and outputs the names of the top hits for each query sequence. There's an option for making a file listing the sequences the queries where the top hit matched in the reverse direction, which is useful, for example with Blastx, to determine whether a nucleotide sequence represents the coding strand, or the non-coding strand.
Here's an overview of some (but not all!) of the scripts in the package:
blast_xml_to_outfmt6.py: Converts Blast+ xml output to '-outfmt 6' style output (a tab separated form). Allows for some additional features not available in the standard outfmt 6, such as printing a line for query sequences that had no hits.
subset_fasta.py: Give it a fasta file and a list of strings, and it will give you a fasta file containing only those sequences whose names contain something from the list of strings as a substring.
extract_massbank.py: A class to read and store data from MassBank format text files, such as those used by MassBank, ReSpect, and Spektraris (my favorite database...).
extract_top_blast_hits.py: Reads a blast xml file and outputs the names of the top hits for each query sequence. There's an option for making a file listing the sequences the queries where the top hit matched in the reverse direction, which is useful, for example with Blastx, to determine whether a nucleotide sequence represents the coding strand, or the non-coding strand.
Thursday, May 1, 2014
Checking md5 sums for lots of files from Windows
I run a lot of local BLAST searches on Windows machines. When you download a blast database from NCBI, you should also download the md5 file so you can check that the downloaded file is exactly the same as the one on the server (sometimes there can be fidelity issues when transferring data). Linux has a handy tool for comparing md5 sums, called md5sum. Example.
Monday, March 31, 2014
Python Numpy Munkres Hungarian matching algorithm
I didn't make this, but there is a numpy implementation of this algorithm available through scikit-learn in sklearn/utils/linear_assignment_.py . I'm glad I found it, as it seems to be about 4 times faster than the munkres package from PyPI (on which it is based, and which is the python implementation that comes up the most on google).
Reference:
http://stackoverflow.com/questions/1398822/the-assignment-problem-a-numpy-function
Reference:
http://stackoverflow.com/questions/1398822/the-assignment-problem-a-numpy-function
Tuesday, March 25, 2014
building a django app that uses ZeroMQ: an annotated webliography
Introduction:
I wanted to build a website that allows people to search their data against a database (in the not too distant future, when the website is live I'll link it and the source code and give more of an explanation. Edit: and here it is, the code, the ZeroMQ stuff is mostly at "/nmr/management/commands", and the website ). Each search takes a few seconds, so in order to be able to serve multiple clients at a time, and allow scaling, I wanted to build a system where the main wsgi process does not block, but passes the search request off to another process that puts it in a queue and executes requests in the queue one by one. I ended up following a simple approach using ZeroMQ. There is a scheduler that runs as a thread in the main wsgi process. When the search input view receives a search request, it writes the search parameters into the database and opens a connection to the scheduler thread and passes it the unique ID of the database record storing the search parameters. There are one or more worker processes each running as a subprocess. The workers are permanently attached via a socket to the scheduler. When a worker completes a job, the scheduler sends it the ID of the next job in the queue, the worker executes the job, writes the results in a database table, and tells the scheduler it is ready for another job. There can be many workers attached to the scheduler, so that multiple searches can be run concurrently.
Here then is a list of (some of) the websites I used for reference while writing this program.
Tuesday, March 18, 2014
ChemDraw ChemAxon synergy
In my previous post, I was complaining that there wasn't any free software with a nice command line interface to reliably convert molfiles to InChI strings, and back again. I also mentioned that there was an issue with the way ChemDraw converts structures to InChI strings that made it unacceptable for my purposes. The technical issue with ChemDraw is that it doesn't preserve the isoform of tautomers. Some of the molecules I'm interested in contain amides that are typically found in the amide form, rather than the imidic acid form. When I copy these molecules as InChI from ChemDraw, and then paste them back in, the amide is changed to the imidic acid form, which I don't want. It turns out that this is due to a feature of the InChI format (a format that is still mostly opaque to me) called "Mobile H Perception", where it simplifies a molecule encoding by not specifying the which tautomer it is (thereby saving 1 bit of information I guess). Many programs have the option to export InChI with Mobile H perception off, which is what I want, but I can't find that option in Chemdraw.
Automating Chemdraw: win32 com scripting with python pywin32
Once again I find myself adventuring in the land of Windows COM scripts. Last time I tried, with mixed success. This time, I'm using it to control ChemDraw to help me convert molecule formats. Anytime I use COM scripts, it feels pretty clumsy, like it would be a lot slicker just to have a command line utility, but in this case I couldn't find anything that seemed like it would work well enough (update: I later found out about ChemAxon Molconverter which is quite nice), so COM scripts it is. Python is currently the language I do general purpose programming in, and pywin32 works quite well for COM scripting.
The problem: I want to take molfiles from multiple sources and normalize them so that they can be rendered with the same style settings by chemdoodle web components. While I'm at it, I'd like to generate SMILES strings, InChI strings, and InChI key strings (I'd also like to generate IUPAC names, but I gave up on that part) for the molecules in these molfiles.
The problem: I want to take molfiles from multiple sources and normalize them so that they can be rendered with the same style settings by chemdoodle web components. While I'm at it, I'd like to generate SMILES strings, InChI strings, and InChI key strings (I'd also like to generate IUPAC names, but I gave up on that part) for the molecules in these molfiles.
Thursday, December 19, 2013
Combining the contents of multiple word files with a win32 com Python script
A former member of the lab used to keep his lab notebook as word files. One word file per day. For 8 years. Searching through these files was a real pain, so I decided to try to combine them all into one single massive file that will hopefully be easier to search through and convert to other formats.
anaconda python 3.3 on Windows
I've been using python 2.7, however it seems that now most of the libraries I use are compatible with 64-bit python 3.3 (for some, such as Biopython, there is no official python 3.3 binary, but they are available here). The one package that keeps me from breaking away from python 2.7 for good is Gurobi, which still has no python 3 support.
My main operating systems are Windows 7 and Windows 8, when I need Linux (which is often) I run it through VirtualBox.
After a few years of playing around with different Python distributions, I've found Anaconda python to be the least frustrating option, it also makes it easy to switch between two versions of Python.
My main operating systems are Windows 7 and Windows 8, when I need Linux (which is often) I run it through VirtualBox.
After a few years of playing around with different Python distributions, I've found Anaconda python to be the least frustrating option, it also makes it easy to switch between two versions of Python.
Friday, September 6, 2013
python crossplatform handling of wildcard command line arguments
Windows and Linux shells handle wildcard arguments differently. Linux (at least under bash) expands wildcard arguments before passing them to a program. Windows passes them without expanding them. This leads to trouble if you want to write a command line utility that will work correctly in both Linux and Windows (or even one compatible with wildcard arguments at all in Windows).
In Python, the typical way to expand a wildcard is with the glob module.
either: glob.glob to return a list, or glob.iglob to return an iterator (which may be preferable if a large list is expected).
Here's a solution that uses the argparse and glob modules:
see also: http://stackoverflow.com/questions/12501761/passing-multple-files-with-asterisk-to-python-shell-in-windows
In Python, the typical way to expand a wildcard is with the glob module.
either: glob.glob to return a list, or glob.iglob to return an iterator (which may be preferable if a large list is expected).
Here's a solution that uses the argparse and glob modules:
import argparse
from glob import glob
def main(file_names):
print file_names
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("file_names", nargs='*')
#nargs='*' tells it to combine all positional arguments into a single list
args = parser.parse_args()
file_names = list()
#go through all of the arguments and replace ones with wildcards with the expansion
#if a string does not contain a wildcard, glob will return it as is.
for arg in args.file_names:
file_names += glob(arg)
main(file_names)
One caveat is that I have noticed that python and bash don't sort the expanded lists in the same way, so if for some reason you need deterministic sorting of input, you should sort the resulting list yourself.
see also: http://stackoverflow.com/questions/12501761/passing-multple-files-with-asterisk-to-python-shell-in-windows
Thursday, August 22, 2013
Instantiating generic BioCyc (MetaCyc) reactions
Most databases of metabolic reactions include reactions that are generic. That is, some of the reactants and/or products are not specific molecules, but classes of molecules. This is a wonderfully abstract way of representing a large number of chemical transformations with a simple notation.
An example of a generic reaction is the CARBOXYLESTERASE-RXN in MetaCyc, which has the formula: a carboxylic ester + water <=> an alcohol + a carboxylate + a proton
As useful and elegant as generic reactions are, they present a problem for people trying to generate mathematical models from a database. The problem is that most mathematical modeling frameworks do not know how to deal with generic reactions.* So reactions in mathematical models should generally be balanced and unambiguous.
Latendresse et al. (2012) describe a strategy for generating specific reactions ("instances") from generic reactions from the BioCyc family of databases. Their strategy is to enumerate all possible combinations of reactants and products for a generic reaction, then check for mass balance. The set of mass balanced instances is further filtered by removing instances that include a reactant or product that appears in more than one balanced instance, as such instances are regarded as ambiguous. They also treat polymerization reactions as a special case and handle them differently from other instantiations.
An example of a generic reaction is the CARBOXYLESTERASE-RXN in MetaCyc, which has the formula: a carboxylic ester + water <=> an alcohol + a carboxylate + a proton
As useful and elegant as generic reactions are, they present a problem for people trying to generate mathematical models from a database. The problem is that most mathematical modeling frameworks do not know how to deal with generic reactions.* So reactions in mathematical models should generally be balanced and unambiguous.
Latendresse et al. (2012) describe a strategy for generating specific reactions ("instances") from generic reactions from the BioCyc family of databases. Their strategy is to enumerate all possible combinations of reactants and products for a generic reaction, then check for mass balance. The set of mass balanced instances is further filtered by removing instances that include a reactant or product that appears in more than one balanced instance, as such instances are regarded as ambiguous. They also treat polymerization reactions as a special case and handle them differently from other instantiations.
Labels:
algorithm,
biology,
modeling,
programming,
python
Sunday, July 7, 2013
A python port of the nonlinear optimization method of Hooke and Jeeves
I ported the Hooke and Jeeves algorithm to Python from C. I ported it because I've been writing a Python toolkit for kinetic modeling of biochemical systems. There are certain modeling methods I want to use that are difficult or impossible to do with COPASI (I'll try to write more about this in a later post), so I'm making a library specific to my needs. I found the Hooke and Jeeves parameter fitting routine from COPASI to be the most useful for fitting parameters to my current system of interest (Nelder-Mead, and Levenberg-Marquardt also seemed to work pretty well, the other ones not nearly as much).
Subscribe to:
Posts (Atom)