示例#1
0
文件: brot.c 项目: marcom/corb
int
brot_main(const char *cmdline)
{
   struct brot_args_info brot_args;
   SeqMatrix* sm               = NULL;
   int retval                  = 0;
   Scmf_Rna_Opt_data* sim_data = NULL;
   GFile* entropy_file = NULL;

   /* command line parsing */
   brot_cmdline_parser_init (&brot_args);

   retval = brot_cmdline_parser_string (cmdline, &brot_args, get_progname());

   if (retval == 0)
   {
      retval = brot_cmdline_parser_required (&brot_args, get_progname());
   }

   /* postprocess arguments */
   if (retval == 0)
   {
      retval = brot_cmdline_parser_postprocess (&brot_args);
   }

   /* init simulation data */
   if (retval == 0)
   {
      sim_data = SCMF_RNA_OPT_DATA_NEW_INIT(brot_args.inputs[1], 
                                            strlen (brot_args.inputs[1]),
                                            RNA_ALPHABET,
                                            strlen(RNA_ALPHABET)/2,
            ((-1) * ((logf (1 / 0.000001f)) / (strlen (brot_args.inputs[1])))));
      if (sim_data == NULL)
      {
         retval = 1;
      }
   }

   /* init matrix */
   if (retval == 0)
   {
      sm = SEQMATRIX_NEW;
      if (sm != NULL)
      {
         retval = SEQMATRIX_INIT (
            alphabet_size (scmf_rna_opt_data_get_alphabet (sim_data)),
                                  strlen (brot_args.inputs[1]),
                                  sm);
         /*seqmatrix_print_2_stdout (6, sm);*/
      }
      else
      {
         retval = 1;
      }
   }

   /* fix certain sites in the matrix */
   if (retval == 0)
   {
      retval = adopt_site_presettings (&brot_args,
                                      scmf_rna_opt_data_get_alphabet (sim_data),
                                       sm);
   }

   /* open entropy file if name given */
   if (brot_args.entropy_output_given)
   {
      entropy_file = GFILE_OPEN (brot_args.entropy_output_arg,
                                 strlen (brot_args.entropy_output_arg),
                                 GFILE_VOID, "a");
      if (entropy_file == NULL)
      {
         retval = 1;
      }
      else
      {
         if (gfile_printf (entropy_file, "# bROT settings:\n") < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# steps: %lu\n",
                                brot_args.steps_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# temp:              %f\n",
                                brot_args.temp_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# beta-short:        %f\n",
                                brot_args.beta_short_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# beta-long:         %f\n",
                                brot_args.beta_long_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# speedup-threshold: %f\n",
                                brot_args.speedup_threshold_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# min-cool:          %f\n",
                                brot_args.min_cool_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# scale-cool:        %f\n",
                                brot_args.scale_cool_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# lambda:            %f\n",
                                brot_args.lambda_arg) < 0)
         {
            retval = 1;
         }
         else if (gfile_printf (entropy_file, "# sm-entropy:        %f\n",
                                brot_args.sm_entropy_arg) < 0)
         {
            retval = 1;
         }
      }
   }

   if (retval == 0)
   {
      if (brot_args.scoring_arg == scoring_arg_simpleNN)
      {
         /* special to NN usage: structure has to be of size >= 2 */
         if (strlen (brot_args.inputs[1]) > 1)
         {
            retval = simulate_using_simplenn_scoring (&brot_args,
                                                      sm,
                                                      sim_data,
                                                      entropy_file);
         }
         else
         {
            THROW_ERROR_MSG (NN_2_SMALL_WARNING,
                             brot_args.inputs[1], 
                             (unsigned long) strlen (brot_args.inputs[1]));
            retval = 1;
         }
      }
      else if (brot_args.scoring_arg == scoring_arg_nussinov)
      {
         retval = simulate_using_nussinov_scoring (&brot_args,
                                                   sm,
                                                   sim_data,
                                                   entropy_file);
      }
      else if (brot_args.scoring_arg == scoring_arg_NN)
      {
         /* special to NN usage: structure has to be of size >= 2 */
         if (strlen (brot_args.inputs[1]) > 1)
         {
            retval = simulate_using_nn_scoring (&brot_args,
                                                sm,
                                                sim_data,
                                                entropy_file);
         }
         else
         {
            THROW_ERROR_MSG (NN_2_SMALL_WARNING,
                             brot_args.inputs[1], 
                             (unsigned long) strlen (brot_args.inputs[1]));
            retval = 1;
         }
      }
   }

   /* close entropy file */
   if (retval == 0)
   {
      retval = gfile_close (entropy_file);
   }
   else
   {
      gfile_close (entropy_file);
   }

   if (retval == 0)
   {
      /* seqmatrix_print_2_stdout (2, sm); */
      mprintf ("%s\n", scmf_rna_opt_data_get_seq(sim_data));
   }   

   /* finalise */
   brot_cmdline_parser_free (&brot_args);
   seqmatrix_delete (sm);
   scmf_rna_opt_data_delete (sim_data);

   if (retval == 0)
   {
      return EXIT_SUCCESS;
   }
   else
   {
      return EXIT_FAILURE;
   }
}
示例#2
0
文件: brot.c 项目: bienchen/corb
int
brot_main(const char *cmdline)
{
   struct brot_args_info brot_args;
   SeqMatrix* sm               = NULL;
   int retval                  = 0;
   Scmf_Rna_Opt_data* sim_data = NULL;
   GFile* entropy_file = NULL;
   GFile* simulation_file = NULL;

   /* command line parsing */
   brot_cmdline_parser_init (&brot_args);

   retval = brot_cmdline_parser_string (cmdline, &brot_args, get_progname());

   if (retval == 0)
   {
      retval = brot_cmdline_parser_required (&brot_args, get_progname());
   }

   /* postprocess arguments */
   if (retval == 0)
   {
      retval = brot_cmdline_parser_postprocess (&brot_args, cmdline);
   }

   /* init simulation data */
   if (retval == 0)
   {
      sim_data = SCMF_RNA_OPT_DATA_NEW_INIT(brot_args.inputs[1], 
                                            strlen (brot_args.inputs[1]),
                                            RNA_ALPHABET,
                                            strlen(RNA_ALPHABET)/2,
             ((-1) * ((logf (1 / 0.000001f)) / (strlen (brot_args.inputs[1])))),
                                            brot_args.file_given);
      if (sim_data == NULL)
      {
         retval = 1;
      }
   }

   /* init matrix */
   if (retval == 0)
   {
      sm = SEQMATRIX_NEW;
      if (sm != NULL)
      {
         retval = SEQMATRIX_INIT (
            alphabet_size (scmf_rna_opt_data_get_alphabet (sim_data)),
                                      scmf_rna_opt_data_get_rna_size(sim_data),
                                      /* strlen (brot_args.inputs[1]), */
                                  sm);
         /*seqmatrix_print_2_stdout (6, sm);*/
      }
      else
      {
         retval = 1;
      }
   }

   /* fix certain sites in the matrix */
   if (retval == 0)
   {
      retval = adopt_site_presettings (&brot_args,
                                      scmf_rna_opt_data_get_alphabet (sim_data),
                                       sim_data,
                                       sm);
   }

   /* open entropy file if name given */
   if (retval == 0)
   {
      print_verbose ("# Entropy file            (-p): ");
      if (brot_args.entropy_output_given)
      {
         print_verbose ("%s", brot_args.entropy_output_arg);
         entropy_file = GFILE_OPEN (brot_args.entropy_output_arg,
                                    strlen (brot_args.entropy_output_arg),
                                    GFILE_VOID, "a");
         if (entropy_file == NULL)
         {
            retval = 1;
         }
         else
         {
            retval = brot_settings_2_file (entropy_file, cmdline);
         }
      }
      /* open simulation/ matrix file if name given */
      print_verbose ("\n# Simulation/ Matrix file (-m): ");
      if (brot_args.simulation_output_given)
      {
         print_verbose ("%s", brot_args.simulation_output_arg);
         simulation_file = GFILE_OPEN (brot_args.simulation_output_arg,
                                       strlen (brot_args.simulation_output_arg),
                                       GFILE_VOID, "a");
         
         if (simulation_file == NULL)
         {
            retval = 1;
         }
         else
         {
            retval = brot_settings_2_file (simulation_file, cmdline);
            if (retval == 0)
            {
               if (gfile_printf (simulation_file, "START\n") < 0)
               {
                  retval = 1;
               }
            }
         }
      }
   }
   
   if (retval == 0)
   {
      print_verbose ("\n# Scoring scheme          (-c): ");

      if (brot_args.scoring_arg == scoring_arg_simpleNN)
      {
         print_verbose ("simpleNN\n");
         /* special to NN usage: structure has to be of size >= 2 */
         if (strlen (brot_args.inputs[1]) > 1)
         {
            retval = simulate_using_simplenn_scoring (&brot_args,
                                                      sm,
                                                      sim_data,
                                                      entropy_file,
                                                      simulation_file);
         }
         else
         {
            THROW_ERROR_MSG (NN_2_SMALL_WARNING,
                             brot_args.inputs[1], 
                             (unsigned long) strlen (brot_args.inputs[1]));
            retval = 1;
         }
      }
      else if (brot_args.scoring_arg == scoring_arg_nussinov)
      {
         print_verbose ("nussinov\n");
         retval = simulate_using_nussinov_scoring (&brot_args,
                                                   sm,
                                                   sim_data,
                                                   entropy_file,
                                                   simulation_file);
      }
      else if (brot_args.scoring_arg == scoring_arg_NN)
      {
         print_verbose ("NN\n");
         /* special to NN usage: structure has to be of size >= 2 */
         if (strlen (brot_args.inputs[1]) > 1)
         {
            retval = simulate_using_nn_scoring (&brot_args,
                                                sm,
                                                sim_data,
                                                entropy_file,
                                                simulation_file);
         }
         else
         {
            THROW_ERROR_MSG (NN_2_SMALL_WARNING,
                             brot_args.inputs[1], 
                             (unsigned long) strlen (brot_args.inputs[1]));
            retval = 1;
         }
      }
   }

   /* close files */
   if (retval == 0)
   {
      retval = gfile_close (entropy_file);
   }
   else
   {
      gfile_close (entropy_file);
   }

   if (simulation_file != NULL)
   {
      if (gfile_printf (simulation_file, "END\n") < 0)
      {
         retval = 1;
      }
   }

   if (retval == 0)
   {
      retval = gfile_close (simulation_file);
   }
   else
   {
      gfile_close (simulation_file);
   }

   if (retval == 0)
   {
      /*seqmatrix_print_2_stdout (2, sm);*/
      mprintf ("%s\n", scmf_rna_opt_data_get_seq(sim_data));
   }

   /* finalise */
   brot_cmdline_parser_free (&brot_args);
   seqmatrix_delete (sm);
   scmf_rna_opt_data_delete (sim_data);

   if (retval == 0)
   {
      return EXIT_SUCCESS;
   }
   else
   {
      return EXIT_FAILURE;
   }
}