Commits

Aaron Wong committed f41b0c5

Added option in Counter to output log-ratios instead of posteriors during inference

Comments (0)

Files changed (4)

tools/Counter/Counter.cpp

     const vector<size_t>*	m_pveciGenes;
     bool			m_fFirst;
     string			m_strName;
+    bool			m_bLogratio;
 };
 
 struct SEvaluate2 {
             vecsData[ i ].m_pYes = vecpYes[ i ];
             vecsData[ i ].m_pNo = vecpNo[ i ];
             vecsData[ i ].m_strName = sArgs.inputs_num ? sArgs.inputs[ i ] : "global";
+	    vecsData[ i ].m_bLogratio = sArgs.logratio_flag;
             if( pthread_create( &vecpthdThreads[ i ], NULL, finalize, &vecsData[ i ] ) ) {
                 cerr << "Couldn't create finalization thread: " << sArgs.inputs[ i ] << endl;
                 return 1;
     size_t		i, j;
     float*		adYes;
     float*		adNo;
-    float		dPrior;
+    float		dPrior, dYes, dNo;
 
     psData = (SEvaluate*)pData;
     dPrior = psData->m_pBN->GetCPT( 0 ).Get( 1, 0 );
     adYes = new float[ psData->m_pYes->GetGenes( ) ];
     adNo = new float[ psData->m_pNo->GetGenes( ) ];
+
+    dYes = log( dPrior );
+    dNo = log( psData->m_pBN->GetCPT( 0 ).Get( 0, 0 ) );
+
     for( i = 0; i < psData->m_pYes->GetGenes( ); ++i ) {
         if( !( i % 1000 ) )
             cerr << "F: " << psData->m_strName << ", " << i << endl;
         memcpy( adYes, psData->m_pYes->Get( i ), ( psData->m_pYes->GetGenes( ) - i - 1 ) * sizeof(*adYes) );
         memcpy( adNo, psData->m_pNo->Get( i ), ( psData->m_pNo->GetGenes( ) - i - 1 ) * sizeof(*adNo) );
-        for( j = 0; j < ( psData->m_pYes->GetGenes( ) - i - 1 ); ++j )
-            adYes[ j ] = CMeta::IsNaN( adYes[ j ] ) ? dPrior :
-                         (float)( 1 / ( 1 + exp( (double)adNo[ j ] - (double)adYes[ j ] ) ) );
+        for( j = 0; j < ( psData->m_pYes->GetGenes( ) - i - 1 ); ++j ) {
+	    if( psData->m_bLogratio ) {
+		adYes[ j ] = CMeta::IsNaN( adYes[ j ] ) ? 0.0 :
+		             (float)( (double)(adYes[ j ] - dYes) - (double)(adNo[ j ] - dNo) );
+	    }
+	    else {
+		adYes[ j ] = CMeta::IsNaN( adYes[ j ] ) ? dPrior :
+		             (float)( 1 / ( 1 + exp( (double)adNo[ j ] - (double)adYes[ j ] ) ) );
+	    }
+	}
         psData->m_pYes->Set( i, adYes );
     }
     delete[] adNo;

tools/Counter/Counter.ggo

 							int	default="-1"
 option	"verbosity"		v	"Message verbosity"
 							int	default="5"
+option	"logratio"		L	"Output log ratios (instead of posteriors)"
+							flag	off

tools/Counter/cmdline.c

 /*
-  File autogenerated by gengetopt version 2.22.5
+  File autogenerated by gengetopt version 2.22
   generated with the following command:
-  /usr/bin/gengetopt -iCounter.ggo --default-optional -u -N -e 
+  /Genomics/fgrid/function/sleipnir-extlib/gengetopt/src/gengetopt -iCounter.ggo --default-optional -u -N -e 
 
   The developers of gengetopt consider the fixed text that goes in all
   gengetopt output files to be in the public domain:
 #include <stdlib.h>
 #include <string.h>
 
-#ifndef FIX_UNUSED
-#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
-#endif
-
-#include <getopt.h>
+#include "getopt.h"
 
 #include "cmdline.h"
 
   "  -M, --memmapout               Memory map output files (only for inference \n                                  mode)  (default=off)",
   "  -t, --threads=INT             Maximum number of threads to spawn  \n                                  (default=`-1')",
   "  -v, --verbosity=INT           Message verbosity  (default=`5')",
+  "  -L, --logratio                Output log ratios (instead of posteriors)  \n                                  (default=off)",
     0
 };
 
 void clear_args (struct gengetopt_args_info *args_info);
 
 static int
-cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
+cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
                         struct cmdline_parser_params *params, const char *additional_error);
 
 static int
   args_info->memmapout_given = 0 ;
   args_info->threads_given = 0 ;
   args_info->verbosity_given = 0 ;
+  args_info->logratio_given = 0 ;
   args_info->Mode_group_counter = 0 ;
 }
 
 static
 void clear_args (struct gengetopt_args_info *args_info)
 {
-  FIX_UNUSED (args_info);
   args_info->answers_arg = NULL;
   args_info->answers_orig = NULL;
   args_info->counts_arg = NULL;
   args_info->threads_orig = NULL;
   args_info->verbosity_arg = 5;
   args_info->verbosity_orig = NULL;
+  args_info->logratio_flag = 0;
   
 }
 
   args_info->memmapout_help = gengetopt_args_info_help[38] ;
   args_info->threads_help = gengetopt_args_info_help[39] ;
   args_info->verbosity_help = gengetopt_args_info_help[40] ;
+  args_info->logratio_help = gengetopt_args_info_help[41] ;
   
 }
 
 void
 cmdline_parser_print_version (void)
 {
-  printf ("%s %s\n",
-     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
-     CMDLINE_PARSER_VERSION);
+  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
 }
 
 static void print_help_common(void) {
   printf("\n");
 
   if (strlen(gengetopt_args_info_description) > 0)
-    printf("%s\n\n", gengetopt_args_info_description);
+    printf("%s\n", gengetopt_args_info_description);
 }
 
 void
   clear_args (args_info);
   init_args_info (args_info);
 
-  args_info->inputs = 0;
+  args_info->inputs = NULL;
   args_info->inputs_num = 0;
 }
 
 
 
 static void
-write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
+write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
 {
-  FIX_UNUSED (values);
   if (arg) {
     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
   } else {
     write_into_file(outfile, "threads", args_info->threads_orig, 0);
   if (args_info->verbosity_given)
     write_into_file(outfile, "verbosity", args_info->verbosity_orig, 0);
+  if (args_info->logratio_given)
+    write_into_file(outfile, "logratio", 0, 0 );
   
 
   i = EXIT_SUCCESS;
 char *
 gengetopt_strdup (const char *s)
 {
-  char *result = 0;
+  char *result = NULL;
   if (!s)
     return result;
 
 }
 
 int
-cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
+cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
 {
   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
 }
 
 int
-cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
+cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
                    struct cmdline_parser_params *params)
 {
   int result;
-  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
+  result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
 
   return result;
 }
 
 int
-cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
 {
   int result;
   struct cmdline_parser_params params;
   params.check_ambiguity = 0;
   params.print_errors = 1;
 
-  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
+  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
 
   return result;
 }
 {
   int result = EXIT_SUCCESS;
 
-  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
+  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
     result = EXIT_FAILURE;
 
   return result;
 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
 {
   int error = 0;
-  FIX_UNUSED (additional_error);
 
   /* checks for required options */
   if (! args_info->output_given)
   
   if (args_info->Mode_group_counter == 0)
     {
-      fprintf (stderr, "%s: %d options of group Mode were given. One is required%s.\n", prog_name, args_info->Mode_group_counter, (additional_error ? additional_error : ""));
+      fprintf (stderr, "%s: %d options of group Mode were given. One is required.%s\n", prog_name, args_info->Mode_group_counter, (additional_error ? additional_error : ""));
       error = 1;
     }
   
 static
 int update_arg(void *field, char **orig_field,
                unsigned int *field_given, unsigned int *prev_given, 
-               char *value, const char *possible_values[],
-               const char *default_value,
+               char *value, char *possible_values[], const char *default_value,
                cmdline_parser_arg_type arg_type,
                int check_ambiguity, int override,
                int no_free, int multiple_option,
   const char *val = value;
   int found;
   char **string_field;
-  FIX_UNUSED (field);
 
   stop_char = 0;
   found = 0;
       return 1; /* failure */
     }
 
-  FIX_UNUSED (default_value);
     
   if (field_given && *field_given && ! override)
     return 0;
 
 
 int
-cmdline_parser_internal (
-  int argc, char **argv, struct gengetopt_args_info *args_info,
+cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
                         struct cmdline_parser_params *params, const char *additional_error)
 {
   int c;	/* Character of the parsed option.  */
         { "memmapout",	0, NULL, 'M' },
         { "threads",	1, NULL, 't' },
         { "verbosity",	1, NULL, 'v' },
-        { 0,  0, 0, 0 }
+        { "logratio",	0, NULL, 'L' },
+        { NULL,	0, NULL, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVw:k:n:o:d:s:e:X:g:G:P:c:C:qQjJuUb:Z:Sp:a:rR:y:lxmMt:v:", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVw:k:n:o:d:s:e:X:g:G:P:c:C:qQjJuUb:Z:Sp:a:rR:y:lxmMt:v:L", long_options, &option_index);
 
       if (c == -1) break;	/* Exit from `while (1)' loop.  */
 
             goto failure;
         
           break;
+        case 'L':	/* Output log ratios (instead of posteriors).  */
+        
+        
+          if (update_arg((void *)&(args_info->logratio_flag), 0, &(args_info->logratio_given),
+              &(local_args_info.logratio_given), optarg, 0, 0, ARG_FLAG,
+              check_ambiguity, override, 1, 0, "logratio", 'L',
+              additional_error))
+            goto failure;
+        
+          break;
 
         case 0:	/* Long option with no short option */
         case '?':	/* Invalid option.  */
 
   if (args_info->Mode_group_counter > 1)
     {
-      fprintf (stderr, "%s: %d options of group Mode were given. One is required%s.\n", argv[0], args_info->Mode_group_counter, (additional_error ? additional_error : ""));
+      fprintf (stderr, "%s: %d options of group Mode were given. One is required.%s\n", argv[0], args_info->Mode_group_counter, (additional_error ? additional_error : ""));
       error = 1;
     }
   

tools/Counter/cmdline.h

 /** @file cmdline.h
  *  @brief The header file for the command line option parser
- *  generated by GNU Gengetopt version 2.22.5
+ *  generated by GNU Gengetopt version 2.22
  *  http://www.gnu.org/software/gengetopt.
  *  DO NOT modify this file, since it can be overwritten
  *  @author GNU Gengetopt by Lorenzo Bettini */
 #endif /* __cplusplus */
 
 #ifndef CMDLINE_PARSER_PACKAGE
-/** @brief the program name (used for printing errors) */
+/** @brief the program name */
 #define CMDLINE_PARSER_PACKAGE "Counter"
 #endif
 
-#ifndef CMDLINE_PARSER_PACKAGE_NAME
-/** @brief the complete program name (used for help and version) */
-#define CMDLINE_PARSER_PACKAGE_NAME "Counter"
-#endif
-
 #ifndef CMDLINE_PARSER_VERSION
 /** @brief the program version */
 #define CMDLINE_PARSER_VERSION "1.0"
   int verbosity_arg;	/**< @brief Message verbosity (default='5').  */
   char * verbosity_orig;	/**< @brief Message verbosity original value given at command line.  */
   const char *verbosity_help; /**< @brief Message verbosity help description.  */
+  int logratio_flag;	/**< @brief Output log ratios (instead of posteriors) (default=off).  */
+  const char *logratio_help; /**< @brief Output log ratios (instead of posteriors) help description.  */
   
   unsigned int help_given ;	/**< @brief Whether help was given.  */
   unsigned int version_given ;	/**< @brief Whether version was given.  */
   unsigned int memmapout_given ;	/**< @brief Whether memmapout was given.  */
   unsigned int threads_given ;	/**< @brief Whether threads was given.  */
   unsigned int verbosity_given ;	/**< @brief Whether verbosity was given.  */
+  unsigned int logratio_given ;	/**< @brief Whether logratio was given.  */
 
   char **inputs ; /**< @brief unamed options (options without names) */
   unsigned inputs_num ; /**< @brief unamed options number */
  * @param args_info the structure where option information will be stored
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser (int argc, char **argv,
+int cmdline_parser (int argc, char * const *argv,
   struct gengetopt_args_info *args_info);
 
 /**
  * @return 0 if everything went fine, NON 0 if an error took place
  * @deprecated use cmdline_parser_ext() instead
  */
-int cmdline_parser2 (int argc, char **argv,
+int cmdline_parser2 (int argc, char * const *argv,
   struct gengetopt_args_info *args_info,
   int override, int initialize, int check_required);
 
  * @param params additional parameters for the parser
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser_ext (int argc, char **argv,
+int cmdline_parser_ext (int argc, char * const *argv,
   struct gengetopt_args_info *args_info,
   struct cmdline_parser_params *params);