char* get_last_word(char * str) {
    char *res;
    int i=0;
    res = (char*)malloc(sizeof(char));
    int l = leng(str);
    l--;
    while (str[l] == ' ' && l != 0)l--;
    while (str[l] != ' ' && l != 0)l--;
    while (str[l] != ' ' && str[l] != '\0')
        res[i++] = str[l++];
    res[i] = '\0';
    return res;
}
Ejemplo n.º 2
0
void ParseSNP::parse_cmd_line(int argc, char *argv[]) {

    CmdLine cmdss("computes local coverage and a derived BOD quality score", ' ', version.c_str());
    
    ValueArg<string> read_filename_arg("q", "mapped_reads",
            "Mapped read file (sam/bam)", true, "#", "string");
    cmdss.add(read_filename_arg);
    //
    ValueArg<string> ref_file_arg("r", "ref_file", "Reference file (fasta)", true, "#", "string");
    cmdss.add(ref_file_arg);
    //
    ValueArg<string> snp_file_arg("s", "snp_file", "VCF file", true, "#", "string");
    cmdss.add(snp_file_arg);
    //
    ValueArg<int> leng("l", "read_length", "maximum read length", true, -1, "int");
    cmdss.add(leng);
    //
    ValueArg<string> db_file_arg("d", "db_file", "Sqlite file to write the output", false, "#", "string");
    //
    ValueArg<string> plot_file_arg("p", "plot_file",
            "Name of the file for the data required for the Python script",
            false, "#", "string");
    //
    cmdss.xorAdd( db_file_arg, plot_file_arg ); // <- whether Sqlite DB or plain text
    //
    ValueArg<string> sample_label_arg("t", "sample_label",
            "sample label for the database",
            false, "#", "string");
    cmdss.add(sample_label_arg);
    //
    MultiArg<string> exclude_contigs_arg("x", "exclude", "exclude contigs from analysis", false, "string");
    cmdss.add(exclude_contigs_arg);
    //
    MultiSwitchArg verbose_arg("v", "verbose", "print snp-by-snp progress", 0);
    cmdss.add(verbose_arg);
    //
    ValueArg<int> num_test_arg("b", "break_after", "max number of position per chromosome [test mode]", false, 0, "int");
    cmdss.add(num_test_arg);
 
    try {
        cmdss.parse(argc, argv); //parse arguments
        read_filename = read_filename_arg.getValue();
/*        output = out.getValue();
        if (output[0] == '#') {
            output = read_filename;
            output += ".mot";
        }
*/
        reffile = ref_file_arg.getValue();
        snpfile = snp_file_arg.getValue();
        read_length = leng.getValue();
        range =  3 * read_length / 2 ;
     
        if ( plot_file_arg.isSet() )
            plot_file = plot_file_arg.getValue();
            //db_file = '#';
        else if ( db_file_arg.isSet() )
            // plot_file = '#';
            plot_file = db_file_arg.getValue();
        //

       if ( sample_label_arg.isSet() )
            sample_label = sample_label_arg.getValue();
        else 
            sample_label = "[" + db_file_arg.getValue() + "]";

        clog << "table base name: " << sample_label << endl;

        exclude_contigs = exclude_contigs_arg.getValue();

        verbose = verbose_arg.getValue();
        if (verbose){
            num_test = num_test_arg.getValue();
            }
        //
        db_flag = db_file_arg.isSet();

        init();
        parseVCF();

    } catch (ArgException &e) {
        StdOutput out;
        out.failure(cmdss, e);
    }
}