#!/usr/bin/perl
if ($0 =~ /([^(\/)]+)$/) {
    push (@INC, "$`lib/");
}
require "RSA.lib";



if ($ARGV[0] eq "-h") {
#### display full help message #####
  open HELP, "| more";
  print HELP <<End_of_help;
NAME
	next-match

        1998 by Jacques van Helden (Jacques.van-Helden\@univ-amu.fr)
	
USAGE
        next-match sequence pattern [subst [offset]]

DESCRIPTION
	returns the position and sequence of the first match with the pattern 
	in the sequence, allowing subst substitutions, and starting with a 
	given offset (0 is the first base of the input sequence).
	
CATEGORY
	sequences
	pattern matching

OPTIONS
        -h      (must be first argument) display full help message
        -help   (must be first argument) display options
	-v	verbose
		
	
INPUT FORMAT
	seq1 and seq2 must be DNA sequence (not proteic). 
	IUPAC degenerate code is accepted in seq1 as well as seq2.

EXAMPLES
       next-match ATATATGATAAGAATT GATWAG 0 0 
       should return
		5	GATAAG
	
End_of_help
  close HELP;
  exit;
}

if ($ARGV[0] eq "-help") {
#### display short help message #####
  open HELP, "| more";
  print HELP <<End_short_help;
next-match options
----------------
usage:
	next-match sequence pattern subst offset

-h      (must be first argument) display full help message
-help   (must be first argument) display options
End_short_help
  close HELP;
  exit;
}

#### initialise parameters ####
$start_time = &RSAT::util::StartScript();


#### read arguments ####
$input_seq = $ARGV[0];
$pattern = $ARGV[1];
$allowed_subst = $ARGV[2];
$offset = $ARGV[3];


($match_pos,$match_seq) = &NextMatch($input_seq, $pattern,$allowed_subst,$offset);


print "$match_pos\t$match_seq\n";

################################################################
## Report execution time and close output stream
my $exec_time = &RSAT::util::ReportExecutionTime($start_time); ## This has to be exectuted by all scripts
warn $exec_time if ($main::verbose >= 1); ## only report exec time if verbosity is specified

exit(0);

