Exemplo n.º 1
0
Settings::Settings(int argc, char** args)
{
        // parse program arguments
        if (argc < 4) {
                if (argc == 1) {
                        printProgramInfo();
                } else {
                        std::string arg = args[1];
                        if (arg == "-h" || arg == "--help") {
                                printUsage();
                                exit(EXIT_SUCCESS);
                        } else if (arg == "-i" || arg == "--info") {
                                printProgramInfo();
                                exit(EXIT_SUCCESS);
                        }
                }
                printUsage();
                exit(EXIT_FAILURE);
        }

        //set standard values
        num_threads_ = std::thread::hardware_concurrency();
        essa_k_ = 1;
        max_passes_ = 2;
        min_len_ = 20;
        directory_ = "Jabba_output";
        output_mode_ = SHORT;
        std::string graph_name = "DBGraph.fasta";
        FileType file_type(FASTA);
        std::vector<std::string> libraries;
        // extract the other parameters
        for (int i = 1; i < argc; i++) {
                std::string arg(args[i]);
                if (arg.empty()) continue;// this shouldn't happen
                if (arg == "-fastq") { // file type
                        std::cout << "FileType is fastq." << std::endl;
                        file_type = FASTQ;
                 } else if (arg == "-fasta") {
                        std::cout << "FileType is fasta." << std::endl;
                        file_type = FASTA;
                } else if (arg == "-t" || arg == "--threads") {
                        ++i;
                        num_threads_ = std::stoi(args[i]);
                } else if (arg == "-g" || arg == "--graph") {
                        ++i;
                        graph_name = args[i];
                } else if (arg == "-k" || arg == "--dbgk") {
                        ++i;
                        dbg_k_ = std::stoi(args[i]);
                } else if (arg == "-e" || arg == "--essak") {
                        ++i;
                        essa_k_ = std::stoi(args[i]);
                } else if (arg == "-p" || arg == "--passes") {
                        ++i;
                        max_passes_ = std::stoi(args[i]);
                } else if (arg == "-l" || arg == "--length") {
                        ++i;
                        min_len_ = std::stoi(args[i]);
                } else if (arg == "-o" || arg == "--output") {
                        ++i;
                        directory_ = args[i];
                } else if (arg == "-s" || arg == "--short") {
                        std::cerr << "-s --short is deprecated, short is now the default output mode.\n";
                        output_mode_ = SHORT;
                } else if (arg == "-m" || arg == "--outputmode") {
                        ++i;
                        if (std::string(args[i]) == std::string("short")) {
                                output_mode_ = SHORT;
                        } else if (std::string(args[i]) == std::string("long")) {
                                output_mode_ = LONG;
                        } else {
                                std::cerr << args[i] << " is not a valid output mode. Use \"long\" or \"short\" instead.\n";
                        }
                } else {// filename
                        libraries.push_back(args[i]);
                }
        }
        for (auto const &lib : libraries) {
                libraries_.insert(ReadLibrary(lib, directory_));
        }
        //
        graph_ = new ReadLibrary(graph_name, "");
        // try to create the output directory
        #ifdef _MSC_VER
        CreateDirectory(directory_.c_str(), NULL);
        #else
        DIR * dir = opendir(directory_.c_str());
        if ((dir == NULL) && (mkdir(directory_.c_str(), 0777) != 0))
                throw std::ios_base::failure("Can't create directory: " + directory_);
        closedir(dir);
        #endif
        // log the instructions
        logInstructions(argc, args);
        //print settings
        std::cout << "Max Number of Threads is " << num_threads_ << std::endl;
        std::cout << "Graph is " << graph_->getInputFilename() << std::endl;
        std::cout << "DBG K is " << dbg_k_ << std::endl;
        std::cout << "ESSA K is " << essa_k_ << std::endl;
        std::cout << "Max Passes is " << max_passes_ << std::endl;
        std::cout << "Min Seed Size is " << min_len_ << std::endl;
        std::cout << "Output Directory is " << directory_ << std::endl;
        std::cout << "Output Mode is ";
        if (output_mode_ == SHORT){
                std::cout << "short" << std::endl;
        } else if (output_mode_ == LONG){
                std::cout << "long" << std::endl;
        } else {
                std::cout << "not implemented" << std::endl;
        }
}
Exemplo n.º 2
0
bool DefFile::Read()
{
    stream = new std::fstream(fileName.c_str(), std::ios::in);
    if (stream != NULL)
    {
        try
        {
            lineno = 0;
            NextToken();
            while (!stream->eof())
            {
                if (token->IsEnd())
                {
                    NextToken();
                }
                else if (!token->IsKeyword())
                {
                    throw new std::runtime_error("Invalid directive");
                }
                else
                {
                    switch(token->GetKeyword())
                    {
                        case edt_name:
                            ReadName();
                            break;
                        case edt_library:
                            ReadLibrary();
                            break;
                        case edt_exports:
                            ReadExports();
                            break;
                        case edt_imports:
                            ReadImports();
                            break;
                        case edt_description:
                            ReadDescription();
                            break;
                        case edt_stacksize:
                            ReadStacksize();
                            break;
                        case edt_heapsize:
                            ReadHeapsize();
                            break;
                        case edt_code:
                            ReadCode();
                            break;
                        case edt_data:
                            ReadData();
                            break;
                        case edt_sections:
                            ReadSections();
                            break;
                        default:
                            throw new std::runtime_error("Invalid directive");
                    }
                }
            }
        }
        catch (std::runtime_error *e)
        {
            std::cout << fileName << "(" << lineno << "): " << e->what() << std::endl ;
            delete e;
        }
        delete stream;
    }
    else
    {
        std::cout << "File '" << name << "' not found." << std::endl;
    }
    return true;
}