#!/usr/bin/perl -w

# patscan_batch.pl
# Run patscan on all seqs in a folder
# Can be easily modified to run any command on every sequence in a folder
# WI Bioinformatics course - Feb 2002 - Lecture 5
# WI Bioinformatics course - Revised - Sep 2003

################  User-supplied variables  #############

# Directory of sequences
#$myDir = "/home/elvis/seqs";
$myDir = "/home/yuan/liverseq";#The directory changed to liverseq, replace yuan with your fladda login name

# Output directory (relative to $myDir or full path)
#$outputDir = "patscan";
$outputDir = "/home/yuan/Palindrome"; #created a Palindrome directory, replace yuan with your fladda login name

# Path to pattern file
#$patFile = "/home/elvis/patterns/polyA.pat"; # You don't need pattern file for palindrome program


#########################################################

# Go to sequence directory and open it (i.e, read contents)
chdir($myDir) || die "Cannot change to $myDir: $!";		# Go to $myDir
opendir(DIR, $myDir) || die "Cannot open $myDir: $!";		# Open $myDir

foreach $seqFile (sort readdir(DIR))
{	
 	if ($seqFile =~ /\.tfa$/)		# if file ends in .tfa
 	{
  		print "Processing $seqFile\n";
  		$outFile = $seqFile;			# Create $outFile name
  		$outFile =~ s/\.tfa/\.palindrome/;		# s/old/new/, the new file name ending with .palindrome

  		############  Run PATSCAN  ###############
  		`palindrome $seqFile -minpallen 10 -maxpallen 100 -gaplimit 100 -nummismatches 2  -overlap  $outputDir/$outFile`; #Command CHANGED 
  	}
} 
closedir(DIR);