#!/usr/bin/perl -w
use strict;
use AnalysisFunctions;
use MotifFunctions;
use Getopt::Std;

#Input options
#############################################
my %options = ();
getopt("iobpswWmchtdlf", \%options);
if ($options{i}){}else{print"Input sequence file not defined\n"; error()};
if ($options{b}){}else{print"Background sequence file not defined\n"; error()};
if ($options{p}){}else{print"Markov file not defined\n"; error()};
if ($options{s}){}else{$options{s} = $options{b}};

if ($options{w}){}else{$options{w} = '8'};
if ($options{W}){}else{$options{W} = '12'};
if ($options{w} > $options{W}){print"Minimum motif width is longer than Maximum motif width\n"};

if ($options{h}){}else{$options{h} = '10000'};
if ($options{m}){}else{$options{m} = '10'};
if ($options{c}){}else{$options{c} = '0.7'};

if ($options{t}){}else{$options{t} = 'gsmbr'};
if ($options{d}){}else{$options{d} = '1000'};
if ($options{f}){}else{$options{f} = 'all'};
if ($options{f} =~ /m/ || $options{f} =~ /all/i) {
	if ($options{p} ){}else{print"Markov background file not defined\n"; error()};
}

#Set directories
#############################################
my $dir = $options{i};
$dir =~ s/\.\w+$//;
if ($options{o}){
	my @tree = split(/\//, $options{i});
	my $root = $tree[$#tree];
	$root =~ s/\.\w+$//;
	$dir = "$options{o}\/$root";
}
#Set Logfile
#############################################
my $logfile = "$dir\.log";
open (OUT, "> $logfile");
open (STDOUT, ">&OUT");
open (STDERR, ">&OUT");

#Set timer
#############################################
my $totaltime = -time();
print localtime(time())."\n";

#load tranfac
#############################################
my $transfac =  new MotifFunctions;
$transfac->load_transfac($options{l});

#set up analysis parameters
#############################################
my $programs = new AnalysisFunctions;
$programs->load_config('./Configure.ini');
$programs->set_background_files($options{s}, $options{b}, $options{p});
$programs->set_transfac_files($options{l});
$programs->set_scansites($options{h});
$programs->set_sequence($options{i});
my $motifs_total = $options{m} * ($options{W} - $options{w} + 1);

#Set programs
#############################################
my %programs = ();
if ($options{f} =~ /all/i) {
	$programs{AlignACE} = 'AlignACE';
	$programs{BioProspector} = 'BioProspector';
	$programs{MEME} = 'MEME';
	$programs{MDscan} = 'MDscan';
}else {
	my @symbols = split('', $options{f});
	foreach my $symbol (@symbols) {
		if ($symbol eq 'm') {
			$programs{MEME} = 'MEME';
		}elsif ($symbol eq 'b'){
			$programs{BioProspector} = 'BioProspector';
		}elsif ($symbol eq 'a'){
			$programs{AlignACE} = 'AlignACE';
		}elsif ($symbol eq 'd'){
			$programs{MDscan} = 'MDscan';
		}else{
			print "Unrecognized program symbol \n";
			error();
		}
	}
}

#Set scoring schemes
#############################################
my %scoringSchemes;
{
	my @schemes = split ('', $options{t});
	foreach my $scheme (@schemes) {
		if ($scheme eq 'g') {
			$scoringSchemes{Group}='Group';
		}elsif ($scheme eq 's'){
			$scoringSchemes{Site} = 'Site';
		}elsif ($scheme eq 'm'){
			$scoringSchemes{Score} ='Score';
		}elsif ($scheme eq 'b'){
			$scoringSchemes{Bits} = 'Bits';
		    }elsif ($scheme eq 'r'){
			$scoringSchemes{Ratio} = 'Ratio';
		    }
		else {
			print "Unrecognized scoring scheme \n";
			error();
		}
	}
}

#Initalize and run MotifSearch
#############################################
my $acefile = undef;
my $outfile = undef;
my $outstat = undef;
my %motifFunctions = ();
foreach my $program (keys(%programs)) {
	my $motifs =  new MotifFunctions;
	$motifFunctions{$program} = $motifs;
};

my $aligntime = 0;
my $mdtime = 0;
my $biotime = 0;
my $memetime = 0;
my $scantime = 0;
my $starttime = 0;
my $endtime = 0;

for my $width($options{w} .. $options{W}){
	my $bases = "$width"."bp";
	if (exists($programs{AlignACE})) {
                print localtime(time())."\n";
		my $motifs = new MotifFunctions;
		$outfile = "$dir$bases"."AlignACE\.txt";
		$acefile = "$dir$bases"."AlignACE\.ace";
		$outstat = "$dir$bases"."AlignACE\.stat";
		$starttime =  time();
		$programs->run_alignace($outfile, $width, '8', '5', '200', '4584'  );
		$endtime =  time();
		$aligntime += ($endtime - $starttime);
  
		$motifs->load_alignace($outfile, $options{m}, 'AlignACE');
                $motifs->eliminate_fragments('6');
		$motifs->list_alignace($acefile, $options{m});

                my $alignmotifs = new MotifFunctions;
                $alignmotifs->load_alignace($acefile, $options{m}, 'AlignACE');
                $alignmotifs->block_filter('0.5', '3', '0.7', '4', '3');
		$starttime =  time();
		$programs->run_scanace($acefile, 1);
		$endtime =  time();
		$scantime += ($endtime - $starttime);
		$programs->run_motifstats($acefile, $outstat, $options{d});
		$alignmotifs->load_stats($outstat, 'AlignACE');
		$alignmotifs->scanace_stats($options{i}, $options{b}, $acefile);
		$motifFunctions{$programs{AlignACE}}->push_motifs($alignmotifs);
		print "\n";
	}
	
	if (exists($programs{BioProspector})) {
                print localtime(time())."\n";
		my $motifs = new MotifFunctions;
		$outfile = "$dir$bases"."BioProspector\.txt";
		$acefile = "$dir$bases"."BioProspector\.ace";
		$outstat = "$dir$bases"."BioProspector\.stat";
		$starttime =  time();
		$programs->run_bioprospector($outfile, $width, '40', $options{m});
		$endtime =  time();
		$biotime += ($endtime - $starttime);

		$motifs->load_bioprospector($outfile, $options{m}, 'BioProspector');
                $motifs->eliminate_fragments('6');
		$motifs->list_alignace($acefile, $options{m});

                my $biomotifs = new MotifFunctions;
                $biomotifs->load_alignace($acefile, $options{m}, 'BioProspector');
                $biomotifs->block_filter('0.5', '3', '0.7', '4', '3');
		$starttime =  time();
		$programs->run_scanace($acefile, 1);
		$endtime =  time();
		$scantime += ($endtime - $starttime);
		$programs->run_motifstats($acefile, $outstat, $options{d});
		$biomotifs->load_stats($outstat, 'BioProspector');
		$biomotifs->scanace_stats($options{i}, $options{b}, $acefile);
		$motifFunctions{$programs{BioProspector}}->push_motifs($biomotifs);
		print "\n";
	}
	
	if (exists($programs{MDscan})) {
                print localtime(time())."\n";
		my $motifs = new MotifFunctions;
		$outfile = "$dir$bases"."MDscan\.txt";
		$acefile = "$dir$bases"."MDscan\.ace";
		$outstat = "$dir$bases"."MDscan\.stat";
		$starttime =  time();
		$programs->run_mdscan($outfile, $width, $options{m}, '50', '10', '20');
		$endtime =  time();
		$mdtime += ($endtime - $starttime);

		$motifs->load_mdscan($outfile, $options{m}, 'MDscan');
                $motifs->eliminate_fragments('6');
		$motifs->list_alignace($acefile, $options{m});

                my $mdscanmotifs = new MotifFunctions;
                $mdscanmotifs->load_alignace($acefile, $options{m}, 'MDscan');
                $mdscanmotifs->block_filter('0.5', '3', '0.7', '4', '3');
		$starttime =  time();
		$programs->run_scanace($acefile, 1);
		$endtime =  time();
		$scantime += ($endtime - $starttime);
		$programs->run_motifstats($acefile, $outstat, $options{d});
		$mdscanmotifs->load_stats($outstat, 'MDscan');
		$mdscanmotifs->scanace_stats($options{i}, $options{b}, $acefile);
		$motifFunctions{$programs{MDscan}}->push_motifs($mdscanmotifs);
		print "\n";
	}
	
	if (exists($programs{MEME})) {
                print localtime(time())."\n";
		my $motifs = new MotifFunctions;
		$outfile = "$dir$bases"."Meme\.txt";
		$acefile = "$dir$bases"."Meme\.ace";
		$outstat = "$dir$bases"."Meme\.stat";
		$starttime =  time();
		$programs->run_meme_fixed($outfile, $width, $options{m});
		$endtime =  time();
		$memetime += ($endtime - $starttime);

		$motifs->load_meme($outfile, $options{m}, 'MEME');
                $motifs->eliminate_fragments('6');
		$motifs->list_alignace($acefile, $options{m});

                my $mememotifs = new MotifFunctions;
                $mememotifs->load_alignace($acefile, $options{m}, 'MEME');
                $mememotifs->block_filter('0.5', '3', '0.7', '4', '3');
		$starttime =  time();
		$programs->run_scanace($acefile, 1);
		$endtime =  time();
		$scantime += ($endtime - $starttime);
		$programs->run_motifstats($acefile, $outstat, $options{d});
		$mememotifs->load_stats($outstat, 'MEME');
		$mememotifs->scanace_stats($options{i}, $options{b}, $acefile);
		$motifFunctions{$programs{MEME}}->push_motifs($mememotifs);
		print "\n";
	}
};

#Set ranks
#############################################
print "Setting Ranks\n";
foreach my $program (keys(%programs)) {
	foreach my $scheme (keys(%scoringSchemes)) {
		if ($scoringSchemes{$scheme} =~ /Group/i) {
			$motifFunctions{$programs{$program}}->sort_group();
			$motifFunctions{$programs{$program}}->rank_group();
		}elsif ($scoringSchemes{$scheme} =~ /Site/i) {
			$motifFunctions{$programs{$program}}->sort_site();
			$motifFunctions{$programs{$program}}->rank_site();
		}elsif ($scoringSchemes{$scheme} =~ /Bits/i) {
			$motifFunctions{$programs{$program}}->sort_bits();
			$motifFunctions{$programs{$program}}->rank_bits();
		}elsif($scoringSchemes{$scheme} =~ /Score/i) {
			$motifFunctions{$programs{$program}}->sort_motifscore();
			$motifFunctions{$programs{$program}}->rank_motifscore();
		}elsif($scoringSchemes{$scheme} =~ /Ratio/i) {
			$motifFunctions{$programs{$program}}->sort_ratio();
			$motifFunctions{$programs{$program}}->rank_ratio();
		}
	}
	$motifFunctions{$programs{$program}}->sort_totalrank();
}
print "\n";

#Combined analysis
#############################################
my $outcomp = undef;
my $outtree = undef;
my $outclust = undef;
my $statsfile = undef;
my $outtrans = undef;
my $outbest = undef;
my $outbeststat = undef;
my $outgroup = undef;
my $outgroupstat = undef;
my $outsvg = undef;

my %bestAll= ();
my %bestClust = ();
my %bestFinder = ();
foreach my $scheme (keys(%scoringSchemes)) {
	$bestAll{$scheme}= new MotifFunctions;
	$bestClust{$scheme}= new MotifFunctions;
}
foreach my $program (keys(%programs)) {
	#for each motif finder list out the combined results ranked by total rank
        print localtime(time())."\n";
	print "Motif finder clustering\n";
	$outfile = "$dir"."Combined"."$programs{$program}"."\.ace";
	$outstat = "$dir"."Combined"."$programs{$program}"."\.stat";
	$outcomp = "$dir"."Combined"."$programs{$program}"."\.comp";
	$outtree = "$dir"."Combined"."$programs{$program}"."\.tree";
	$outclust = "$dir"."Combined"."$programs{$program}"."\.clust";
	$outtrans = "$dir"."Combined"."$programs{$program}"."\.trans";
	$outsvg = "$dir"."Combined"."$programs{$program}"."\.svg";
	
	$motifFunctions{$programs{$program}}->list_alignace($outfile, $motifs_total);
	$programs->run_compareace_self($outfile, $outcomp);
	$programs->run_tree($outcomp, $outtree, $options{c});
	$programs->run_list_clusters($outtree, $outclust, $options{c});
	$motifFunctions{$programs{$program}}->load_clusters($outclust);
	$motifFunctions{$programs{$program}}->load_finders();
	$programs->run_compare_transfac($outfile, $outtrans, $options{c});
	$motifFunctions{$programs{$program}}->put_transfac_id_pfm($outtrans, $options{c}, $transfac);
	$motifFunctions{$programs{$program}}->list_stats_full2($outstat);
	$motifFunctions{$programs{$program}}->motif_writer_full2($outsvg, $options{c});

	#Now for each scoring scheme load clusters
	foreach my $scheme (keys(%scoringSchemes)) {
                print localtime(time())."\n";
		print "Scoring for $scheme\n";
		
		#For each program load the best cluster memebers into the bestAll hash
		if ($scoringSchemes{$scheme} =~ /Group/i) {
			$motifFunctions{$programs{$program}}->sort_group();
			$bestAll{$scheme}->best_clusters_load($motifFunctions{$programs{$program}});
		}elsif ($scoringSchemes{$scheme} =~ /Site/i) {
			$motifFunctions{$programs{$program}}->sort_site();
			$bestAll{$scheme}->best_clusters_load($motifFunctions{$programs{$program}});
		}elsif ($scoringSchemes{$scheme} =~ /Bits/i) {
			$motifFunctions{$programs{$program}}->sort_bits();
			$bestAll{$scheme}->best_clusters_load($motifFunctions{$programs{$program}});
		}elsif($scoringSchemes{$scheme} =~ /Score/i) {
			$motifFunctions{$programs{$program}}->sort_motifscore();
			$bestAll{$scheme}->best_clusters_load($motifFunctions{$programs{$program}});
		}elsif($scoringSchemes{$scheme} =~ /Ratio/i) {
			$motifFunctions{$programs{$program}}->sort_ratio();
			$bestAll{$scheme}->best_clusters_load($motifFunctions{$programs{$program}});
		}
		
		#Resort by scheme of interest and then load into a new object
		if ($scoringSchemes{$scheme} =~ /Group/i) {
			$motifFunctions{$programs{$program}}->sort_group();
		}elsif ($scoringSchemes{$scheme} =~ /Site/i) {
			$motifFunctions{$programs{$program}}->sort_site();
		}elsif ($scoringSchemes{$scheme} =~ /Bits/i) {
			$motifFunctions{$programs{$program}}->sort_bits();
		}elsif($scoringSchemes{$scheme} =~ /Score/i) {
			$motifFunctions{$programs{$program}}->sort_motifscore();
		}elsif($scoringSchemes{$scheme} =~ /Ratio/i) {
			$motifFunctions{$programs{$program}}->sort_ratio();
		}
		$bestFinder{$scheme}{$programs{$program}} = new MotifFunctions;
		$bestFinder{$scheme}{$programs{$program}}->best_clusters_load($motifFunctions{$programs{$program}});
		
		#Rerank best cluster members
		foreach my $scheme2 (keys(%scoringSchemes)) {
			if ($scoringSchemes{$scheme2} =~ /Group/i) {
				$bestFinder{$scheme}{$programs{$program}}->sort_group();
				$bestFinder{$scheme}{$programs{$program}}->rank_group();
			}elsif ($scoringSchemes{$scheme2} =~ /Site/i) {
				$bestFinder{$scheme}{$programs{$program}}->sort_site();
				$bestFinder{$scheme}{$programs{$program}}->rank_site();
			}elsif ($scoringSchemes{$scheme2} =~ /Bits/i) {
				$bestFinder{$scheme}{$programs{$program}}->sort_bits();
				$bestFinder{$scheme}{$programs{$program}}->rank_bits();
			}elsif($scoringSchemes{$scheme2} =~ /Score/i) {
				$bestFinder{$scheme}{$programs{$program}}->sort_motifscore();
				$bestFinder{$scheme}{$programs{$program}}->rank_motifscore();
			}elsif($scoringSchemes{$scheme2} =~ /Ratio/i) {
				$bestFinder{$scheme}{$programs{$program}}->sort_ratio();
				$bestFinder{$scheme}{$programs{$program}}->rank_ratio();
			}
		}
		
		$bestFinder{$scheme}{$programs{$program}}->sort_totalrank();
		if ($scoringSchemes{$scheme} =~ /Group/i) {
			$bestFinder{$scheme}{$programs{$program}}->sort_group();
		}elsif ($scoringSchemes{$scheme} =~ /Site/i) {
			$bestFinder{$scheme}{$programs{$program}}->sort_site();
		}elsif ($scoringSchemes{$scheme} =~ /Bits/i) {
			$bestFinder{$scheme}{$programs{$program}}->sort_bits();
		}elsif($scoringSchemes{$scheme} =~ /Score/i) {
			$bestFinder{$scheme}{$programs{$program}}->sort_motifscore();
		}elsif($scoringSchemes{$scheme} =~ /Ratio/i) {
			$bestFinder{$scheme}{$programs{$program}}->sort_ratio();
		}
		
		$outbest = "$dir"."Best"."$scoringSchemes{$scheme}"."$programs{$program}"."\.ace";
		$outbeststat = "$dir"."Best"."$scoringSchemes{$scheme}"."$programs{$program}".".stat";
		$outsvg = "$dir"."Best"."$scoringSchemes{$scheme}"."$programs{$program}"."\.svg";
		$bestFinder{$scheme}{$programs{$program}}->list_alignace($outbest, 'all');
		$bestFinder{$scheme}{$programs{$program}}->list_stats_full2($outbeststat);
		$bestFinder{$scheme}{$programs{$program}}->motif_writer_full2($outsvg, $options{c});
		print "\n";
	}
	$outbest = "$dir"."BestTotalRank"."$programs{$program}"."\.ace";
	$outbeststat = "$dir"."BestTotalRank"."$programs{$program}"."\.stat";
	$outsvg = "$dir"."BestTotalRank"."$programs{$program}"."\.svg";
	$motifFunctions{$programs{$program}}->sort_totalrank();
	$bestFinder{'total'}{$programs{$program}} = new MotifFunctions;
	$bestFinder{'total'}{$programs{$program}}->best_clusters_load($motifFunctions{$programs{$program}});
	$bestFinder{'total'}{$programs{$program}}->list_alignace($outbest, 'all');
	$bestFinder{'total'}{$programs{$program}}->list_stats_full2($outbeststat);
	$bestFinder{'total'}{$programs{$program}}->motif_writer_full2($outsvg, $options{c});
	print "\n"
}

#Combining best results across different motif finders
#############################################
my @keys = keys(%programs);
my $minnumber = $#keys;
if ($minnumber >= 1) {
	print "Combined finder clustering\n";
	foreach my $best (keys(%bestAll)) {
		print "Combined results for $best\n";
		$outfile = "$dir".'Combined'."$best".'All'.'.ace';
		$outstat = "$dir".'Combined'."$best".'All'.'.stat';
		$outcomp = "$dir".'Combined'."$best".'All'.'.comp';
		$outtree = "$dir".'Combined'."$best".'All'.'.tree';
		$outclust = "$dir".'Combined'."$best".'All'.'.clust';
		$outsvg = "$dir".'Combined'."$best".'All'.'.svg';
		
		foreach my $scheme2 (keys(%scoringSchemes)) {
			if ($scoringSchemes{$scheme2} =~ /Group/i) {
				$bestAll{$best}->sort_group();
				$bestAll{$best}->rank_group();
			}elsif ($scoringSchemes{$scheme2} =~ /Site/i) {
				$bestAll{$best}->sort_site();
				$bestAll{$best}->rank_site();
			}elsif ($scoringSchemes{$scheme2} =~ /Bits/i) {
				$bestAll{$best}->sort_bits();
				$bestAll{$best}->rank_bits();
			}elsif($scoringSchemes{$scheme2} =~ /Score/i) {
				$bestAll{$best}->sort_motifscore();
				$bestAll{$best}->rank_motifscore();
			}elsif($scoringSchemes{$scheme2} =~ /Ratio/i) {
				$bestAll{$best}->sort_ratio();
				$bestAll{$best}->rank_ratio();
			}
		}
		$bestAll{$best}->sort_totalrank();
		if ($best =~ /Group/i) {$bestAll{$best}->sort_group()};
		if ($best =~ /Site/i) {$bestAll{$best}->sort_site()};
		if ($best =~ /Bits/i) {$bestAll{$best}->sort_bits()};
		if ($best =~ /Score/i) {$bestAll{$best}->sort_motifscore()};
		if ($best =~ /Ratio/i) {$bestAll{$best}->sort_ratio()};

		$bestAll{$best}->list_alignace($outfile, 'all');
		$bestAll{$best}->list_stats_full2($outstat);
		$bestAll{$best}->motif_writer_full2($outsvg, $options{c});
		$programs->run_compareace_self($outfile, $outcomp);
		$programs->run_tree($outcomp, $outtree, $options{c});
		$programs->run_list_clusters($outtree, $outclust, $options{c});
		$bestAll{$best}->load_clusters($outclust);
		$bestAll{$best}->load_finders();
		
		$outfile = "$dir".'Best'."$best".'All'.'.ace';
		$outstat = "$dir".'Best'."$best".'All'.'.stat';
		$outsvg = "$dir".'Best'."$best".'All'.'.svg';
		$bestClust{$best}->best_clusters_load($bestAll{$best});
		
		foreach my $scheme2 (keys(%scoringSchemes)) {
			if ($scoringSchemes{$scheme2} =~ /Group/i) {
				$bestClust{$best}->sort_group();
				$bestClust{$best}->rank_group();
			}elsif ($scoringSchemes{$scheme2} =~ /Site/i) {
				$bestClust{$best}->sort_site();
				$bestClust{$best}->rank_site();
			}elsif ($scoringSchemes{$scheme2} =~ /Bits/i) {
				$bestClust{$best}->sort_bits();
				$bestClust{$best}->rank_bits();
			}elsif($scoringSchemes{$scheme2} =~ /Score/i) {
				$bestClust{$best}->sort_motifscore();
				$bestClust{$best}->rank_motifscore();
			}elsif($scoringSchemes{$scheme2} =~ /Ratio/i) {
				$bestClust{$best}->sort_ratio();
				$bestClust{$best}->rank_ratio();
			}
		}
		$bestClust{$best}->sort_totalrank();
		if ($best =~ /Group/i) {$bestClust{$best}->sort_group()};
		if ($best =~ /Site/i) {$bestClust{$best}->sort_site()};
		if ($best =~ /Bits/i) {$bestClust{$best}->sort_bits()};
		if ($best =~ /Score/i) {$bestClust{$best}->sort_motifscore()};
		if ($best =~ /Ratio/i) {$bestClust{$best}->sort_ratio()};
		
		$bestClust{$best}->list_alignace($outfile, 'all');
		$bestClust{$best}->list_stats_full2($outstat);
		$bestClust{$best}->motif_writer_full2($outsvg, $options{c});
		print "\n"
	}
	print "\n"
}

$totaltime += time();
print localtime(time())."\n";
print "AlignACE time\: $aligntime sec\n";
print "MDscan time\: $mdtime sec\n";
print "BioProspector time\: $biotime sec\n";
print "MEME time\: $memetime sec\n";
print "ScanACE time\: $scantime sec\n";
print "Time to finish\: $totaltime sec\n";
close STDOUT;
close STDERR;
close OUT;

#Error function
#############################################
sub error {
	print "\n\nUsage\: perl Multifinder.pl \-i <file.seq> <options>\n";
	print"\-i    Input sequence file in fasta format\n";
	print"       \>seq1\n";
	print"       AGGTACCTGACCCAATACG\.\.\.\.\.\n";
	print"       \>seq2\n";
	print"       AGGTACCTGACCCAATACG\.\.\.\.\.\n";
	print"\-o    Output directory\n";
	print"\-b    Background sequence file in fasta format\n";
	print"       \>seq1\n";
	print"       AGGTACCTGACCCAATACG\.\.\.\.\.\n";
	print"       \>seq2\n";
	print"       AGGTACCTGACCCAATACG\.\.\.\.\.\n";
	print"\-p    Markov model of the background\n";
	print"       Same type of background file used with MEME\n";
	print"       use markov_generator\.pl\n";
	print"\-s    Sequence file used with ScanACE\n";
	print"       \(optional\) defaults to the background sequence\n";
	print"\-w    Minimum width of motif search range\n";
	print"       \(8\) The minimum motif width to be searched\n";
	print"       this value may not be less than 6\n";
	print"\-W    Maximum width of motif search range\n";
	print"       \(12\) The maximum motif width to be searched\n";
	print"       this value may not be larger than 18\n";
	print"\-m    Number of motifs to find at each width\n";
	print"       \(10\) the motif finders with attempt to find this many motifs\n";
	print"       in each width bin\n";
	print"\-c    Correlation coeffcient used to eliminate duplicates\n";
	print"       \(0\.6\)the Pearson correlation cofficent used with CompareACE\n";
	print"\-h    Maximum number of ScanACE hits \(default 10000\)\n";
	print"\-t    Target scoring functions used to cluster motifs\n";
	print"       \(gsmbr\) this is the scoring function used to select\n";
	print"       g = Group Specificity\n";
	print"       s = Site Specificity\n";
	print"       m = Motif Score\n";
	print"       b = Bit Score\n";
	print"       r = Ratio Score\n";
	print"\-d    Distance used for positional specificity calculations\n";
	print"       \(1000\) this is the distance that MotifStats considers\n";
	print"       when calculating positional specificity\n";
	print"\-l    List of transfac motifs in AlignACE format\n";
	print"       This file should contain the names of the transcription factors\n";
	print"\-f    MotifFinding programs to use\.\n";
	print"       all MDscan, BioProspector, AlignACE and MEME \(default and equivalent to \-f abmd\)\n";
	print"       a AlignACE\n";
	print"       d MDscan\n";
	print"       b BioProspector\n";
	print"       m MEME \n\n";
	die;
};

exit;

=head1 Multifinder.pl

=head2 Usage

=over 4

=item 1
perl Multifinder.pl -i <file.seq> <options>

=item 2
This script is designed to perform a 

=back

=head2 Command Line Options

=over 4

=item 1
-i    Input sequence file in fasta format
-b    Background sequence file in fasta format
Both sequence files must have unique identifiers for each sequence or MEME will eliminate the duplicates
>seq1
>NM_000034
TGCCCGTGCTCCTGCATAATGTATGAGCCCATGGTAGGAACAAAACACCAGCACCAGCGAGTCTGGGCACTGCAGGCCACGGACGTGTCCAGGGGCCTTGCCAAGGCTGAAGTCTCTCTGTTGG
>NM_000080
GTTCTCAGGGTTATTCTGAGCTCTGGCAGGCTTGGAGGGGGCATGCCAGGGTGCCTGTGTGAGGGGGAGGAGGGTGTTAGTTCCGGGCTGTTAGGGGACTGTCACCTAATCCTCTG
>NM_000257
CAGAGCAGGACAGAGCTGTGGAGCCAGACCTGGTCTCAGGGGCTGTATATATGGGGCAGCAGGGCACCCCCACCCCCAACGGCACCCAGTCCCTAGCCGGATTTAGAAAGGGCTGTTGTCACTAGAAGCATTTCCCCCAGGCTCCCCCCCTTCCCAAACAGTGCTCCCCTCCCCGCCTCTCCAGCTAGGAAACAATTGGAAGTGGTCGTCATTGTTATGGCATGG
>NM_000364
CTAAAAAGAGAACTTTCCATCTCAGGGTTTAGGGCCCTTGGCAGCAGCGAGGCATGTTCAGAGGCCCTGGAATGGG
>NM_000432
GGAACAATAAATACTTCCTCCCCATGTTTAAAAATAACCCCATGACCGCTTTTGGCAGTCATAGGTGAGGCGGGCACCACCTAAGGCCCCCCCACCCCATGCCGTTCTTCTGAAGTAAG
>NM_000747
GTAAGTAACCCTACTTGCCTTTGGGAACTCACAGCTCTCAGCCTCACCA

=item 2
Subindices can be used multiple sequences come from the same acession number
>NM_000034_1
TGCCCGTGCTCCTGCATAATGTATGAGCCCATGGTAGGAACAAAACACCAGCACCAGCGAGTCTGGGCACTGCAGGCCACGGACGTGTCCAGGGGCCTTGCCAAGGCTGAAGTCTCTCTGTTGG
>NM_000080_1
GTTCTCAGGGTTATTCTGAGCTCTGGCAGGCTTGGAGGGGGCATGCCAGGGTGCCTGTGTGAGGGGGAGGAGGGTGTTAGTTCCGGGCTGTTAGGGGACTGTCACCTAATCCTCTG
>NM_000257_2
CAGAGCAGGACAGAGCTGTGGAGCCAGACCTGGTCTCAGGGGCTGTATATATGGGGCAGCAGGGCACCCCCACCCCCAACGGCACCCAGTCCCTAGCCGGATTTAGAAAGGGCTGTTGTCACTAGAAGCATTTCCCCCAGGCTCCCCCCCTTCCCAAACAGTGCTCCCCTCCCCGCCTCTCCAGCTAGGAAACAATTGGAAGTGGTCGTCATTGTTATGGCATGG
>NM_000257_3
AGCTGGGAAGGGGCTGAGTGTCAGCAGCAGAGAAGGGTAGGACAGAGTTGGGGGCATGGC
>NM_000257_4
ACCATGGAGCTTAGAGATGGGGACTCTGGCTCAGGCACTGATTTCCTTGGACCAGCAGGCAATGTGT
>NM_000257_5
GCATTGTGCCGGCTTTGTCTGCACTCTGTCACCACCCTGATCAAGTGTCAAGCCAAAACAGGGGCCATTTGCTGTGAACACGCCAGCGG

=item 3
-o    Output directory

=item 4
-p    Markov model of the background Same type of background file used with MEME use markov_generator.pl

=item 5
Sequence file used with ScanACE (optional) defaults to the background sequence

=item 6
-w    Minimum width of motif search range (8) The minimum motif width to be searched this value may not be less than 6

=item 7
-W    Maximum width of motif search range (12) The maximum motif width to be searched this value may not be larger than

=item 8
-m    Number of motifs to find at each width (10) the motif finders with attempt to find this many motifs in each width bin

=item 9
-c    Correlation coeffcient used to eliminate duplicates (0.6)the Pearson correlation cofficent used with CompareACE

=item 10
-g    GC content of the background (0.5) the percentage of background sequencecomposed of Guanosine and Cytosine residues

=item 11
-h    Maximum number of ScanACE hits (default 10000)

=item 12
-t    Target scoring functions used to cluster motifs (gsmubr) this is the scoring function used to select and rank motif clusters

=item 13
-d    Distance used for positional specificity calculations (1000) this is the distance that MotifStats considers when calculating positional specificity

=item 14
-l    List of transfac motifs in AlignACE format This file should contain the names of the transcription factors

=item 15
-f    MotifFinding programs to use
all MDscan, BioProspector, AlignACE and MEME \(default and equivalent to \-f abmd\)
a AlignACE
d MDscan
b BioProspector
m MEME

=back

=head4 Returns

=over 4

=item 1 
A new uninitialized ScanFunction

=back

=head4 Description

=over 4

=item 1
Constructor. Returns a new ScanFunctions object.  All attributes still need to be set

=back

=cut


