]> git.donarmstrong.com Git - biopieces.git/commitdiff
inline::c code for adaptor removal
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 16 Sep 2008 04:36:54 +0000 (04:36 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 16 Sep 2008 04:36:54 +0000 (04:36 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@258 74ccb610-7750-0410-82ae-013aeee3265d

code_c/Maasha/src/bed_sort.c
code_perl/Maasha/Biopieces.pm
code_perl/Maasha/Common.pm
code_perl/Maasha/Seq.pm

index 851a74e5af2b2736edcd51e2e67313897e7fda16..6c7bf6927a9c463074660c7ccfb823151e6b8576 100644 (file)
@@ -56,7 +56,7 @@ int main( int argc, char *argv[] )
         }
     }
 
-    printf( "sort: %d  cols: %d   dir: %s\n", sort, cols, dir );
+    fprintf( stderr, "sort: %d  cols: %d   dir: %s\n", sort, cols, dir );
 
     argc -= optind;
     argv += optind;
index 041cbb2fe4b51e23473f1129fb028b507ec9c5ca..ab7add7e4adb71c953f954918a0c2b9f72345e20 100644 (file)
@@ -4705,21 +4705,17 @@ sub script_remove_adaptor
         $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;
 
index 8428aa672cffbbde2dec288d8033423f4abeaca3..16e069f1312d22f0ffbc58508bdf54bf0a8efc99 100644 (file)
@@ -42,6 +42,83 @@ use vars qw( @ISA @EXPORT @EXPORT_OK );
 
 @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
+
+
 
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
index c224808f2ad109bf31140d947130ab0e79bf57cb..9304d7b832a56511f3a3458d9f1035bbcf6a632b 100644 (file)
@@ -38,7 +38,6 @@ use vars qw ( @ISA @EXPORT );
 
 @ISA = qw( Exporter );
 
-
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 
@@ -1389,6 +1388,10 @@ sub seq_word_unpack
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 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