# $NetBSD$
#
###########################################################
#               Generated by fbsd2pkg                     #
###########################################################

# To-do:
#	Unbundle collectl (low priority)

# 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.
# collectl 3.7.4
# samtools 0.1.19 (must use this version: 1.x does not work well)
# jellyfish 2.1.4 (2.2.0 seems OK)
# parafly 0.1 (determined from config.h)
# fastool 7c3e034f05 Nov 18 2013 commit on Github
# htslib 1.2.1
# slclust unknown (last version on SF is 02022010)
# Trimmomatic 0.32

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

#USE_JAVA=	yes
#JAVA_VERSION=	1.7 1.6
#		slclust:/usr/wip/biology/slclust

DEPENDS+=	coreutils>=0:../../sysutils/coreutils
DEPENDS+=	bowtie<2:../../wip/bowtie
DEPENDS+=	bowtie2>=2:../../wip/bowtie2
DEPENDS+=	jellyfish>=2.1.4:../../wip/jellyfish2
DEPENDS+=	parafly>=0:../../wip/parafly
DEPENDS+=	fastool>=0:../../wip/fastool
DEPENDS+=	p5-transdecoder>=0:../../wip/p5-transdecoder
DEPENDS+=	Trimmomatic>=0.32:../../wip/trimmomatic
DEPENDS+=	rsem>=1.2.30:../../wip/rsem
DEPENDS+=	slclust>=0:../../wip/slclust
DEPENDS+=	samtools>=1.3:../../wip/samtools

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

MAINTAINER=	bacon4000@gmail.com
HOMEPAGE=	http://trinityrnaseq.github.io/
COMMENT=	Trinity assembles transcript sequences from Illumina RNA-Seq data

DEPENDS+=	dos2unix>=0:../../converters/dos2unix

# Check this
LICENSE=	modified-bsd

# Test and change if necessary.
# MAKE_JOBS_SAFE=	no

ONLY_FOR_PLATFORM=	 *-*-x86_64

SUBST_CLASSES+=		env
SUBST_STAGE.env=	post-patch
SUBST_SED.env+=		-e "s|gcc|${CC}|g"
SUBST_SED.env+=		-e "s|g++|${CXX}|g"
SUBST_FILES.env+=	${WRKSRC}/Chrysalis/Makefile*
SUBST_FILES.env+=	${WRKSRC}/trinity-plugins/fstrozzi-Fastool-7c3e034f05/Makefile
SUBST_FILES.env+=	${WRKSRC}/trinity-plugins/slclust/src/Makefile

SUBST_CLASSES+=		collectl
SUBST_STAGE.collectl=	post-patch
SUBST_SED.collectl+=	-e 's|make |${MAKE} |g'
SUBST_FILES.collectl+=	${WRKSRC}/trinity-plugins/collectl/build_collectl.sh

SUBST_CLASSES+=		path
SUBST_STAGE.path=	post-patch
SUBST_SED.path+=	-e 's|$$FindBin::Bin|$$FindBin::Bin/../libexec/trinity|g'
SUBST_SED.path+=	-e 's|$$FindBin::RealBin|$$FindBin::RealBin/../libexec/trinity|g'
SUBST_SED.path+=	-e 's|$$ROOTDIR/trinity-plugins/BIN|&:$$JELLYFISH_DIR/bin:$$FASTOOL_DIR|g'
SUBST_SED.path+=	-e 's|$$JELLYFISH_DIR/bin/jellyfish|jellyfish|g'
SUBST_SED.path+=	-e 's|$$FASTOOL_DIR/fastool|fastool|g'
SUBST_SED.path+=	-e 's|$$ROOTDIR/trinity-plugins/parafly/bin/ParaFly|ParaFly|g'
SUBST_SED.path+=	-e 's|$$ROOTDIR/trinity-plugins/Trimmomatic/trimmomatic.jar|${PREFIX}/lib/java/trimmomatic.jar|g'
SUBST_SED.path+=	-e 's|$$ROOTDIR/trinity-plugins/Trimmomatic|${PREFIX}/share/Trimmomatic|g'
SUBST_FILES.path+=	${WRKSRC}/Trinity

SUBST_CLASSES+=		upath
SUBST_STAGE.upath=	post-patch
SUBST_SED.upath+=	-e 's|$$JELLYFISH_DIR/bin/jellyfish|jellyfish|g'
SUBST_SED.upath+=	-e 's|$$FASTOOL_DIR/fastool|fastool|g'
SUBST_FILES.upath+=	${WRKSRC}/util/insilico_read_normalization.pl

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

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

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

SUBST_CLASSES+=		trinpath
SUBST_STAGE.trinpath=	post-patch
SUBST_SED.trinpath+=	-e 's|$$BASEDIR/Trinity|Trinity|g'
SUBST_FILES.trinpath+=	${WRKSRC}/util/run_Trinity_edgeR_pipeline.pl

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

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

USE_LANGUAGES=	c c++
USE_TOOLS+=	bash gmake pax perl
REPLACE_BASH=	util/*/*.sh trinity-plugins/collectl/build_collectl.sh
REPLACE_PERL=	Trinity util/*.pl util/fasta_tool util/misc/Monarch \
		util/*/*.pl util/*/*/*.pl util/*/*/*/*.pl \
		Chrysalis/*.pl PerlLib/*.p* PerlLib/*/*.pm \
		trinity-plugins/GAL_0.2.1/fasta_tool
REPLACE_PYTHON=	trinity-plugins/collectl/collectl2html \
		util/deprecated/eXpress_util/*.py

WRKSRC=		${WRKDIR}/trinityrnaseq-${PORTVERSION}

CFLAGS+=	-fopenmp
CXXFLAGS=	-fopenmp

PORTVERSION=	2.1.1
EXAMPLESDIR=	${PREFIX}/share/examples/trinity
LIBEXEC_DIR=	${PREFIX}/libexec/trinity
PLUGINS_DIR=	${LIBEXEC_DIR}/trinity-plugins

INSTALLATION_DIRS= \
	bin \
	libexec/trinity/Chrysalis \
	libexec/trinity/Inchworm/bin \
	libexec/trinity/Butterfly \
	libexec/trinity/trinity-plugins/collectl \
	libexec/trinity/trinity-plugins/scaffold_iworm_contigs

pre-patch:
	dos2unix \
		${WRKSRC}/PerlLib/HPC/GridRunner.pm \
		${WRKSRC}/PerlLib/HPC/SLURM_handler.pm

.if ${CXX} != g++
post-patch:
	${MV} -n ${WRKSRC}/Chrysalis/Makefile_g++ \
		${WRKSRC}/Chrysalis/Makefile_${CXX}
	${MV} -n ${WRKSRC}/Chrysalis/Makefile_g++_x86_64 \
		${WRKSRC}/Chrysalis/Makefile_${CXX}_x86_64
	${MV} -n ${WRKSRC}/Chrysalis/Makefile_g++_i386 \
		${WRKSRC}/Chrysalis/Makefile_${CXX}_i386
.endif

# FIXME: More may need to be installed
do-install:
	${INSTALL_SCRIPT} ${WRKSRC}/Trinity ${DESTDIR}${PREFIX}/bin
	cd ${WRKSRC}/Chrysalis && \
		${INSTALL_PROGRAM} BreakTransByPairs Chrysalis \
			CreateIwormFastaBundle \
			GraphFromFasta GraphFromFasta_MPI \
			IsoformAugment JoinTransByPairs QuantifyGraph \
			ReadsToTranscripts ReadsToTranscripts_MPI \
			ReadsToTranscripts_MPI_chang RunButterfly \
			TranscriptomeFromVaryK checkLock \
			${DESTDIR}${LIBEXEC_DIR}/Chrysalis
	${INSTALL_SCRIPT} ${WRKSRC}/Chrysalis/ReadsToComponents.pl \
		${DESTDIR}${LIBEXEC_DIR}/Chrysalis
	${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 -s ',.*.orig$$,,' \
		${DESTDIR}${LIBEXEC_DIR}
	cd ${WRKSRC} && pax -rw util ${DESTDIR}${LIBEXEC_DIR}
	cd ${WRKSRC}/trinity-plugins/collectl && \
		pax -rw bin ${DESTDIR}${PLUGINS_DIR}/collectl
	cd ${WRKSRC}/trinity-plugins && \
		pax -rw GAL_0.2.1 ${DESTDIR}${PLUGINS_DIR}
	${INSTALL_PROGRAM} ${WRKSRC}/trinity-plugins/scaffold_iworm_contigs/scaffold_iworm_contigs \
		${DESTDIR}${PLUGINS_DIR}/scaffold_iworm_contigs
	cd ${WRKSRC}/sample_data && pax -rw * \
		${DESTDIR}${EXAMPLESDIR}

.include "../../wip/htslib/buildlink3.mk"
.include "../../devel/libexecinfo/buildlink3.mk"
.include "../../devel/zlib/buildlink3.mk"
.include "../../lang/python/application.mk"
.include "../../mk/curses.buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
