Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,78 @@
# HogProf
- HogProf is an extensible and tunable approach to phylogenetic profiling using orthology data. It is powered by minhash based datastructures and computationally efficient.
- Still under major development and may change
HogProf is an extensible and tunable approach to phylogenetic profiling using orthology data. It is powered by minhash-based data structures and computationally efficient.

# Features

- Using orthoxoml files and a taxonomy calculated enhanced phylogenies of each family
- These are transformed into minhash signatures and a locally sensitive hashing forest object for search and comparison of profiles
- Taxonomic levels and evolutionary event types ( presence, loss, duplication ) can have custom weight in profile construction
- Taxonomic levels and evolutionary event types (presence, loss, duplication) can have custom weight in profile construction
- Optimization of weights using machine learning

If you run into any problems feel free to contact me at [dmoi@unil.ch](dmoi@unil.ch)
If you run into any problems, feel free to contact me at [dmoi@unil.ch](dmoi@unil.ch)

# Quickstart
## Install from PyPI (recommended)

to install from github
```
$ git clone https://github.com/DessimozLab/HogProf.git
$ pip install -r pipreqs.txt .
```bash
pip install hogprof
```
or to install from pypi
```
$ pip install hogprof

## Install from sources
```bash
git clone https://github.com/DessimozLab/HogProf.git
cd HogProf
pip install .
```


lets get a current version of the OMA hdf5 file and GAF. This will alow us to use the HOGs and study the functional enrichment of our search results.
# Usage

## Example: using the OMA database
Let's get a current version of the OMA hdf5 file and GAF. This will aloww us to use the HOGs and study the functional enrichment of our search results. **Careful, this download is heavy (hundreds of GB)**:

```bash
mkdir YourOmaDirectory
cd YourOmaDirectory
wget https://omabrowser.org/All/OmaServer.h5
wget https://omabrowser.org/All/oma-go.txt.gz
```
$ cd ../..
$ mkdir YourOmaDirectory
$ cd YourOmaDirectory
$ wget https://omabrowser.org/All/OmaServer.h5
$ wget https://omabrowser.org/All/oma-go.txt.gz

The latest release (May.2026) is more than 300GB in size. Alternatively, you can use earlier releases, for example:
```bash
wget https://omabrowser.org/All.Jul2024/OmaServer.h5
```
which is 180GB in size. For other releases, check `https://omabrowser.org/oma/archives/`, select release and search for "OMA Browser database (as hdf5)".


We also need to make a location to store our pyprofiler databases

```bash
cd ..
mkdir YourHogProfDirectory
```
$ cd ..
$ mkdir YourHogProfDirectory
```

Ok. We're ready! Now let's compile a database containing all HOGs and our desired taxonomic levels using default settings. Launch the lshbuilder.
dbtypes available on the command line are : all , plants , archaea, bacteria , eukarya , protists , fungi , metazoa and vertebrates. These will use the NCBI taxonomy as a tree to annotate events in different gene family's histories.

Let's now compile a database containing all HOGs and our desired taxonomic levels using default settings. Launch the lshbuilder as shown below.
`dbtypes` available on the command line are: `all`, `plants`, `archaea`, `bacteria`, `eukarya`, `protists`, `fungi`, `metazoa`, and `vertebrates`. These will use the NCBI taxonomy as a tree to annotate events in different gene family's histories.

If you are using an OMA release before 2022 you will need to use the NCBI tree. This is the default tree used by HogProf.



```
$python lshbuilder.py --outpath YourHogProfDirectory --dbtype all --OMA YourOmaDirectory/OmaServer.h5 --nthreads numberOfCPUcores
lshbuilder --outpath YourHogProfDirectory --dbtype all --OMA YourOmaDirectory/OmaServer.h5 --nthreads numberOfCPUcores

```

If you are using OMA releases after 2022 we will also be downloading the OMA taxonomic tree since it is more accurate than the NCBI tree. This will be used to annotate the events in the gene family histories.

```
```bash
wget https://omabrowser.org/All/speciestree.nwk

```

Ok now we're ready to use the OMA tree to build our database.

```
We are ready to use the OMA tree to build our database.

$python lshbuilder.py --outpath YourHogProfDirectory --dbtype all --OMA YourOmaDirectory/OmaServer.h5 --nthreads numberOfCPUcores --mastertree YourOmaDirectory/speciestree.nwk --reformat_names True
```bash
lshbuilder --outpath YourHogProfDirectory --dbtype all --OMA YourOmaDirectory/OmaServer.h5 --nthreads numberOfCPUcores --mastertree YourOmaDirectory/speciestree.nwk --reformat_names True

```

This should build a taxonomic tree for the genomes contained in the release and then calculate enhanced phylogenies for all HOGs in OMA.

Once the database is completed it can be interogated using a profiler object. Construction and usage of this object should be done using a python script or notebook. This shown in the example notebook searchenrich.ipynb found in the examples. Please feel free to modify it to suit the needs of your own research.
Once the database is completed it can be interogated using a profiler object. Construction and usage of this object should be done using a python script or notebook. This shown in the example notebook `searchenrich.ipynb` found in the examples. Please feel free to modify it to suit the needs of your own research.
30 changes: 12 additions & 18 deletions src/HogProf/lshbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,8 @@ class LSHBuilder:
with a list of taxonomic codes for all the species in your db
"""

def __init__(self,
h5_oma=None,
fileglob=None,
masterTree: Optional[Path] = None,
saving_name=None,
numperm=256,
treeweights=None,
taxfilter=None,
taxmask=None,
lossonly=False,
duplonly=False,
verbose=False,
use_taxcodes=False,
datetime=datetime.now(),
reformat_names=False):
def __init__(self,h5_oma=None,fileglob = None, taxa=None,masterTree=None, saving_name=None , numperm = 256, treeweights= None , taxfilter = None, taxmask= None , lossonly = False, duplonly = False, verbose = False , use_taxcodes = False , datetime = datetime.now() , reformat_names = False,
limit_species = 10):

"""
Initializes the LSHBuilder class with the specified parameters and sets up the necessary objects.
Expand All @@ -73,6 +60,8 @@ def __init__(self,
- taxfilter (str): path to a file containing a list of taxonomic codes to filter from the tree
- taxmask (str): path to a file containing a list of taxonomic codes to mask from the tree
- verbose (bool): whether to print verbose output (default: False)
- limit_species (int): the minimum number of species in a subHOG that is included in the database (default: 10)


"""
if h5_oma:
Expand All @@ -93,6 +82,7 @@ def __init__(self,
self.fileglob = fileglob
self.idmapper = None
self.date_string = "{:%B_%d_%Y_%H_%M}".format(datetime.now())
self.limit_species = limit_species
if saving_name:
self.saving_name= saving_name
if self.saving_name[-1]!= '/':
Expand Down Expand Up @@ -445,7 +435,7 @@ def mp_with_timeout(functypes, data_generator):
gc.collect()
print('DONE!')

mp_with_timeout(functypes=functype_dict, data_generator=self.generates_dataframes(100))
mp_with_timeout(functypes=functype_dict, data_generator=self.generates_dataframes(size=100, minhog_size=self.limit_species))
return self.hashes_path, self.lshforestpath , self.mat_path


Expand All @@ -470,6 +460,8 @@ def main():
parser.add_argument('--taxcodes', help='use taxid info in HOGs' , type = bool)
parser.add_argument('--verbose', help='print verbose output' , type = bool)
parser.add_argument('--reformat_names', help='try to correct broken species trees by replacing all names with numbers.' , type = bool)
parser.add_argument('--specieslim', help='minimum number of species in a subhog' , type = int, default=10)

dbdict = {
'all': { 'taxfilter': None , 'taxmask': None },
'plants': { 'taxfilter': None , 'taxmask': 33090 },
Expand Down Expand Up @@ -572,12 +564,14 @@ def main():
with open_file( omafile , mode="r") as h5_oma:
lsh_builder = LSHBuilder(h5_oma = h5_oma, fileglob=orthoglob ,saving_name=dbname , numperm = nperm ,
treeweights= weights , taxfilter = taxfilter, taxmask=taxmask , masterTree =mastertree ,
lossonly = lossonly , duplonly = duplonly , use_taxcodes = taxcodes , reformat_names=reformat_names, verbose=verbose )
lossonly = lossonly , duplonly = duplonly , use_taxcodes = taxcodes , reformat_names=reformat_names, verbose=verbose,
limit_species=args['specieslim'])
lsh_builder.run_pipeline(threads)
else:
lsh_builder = LSHBuilder(h5_oma = None, fileglob=orthoglob ,saving_name=dbname , numperm = nperm ,
treeweights= weights , taxfilter = taxfilter, taxmask=taxmask ,
masterTree =mastertree , lossonly = lossonly , duplonly = duplonly , use_taxcodes = taxcodes , reformat_names=reformat_names, verbose=verbose)
masterTree =mastertree , lossonly = lossonly , duplonly = duplonly , use_taxcodes = taxcodes , reformat_names=reformat_names, verbose=verbose,
limit_species=args['specieslim'])
lsh_builder.run_pipeline(threads)
print(time.time() - start)
print('DONE')
Expand Down
Loading