bool ribo_profile::assign_reads(fp_list_t& fp_base_list, const unordered_set<int>& type_set) { for (auto& r: fp_base_list) { // round 1: get candidate alignment loci if (r.used) continue; vector<position> loci; for (auto loc: r.al_loci) { rid_t refID(loc.refID); //transcript index rid_t t(get_transcript_index(refID)); if (loc.start<0 or loc.stop>len(t)) { cout<<"profile index out of bound! readID:"<<*r.seqs.begin()<<" "; cout<<r.al_loci.size()<<" "<<refID<<" "<<loc.start<<"-"<<loc.stop<<" "<<len(t)<<endl; continue; } if (type_set.find(loc.type)!=type_set.end()) loci.emplace_back(loc); } // for r.al_loci // no mappings of the desired type, move on to the next read if (loci.size() == 0) continue; // read processed mark as used r.used = true; // round 2: get transcript abundance vector<double> prob(loci.size(), 0); double tot_prob(0); for (size_t i=0; i!=prob.size(); ++i) { const position& loc(loci[i]); rid_t refID(loc.refID); rid_t t(get_transcript_index(refID)); prob[i] = get_tot_abundance(t); tot_prob += prob[i]; } // round 3: asign reads to loci proportional to loci prob for (size_t i=0; i!=prob.size(); ++i) { const position& loc(loci[i]); rid_t refID(loc.refID); rid_t t(get_transcript_index(refID)); double count(r.count); if (prob.size()!=1) count *= prob[i] / tot_prob; for (rid_t base = loc.start; base != loc.stop; ++base) add_read_count(t,base, count); add_tot_count(t, count); } }// for r: fp_base_list return check_tot_count(fp_base_list); }
size_t fread(void *ptr, size_t size, size_t nmemb,FILE *stream) { int realsize=size*nmemb; int retsize; orig_fwrite_f_type orig_fread; //int gettimeofday(struct timeval *tv, struct timezone *tz); struct timeval tv0; struct timeval tv1; struct timezone tz; int fd; //mtx.lock(); fd=fileno(stream); orig_fread = (orig_fread_f_type)dlsym(RTLD_NEXT,"fread"); gettimeofday(&tv0,&tz); retsize=orig_fread(ptr,size,nmemb,stream); gettimeofday(&tv1,&tz); std::string str; std::ostringstream oss; oss << "fread(" << ptr << "(" << fd << ")" << "," << size << "," << nmemb << "," << stream << ")="<< retsize << "\n"; log.add(oss.str()); if (size>=0) { if (myiio.existFd(fd)==-1) { Ifile ifi; ifi.setFd(fd); //ifi.setName(std::string("UNKNOWN-FWRITE")); ifi.setName(getStrFDInfo(fd)); ifi.setState(IOBYFILE_WRITE); myiio.iiof.push_back(ifi); } add_read_count(fd,retsize); add_read_time(fd,tv0,tv1); } //mtx.unlock(); return retsize; }
ssize_t read(int fd, void *buf, size_t count) { int size; int size_t_count=count; orig_read_f_type orig_read; //int gettimeofday(struct timeval *tv, struct timezone *tz); struct timeval tv0; struct timeval tv1; struct timezone tz; //mtx.lock(); orig_read = (orig_read_f_type)dlsym(RTLD_NEXT,"read"); gettimeofday(&tv0,&tz); size=orig_read(fd,buf,count); gettimeofday(&tv1,&tz); std::string str; std::ostringstream oss; oss << "read(" << fd << "," << buf << "," << count << ")\n"; log.add(oss.str()); if (size>=0) { if (myiio.existFd(fd)==-1) { Ifile ifi; ifi.setFd(fd); ifi.setName(getStrFDInfo(fd)); //ifi.setName(std::string("UNKNOWN-WRITE")); ifi.setState(IOBYFILE_READ); myiio.iiof.push_back(ifi); } add_read_count(fd,size); add_read_time(fd,tv0,tv1); } //mtx.unlock(); return size; }