#!/usr/bin/csh -f 
# purchact_one
# this script loops over each purchasable library
# and considers all bioactive molecules from a given source catalog
# we look for a. exact match, b. up to anon=2,dist=3, 
# c. (future) BM scaffold,
# d. (future) bioisosteres,
# e. (future)  retrosynthesis analog library

setenv ROOT /export/exk/newdbpublic
setenv BCTYPE  invivo # Bioactive Catalog Type.  one of invitro invivo natural
setenv BCSUBTYPE  approve  # Bioactive Catalog Subtype. one of available
setenv SWDIR /nfs/db2/sw_anon_25Q4
setenv PURCH /nfs/db5/newdb/Purch/maps


foreach i ($ROOT/Bioact/$BCTYPE/$BCSUBTYPE/*)
	mkdir -p $ROOT/Purchbioact/$BCTYPE/$BCSUBTYPE
	cd $ROOT/Purchbioact/$BCTYPE/$BCSUBTYPE

	setenv bacat $i:t:r:r # bioactive catalog name
	echo bacat $bacat
	mkdir -p $bacat
	pushd $bacat
	#foreach bioactive compound in this catalog
	foreach thiscmpd (`cat $i`)
		#for each compound
		echo i $i
		echo thiscmpd $thiscmpd
		echo $thiscmpd > tmp
		# here is where we start to blast
		# for each purch catalog class
		exit
		foreach class (cc ise iso ode odo oth) 
			pushd $class
			# now look over each purchasable catalog in this class
			foreach purchcat ( /mnt/nfs/db5/newdb/Purch/maps/$class/*.map )
				setenv k $cat:t:r:r
				setenv l $k:r
				echo k $k l  $l class $class i $i 
				echo python  /nfs/exk/newdb/SWAG/prog9a.py -f $i.smi -d $k
				# if (-z $l.txt) then /bin/rm -f $l.txt else echo not empty $l endif
				# end of catalogs for this purchasable class 
			end
		
			popd
			# end of this purchasable class
		end
		# end of this bioactive catalog subtype
	popd
	end
	# end of this bioactive class
end
