Commit 4456a07b authored by Raquel Bromberg's avatar Raquel Bromberg

readme.txt --> README. Deleted commented out code and also code that wasn't...

readme.txt --> README. Deleted commented out code and also code that wasn't necessary for the class's main functions (e.g. all_matches and all_all_matches)
parent b0131d06
#ifndef UTIL_H
#define UTIL_H
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <sstream>
#include <time.h>
using namespace std;
class util
{
private:
public:
util();
vector<string> load_names(string dir);
void extract_paths(string full_path, string& p, string& b);
int rm_mkdir(string path, string dirname);
int rm(string path, string dirname);
int rm(string full_path);
void open_ifile(ifstream& instream, string infile, string var_name);
void open_ofile(ofstream& outstream, string outfile, string var_name);
void open_ofile_ne(ofstream& outstream, string outfile, string var_name);
void open_ofile_app(ofstream& outstream, string outfile, string var_name);
void get_tl(string infile,int& tl);
void get_rss(string infile,int& rss);
string int_to_string(int i);
void write_out_time(ofstream& logstream);
};
util::util()
{
}
void util::extract_paths(string full_path, string& p, string& b)
{
if(full_path[full_path.length()-1]=='/')
{
full_path = full_path.substr(0,full_path.length()-1);
}
p=b="";
bool slash_seen=false;
for(int i=full_path.length()-1; i>=0; i--)
{
if(!slash_seen && full_path[i]!='/')
{
b=full_path[i]+b;
}
else if(full_path[i]=='/' || slash_seen)
{
slash_seen=true;
p=full_path[i]+p;
}
}
}
int util::rm_mkdir(string path, string dirname)
{
string full_path = path+"/"+dirname;
string outcommand = "rm -r "+full_path;
if(system(NULL)) puts ("Ok");
else
{
exit(EXIT_FAILURE);
}
int system_return = system(outcommand.c_str());
//cout<<"rm -r "<<path<<" - system_return="<<system_return<<endl;
outcommand = "mkdir "+full_path;
system_return = system(outcommand.c_str());
//cout<<"mkdir "<<path<<" - system_return="<<system_return<<endl;
return system_return;
}
int util::rm(string path, string dirname)
{
string full_path = path+"/"+dirname;
string outcommand = "rm -r "+full_path;
if(system(NULL)) puts ("Ok");
else
{
exit(EXIT_FAILURE);
}
int system_return = system(outcommand.c_str());
return system_return;
}
int util::rm(string full_path)
{
string outcommand = "rm "+full_path;
if(system(NULL)) puts ("Ok");
else
{
exit(EXIT_FAILURE);
}
int system_return = system(outcommand.c_str());
return system_return;
}
vector<string> util::load_names(string dir)
{
vector<string> folders;
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
{
cout<<"Failed to open path to dir="<<dir<<endl;
return folders;
}
while ((dirp = readdir(dp)) != NULL)
{
string temp = string(dirp->d_name);
if(temp.length()>5)
{
folders.push_back(string(dirp->d_name));
}
else
{
//cout<<"Rejecting directory named "<<temp<<endl;
}
}
closedir(dp);
return folders;
}
void util::open_ifile(ifstream& instream, string infile, string var_name)
{
instream.open(infile.c_str());
if(instream.fail())
{
cout<<"Failed to open ifstream to "<<var_name<<" = "<<infile<<endl;
exit(1);
}
}
void util::open_ofile(ofstream& outstream, string outfile, string var_name)
{
outstream.open(outfile.c_str());
if(outstream.fail())
{
cout<<"Failed to open ofstream to "<<var_name<<" = "<<outfile<<endl;
exit(1);
}
}
void util::open_ofile_ne(ofstream& outstream, string outfile, string var_name)
{
outstream.open(outfile.c_str());
while(outstream.fail())
{
cout<<"util::open_ofile_ne(ofstream&,string,string)"<<endl;
cout<<"Failed to open stream to outfile = "<<outfile<<endl;
cout<<"Does the directory exist? Please create it otherwise and then enter any int to continue: ";
int wfd;
cin>>wfd;
outstream.open(outfile.c_str());
}
cout<<"util::open_ofile_ne(ofstream&,string,string): Successfully opened ofstream to "<<outfile<<endl;
}
void util::open_ofile_app(ofstream& outstream, string outfile, string var_name)
{
outstream.open(outfile.c_str(), ios::out | ios::app);
if(outstream.fail())
{
cout<<"Failed to open ofstream to "<<var_name<<" = "<<outfile<<endl;
exit(1);
}
}
void util::get_tl(string infile,int& tl)
{
ifstream instream;
open_ifile(instream,infile,"infile");
int i;
instream>>i>>i>>tl;
instream.close();
}
void util::get_rss(string infile,int& rss)
{
ifstream instream;
open_ifile(instream,infile,"infile");
instream>>rss;
instream.close();
}
string util::int_to_string(int i)
{
stringstream ss;
ss<<i;
string result;
ss>>result;
return result;
}
void util::write_out_time(ofstream& logstream)
{
time_t current_time;
current_time=time(NULL);
struct tm* timeinfo;
timeinfo=localtime(&current_time);
logstream<<"Date of run: "<<asctime(timeinfo)<<endl;
}
#endif /*UTIL_H*/
...@@ -24,3 +24,5 @@ script_do_tmerg.sh ...@@ -24,3 +24,5 @@ script_do_tmerg.sh
buildconcat_output.txt buildconcat_output.txt
rzs.cpp rzs.cpp
script_filter.sh script_filter.sh
#util.h#
readme.txt
...@@ -7,12 +7,11 @@ For all commands listed below, the character "$" indicates the commandline, and ...@@ -7,12 +7,11 @@ For all commands listed below, the character "$" indicates the commandline, and
************************************************************************************************************** **************************************************************************************************************
CONTENTS OF README: CONTENTS OF README:
1. COMPILING SLOPETREE 1) COMPILING SLOPETREE
2. RUNNING SLOPETREE WITHOUT FILTERING OR A REFERENCE SET (most basic run) 2) RUNNING SLOPETREE WITHOUT FILTERING OR A REFERENCE SET (most basic run)
3. ST-TREES WITH MOBILE ELEMENTS REMOVED 3) ST-TREES WITH MOBILE ELEMENTS REMOVED
4) ST-TREES FILTERED BY CONSERVATION 4) ST-TREES FILTERED BY CONSERVATION
5) USING THE PAIR-WISE CORRECTION FOR HORIZONTAL GENE TRANSFER 5) USING THE PAIR-WISE CORRECTION FOR HORIZONTAL GENE TRANSFER
6) DESCRIPTION OF EACH SLOPETREE PROGRAM
************************************************************************************************************** **************************************************************************************************************
1. COMPILING SLOPETREE 1. COMPILING SLOPETREE
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment