
#This code was made with the help from a tutorial supplied by Chad Poloni
#installing PICRUSt2 from source (manually)
#Make sure you are in the location that you want to install PICRUSt2
 
wget https://github.com/picrust/picrust2/archive/v2.5.2.tar.gz	#This line downloads the PICRUSt2 tool as a compressed file to your current directory
tar xvzf  v2.5.2.tar.gz	# Decompress the file
cd picrust2-2.5.2/	#Enter the picrust2 directory


#Before running the below lines of code, exit the qiime environment if you are in one. 
conda deactivate

conda env create -f picrust2-env.yaml	#create the conda environment with some modifications from the picrust2-env.yaml file. This can take up to 30mins.
conda activate picrust2		#Activate the environment
pip install --editable .	#Install PICRUSt2

pytest		#Run a test with sample data to make sure it is working!
			#If your test passes with 59/60 tests successful, we will ingore the failed test and move forward.




#To Run, we need these files:

									
									#seqs.fna	 (The rep-seqs.qza file)
									#feature-table.biom	 (the table.qza*)
qiime tools export --input-path /picrust/rep-seqs.qza --output-path seqs_export #This is how you can export your rep-seqs.qza to a .fna or .fasta file format


* - filter the table.qza to remove all the features with 5 or lower counts. This will make the PICRUSt2 analysis much faster.
							qiime feature-table filter-features \
							  --i-table table.qza \
							  --p-min-frequency 5 \
							  --o-filtered-table feature-freq-filt-table.qza
qiime tools export \
   --input-path feature-freq-filt-table.qza \
   --output-path /picrust2-2.5.2	#this will create the feature-table.biome file needed						  
							  
							  
#Running PICRUSt2 Analysis!
#Move the dna-sequences.fasta (the seqs.fna file) file to the picrust2-2.5.2/ folder
#Make sure you are in the picrust2-2.5.2/ folder for the following code

picrust2_pipeline.py -s /dna-sequences.fasta -i /feature-table.biom -o picrust2_out_pipeline -p 1 	#This will 30-60 mins depending on your dataset.


# Your result will be a folder titled picrust2_out_pipeline
# transfer this folder to your personal computer using the scp -r command to run the picrust function in R