}
-double solexa_str_mean_window( char *scores, int window_size, double min )
+void solexa_str_mean_window( char *scores, int window_size, double min )
{
/* Martin A. Hansen, June 2010. */
/* is lower than a given minimum otherwise the smallest mean */
/* score is returned. */
- int i = 0;
- double sum = 0;
- double mean = 0.0;
+ int found = 0;
+ int i = 0;
+ int pos = -1;
+ double sum = 0;
+ double mean = 0.0;
if ( window_size > strlen( scores ) )
{
mean = sum / window_size;
- if ( mean < min ) {
- return mean;
+ if ( mean <= min ) {
+ found = 1;
+ pos = 0;
}
/* --- scan the rest of the scores ---- */
- while ( i < strlen( scores ) )
+ while ( ! found && i < strlen( scores ) )
{
sum += solexa2dec( scores[ i ] );
sum -= solexa2dec( scores[ i - window_size ] );
// printf( "char->%c score->%d sum->%f mean->%f\n", scores[i], solexa2dec(scores[i]),sum, mean);
- if ( mean < min ) {
- return mean;
- }
-
i++;
+
+ if ( mean <= min ) {
+ found = 1;
+ pos = i - window_size;
+ }
}
- return mean;
+ Inline_Stack_Vars;
+ Inline_Stack_Reset;
+
+ Inline_Stack_Push( sv_2mortal( newSViv( mean ) ) );
+ Inline_Stack_Push( sv_2mortal( newSViv( pos ) ) );
+
+ Inline_Stack_Done;
}
}
+int trim_left( char *scores, int min )
+{
+ /* Martin A. Hansen, June 2010 */
+
+ /* Starting from the left in a score string, */
+ /* locate the position when the score is above */
+ /* a given min.*/
+
+ int pos = 0;
+
+ while ( pos < strlen( scores ) && solexa2dec( scores[ pos ] ) <= min ) {
+ pos++;
+ }
+
+ return pos;
+}
+
+
+int trim_right( char *scores, int min )
+{
+ /* Martin A. Hansen, June 2010 */
+
+ /* Starting from the right in a score string, */
+ /* locate the position when the score is above */
+ /* a given min.*/
+
+ int len = strlen( scores );
+ int pos = len;
+
+ while ( pos > 0 && solexa2dec( scores[ pos ] ) <= min ) {
+ pos--;
+ }
+
+ if ( pos == 0 ) {
+ pos = len;
+ }
+
+ return pos;
+}
+
END_C
# Returns a string.
+ $scores =~ s/(-\d{1,2})/0/g;
$scores =~ s/(\d{1,2});?/dec2solexa( $1 )/eg;
return $scores;
}
+sub dec_str2phred_str
+{
+ # Martin A. Hansen, November 2013.
+
+ # Converts a ; separated string of decimal scores to a
+ # string of Phred scores.
+
+ my ( $scores, # Decimal score string
+ ) = @_;
+
+ # Returns a string.
+
+ $scores =~ s/(-\d{1,2})/0/g;
+ $scores =~ s/(\d{1,2});?/dec2phred( $1 )/eg;
+
+ return $scores;
+}
sub get_entry
{