Commit 0d1f2ef2 authored by Hermann Zellner's avatar Hermann Zellner
Browse files

Initial commit of UniFIRE codebase

parents
# maven build:
/**/target/
# IntelliJ Idea:
/**/*.iml
/**/*.eml
/.idea
# Eclipse:
/.classpath
/.project
/.settings
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
### Changed
- Replace Null positions by "" in output TSV file
### Removed
\ No newline at end of file
Copyright 2018 European Molecular Biology Laboratory, EMBL-EBI
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\ No newline at end of file
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the 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.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
\ No newline at end of file
# UniFIRE Project
UniFIRE (The UniProt Functional annotation Inference Rule Engine) is an engine to execute rules in the UniProt Rule Markup Language (URML) format.
It can be used to execute the UniProt annotation rules (UniRule and SAAS).
This project is a work in progress, open for private collaboration only. Please do not share this code without explicit authorization.
Introducing presentation: [UniFIRE-URML.pptx](misc/media/UniFIRE-URML.pptx)
## Getting Started
### Prerequisites
#### Hardware
A machine with at least 2 Go of memory.
#### Operating system support
The Java software is portable for any system.
Scripts are only provided for Linux and Mac OS.
#### Software
- Java (>=1.8)
### Usage
#### Try it out
We provide some sample files in the [sample](samples) folder to test the software.
**Example with UniRule rules & InterProScan XML input:**
``` bash
$ ./distribution/bin/unifire.sh -r samples/unirule-urml-2019_04.xml -i samples/input_ipr.fasta.xml -t samples/unirule-templates-2019_04.xml -o ~/output_unirule_annotations.csv
```
*Note: To be able to predict the UniRule positional annotations, a template file is provided (`samples/unirule-templates-2018_05.xml`) (optional.)*
**Example with SAAS rules & Fact XML input:**
``` bash
$ ./distribution/bin/unifire.sh -r samples/saas-urml-2019_04.xml -i samples/input_facts.xml -s XML -o ~/output_saas_annotations.csv
```
_Note_: With all rule systems, it is possible that a protein get the exact same annotation from different rules due to overlap in condition spaces.
#### Options
```
usage: unifire -i <INPUT_FILE> -o <OUTPUT_FILE> -r <RULE_URML_FILE> [-f <OUTPUT_FORMAT>] [-n
<INPUT_CHUNK_SIZE>] [-s <INPUT_SOURCE>] [-t <TEMPLATE_FACTS>] [-m <MAX_MEMORY>] [-h]
--------------------------------------------
-i,--input <INPUT_FILE> Input file (path) containing the proteins to annotate
and required data, in the format specified by the -s
option.
-o,--output <OUTPUT_FILE> Output file (path) containing predictions in the format
specified in the -f option.
-r,--rules <RULE_URML_FILE> Rule base file (path) provided by UniProt (e.g UniRule
or SAAS) (format: URML).
-f,--output-format <OUTPUT_FORMAT> Output file format. Supported formats are:
- TSV (Tab-Separated Values)
- XML (URML Fact XML)
(default: TSV).
-n,--chunksize <INPUT_CHUNK_SIZE> Chunk size (number of proteins) to be batch processed
simultaneously
(default: 1000).
-s,--input-source <INPUT_SOURCE> Input source type. Supported input sources are:
- InterProScan (InterProScan Output XML)
- UniParc (UniParc XML)
- XML (Input Fact XML)
(default: InterProScan).
-t,--templates <TEMPLATE_FACTS> UniRule template sequence matches, provided by UniProt
(format: Fact Model XML).
-m <MAX_MEMORY> Max size of the memory allocation pool in MB (JVM -Xmx)
(default: 4096 MB).
-h,--help Print this usage.
```
***
## Data preparation
This section is a walkthrough on how to prepare your data, assuming you are starting from scratch: from a set of sequences (multifasta) that you would like to annotate.
More advanced users / developers with an existing bioinformatics pipeline already integrating InterProScan results should try to load their existing data into the fact model described on the Developer Guide below.
### MultiFasta header format
The MultiFasta headers should, more or less, follow the UniProtKB conventions ([https://www.uniprot.org/help/fasta-headers](https://www.uniprot.org/help/fasta-headers))
The minimal structure of the header is the following:
```
>{id}|{name} {flags}
```
* `{id}` must be a unique string amongst the processed sequences
* `{name}`:
* can be any string starting from the previous separator, that should not contain any flag
* might contains `(Fragment)` if applicable (e.g "`ACN2_ACAGO Acanthoscurrin-2 (Fragment)`")
* `{flags}` \[mandatory]: to be considered a valid header, only the following flags should be provided:
* OX=`{taxonomy Id}`
* `{flags}` \[optional]: If possible / applicable, you should also provide:
* OS=`{organism name}`
* GN=`{recommended gene name}`
* GL=`{recommended ordered locus name (OLN) or Open Reading Frame (OLN) name}`
* OG=`{gene location(s), comma-separated if multiple}` ([cf. organelle ontology](https://www.ebi.ac.uk/ena/WebFeat/qualifiers/organelle.html))
The UniProt header format has been slightly extended with GL and OG flags.
Optionally, `{id}` can be prepended by `{database}|`, to follow UniProt conventions. If used, it will simply be skipped during the parsing.
Also note that any additional flags will also be ignored.
#### Examples of valid headers:
From UniProt:
```
>tr|Q3SA23|Q3SA23_9HIV1 Protein Nef (Fragment) OS=Human immunodeficiency virus 1 OX=11676 GN=nef PE=3 SV=1
```
From UniProt, customized with additional flags:
```
>tr|A0A0D6DT88|A0A0D6DT88_BRADI Maturase K (Fragment) OS=Brachypodium distachyon OX=15368 GN=matK GL=BN3904_34004 OG=Plastid,Chloroplast PE=3 SV=1
```
Customized minimal:
```
>123|Mystery protein OX=62977
```
Customized full:
```
>MyPlantDB|P987|Photosystem II protein D1 OS=Lolium multiflorum OX=4521 GN=psbA GL=LomuCp001 OG=Plastid
```
### Fetching the full lineages
From the previously described multifasta format, you can use the following scripts to fetch the full NCBI taxonomy id lineage.
* [fetchLineageLocal.py](misc/taxonomy/fetchLineageLocal.py) `<input` `<output>` - for large amount of data on multiple species
* [fetchLineageRemote.py](misc/taxonomy/fetchLineageRemote.py) `<input` `<output>` - for one-off usage / few species
Both scripts will simply replace the OX={taxId} by OX={fullLineage}.
Having the full lineage is necessary for the majority of the rules to be executed.
### Validating the MultiFasta file
If you want to ensure the headers are in the correct format, you can run the following script:
``` bash
$ ./distribution/bin/fasta-header-validator.sh multifasta_sequences.fasta
```
You will get an error message if at least one sequence's header is invalid.
The script also print out warnings if an important data (e.g organism name) is missing. The warnings can be ignored.
### Running InterProScan
Once the multifasta file is ready (cf. previous steps), you can find the matches of all sequences using InterProScan.
It is advised to download the last version from [https://www.ebi.ac.uk/interpro/download.html](https://www.ebi.ac.uk/interpro/download.html) and keep it up-to-date.
The output format must be XML to be accepted as a valid input for UniFIRE.
The option `-dp` or `--disable-precalc` must be used to be able to get the sequence alignments (necessary if you are interested by the positional features annotations provided by UniRule).
Command:
``` bash
./interproscan.sh -f xml -dp -i multifasta_sequences.fasta --appl "Hamap,ProSiteProfiles,ProSitePatterns,Pfam,TIGRFAM,SMART,PRINTS,SFLD,CDD,Gene3D,ProDom,PIRSF,PANTHER,SUPERFAMILY"
```
#### Analyses to run
* Hamap
* ProSiteProfiles
* ProSitePatterns
* Pfam
* TIGRFAM
* SMART
* PRINTS
* SFLD
* CDD
* Gene3D
* ProDom
* PIRSF
* PANTHER
* SUPERFAMILY
It is possible to include/exclude some of the analyses by modifying the `--appl` option in the above command. UniFIRE will still be able to process the data.
By excluding some of those analyses, some rules might not be triggered as a result.
If you do not wish to install InterProScan, you can use the [online version](https://www.ebi.ac.uk/interpro/search/sequence-search) and then download the results in XML.
The only limitation is that the online version does not provide the sequence alignments for the matches, making the execution of UniRule positional features impossible (non-positional rules will still be executed).
### Running UniFIRE
Once you get the InterProScan output (by default, it is the name of the input file, appended with .xml), you can use it as a input for UniFIRE (e.g `--input multifasta_sequences.fasta.xml`).
***
## Developer guide
### Fact Model
The fact model is automatically created from the following XML Schema: [urml-facts.xsd](core/src/main/resources/schemas/xsd/urml-facts.xsd)
The corresponding Java classes are built in the [core](core) module under the package `org.uniprot.urml.facts`, after building the project with Maven (or using the `./build.sh` script).
You can use theses classes (described in the UML diagram below) and the container `org.uniprot.urml.facts.FactSet` to load your own data directly into objects (via an ORM or a custom parser).
### Fact Model Diagram
![fact-model-diagram](misc/media/fact-model.png)
### Rule Model
The rule model is described in another XML Schema available here: [urml-rules.xsd](core/src/main/resources/schemas/xsd/urml-rules.xsd)
The corresponding Java classes are built in the [core](core) module under the package `org.uniprot.urml.rules`.
### Building the software
#### Requirement
- Maven (>= 3.0)
- Java (=1.8 required, cf. limitations)
#### Command
``` bash
$ ./build.sh
```
This script is installing some libraries in your local maven repository (temporary solution before publishing the artifacts on a public repository).
Then it runs `mvn clean install`, assembling all the libs and the execution script under `./distribution/target/unifire-distribution/`.
To use the newly built distribution, you will need to run: `./distribution/target/unifire-distribution/bin/unifire.sh` instead.
### Execution
The execution of the rules relies on [Drools](https://www.drools.org), an open-source rule-based technology developed by RedHat.
It is using an optimized version of the [Rete algorithm](https://en.wikipedia.org/wiki/Rete_algorithm) to match facts and rules in a scalable way.
This tool translates the URML rules into the Drools language, converts the input data according to the rule model and execute all the rules to produce a list of protein annotations.
***
## Limitations
### Memory
A minimum of 2 Go of memory is required for this software to run.
For a large number of protein to process, it is advised to split them into chunks of approx. 1000 proteins per rule evaluation to keep the memory usage low.
This is automatically handled by the `-n / --chunksize` option of UniFIRE (by default 1000).
### Java 9 / 10 issues
- For users, the software will be functional under Java 9 or 10, but you will get some warning messages complaining about illegal reflective accesses. You can simply ignore them at the moment.
- For developers, building the software with JDK 9 / 10 is currently not possible because of JAXB Maven plugin issues. Cf:
* https://github.com/highsource/maven-jaxb2-plugin/issues/120
* https://stackoverflow.com/questions/49717155/failed-to-run-custom-xjc-extension-within-cxf-xjc-plugin-on-java-9
Those issues have been raised very recently. The fixes will be applied as soon as there are available.
***
## Issues & Suggestions
Please do not hesitate to raise new issues if you experience any bugs or you have improvement suggestions on the software, the models, the helper scripts, the documentation, etc...
[UniFIRE Issue Tracker](https://gitlabci.ebi.ac.uk/uniprot.aa/UniFIRE/issues)
## Authors
* **Alexandre Renaux**
## Contact
* **UniProt Help** - [help@uniprot.org](mailto:help@uniprot.org)
\ No newline at end of file
#!/usr/bin/env bash
############################################################################
# Copyright (c) 2018 European Molecular Biology Laboratory
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################################################################
function backup_file {
filename=$1
if [[ -e ${filename} ]]; then
mv ${filename} ${filename}_
fi
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DISTRIBUTION_DIR="${SCRIPT_DIR}/distribution"
FTP_SRC="http://ftp.ebi.ac.uk/pub/contrib/UniProtKB/UniFIRE/rules/"
pushd ${SCRIPT_DIR} > /dev/null
echo "Building UniFIRE and downloading dependencies..."
mvn clean install -Dmaven.test.skip=true -Dmaven.source.skip=true
cd ${DISTRIBUTION_DIR}
mvn dependency:copy-dependencies
echo "Done building UniFIRE and downloading dependencies."
popd > /dev/null
echo "Downloading rule urml files..."
for i in aa-rules-saas-urml-latest.xml aa-rules-unirule-urml-latest.xml unirule-templates-latest.xml;
do
backup_file ${SCRIPT_DIR}/samples/${i}
wget ${FTP_SRC}/${i} -O ${SCRIPT_DIR}/samples/${i}
done
echo "Done downloading rule urml files."
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018 European Molecular Biology Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>uk.ac.ebi.uniprot.aa</groupId>
<artifactId>unifire</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>unifire-core</artifactId>
<properties>
<reflections.version>0.9.10</reflections.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</dependency>
<!-- CXF plugin - alternative to the JVNET one in case migration to Java 9 is faster -->
<!--<dependency>-->
<!--<groupId>org.apache.cxf.xjcplugins</groupId>-->
<!--<artifactId>cxf-xjc-ts</artifactId>-->
<!--<version>3.2.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.apache.cxf.xjc-utils</groupId>-->
<!--<artifactId>cxf-xjc-runtime</artifactId>-->
<!--<version>3.2.1</version>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>javax.xml.bind</groupId>-->
<!--<artifactId>jaxb-api</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->