# $NetBSD$
#
###########################################################
#                  Generated by fbsd2pkg                  #
#              Fri Sep 14 20:48:17 CDT 2018               #
###########################################################

###########################################################
# Unconverted and partially converted FreeBSD port syntax:

# Trinity core programs: Inchworm, Chrysalis, Butterfly
# Bundled plugins: Trinity is very sensitive to having the correct versions
# of some of these.  Test thoroughly if you change any of them.
# To-do:
#	Unbundle collectl (low priority)
## Should work on other 64-bit archs, but untested
#ONLY_FOR_ARCH=	amd64

# Should salmon use bl3?
# bowtie should not have bl3
DEPENDS=	coreutils>=0:../../sysutils/coreutils
DEPENDS+=	slclust>=0.0.0.20100202:../../wip/slclust
DEPENDS+=	salmon>=0.11.3:../../wip/salmon
DEPENDS+=	bowtie>=1.1.2:../../wip/bowtie
DEPENDS+=	bowtie2>=2.3.4.2:../../wip/bowtie2
DEPENDS+=	samtools>=1.9:../../wip/samtools
DEPENDS+=	jellyfish>=2.2.10:../../wip/jellyfish2
DEPENDS+=	parafly>=2013.01.21:../../wip/parafly
DEPENDS+=	fastool>=0.1.4:../../wip/fastool
DEPENDS+=	p5-transdecoder>=5.3.0:../../wip/p5-transdecoder
DEPENDS+=	Trimmomatic>=0.38:../../wip/trimmomatic
DEPENDS+=	rsem>=1.2.30:../../wip/rsem
DEPENDS+=	ncbi-blast+>=2.7.1:../../biology/ncbi-blast+

DISTNAME=	trinity-${PV}
CATEGORIES=	biology
MASTER_SITES=	${MASTER_SITE_GITHUB:=trinityrnaseq/}
GITHUB_PROJECT=	trinityrnaseq
GITHUB_TAG=	Trinity-v${PV}

MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	https://trinityrnaseq.github.io/
COMMENT=	Assembles transcript sequences from Illumina RNA-Seq data
LICENSE=	modified-bsd

USE_LANGUAGES=	c c++
USE_JAVA=	run
USE_TOOLS+=	bash cmake gmake pax perl

REPLACE_BASH=		util/*/*.sh
REPLACE_BASH+=		util/*/*/*.sh
REPLACE_BASH+=		Analysis/*/*/*.sh
REPLACE_PERL=		Trinity util/misc/Monarch
REPLACE_PERL+=		util/*.pl util/*/*.pl util/*/*/*.pl util/*/*/*/*.pl
REPLACE_PERL+=		Chrysalis/analysis/*.pl
REPLACE_PERL+=		Analysis/*/*.pl Analysis/*/*/*.pl Analysis/*/*/*/*.pl
REPLACE_PERL+=		Analysis/*/*.cgi Analysis/*/PtR
REPLACE_PERL+=		PerlLib/*.pm PerlLib/*/*.pm PerlLib/*.ph PerlLib/*.pl
REPLACE_PYTHON=		util/support_scripts/trinity_installer.py
REPLACE_PYTHON+=	util/misc/alt_GG_read_partitioning_JCornish/genwig2.py
REPLACE_PYTHON+=	util/misc/sim_test_framework/run_Trinity_eval.sh
REPLACE_PYTHON+=	util/misc/TPM_weighted_gene_length.py
REPLACE_PYTHON+=	Analysis/SuperTranscripts/*.py
REPLACE_PYTHON+=	Analysis/SuperTranscripts/*/*.py
REPLACE_RSCRIPT+=	Analysis/*/*.Rscript
REPLACE_RSCRIPT+=	util/misc/*.Rscript

SUBST_CLASSES+=		paths
SUBST_STAGE.paths=	post-patch
SUBST_SED.paths+=	-e 's|$$FindBin::Bin|$$FindBin::Bin/../libexec/trinity|g'
SUBST_SED.paths+=	-e 's|$$FindBin::RealBin|$$FindBin::RealBin/../libexec/trinity|g'
SUBST_SED.paths+=	-e 's|$$ROOTDIR/trinity-plugins/BIN/ParaFly|ParaFly|g'
SUBST_SED.paths+=	-e 's|$$ROOTDIR/trinity-plugins/Trimmomatic/trimmomatic.jar|${JAVAJARDIR}/trimmomatic.jar|g'
SUBST_SED.paths+=	-e 's|$$ROOTDIR/trinity-plugins/Trimmomatic|${PREFIX}/share/Trimmomatic|g'
SUBST_FILES.paths+=	${WRKSRC}/Trinity

SUBST_CLASSES+=		jelly
SUBST_STAGE.jelly=	post-patch
SUBST_SED.jelly+=	-e 's|$$JELLYFISH_DIR/bin/jellyfish|jellyfish|g'
SUBST_FILES.jelly+=	${WRKSRC}/util/misc/run_jellyfish.pl

SUBST_CLASSES+=		trimmo
SUBST_STAGE.trimmo=	post-patch
SUBST_SED.trimmo+=	-e 's|$$FindBin::RealBin/../../trinity-plugins/Trimmomatic/trimmomatic.jar|${JAVAJARDIR}/trimmomatic.jar|g'
SUBST_SED.trimmo+=	-e 's|/seq/regev_genome_portal/SOFTWARE/BIN/trimmomatic.jar|${JAVAJARDIR}/trimmomatic.jar|g'
SUBST_FILES.trimmo+=	${WRKSRC}/util/misc/run_trimmomatic_qual_trimming.pl

SUBST_CLASSES+=		rpath
SUBST_STAGE.rpath=	post-patch
SUBST_SED.rpath+=	-e "s|-lm -pthread|-lm -pthread -Wl,-rpath=${_GCC_RUNTIME}|g"
SUBST_FILES.rpath+=	${WRKSRC}/Chrysalis/Makefile

SUBST_CLASSES+=		trinity
SUBST_STAGE.trinity=	post-patch
SUBST_SED.trinity+=	-e 's|$$FindBin::Bin/../../Trinity|Trinity|g'
SUBST_FILES.trinity+=	${WRKSRC}/util/support_scripts/write_partitioned_trinity_cmds.pl

SUBST_CLASSES+=		build
SUBST_STAGE.build=	post-build
SUBST_SED.build+=	-e "s|/usr/bin/perl|${PREFIX}/bin/perl|g"
SUBST_FILES.build+=	${WRKSRC}/trinity-plugins/COLLECTL/collectl/collectl
SUBST_FILES.build+=	${WRKSRC}/trinity-plugins/COLLECTL/collectl/*.pl

CFLAGS+=	-fopenmp
CXXFLAGS=	-fopenmp

PV=		2.8.3
EXAMPLESDIR=	${PREFIX}/share/examples/trinity
LIBEXEC_DIR=	${PREFIX}/libexec/trinity
PLUGINS_DIR=	${LIBEXEC_DIR}/trinity-plugins

REPLACE_INTERPRETER+=	Rscript
REPLACE.Rscript.old=	.*Rscript
REPLACE.Rscript.new=	${PREFIX}/bin/Rscript
REPLACE_FILES.Rscript=	${REPLACE_RSCRIPT}

# Sets OPSYS, OS_VERSION, MACHINE_ARCH, etc..
# .include "../../mk/bsd.prefs.mk"

INSTALLATION_DIRS=	bin libexec/trinity/Chrysalis/bin libexec/trinity/Inchworm/bin libexec/trinity/Butterfly libexec/trinity/trinity-plugins/scaffold_iworm_contigs libexec/trinity/trinity-plugins/BIN share/examples

post-extract:
	${CHMOD} -R g-w ${WRKSRC}

# FIXME: More may need to be installed
do-install:
	${INSTALL_SCRIPT} ${WRKSRC}/Trinity ${DESTDIR}${PREFIX}/bin
	${INSTALL_PROGRAM} ${WRKSRC}/Chrysalis/bin/* \
		${DESTDIR}${LIBEXEC_DIR}/Chrysalis/bin
	${INSTALL_SCRIPT} ${WRKSRC}/Chrysalis/analysis/ReadsToComponents.pl \
		${DESTDIR}${LIBEXEC_DIR}/Chrysalis/bin
	${INSTALL_PROGRAM} ${WRKSRC}/Inchworm/bin/* \
		${DESTDIR}${LIBEXEC_DIR}/Inchworm/bin
	${INSTALL_SCRIPT} ${WRKSRC}/Butterfly/Butterfly.jar \
		${DESTDIR}${LIBEXEC_DIR}/Butterfly
	cd ${WRKSRC} && pax -rw PerlLib \
		${DESTDIR}${LIBEXEC_DIR}
	cd ${WRKSRC} && pax -rw util \
		${DESTDIR}${LIBEXEC_DIR}
	cd ${WRKSRC} && pax -rw Analysis \
		${DESTDIR}${LIBEXEC_DIR}
	${INSTALL_PROGRAM} ${WRKSRC}/trinity-plugins/scaffold_iworm_contigs/scaffold_iworm_contigs \
		${DESTDIR}${PLUGINS_DIR}/scaffold_iworm_contigs
	${INSTALL_PROGRAM} ${WRKSRC}/trinity-plugins/BIN/seqtk-trinity \
		${DESTDIR}${PLUGINS_DIR}/BIN
	cd ${WRKSRC}/sample_data && pax -rw * \
		${DESTDIR}${EXAMPLESDIR}
	${LN} -fs ${PREFIX}/bin/Trinity \
		${DESTDIR}${PREFIX}/libexec/trinity/Trinity
	${RM} ${DESTDIR}${PREFIX}/libexec/trinity/util/support_scripts/plugin_install_tests.sh.orig

.include "../../biology/htslib/buildlink3.mk"
.include "../../lang/python/application.mk"
.include "../../devel/zlib/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
