linsalrob / PhiSpy

Prediction of prophages from bacterial genomes
MIT License
70 stars 20 forks source link

Edwards Lab DOI License: MIT GitHub language count Build Status PyPi Anaconda-Server Badge BioConda Install Anaconda-Server Badge

What is PhiSpy?

PhiSpy identifies prophages in Bacterial (and probably Archaeal) genomes. Given an annotated genome it will use several approaches to identify the most likely prophage regions.

Initial versions of PhiSpy were written by

Sajia Akhter (sajia@stanford.edu) Edwards Bioinformatics Lab

Improvements, bug fixes, and other changes were made by

Katelyn McNair Edwards Bioinformatics Lab and Przemyslaw Decewicz DEMB at the University of Warsaw

Installation

Conda

The easiest way to install for all users is to use bioconda.

conda install -c bioconda phispy

PIP

python-pip requires a C++ compiler and the Python header files. You should be able to install it like this:

sudo apt install -y build-essential python3-dev python3-pip
python3 -m pip install --user PhiSpy

This will install PhiSpy.py in ~/.local/bin which should be in your $PATH but might not be (see this detailed discussion). See the tips and tricks below for a solution to this.

Advanced Users

For advanced users, you can clone the git repository and use that (though pip is the recommended install method).

git clone https://github.com/linsalrob/PhiSpy.git
cd PhiSpy
python3 setup.py install --user --record installed_files.txt

Note that we recommend using --record to save a list of all the files that were installed by PhiSpy. If you ever want to uninstall it, or to remove everything to reinstall e.g. from pip, you can simply use the contents of that file:

cat installed_files.txt | xargs rm -f

If you have root and you want to install globally, you can change the setup command.

git clone https://github.com/linsalrob/PhiSpy.git
cd PhiSpy
python3 setup.py install

For ease of use, you may wish to add the location of PhiSpy.py to your $PATH.

Software Requirements

PhiSpy requires following programs to be installed in the system. Most of these are likely already on your system or will be installed using the mechanisms above.

  1. Python - version 3.4 or later
  2. Biopython - version 1.58 or later
  3. gcc - GNU project C and C++ compiler - version 4.4.1 or later
  4. The Python.h header file. This is included in python3-dev that is available on most systems.

Testing PhiSpy.py

Download the Streptococcus pyogenes M1 genome

curl -Lo Streptococcus_pyogenes_M1_GAS.gb https://bit.ly/37qFArb
PhiSpy.py -o Streptococcus.phages Streptococcus_pyogenes_M1_GAS.gb

or to run it with the Streptococcus training set:

PhiSpy.py -o Streptococcus.phages -t data/trainSet_160490.61.txt Streptococcus_pyogenes_M1_GAS.gb

This uses the GenBank format file for Streptococcus pyogenes M1 GAS that we provide in the tests/ directory, and we use the training set for S. pyogenes M1 GAS that we have pre-calculated. This quickly identifies the four prophages in this genome, runs the repeat finder on all of them, and outputs the answers.

You will find the output files from this query in output_directory.

Download more testing data

You can also download all the genomes in tests/. These are not installed with PhiSpy if you use pip/conda, but will be if you clone the repository. Please note that these are stored on git lfs, and so if you notice an error that the files are small and don't ungzip, you may need to (i) install git lfs and (ii) use git lfs fetch to update this data.

Running PhiSpy.py

The simplest command is:

PhiSpy.py genbank_file -o output_directory

where:

If you have new genome, we recommend annotating it using the RAST server or PROKKA. RAST has a server that allows you to upload and download the genome (and can handle lots of genomes), while PROKKA is stand-alone software.

phage_genes

By default, PhiSpy.py uses strict mode, where we look for two or more genes that are likely to be a phage in each prophage region. If you increase the value of --phage_genes that will reduce the number of prophages that are predicted. Conversely, if you reduce this, or set it to 0 we will overcall mobile elements.

When --phage_genes is set to 0, PhiSpy.py will identify other mobile elements like plasmids, integrons, and pathogenicity islands. Somewhat unexpectedly, it will also identify the ribosomal RNA operons as likely being mobile since they are unlike the host's backbone!

color

If you add the --color flag, we will color the CDS based on their function. The colors are primarily used in artemis for visualizing phage regions.

file name prefixes

By default the outputs from PhiSpy.py have standard names. If you supply a file name prefix it will be prepended to all the file so that you can run PhiSpy.py on multiple genomes and have the outputs in the same directory without overwriting each other.

gzip support

PhiSpy.py natively supports both reading and writing files in gzip format. If you provide a gzipped input file, we will write a gzipped output file.

HMM Searches

When also considering the signal from HMM profile search:

PhiSpy.py genbank_file -o output_directory --phmms hmm_db --threads 4 --color

where:

Training sets were searched with pVOG database HMM profiles: AllvogHMMprofiles.tar.gz. To use it:

wget http://dmk-brain.ecn.uiowa.edu/pVOGs/downloads/All/AllvogHMMprofiles.tar.gz
tar -zxvf AllvogHMMprofiles.tar.gz
cat AllvogHMMprofiles/* > pVOGs.hmm

Then use pVOGs.hmm as hmm_db.

Since extra step before the regular processing of PhiSpy is performed, input genbank file is updated and saved in output_directory. When --color flag is used, additional qualifier /color will be added in the updated GenBank file so that the user could easily distinguished proteins with hits to hmm_db while viewing the file in Artemis

When running PhiSpy again on the same input data and with --phmms option you can skip the search step by --skip_search flag.

Another database that maybe of interest is the VOGdb database. You can download all their VOGs, and the press them into a compiled format for hmmer:

curl -LO http://fileshare.csb.univie.ac.at/vog/latest/vog.hmm.tar.gz
mkdir vog
tar -C vog -xf vog.hmm.tar.gz
cat vog/* > VOGs.hmms
hmmpress VOGs.hmms

Metrics

We use several different metrics to predict regions that are prophages, and there are some optional metrics you can add. The default set of metrics are:

You can specify each of these options with the --metrics flag, for example:

PhiSpy.py --metrics shannon_slope

or

PhiSpy.py --metrics gc_skew

If you wish to specify more than one metric, you can either use one --metrics flag and list your options, e.g.

PhiSpy.py --metrics shannon_slope gc_skew

or provide each one, e.g.:

PhiSpy.py --metrics shannon_slope --metrics gc_skew

The default is all of these, and so ommitting a --metrics flag is equivalent to

PhiSpy.py --metrics orf_length_med shannon_slope at_skew gc_skew max_direction

The choice(s) you provide are recorded in the log file.

You can also add a few other options

Help

For the help menu use the -h option:

python PhiSpy.py -h

Output Files

PhiSpy has the option of creating multiple output files with the prophage data:

  1. prophage_coordinates.tsv (code: 1)

This is the coordinates of each prophage identified in the genome, and their att sites (if found) in tab separated text format.

The columns of the file are:

  1. GenBank format output (code: 2)

We provide a duplicate GenBank record that is the same as the input record, but we have inserted the prophage information, including att sites into the record.

If the original GenBank file was provided in gzip format this file will also be created in gzip format.

  1. prophage and bacterial sequences (code: 4)

PhiSpy can automatically separate the DNA sequences into prophage and bacterial components. If this output is chosen, we generate both fasta and GenBank format outputs:

  1. prophage_information.tsv (code: 8)

    This is a tab separated file, and is the key file to assess prophages in genomes (see assessing predictions, below). The file contains all the genes of the genome, one per line. The tenth colum represents the status of a gene. If this column is 0 then we consider this a bacterial gene. If it is non-zero it is probably a phage gene, and the higher the score the more likely we believe it is a phage gene. This is the raw data that we use to identify the prophages in your genome.

This file has 16 columns:

If we can detect the att sites, the additional columns are:

  1. prophage.tsv (code: 16)

This is a simpler version of the _prophagecoordinates.tsv file that only has prophage number, contig, start, and stop.

  1. GFF3 format (code: 32)

This is the prophage information suitable for insertion into a GFF3. This is a legacy file format, however, since GFF3 is no longer widely supported, this only has the prophage coordinates. Please post an issue on GitHub if more complete GFF3 files are required.

  1. prophage.tbl (code: 64)

This file has two columns separated by tabs [prophage_number, location]. This is a also a legacy file that is not generated by default. The prophage number is a sequential number of the prophage (starting at 1), and the location is in the format: contig_start_stop that encompasses the prophage.

  1. test data (code: 128)

This file has the data used in the random forest. The columns are:

The numbers are averaged across a window of size specified by --window_size

Choosing which output files are created.

We have provided the option (--output_choice) to choose which output files are created. Each file above has a code associated with it, and to include that file add up the codes:

Code File
1 prophage_coordinates.tsv
2 GenBank format output
4 prophage and bacterial sequences
8 prophage_information.tsv
16 prophage.tsv
32 GFF3 format output of just the prophages
64 prophage.tbl
128 test data used in the random forest
256 GFF3 format output for the annotated genomic contigs

So for example, if you want to get GenBank format output (2) and prophage_information.tsv (8), then enter an --output_choice of 10.

The default is 3: you will get both the prophage_coordinates.tsv and GenBank format output files.

Note: Choice 32 will only output the prophages themselves in GFF3 format. In contrast, choice 256 outputs annotated genomes. This is probably the best choice to bring the genome into Artemis as it will handle multiple contigs correctly.

If you want all files output, use --output_choice 512.

Example Data

To analyze this data, you can use:

PhiSpy.py -o output_directory -t data/trainSet_160490.61.txt tests/Streptococcus_pyogenes_M1_GAS.gb.gz

And you should get a prophage table that has this information (for example, take a look at output_directory/prophage.tbl).

Prophage number Contig Start Stop
pp_1 NC_002737 529631 569288
pp_2 NC_002737 778642 820599
pp_3 NC_002737 1192630 1222549
pp_4 NC_002737 1775862 1782822

Assessing predictions

As with any software, it is critical that you assess the output from phispy to see if it actually makes sense! We start be ensuring we have the prophage_information.tsv file output (this is not output by default, and requires adding 8 to the --output-choice flag).

That is a tab-separated text file that you can import into Microsoft Excel, LibreOffice Calc, Google Sheets, or your favorite spreadsheet viewing program.

There are a few columns that you should pay attention to:

We recommend:

  1. Freeze the first row of the spreadsheet so you can see the column headers
  2. Sort the spreadsheet by the my status column and color any row red where the value in this column is greater than 0
  3. Sort the spreadsheet by the final status column and color those rows identified as a prophage green.
  4. Sort the spreadsheet by the position column.

Now all the prophages are colored green, while all the potential prophage genes that are not included as part of a prophage are colored red. You can easily review those non-prophage regions and determine whether you think they should be included in prophages. Note that in most cases you can adjust the phispy parameters to include regions you think are prophages.

Note: Ensure that while you are reviewing the results, you pay particular attention to the contig column. In partial genomes, contig breaks are very often located in prophages. This is usual because prophages often contain sequences that are repeated around the genome. We have an open issue open issue to try and resolve this in a meaningful way.

Interactive PhiSpy

We have created a jupyter notebook example where you can run PhiSpy to test the effect of the different parameters on your prophage predictions. Change the name of the genbank file to point to your genome, and change the values in parameters and see how the prophage predictions vary!

Tips, Tricks, and Errors

If you are feeling lazy, you actually only need to use sudo apt install -y python3-pip; python3 -m pip install phispy since python3-pip requires build-essential and python3-dev!

If you try PhiSpy.py -v and get an error like this:

$ PhiSpy.py -v
-bash: PhiSpy.py: command not found

Then you can either use the full path:

~/.local/bin/PhiSpy.py -v

or add that location to your $PATH:

echo "export PATH=\$HOME/.local/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
PhiSpy.py -v

Exit (error) codes

We use a few different error codes to signify things that we could not compute. So far, we have:

Exit Code Meaning Suggested solution
2 No input file provided We need a file to work with!
3 No output directory provided We need somewhere to write the results to!
10 No training sets available This should be in the default install. Please check your installation
11 The specific training set is not available Check the argument passed to the --training_set parameter
13 No kmers file found This should be in the default install. Please check your installation
20 IO Error There was an error reading your input file.
25 Non nucleotide base found Check for a non-standard base in your sequence
26 An ORF with no bases This is probably a really short ORF and should be deleted.
30 No contigs We filter contigs by length, and so try adjusting the --min_contig_size parameter, though the default is 5,000 bp and you will need some adjacent genes!
40 No ORFs in your genbank file Please annotate your genome, e.g. using RAST or PROKKA
41 Less than 100 ORFs are in your annotated genome. This is not enough to find a prophage Please annotate your genome, e.g. using RAST or PROKKA

Making your own training sets

If within reference datasets, close relatives to bacteria of your interest are missing, you can make your own training sets by providing at least a single genome in which you indicate prophage proteins. This is done by adding a new qualifier to GenBank annotation for each CDS feature within a prophage region: /is_phage="1". This allows PhiSpy to distinguish the signal from bacterial/phage regions and make a training set to use afterwards during classification with random forest algorithm.

We provide a script - mark_prophage_features.py, to automate that process. It updates GenBank files based on PhiSpy's prophage_predictions.tsv file format or user's tab-delimited table with the following information in columns for each prophage region:

  1. path to GenBank file
  2. replicon id
  3. prophage start coordinate
  4. prophage end coordinate

To make training sets out of your files use make_training_sets.py script. It allows you to update/extend PhiSpy's default training sets or overwrite them with just your data.

make_training_sets.py prepares all required input files, i.e. it makes phage/bacteria-specific kmers sets based on /is_phage="1" qualifiers, reads information about taxonomy (if requested for grouping with --use_taxonomy), calls PhiSpy in a training mode and prepares training sets.

make_training_sets.py -d input_directory -g groups_file --use_taxonomy -k kmer_size -t kmers_type --phmms hmm_db --threads num_threads --retrain

where:

Beside the flags that allow training with phmm signal, there are also --retrain and --absolute_retrain flags. Each of them triggers complete reanalysis of input files but were added for different reasons. The first should be used whenever any file previously used for training has changed, e.g. more/less phage proteins were marked with /is_phage="1", as it triggers preparation of new kmers files. The second additionally ignores trainingGenome_list.txt file and therefore allows to ommit PhiSpy's default reference genomes. The same will happen when trainingGenome_list.txt is missing in PhiSpy's installation directory.

All files created while training, i.e. phage/bacteria kmers and testSet for each GenBank file are stored in PhiSpyModules/data/testSets/ directory in PhiSpy's installation directory. This allows to save a bit of time when adding new genomes and retraining.

Preparing GenBank files