int Bedpe::loadFromFile(char * filename)
{
  bedpevec.clear();
  string line;
  ifstream myfile (filename);
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
    {
        bedpe_t bt;
        std::vector<std::string> tmp = my_split(line, '\t');
        bt.chr1=tmp[0];
        bt.start1=atol(tmp[1].c_str());
        bt.end1=atol(tmp[2].c_str());
        bt.chr2=tmp[3];
        bt.start2=atol(tmp[4].c_str());
        bt.end2=atol(tmp[5].c_str());
        bt.name=tmp[6];
        bt.score=atof(tmp[7].c_str()); 
        bt.strand1=tmp[8][0];
        bt.strand2=tmp[9][0];
        if(tmp.size()>10)
        {
            vector<string>::iterator it;
            for(it=tmp.begin()+10;it!=tmp.end();it++)
                bt.others.push_back(*it);
        }
        bedpevec.push_back(bt);
    }
    myfile.close();
  }    

  return 0;
}
Example #2
0
int		check_builtins(t_cmd *cmds, char **env)
{
    int		cur_case;
    char		**builtins;
    int		found;
    int		(*fptr[6])(t_cmd *, char ***);

    found = -1;
    cur_case = -1;
    if ((builtins = my_split(get_builtins(), ';')) == NULL)
        return (-1);
    fill_func_ptr(fptr);
    if (cmds->name != NULL)
    {
        while (builtins[++cur_case])
            if (my_strncmp(builtins[cur_case], cmds->name,
                           get_longest_string(builtins[cur_case], cmds->name)) == 0)
            {
                fptr[cur_case](cmds, &env);
                found = 1;
            }
        free_tab(builtins);
    }
    return (found);
}
int get_pseudo_counts(string & input, pseudo_counts_t & pct)
{
   pct.t_t=0;pct.f_t=0;pct.truth_t=0;pct.t_g=0;pct.f_g=0;pct.truth_g=0;
   vector<string> numStrs=my_split(input,',');
   if(numStrs.size()!=6)
   {
       cerr<<"We need 6 numbers for pseudo counts."<<endl;
       exit(0);
   }
   int t_t,f_t,truth_t,t_g,f_g,truth_g;
   t_t=atoi(numStrs[0].c_str());
   f_t=atoi(numStrs[1].c_str());
   truth_t=atoi(numStrs[2].c_str());
   t_g=atoi(numStrs[3].c_str());
   f_g=atoi(numStrs[4].c_str());
   truth_g=atoi(numStrs[5].c_str());
   
   if(t_t>truth_t)
   {
       cerr<<"For pseudo counts: True positive fusions transcripts should be less than or equal to transcripts in truth."<<endl;
       exit(0);
   }
   if(t_g>truth_g)
   {
       cerr<<"For pseudo counts: True positive fusions should be less than or equal to fusions in truth."<<endl;
       exit(0);
   }
   if(t_t<t_g)
   {
       cerr<<"For pseudo counts: True positive fusions transcripts should be greater than or equal to true positive fusions ."<<endl;
       exit(0);
   }
   if(f_t<f_g)
   {
       cerr<<"For pseudo counts: False positive fusions transcripts should be greater than or equal to false positive fusions ."<<endl;
       exit(0);
   }
   if(truth_t<truth_g)
   {
       cerr<<"For pseudo counts: Fusions transcripts in truth should be greater than or equal to fusions in truth."<<endl;
       exit(0);
   }

   pct.t_t=t_t;
   pct.f_t=f_t;
   pct.truth_t=truth_t;

   pct.t_g=t_g;
   pct.f_g=f_g;
   pct.truth_g=truth_g;


   return 0;
}
Example #4
0
void KKInOut::readInput(std::string fileName) {
	std::ifstream infile(fileName.c_str(), std::ios::in);
	char* buffer = new char[BUF_SIZE];
	buffer[0] = '#';
	std::string line;
	std::string param;
	std::string value;
	//std::cout << filename << std::endl;
	while (!infile.eof()) {
		while (buffer[0] == '#' || buffer[0] == ' ') {
			infile.getline(buffer, BUF_SIZE);
		}
		line  = buffer;
		line  = my_split(line, '#')[0];
		param = my_split(line, ' ')[0];
		value = my_split(line, ' ')[1];
		if (!param.compare("format:")) {
			if (!value.compare("bin"))  format = bin;
			if (!value.compare("txt"))  format = txt;
		}
		if (!param.compare("infile:"))  inFileName      = value;
		if (!param.compare("outfile:")) outFileName     = value;
		if (!param.compare("Wmax:"))    Wmax       = atof(value.c_str());
		if (!param.compare("Npoints:")) NpointsOut = atoi(value.c_str());
		if (!param.compare("check:"))   check = true;
		if (!param.compare("eps:"))     eps = atof(value.c_str());
		infile.getline(buffer, BUF_SIZE);
	}
	std::cout << "Input parameters for KK:" << std::endl;
	std::cout << "Data format: " << (format == txt ? "txt" : "bin") << std::endl;
	std::cout << "Input data file: "  << inFileName << std::endl;
	std::cout << "Output data file: " << outFileName << std::endl;
	std::cout << "Wmax: "        << Wmax << std::endl;
	std::cout << "NpointsOut: "  << NpointsOut << std::endl;
	std::cout << "check: "       << (check ? "yes" : "no") << std::endl;
	std::cout << "eps: "         << eps << std::endl;
	return;
}
Example #5
0
bool ReadEnergyDistributionCSV(const std::string &filepath,
			       std::vector<EnergyDistribution_t> &EnergyDistribution,
			       std::vector<EnergyDistribution_t> &CumulativeEnergyDistribution)
{
  // Open file
  std::ifstream ifs(filepath.c_str());
  if(ifs.fail()){
    std::cout << "file not found:" << filepath << std::endl;
    return false;
  }  
  

  // Read all data from csv
  std::string str;
  std::string delim(",");
  std::vector<double> data;
  
  while( getline(ifs, str) ){
    std::vector<std::string> token;
    token = my_split(str, delim);
    for(int i=0; i<token.size(); i++){
      data.push_back( my_stod(token[i]) );
    }
  }

  
  // Generate energy distribution
  for(int i=0; i< data.size()/2; i++){
    EnergyDistribution_t token;
    token.Energy_MeV =data[2*i];
    token.Probability =data[2*i+1];
    EnergyDistribution.push_back(token);
  }
  
  std::sort(EnergyDistribution.begin(), EnergyDistribution.end(), PredicateGreaterEnergyDistribution());

  // Gen cumulative
  double probSum=0.0;
  for(int i=0; i<EnergyDistribution.size(); i++){
    probSum += EnergyDistribution[i].Probability;
    EnergyDistribution_t ced;
    ced.Probability =probSum;
    ced.Energy_MeV =EnergyDistribution[i].Energy_MeV;
    CumulativeEnergyDistribution.push_back(ced);
  }

  return true;
}
Example #6
0
char		*get_filename(char *cmd)
{
  int		cur_case;
  char		**tab;
  char		*name;

  cur_case = -1;
  if (!cmd)
    return (NULL);
  tab = my_split(cmd, ' ');
  if ((cur_case = get_index_elem(tab, ">")) == -1 &&
      (cur_case = get_index_elem(tab, ">>")) == -1 &&
      (cur_case = get_index_elem(tab, "<")) == -1)
        return (NULL);
  name = my_strdup(tab[cur_case + 1]);
  free_tab(tab);
  return (name);
}
Example #7
0
std::vector<std::string> my_split(const std::string &s, 
								char delim) {
	std::vector<std::string> elems;
	my_split(s, delim, elems);
	return elems;
}
Example #8
0
my_tab my_tsplit(const char *str, const char *sep)
{
    int i;
    char **t = my_split(str, sep, &i);
    return my_tbuild((void**)t, i);
}
Example #9
0
static void proc_gps_gpx(struct gpsfile *gpsf,
			 void (*gpsproc)(struct nmea_pointinfo *,void *),
			 void *data)
{
  static xmlSAXHandler myhandler={
    .initialized = 1,
    .startElement = mystarthandler,
    .endElement = myendhandler,
    .characters = mycharacters
  };

  gpsf->gpsproc=gpsproc;
  gpsf->gpsproc_data=data;
  if (!gpsf->ctxt) {
    
    gpsf->ctxt = xmlCreatePushParserCtxt(&myhandler, gpsf,
					 gpsf->buf,gpsf->bufpos,
					 "gpxfile");
  } else {
    xmlParseChunk(gpsf->ctxt,gpsf->buf,gpsf->bufpos,0);
  }
  gpsf->bufpos=0;
}

static void proc_gps_nmea(struct gpsfile *gpsf,
			  void (*gpsproc)(struct nmea_pointinfo *,void *),
			  void *data)
{
  char *endp;
  if (!strncmp(gpsf->buf,"<?xml",5)) {
    gpsf->handling_procedure=proc_gps_gpx;
    proc_gps_gpx(gpsf,gpsproc,data);
    return;
  }
  while ((endp=memchr(gpsf->buf,'\n',gpsf->bufpos))) {
    int readlen;
    *endp=0;
    /* printf("gps line: %s ENDLINE\n",gpsf->buf); */
    if (strstr(gpsf->buf,"<?xml")) {
      *endp='\n';
      gpsf->handling_procedure=proc_gps_gpx;
      proc_gps_gpx(gpsf,gpsproc,data);
      return;
    }
    if (strncmp(gpsf->buf,"$GPRMC",6)==0) {
      char *fields[13];
      int numfields=my_split(gpsf->buf,fields,",",13);
      if (((numfields == 13)||(numfields == 12))&&(strlen(fields[3])>3)) {
	struct tm tm;
        time_t t;
	gpsf->curpoint.lat=to_seconds(fields[3]);
        gpsf->curpoint.lon=to_seconds(fields[5]);
        if ((fields[4])[0] == 'S')
          gpsf->curpoint.lat=-gpsf->curpoint.lat;
        if ((fields[6])[0] == 'W')
          gpsf->curpoint.lon=-gpsf->curpoint.lon;
	memset(&tm,0,sizeof(tm));
	sscanf(fields[1],"%02d%02d%02d",&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
	sscanf(fields[9],"%02d%02d%02d",&tm.tm_mday,&tm.tm_mon,&tm.tm_year);
	tm.tm_mon--;
	if (tm.tm_year<70)
	  tm.tm_year+=100;
	t=gmmktime(&tm);  /* t=tm-tz */
        gpsf->curpoint.time=t;
	gpsf->curpoint.start_new=gpsf->first?1:0;
        if ((gpsf->curpoint.time-gpsf->last_fix)>20) {
          gpsf->curpoint.start_new=1; 
        }
        gpsf->last_fix=t;
        gpsf->curpoint.speed=atof(fields[7]);
	if (strlen(fields[8]))
	  gpsf->curpoint.heading=atof(fields[8]);
        else
	  gpsf->curpoint.heading=INVALID_HEADING;
	gpsf->curpoint.state=(numfields==13)?((fields[12])[0]):'?';
        gpsproc(&gpsf->curpoint,data);
	gpsf->first=0;
      }
    } else if (!strncmp(gpsf->buf,"$GPGGA",6)) {
      char *fields[15];
      int numfields=my_split(gpsf->buf,fields,",",15);
      if (numfields>8)
	gpsf->curpoint.hdop=10.0*atof(fields[8]);
    }
    endp++;
    readlen=endp-gpsf->buf;
    if (readlen != gpsf->bufpos)
      memmove(gpsf->buf,endp,gpsf->bufpos-readlen);
    gpsf->bufpos-=readlen;
  }
 
}