]> git.donarmstrong.com Git - biopieces.git/commitdiff
added str_analyze to Common.pm
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 10 Jul 2009 16:47:52 +0000 (16:47 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Fri, 10 Jul 2009 16:47:52 +0000 (16:47 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@563 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/Common.pm
code_perl/Maasha/Seq.pm

index dbe43b759f775ac759aea14a41e1556c7a686345..64c9182cde053a7af648eca3ac2f306d41440d39 100644 (file)
@@ -118,6 +118,30 @@ int match_m( char *str, char *substr, size_t str_len, size_t substr_len, size_t
 }
 
 
+void str_analyze_C( const char *string )
+{
+    /* Martin A. Hansen, July 2009 */
+
+    /* Scans a string incrementing the char count in an array. */
+
+    int count[ 256 ] = { 0 };   /* Integer array spanning the ASCII alphabet */
+    int i;
+
+    for ( i = 0; i < strlen( string ); i++ ) {
+        count[ ( int ) string[ i ] ]++;
+    }
+
+    Inline_Stack_Vars;
+    Inline_Stack_Reset;
+
+    for ( i = 0; i < 256; i++ ) {
+        Inline_Stack_Push( sv_2mortal( newSViv( count[ i ] ) ) );
+    }
+
+    Inline_Stack_Done;
+}
+
+
 END_C
 
 
@@ -697,6 +721,29 @@ sub wrap_line
 }
 
 
+sub str_analyze
+{
+    # Martin A. Hansen, July 2009.
+
+    # Analyzes the string composition of a given string.
+
+    my ( $str,   # string to analyze
+       ) = @_;
+
+    # Returns hash
+
+    my ( @composition, %hash, $i );
+
+    @composition = Maasha::Common::str_analyze_C( $str ); 
+
+    for ( $i = 32; $i < 128; $i++ ) {          # Only include printable chars
+        $hash{ chr $i } = $composition[ $i ]
+    }
+
+    return wantarray ? %hash : \%hash;
+}
+
+
 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
 1;
index 93e9ba6c9f09350d524749f848c637971769b73e..cfedd89b96e6cbc38d22b65e15b24d1fbca5d65c 100644 (file)
@@ -950,7 +950,7 @@ sub seq_analyze
 
     my ( %analysis, @chars, @chars_lc, $char, %char_hash, $gc, $at, $lc, $max, $res_sum, @indels, %indel_hash );
 
-    $analysis{ "SEQ_TYPE" } = uc Maasha::Seq::seq_guess_type( $seq );
+    $analysis{ "SEQ_TYPE" } = Maasha::Seq::seq_guess_type( $seq );
     $analysis{ "SEQ_LEN" }  = length $seq;
 
     @indels = qw( - ~ . _ );
@@ -1005,7 +1005,7 @@ sub seq_analyze
     map { $analysis{ "RES[$_]" } = $indel_hash{ $_ } } @indels;
 
     $analysis{ "MIX_INDEX" } = sprintf( "%.2f", $max / $analysis{ "SEQ_LEN" } );
-    $analysis{ "MELT_TEMP" } = sprintf( "%.2f", 4 * $gc + 2 * $at );
+    #$analysis{ "MELT_TEMP" } = sprintf( "%.2f", 4 * $gc + 2 * $at );
 
     return wantarray ? %analysis : \%analysis;
 }