示例#1
0
int main(int argc, char** argv)
{
  exitFunction = myExit; 

  NUM_BRANCHES = 1; // BAD 

  if(argc < 2) 
    {
      printUsage(std::cout);
      exitFunction(-1, false); 
    }

  auto files = std::vector<std::string>{};
  double burnin = 0; 
  auto id = std::string{};

  std::tie(id,files,burnin) = processCommandLine(argc, argv); 

  for(auto f : files)
    std::cout  << "file: " << f << std::endl; 

  for(auto file : files)
    {
      if(not std::ifstream(file))
	{
	  std::cerr << "Error: could not open file >" <<  file  << "<" << std::endl; 
	  exitFunction(-1, false); 
	}    
    }

  assert(files.size() >  0); 

  auto&& bipEx = BipartitionExtractor(files, false, true);

  nat numTree = bipEx.getNumTreesInFile( files.at(0) );
  
  // std::cout <<  "have "<< numTree << std::endl; 
  
  nat absBurnin = nat(double(numTree) * burnin); 

  bipEx.extractBips<true>(absBurnin);
  bipEx.printBipartitions(id);
  bipEx.printBipartitionStatistics(id); 
  bipEx.printFileNames(id);
  bipEx.printBranchLengths(id);

  return 0; 
}
void MainWindow::loginDialog()
{
    QDialog dialog(this);
    // Use a layout allowing to have a label next to each field
    QFormLayout form(&dialog);

    // Add some text above the fields
    form.addRow(new QLabel("Please enter credentials:"));

    // Add the lineEdits with their respective labels
    QLineEdit *userEdit = new QLineEdit(&dialog);
    QString userString = QString("Username:"******"Password:"******"Register");
    okButton->setText("Ok");
    cancelButton->setText("Cancel");

    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget(okButton);
    layout->addWidget(cancelButton);
    layout->addWidget(regButton);

    //QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
    form.addRow(layout);
    QObject::connect(regButton, SIGNAL(clicked()), this, SLOT(registerAccount()));
    QObject::connect(okButton, SIGNAL(clicked()), &dialog, SLOT(accept()));
    QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(exitFunction()));

    dialog.setWindowFlags( ( (dialog.windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowCloseButtonHint) );

    // ok button pressed enters the if statement
    // cancel button closes application
    // register button opens register dialog
    if (dialog.exec() == QDialog::Accepted) {
        // If the user didn't dismiss the dialog, do something with the fields
        std::string user = userEdit->text().toStdString();
        std::string pss = passEdit->text().toStdString();
        if (userEdit->text() == "" || passEdit->text() == "")
        {
            invalidDialog("Please enter a valid username or password");
            on_loginButton_clicked();
        }
        else
        {
            authenticate(user, pss);
            enableStatus(true);
        }
    }
}
示例#3
0
void CommandLine::assertFileExists(std::string filename)
{
  auto &&in = std::ifstream{filename}; 
  if( not in  )
    {
      std::cerr << "could not file file " << filename << ". Aborting." << std::endl; 
      exitFunction(-1, true); 
    }
}
示例#4
0
void BlockParams::Read(NxsToken &token)
{
  DemandEndSemicolon(token, "PARAMS");
  nat idCtr = 0; 

  auto catsFound = std::unordered_set<Category>{}; 

  while(true)
    {
      token.GetNextToken();
      NxsBlock::NxsCommandResult res = HandleBasicBlockCommands(token); 

      if (res == NxsBlock::NxsCommandResult(STOP_PARSING_BLOCK))
	return;

      if (res != NxsBlock::NxsCommandResult(HANDLED_COMMAND))
	{	  
	  auto str = token.GetToken(false); 

	  auto cat = CategoryFuns::getCategoryFromLinkLabel(str); 	  
	  parseScheme(token, cat, idCtr); 

	  if(catsFound.find(cat) != catsFound.end())
	    {
	      cerr << "parsing error: found a linking scheme for category  " <<  CategoryFuns::getShortName(cat) << " twice. Aborting." ; 
	      exitFunction(-1, true); 
	    }

	  if( cat == Category::TOPOLOGY)
	    {
	      cerr <<  "not implemented"; 
	      assert(0); 
	    }	    
	}
    }
}
示例#5
0
void CommandLine::initialize(  int argc, char **argv)
{
  // first copy the command line string 
  for(int i = 0; i < argc; ++i)
    {
      _cmdString += std::string(argv[i], argv[i] + strlen(argv[i])); 
      _cmdString += " "; 
    }

  int c ; 

  // TODO threads/ processes? 
  
  while( (c = getopt(argc,argv, "c:df:vhn:w:s:t:R:r:M:C:m:Sq:zxT:")) != EOF)
    {
      try
	{	  
	  switch(c)
	    {
	    case 'z': 
	      {
		quiet = true; 
	      }
	      break; 
	    case 'c': 		// config file 	  
	      {
		configFileName = std::string(optarg); 
		assertFileExists(configFileName);
	      }
	      break; 
	    case 'f': 		// aln file 
	      alnFileName = std::string(optarg); 
	      assertFileExists(alnFileName); 
	      break; 
	    case 'v':  		// version 
	      _onlyPrintVersion = true; 
	      break; 
	    case 'd': 
	      dryRun = true; 
	      break; 
	    case 'h': 		// help 
	      _onlyPrintHelp = true; 
	      break; 
	    case 'n': 		// runid 
	      runid = std::string(optarg); 	  
	      break; 
	    case 't': 		// trees -- have that in the config file? 
	      treeFile = std::string(optarg); 
	      break; 
	    case 'w':		// working dir  
	      workDir = std::string(optarg); 
	      break; 
	    case 's': 		// seed 
	      seed.v[0] = std::stoi(optarg);
	      break; 
	    case 'r': 
	      checkpointId = std::string{optarg};   
	      break; 
	    case 'q':
	      modelFile = std::string{optarg}; 
	      break; 
	    case 'm': 
	      singleModel = std::string{optarg}; 
	      break; 
	    case 'S': 
	      saveMemorySEV = true; 
	      break; 
	    case 'M': 
	      memoryMode = MemoryMode(std::stoi(optarg)); 
	      break; 
	    case 'C': 
	      chainNumParallel = std::stoi(optarg); 
	      break; 
	    case 'R': 
	      runNumParallel = std::stoi(optarg);
	      break; 
	    case 'T': 
	      _totalThreads = std::stoi(optarg); 
	      break; 
	      // case 'x': 
	      //   readerStride = std::stoi(optarg); 
	      //   break; 
	    case 'x': 
	      _hasThreadPinning = false; 
	      break;
	    default: 
	      {
		std::cerr << "Encountered unknown command line option -" <<  char(c) 
			  << "\n\nFor an overview of program options, please use -h" << std::endl ; 
		// TODO mpi-finalize stuff 
		exitFunction(-1, true); 
	      }
	    }
	}
      catch(const std::invalid_argument& ia)
	{
	  std::cerr << "Invalid argument >" << optarg << "< to option >" << reinterpret_cast<char*>(&c) << "<" << std::endl; 
	  exitFunction(-1, true);
	}
    }  
  
  if(_onlyPrintHelp || _onlyPrintVersion)
    return; 


  if(isYggdrasil
     && (_totalThreads % (runNumParallel * chainNumParallel)) != 0 )
    {
      std::cerr << "Error: for the threaded version it is currently necessary that the number of threads is a multiple of the product of the number of chains and runs that is executed in parallel." << std::endl; 
      exitFunction(-1, true); 
    }


  if(runid.compare("") == 0 )
    {
      std::cerr << "please specify a runid with -n runid" << std::endl; 
      exitFunction(-1, true); 
    }
  
  if(seed.v[0] != 0 && checkpointId.compare("") != 0 )
    {
      std::cout << std::endl << "You provided a seed and run-id for a restart from a checkpoint.\n"
		<< "Please be aware that the seed will be ignored." << std::endl; 
    }

  if(checkpointId.compare("") == 0 && seed.v[0] == 0 )
    {
      std::cerr << "please specify a seed via -s seed (must NOT be 0)"   << std::endl; 
      exitFunction(-1, true); 
    }

  if(workDir.compare("") != 0 && not OutputFile::directoryExists(workDir))
    {
      std::cout << std::endl << "Could not find the provided working directory >" << workDir << "<" << std::endl; 
      exitFunction(-1, true);
    }

  if(alnFileName.compare("") == 0 )
    {
      std::cerr << "please specify an alignment file via -f file" <<  std::endl 
		<< "You have to transform your NEWICK-style alignment into a binary file using the appropriate parser (see manual)." << std::endl; 

      exitFunction(-1, true); 
    }

  if(alnFileIsBinary())
    {
      if(singleModel.compare("") != 0 || modelFile.compare("") != 0 )
	{
	  std::cout << "Found binary alignment file. Additionally, you provided a model file\n"
	    "(-q) or specified a data type for a single partiton. This information\n"
	    "will be ignored.\n"; 
	  modelFile = ""; 
	  singleModel = ""; 
	}
    }
  else 
    {
      if(singleModel.compare("") == 0 && ( modelFile.compare("") == 0 || not std::ifstream(modelFile) )  )
	{
	  std::cout << "Found a phylip-style alignment file. However, you did not provide a\n"
		    << "model file (see -q, resp. it coul not be found) or a data type specification for a single\n"
		    << "partition (-m). Cannot proceed.\n" ; 
	  exitFunction(-1, true); 
	}
    }

  if( treeFile.compare("") != 0 && not std::ifstream(treeFile))
    {
      std::cout << "Could not find tree file passed via -t >"  << treeFile << "<"<< std::endl; 
      exitFunction(-1, true); 
    }
}
示例#6
0
static std::tuple<std::string,std::vector<std::string>,double, nat,bool>
processCommandLine(int argc, char **argv)
{
  auto id = std::string{}; 
  auto thresh = double(50); 
  bool isRefined = true; 
  auto files = std::vector<std::string>{}; 
  double burnin = 0.25; 

  int c = 0; 
  while( ( c = getopt(argc, argv, "n:t:f:b:h") ) != EOF )
    {
      switch(c)
	{
	case 'h': 
	  printUsage(std::cout);
	  exitFunction(0, false);
	  break; 
	case 'n': 
	  {
	    id = std::string{optarg, strlen(optarg)}; 
	  }
	  break; 
	case 't' : 
	  {
	    if(std::string{"MRE"}.compare(optarg) == 0 
	       || std::string{"mre"}.compare(optarg) == 0)
	      {
		thresh = 50; 
		isRefined = true; 
	      }
	    else 
	      {
		auto &&iss = std::istringstream{optarg}; 
		iss >> thresh	; 
		isRefined = false; 
	      }
	  }
	  break; 
	case 'f': 
	  {
	    int index = optind -1; 
	    while(index < argc)
	      {
		auto next = std::string{argv[index]}; 
		++index; 
		if(next[0] != '-') 
		  files.push_back(next);
		else 
		  {
		    optind =  index -1 ; 
		    break; 
		  }
	      }
	  }
	  break; 
	case 'b': 
	  {
	    auto &&iss = std::istringstream {optarg}; 
	    iss >> burnin; 
	  }
	  break; 
	default: 
	  {
	    std::cerr << "Unrecognized option >" <<  optarg << "<"  << std::endl; 
	    exitFunction(-1, false); 
	  }
	}
    }

  if(thresh < 50 || thresh > 100 )
    {
      std::cerr << "error: correct values for -t in [50,100] or MRE." << std::endl; 
      exitFunction(-1, false); 
    }

  if(files.size() == 0 )
    {
      std::cerr << "Please specfiy tree input files via -f" << std::endl; 
      exitFunction(-1, false); 
    }
  if(id.compare("") == 0)
    {
      std::cerr << "Please specify a runid for the output via -n. " << std::endl; 
      exitFunction(-1, false); 
    }
 
  if(not (  0 <= burnin   &&  burnin < 1. ))
    {
      std::cerr << "The relative burn-in range is [0,1)." << std::endl;
      exitFunction(-1, false); 
    }


  return std::make_tuple(id, files, burnin, thresh, isRefined);
}
示例#7
0
int main(int argc, char **argv)
{
  exitFunction = myExit; 

  NUM_BRANCHES = 1;   // BAD

  if(argc < 2 ) 
    {
      printUsage(std::cout);
      exitFunction(-1, false); 
    }

  bool isMre = false;   
  auto threshold = double{0.}; 
 
  std::string id= {}; 
  double burnin = 0; 
  auto files = std::vector<std::string>{}; 

  std::tie(id, files, burnin, threshold, isMre) = processCommandLine(argc, argv);

  for(auto &file : files)
    {
      if(not std::ifstream(file))
	{
	  std::cerr << "Error: could not open file >" << file << "<" << std::endl; 
	  exitFunction(-1, false); 
	}    
    }

  assert(threshold > 1); 
  threshold /= 100.; 

  auto&& ct = ConsensusTree(files, burnin, threshold,isMre); 
  auto header = ct.getTreeHeader(); 
  auto result = ct.getConsensusTreeString(false);
  auto type = ct.getType();

  auto&& ss = std::stringstream{}; 
  ss << PROGRAM_NAME << "_" << type << "Nexus." << id; 

  auto &&ss2 = std::ostringstream{}; 
  ss2 << PROGRAM_NAME << "_" << type << "Newick." << id ; 

  if(std::ifstream(ss.str()))
    {
      std::cerr << std::endl << "File " << ss.str() << " already exists (probably \n"
		<< "left over from a previous run). Please choose a new run-id or remove\n"
		<< "previous output files." << std::endl; 
      exitFunction(-1, false); 
    }

  auto &&outfile = std::ofstream(ss.str()); 
  outfile << header  << result << std::endl; 
  outfile << "end;" << std::endl; 


  auto &&outfile2 = std::ofstream{ss2.str()}; 
  outfile2 << ct.getConsensusTreeString(true) << std::endl; 


  std::cout << "Printed consensus tree in nexus format to " << ss.str() << std::endl; 
  std::cout << "Printed consensus tree in newick format to " << ss2.str() << std::endl; 

  return 0; 
}
示例#8
0
void BlockParams::partitionError(nat partition, size_t totalPart) const
{
  std::cerr << "In the parameter block of the configuration file you specified partition " << partition << ". However, there are only " << totalPart << " partitions in total in your alignment." << std::endl; 
  std::cerr << "NOTICE that the first partition has id 0 and the last of n partitions has the id (n-1) . " << std::endl; 
  exitFunction(-1, true); 
}
示例#9
0
void BlockParams::parseScheme(NxsToken& token, Category cat, nat &idCtr)
{
  auto numPart = tralnPtr->getNumberOfPartitions();
  auto partAppeared = std::vector<bool>(numPart, false); 

  token.GetNextToken();
  assert(token.GetToken().EqualsCaseInsensitive("=")); 
  token.GetNextToken();
  assert(token.GetToken().EqualsCaseInsensitive("(")); 

  auto scheme = std::vector<std::vector<nat>>{}; 
  while(not token.GetToken().EqualsCaseInsensitive(")") )
    {
      auto schemePart = std::vector<nat>{}; 
      bool startingNext = true; 
      
      // parse one partition part 
      while( not token.GetToken().EqualsCaseInsensitive(")") 	     
	     && (startingNext || not token.GetToken().EqualsCaseInsensitive(",")) )
	{
	  startingNext = false; 
	  // check if the separation item is an expasion item (-)
	  auto isLinkedRange =  token.GetToken().EqualsCaseInsensitive("-") ; 
	  auto isUnlinkedRange = token.GetToken().EqualsCaseInsensitive(":") ; 

	  token.GetNextToken();
	  nat part = token.GetToken().ConvertToInt();
	  nat start = ( isLinkedRange || isUnlinkedRange )  ? schemePart.back() +1  : part; 
	  nat end = part + 1 ;  

	  for(nat i = start ;  i < end ; ++i )
	    {
	      if(not (i < numPart))
		partitionError(i, numPart); 
	      if(partAppeared.at(i))
		{
		  tout << "error: partition " << i << " occurring twice in the same scheme. Check your parameter-block!" << std::endl; 
		  exitFunction(-1, true); 
		}
	      partAppeared.at(i) = true; 

	      if(isUnlinkedRange)
		{
		  scheme.push_back(schemePart);
		  schemePart = {i}; 
		}
	      else 
		schemePart.push_back(i); 
	    }

	  token.GetNextToken(); 
	}

      scheme.push_back(schemePart); 
    }

  // instantiate the parameters 
  for(auto schemePart : scheme )
    {
      assert(schemePart.size()  > 0 ); 
      parameters.push_back(CategoryFuns::getParameterFromCategory(cat,idCtr,getNumSeen(cat), schemePart, tralnPtr->getNumberOfTaxa()));
      ++idCtr; 
    }
}
示例#10
0
static std::tuple<std::string, std::vector<std::string>,double> processCommandLine(int argc, char **argv)
{
  double burnin = 0.25; 
  auto files = std::vector<std::string> {}; 
  auto id = std::string{}; 

  int c = 0; 
  while(   (c = getopt(argc, argv, "n:f:b:h") ) != EOF )
    {
      switch(c)
	{
	case 'h': 
	  {
	    printUsage(std::cout); 
	    exitFunction(-1, false); 
	  }
	  break; 
	case 'n': 
	  {
	    id = std::string{optarg, optarg + strlen(optarg)}; 
	  }
	  break; 
	case 'f': 
	  {
	    int index  = optind -1; 
	    while(index < argc)
	      {
		auto next = std::string{strdup(argv[index])}; 
		++index; 
		if(next[0] != '-') 
		  files.push_back(next);
		else 
		  {
		    optind =  index -1 ; 
		    break; 
		  }
	      }
	  }
	  break; 
	case 'b': 
	  {
	    auto &&iss = std::istringstream{optarg}; 
	    iss >> burnin; 
	  }
	  break; 
	default : 
	  {
	    std::cerr << "Error: unknown option >" << char(c) << "<. " << std::endl; 
	    exitFunction(-1, false); 
	  }
	}
    }

  if(not ( 0<= burnin && burnin < 1.  ) )
    {
      std::cerr << "The relative burn-in to be discarded must be in the range [0,1)." << std::endl; 
      exitFunction(-1, false); 
    }
 
  if(id.compare("") == 0)
    {
      std::cerr << "Please provide a run-id via -n " << std::endl; 
      exitFunction(-1, false); 
    }    
  
  return std::make_tuple(id, files, burnin);
}
示例#11
0
void Parser::constructor(string const& name, IntrusiveRefCntPtr<TypeDef> type, TypePtr const& typeRef)
{
	IntrusiveRefCntPtr<TypeConstructor> ctor(new TypeConstructor(name));
	type->constructors.push_back(ctor);
	ctor->type = typeRef;

	expect(TLParen);

	if(token != TRParen)
	{
		do
		{
			bool isLet = test(TLet);

			string name;

			// TODO: Common pattern?
			TypePtr type = maybeType(false);
			if(! type)
			{
				name = expectIdent();
				type = typeName(false);
			}

			ctor->members.push_back(TypeMember(name, type));
			++ctor->ctorParams;
		}
		while(test(TComma));
	}

	{
		string const& ctorName = name;
		// Constructor function
		IntrusiveRefCntPtr<FuncDef> ctorFunc(new FuncDef(ctorName));

		enterFunction(ctorFunc);
		enterScope(new Scope);

		// Constructor function has the same type parameters
		for(auto& p : type->typeParams)
			ctorFunc->typeParams.push_back(p);

		int dummy = 0;

		IntrusiveRefCntPtr<CreateExpr> body(new CreateExpr());

		body->ctor = ctor;

		for(int i = 0; i < ctor->ctorParams; ++i)
		{
			auto& member = ctor->members[i];
			auto p = declParam(ctorFunc, member.name, member.type->fresh(), &dummy);
			body->parameters.push_back(ExprPtr(new VarRef(p)));
		}

		ctorFunc->body = exitScope<Expr>(body);
		ctorFunc->returnType = typeRef;

		// TODO: Check for name collision
		mod->functions[ctorName] = ctorFunc;
		mod->constructorDefs[ctorName] = ctor;
		exitFunction();
	}

	expect(TRParen, true);
}
示例#12
0
IntrusiveRefCntPtr<FuncDef> Parser::funcDef(bool allowImplicitTypeVars)
{
	string const& name = nextIdent(false);

	// TODO: Always surround this in a type scope?

	IntrusiveRefCntPtr<FuncDef> def(new FuncDef(name));

	int paramCount = 0;
	enterFunction(def);
	enterScope(new Scope);

	if(test(TLParen))
	{
		if(token != TRParen)
		{
			do
			{
				TypePtr type;
				string paramName;
				if(allowImplicitTypeVars)
				{
					paramName = expectIdent();
					type = typeNameOrNewVar(false);
				}
				else
				{
					type = maybeType(false);
					if(! type)
					{
						paramName = expectIdent();
						type = typeName(false);
					}
				}

				declParam(def, paramName, type, &paramCount);
			}
			while(test(TComma));
		}

		expect(TRParen, true);
	}

	TypePtr returnType;
			
	if(firstType[token] || token == TIdent) // TODO: Types may be TIdent too, in certain circumstances
	{
		returnType = typeNameOrNewVar(true);
	}

	if(test(TLBrace))
	{
		auto const& body = statements();
		expect(TRBrace, true);

		def->body = exitScope<Expr>(body);
	}
	
	def->returnType = returnType;
	assert(paramCount == def->parameters.size());

	// TODO: Check for name collision
	mod->functions[def->name] = def;
	exitFunction();

	return def;
}