$offset--;
}
- $adaptor = $options->{ "adaptor" };
+ $adaptor = uc $options->{ "adaptor" };
$adaptor_len = length $adaptor;
- $adaptor = [ split //, uc $adaptor ];
-
- $max_match = $adaptor_len - $max_mismatch;
while ( $record = get_record( $in ) )
{
if ( $record->{ "SEQ" } )
{
- $seq = $record->{ "SEQ" };
+ $seq = uc $record->{ "SEQ" };
$seq_len = length $seq;
- $seq = [ split //, uc $seq ];
- $pos = Maasha::Seq::find_adaptor( $adaptor, $seq, $adaptor_len, $seq_len, $offset, $max_match, $max_mismatch );
+ $pos = Maasha::Common::index_m( $seq, $adaptor, $seq_len, $adaptor_len, $offset, $max_mismatch );
$record->{ "ADAPTOR_POS" } = $pos;
@ISA = qw( Exporter ) ;
+use Inline ( C => <<'END_C', DIRECTORY => $ENV{ "BP_TMP" } );
+
+int index_m( char *str, char *substr, size_t str_len, size_t substr_len, size_t offset, size_t max_mismatch )
+{
+ /* Martin A. Hansen & Selene Fernandez, August 2008 */
+
+ /* Locates a substring within a string starting from offset and allowing for max_mismatch mismatches. */
+ /* The begin position of the substring is returned if found otherwise -1 is returned. */
+
+ int i = 0;
+ int j = 0;
+
+ size_t max_match = substr_len - max_mismatch;
+
+ i = offset;
+
+ while ( i < str_len - ( max_match + max_mismatch ) + 1 )
+ {
+ j = 0;
+
+ while ( j < substr_len - ( max_match + max_mismatch ) + 1 )
+ {
+ if ( match_m( str, substr, str_len, substr_len, i, j, max_match, max_mismatch ) != 0 ) {
+ return i;
+ }
+
+ j++;
+ }
+
+ i++;
+ }
+
+ return -1;
+}
+
+
+int match_m( char *str, char *substr, size_t str_len, size_t substr_len, size_t str_offset, size_t substr_offset, size_t max_match, size_t max_mismatch )
+{
+ /* Martin A. Hansen & Selene Fernandez, August 2008 */
+
+ /* Compares a string and substring starting at speficied string and substring offset */
+ /* positions allowing for a specified number of mismatches. Returns 1 if there is a */
+ /* match otherwise returns 0. */
+
+ size_t match = 0;
+ size_t mismatch = 0;
+
+ while ( str_offset <= str_len && substr_offset <= substr_len )
+ {
+ if ( str[ str_offset ] == substr[ substr_offset ] )
+ {
+ match++;
+
+ if ( match >= max_match ) {
+ return 1;
+ };
+ }
+ else
+ {
+ mismatch++;
+
+ if ( mismatch > max_mismatch ) {
+ return 0;
+ }
+ }
+
+ str_offset++;
+ substr_offset++;
+ }
+
+ return 0;
+}
+
+
+END_C
+
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ISA = qw( Exporter );
-
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ADAPTOR LOCATING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+############################### REDUNDANT ##############################
+
+# these functions have been replaced by index_m and match_m in Common.pm
+
sub find_adaptor
{
# Martin A. Hansen & Selene Fernandez, August 2008