Mercurial > repos > damion > ffp_phylogeny
changeset 1:d1c88b118a3f draft
Uploaded
author | damion |
---|---|
date | Fri, 13 Mar 2015 20:59:28 -0400 |
parents | eb6e5e78a066 |
children | 671667722d3d |
files | LICENSE.md README.md ffp_phylogeny.py ffp_phylogeny.xml tarballit.sh test-data/test_length_2b_output.tabular test.txt |
diffstat | 7 files changed, 146 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.md Fri Mar 13 20:59:28 2015 -0400 @@ -0,0 +1,48 @@ +Source Code License + +An Open Source Initiative (OSI) approved license +ffp_phylogeny source code is licensed under the Academic Free License version 3.0. + +Licensed under the Academic Free License version 3.0 + +1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + +a) to reproduce the Original Work in copies, either alone or as part of a collective work; + +b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + +c) to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + +d) to perform the Original Work publicly; and + +e) to display the Original Work publicly. + +2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + +3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + +4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + +5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + +6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + +7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + +8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + +9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + +10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + +11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + +12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + +13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + +14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + +16) Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Fri Mar 13 20:59:28 2015 -0400 @@ -0,0 +1,44 @@ +Feature Frequency Profile Phylogenies +===================================== + + +Introduction +------------ + +FFP (Feature frequency profile) is an alignment free comparison tool for phylogenetic analysis and text comparison. It can be applied to nucleotide sequences, complete genomes, proteomes and even used for text comparison. This software is a Galaxy (http://galaxyproject.org) tool for calculating FFP on one or more fasta sequence or text datasets. + +The original command line ffp-phylogeny code is at http://ffp-phylogeny.sourceforge.net/ . This tool uses Aaron Petkau's modified version: https://github.com/apetkau/ffp-3.19-custom . Aaron has quite a good writeup of the technique as well at https://github.com/apetkau/microbial-informatics-2014/tree/master/labs/ffp-phylogeny . + +This Galaxy tool prepares a mini-pipeline consisting of **[ffpry | ffpaa | ffptxt] > [ ffpfilt | ffpcol > ffprwn] > ffpjsd > ffptree** . The last step is optional - by deselecting the "Generate Tree Phylogeny" checkbox, the tool will output a distance matrix rather than a Newick (.nhx) formatted tree file. + +Each sequence or text file has a profile containing tallies of each feature found. A feature is a string of valid characters of given length. + +For nucleotide data, by default each character (ATGC) is grouped as either purine(R) or pyrmidine(Y) before being counted. + +For amino acid data, by default each character is grouped into one of the following: (ST),(DE),(KQR),(IVLM),(FWY),C,G,A,N,H,P. Each group is represented by the first character in its series. + +One other key concept is that a given feature, e.g. "TAA" is counted in forward AND reverse directions, mirroring the idea that a feature's orientation is not so important to distinguish when it comes to alignment-free comparison. The counts for "TAA" and "AAT" are merged. + +The labeling of the resulting counted feature items is perhaps the trickiest concept to master. Due to computational efficiency measures taken by the developers, a feature that we see on paper as "TAC" may be stored and labeled internally as "GTA", its reverse compliment. One must look for the alternative if one does not find the original. + +Also note that in amino acid sequences the stop codon "*" (or any other character that is not in the Amino acid alphabet) causes that character frame not to be counted. Also, character frames never span across fasta entries. + +A few tutorials: + * http://sourceforge.net/projects/ffp-phylogeny/files/Documentation/tutorial.pdf + * https://github.com/apetkau/microbial-informatics-2014/tree/master/labs/ffp-phylogeny + +------- +**Note** + +Taxonomy label details: If each file contains one profile, the file's name is used to label the profile. If each file contains fasta sequences to profile individually, their fasta identifiers will be used to label them. The "short labels" option will find the shortest label that uniquely identifies each profile. Either way, there are some quirks: ffpjsd clips labels to 10 characters if they are greater than 50 characters, so all labels are trimmed to 50 characters first. Also "id" is prefixed to any numeric label since some tree visualizers won't show purely numeric labels. In the accidental case where a Fasta sequence label is a duplicate of a previous one it will be prefixed by "DupLabel-". + +The command line ffpjsd can hang if one provides an l-mer length greater than the length of file content. One must identify its process id ("ps aux | grep ffpjsd") and kill it ("kill [process id]"). + +Finally, it is possible for the ffptree program to generate a tree where some of the branch distances are negative. See https://www.biostars.org/p/45597/ +------- +**References** + +The development of the ffp-phylogeny command line software should be attributed to: + +Sims GE, Jun S-R, Wu GA, Kim S-H. Alignment-free genome comparison with feature frequency profiles (FFP) and optimal resolutions. Proceedings of the National Academy of Sciences of the United States of America 2009;106(8):2677-2682. doi:10.1073/pnas.0813249106. +
--- a/ffp_phylogeny.py Mon Feb 23 18:25:25 2015 -0500 +++ b/ffp_phylogeny.py Fri Mar 13 20:59:28 2015 -0400 @@ -1,5 +1,6 @@ #!/usr/bin/python import optparse +import re import time import os import tempfile @@ -160,6 +161,8 @@ commands = command.split("|") processes = [] ptr = 0 + substantive = re.compile('[a-zA-Z0-9]+') + for command_line in commands: print command_line.strip() args = shlex.split(command_line.strip()) @@ -167,22 +170,26 @@ proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) processes.append(proc) else: + + #this has to come before error processing? + newProcess = subprocess.Popen(args, stdin=processes[ptr-1].stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # It seems the act of reading standard error output is enough to trigger # error code signal for that process, i.e. so that retcode returns a code. + retcode = processes[ptr-1].poll() stderrdata = processes[ptr-1].stderr.read() - retcode = processes[ptr-1].poll() - if retcode or len(stderrdata) > 0: - stop_err(stderrdata) + #Issue with ffptree is it outputs ----....---- on stderr + if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)): + stop_err(stderrdata) - newProcess = subprocess.Popen(args, stdin=processes[ptr-1].stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - processes.append(newProcess) + processes.append(newProcess) processes[ptr-1].stdout.close() # Allow prev. process to receive a SIGPIPE if current process exits. ptr += 1 + retcode = processes[ptr-1].poll() (stdoutdata, stderrdata) = processes[ptr-1].communicate() - retcode = processes[ptr-1].poll() - if retcode or len(stderrdata) > 0: + if retcode or (len(stderrdata) > 0 and substantive.search(stderrdata)): stop_err(stderrdata) return stdoutdata @@ -322,6 +329,7 @@ #Now create a taxonomy label file, ensuring a name exists for each profile. taxonomyNames = getTaxonomyNames(options.type, options.multiple, options.abbreviate, in_files, options.taxonomy) taxonomyTempFile = getTaxonomyFile(taxonomyNames) + # -p = Include phylip format 'infile' of the taxon names to use. Very simple, just a list of fasta identifier names. command += ' | ffpjsd -p ' + taxonomyTempFile @@ -337,6 +345,8 @@ else: stop_err("For a phylogenetic tree display, one must have at least 3 ffp profiles.") + #print command + result = check_output(command) with open(options.output,'w') as fw: fw.writelines(result)
--- a/ffp_phylogeny.xml Mon Feb 23 18:25:25 2015 -0500 +++ b/ffp_phylogeny.xml Fri Mar 13 20:59:28 2015 -0400 @@ -1,4 +1,4 @@ -<tool id="ffp_phylogeny" name="Feature Frequency Profile Phylogeny" version="0.1.00"> +<tool id="ffp_phylogeny" name="Feature Frequency Profile Phylogeny" version="0.1.02"> <description>An alignment free comparison tool for phylogenetic analysis and text comparison</description> <requirements> <requirement type="package" version="0.3.19_d4382db015acec0e5cc43d6c1ac80ae12cb7e6b3">ffp-phylogeny</requirement> @@ -22,35 +22,36 @@ -t "$(sequence.file_type.split('-')[0])" -l "$length" -o "$info" - ##if $normalize: + ##if $normalize ## -n ##end if - #if $sequence.file_type != 'text': - #if $sequence.file_type.find('multi') > 0: + #if $sequence.file_type != 'text' + #if $sequence.file_type == 'amino-multi' or $sequence.file_type == 'nucleotide-multi' -m #end if - #if $sequence.grouping: + #if $sequence.groupings + #pass + #else -d #end if - #if $metric: + #if $metric -M "$metric" #end if - #if $similarity: + #if $similarity -s #end if - #if $abbreviate: + #if $abbreviate -a #end if #end if - #if $phylogeny.phylo_type == 'filter': + #if $phylogeny.phylo_type == 'filter' -f "$phylogeny.filt.filter_type" -L "$phylogeny.filt.lower" -U "$phylogeny.filt.upper" #end if - #if $tree: + #if $tree -T #end if - ##ffpjsd -n FLOAT , --normval=FLOAT ## For option -e, --euclid, change the n-norm distance (Default is n=2) to any other value where n > 1 @@ -66,32 +67,32 @@ <param name="normalize" label="Normalize counts into relative frequency" type="boolean" checked="true" help="" /> --> <conditional name="sequence"> - <param type="select" name="file_type" label="File type" help="Note: For phylogeny display, at least three profiles are required, as files or fasta sequences within a file."> - <option value="amino">Amino Acids, one sequence per file</option> - <option value="amino-multi">Amino Acids, multiple fasta sequences per file</option> - <option value="nucleotide">Nucleic acids, one sequence per file</option> - <option value="nucleotide-multi">Nucleic acids, multiple fasta sequences per file</option> + <param type="select" name="file_type" label="File type" help="Note: For phylogeny display, at least three profiles are required."> + <option value="amino">Amino Acids, one profile per file</option> + <option value="amino-multi">Amino Acids, one profile per fasta sequence in file</option> + <option value="nucleotide">Nucleic acids, one profile per file</option> + <option value="nucleotide-multi">Nucleic acids, one profile per fasta sequence in file</option> <option value="text">Text, single file</option> </param> <when value="amino"><!-- ffpaa --> <param name="filesin" type="data" label="Select input file(s)" format="fasta" multiple="true" /> - <param name="grouping" label="Enable amino acid grouping" type="boolean" checked="true" help="Counts amino acids in groups rather than individually (usually advantageous, see below)." /> + <param name="groupings" label="Enable amino acid grouping" type="boolean" checked="true" help="Counts amino acids in groups rather than individually (usually advantageous, see below)." /> </when> <when value="amino-multi"> <param name="filesin" type="data" label="Select input file(s)" format="fasta" multiple="true" /> - <param name="grouping" label="Enable amino acid grouping" type="boolean" checked="true" help="Counts amino acids in groups rather than individually (usually advantageous, see below)." /> + <param name="groupings" label="Enable amino acid grouping" type="boolean" checked="true" help="Counts amino acids in groups rather than individually (usually advantageous, see below)." /> </when> <when value="nucleotide"><!-- ffpry --> <param name="filesin" type="data" label="Select input file(s)" format="fasta" multiple="true" /> - <param name="grouping" label="Enable purine / pyrimidine grouping" type="boolean" checked="true" help="Counts each nucleotide as a purine(R) or pyrimidine(Y) rather than individually (usually advantageous)." /> + <param name="groupings" label="Enable purine / pyrimidine grouping" type="boolean" checked="true" help="Counts each nucleotide as a purine(R) or pyrimidine(Y) rather than individually (usually advantageous)." /> </when> <when value="nucleotide-multi"> <param name="filesin" type="data" label="Select input file(s)" format="fasta" multiple="true" /> - <param name="grouping" label="Enable purine / pyrimidine grouping" type="boolean" checked="true" help="Counts each nucleotide as a purine(R) or pyrimidine(Y) rather than individually (usually advantageous)." /> + <param name="groupings" label="Enable purine / pyrimidine grouping" type="boolean" checked="true" help="Counts each nucleotide as a purine(R) or pyrimidine(Y) rather than individually (usually advantageous)." /> </when> <when value="text"><!-- ffptxt --> @@ -200,7 +201,7 @@ <test> <param name="length" value="1"/> <param name="tree" value="0"/> - <param name="grouping" value="true"/> + <param name="groupings" value="false"/> <param name="file_type" value="nucleotide"/> <param name="filesin" value="genome1,genome2"/> <output name="info" file="test_length_1_output.tabular"/> @@ -208,11 +209,19 @@ <test> <param name="length" value="2"/> <param name="tree" value="0"/> - <param name="grouping" value="true"/> + <param name="groupings" value="false"/> <param name="file_type" value="nucleotide"/> <param name="filesin" value="genome1,genome2"/> <output name="info" file="test_length_2_output.tabular"/> </test> + <test> + <param name="length" value="2"/> + <param name="tree" value="0"/> + <param name="groupings" value="true"/> + <param name="file_type" value="nucleotide-multi"/> + <param name="filesin" value="genome1,genome2"/> + <output name="info" file="test_length_2b_output.tabular"/> + </test> </tests> <help><![CDATA[ @@ -224,7 +233,7 @@ FFP (Feature frequency profile) is an alignment free comparison tool for phylogenetic analysis and text comparison. It can be applied to nucleotide sequences, complete genomes, proteomes and even used for text comparison. -This galaxy tool prepares a mini-pipeline consisting of **[ffpry | ffpaa | ffptxt] > [ ffpfilt | ffpcol > ffprwn] > ffpjsd > ffptree** . The last step is optional - by deselecting the "Generate Tree Phylogeny" checkbox, the tool will output a distance matrix rather than a Newick (.nhx) formatted tree file. +This galaxy tool prepares a mini-pipeline consisting of **[ffpry | ffpaa | ffptxt] > [ ffpfilt | ffpcol > ffprwn] > ffpjsd > ffptree** . The last step is optional - by deselecting the "Generate Tree Phylogeny" checkbox, the tool will output only the precursor distance matrix file rather than a Newick (.nhx) formatted tree file. Each sequence or text file has a profile containing tallies of each feature found. A feature is a string of valid characters of given length.
--- a/tarballit.sh Mon Feb 23 18:25:25 2015 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -#!/bin/bash - tar -zcvf ffp_phylogeny.tar.gz * --exclude "*~" --exclude "tool_test_output*" --exclude "*gz"