Ejemplo n.º 1
0
bool ProtoBuf::ImportFile(const string& pbfile, const string& pbinc,
        DiskSourceTree& dst, Importer*& ipt, 
        const FileDescriptor*& fd)
{
    // 分离proto_file的目录和文件名
    char* dd;
    dd = strdup(pbfile.c_str());
    string dir = dirname(dd);
    free(dd);
    dd = strdup(pbfile.c_str());
    string file = basename(dd);
    free(dd);

    // 增加proto_inc
    EList<string> arrPath;
    if (! pbinc.empty())
    {
        Str::SplitTrimNoNull(pbinc, arrPath, ":");
    }

    // 构造proto,遍历所有的service
    dst.MapPath("", dir);
    GLOG(IM_DEBUG, "add %s to map path", dir.c_str());
    for(string* i = arrPath.begin(); ! arrPath.end(); i = arrPath.next())
    {
        GLOG(IM_DEBUG, "add %s to map path", i->c_str());
        dst.MapPath("", *i);
    }
    dst.MapPath("", SETUP_ROOT_DIR "" PROTO_DIR "/");
    dst.MapPath("", SETUP_ROOT_DIR "/dev/proto/");
    ipt = new Importer(&dst, new IM_ErrorCollector());
    fd = ipt->Import(file);
    return fd != NULL;
}
void MechPurchaseScreen::end()
{
	if ( !acceptPressed && status != MAINMENU )
	{ 
		// sell all current stuff
		EList< LogisticsMech*, LogisticsMech* > list;
		LogisticsData::instance->getInventory( list );
		for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.End(); !iter.IsDone(); iter-- )
		{
			LogisticsData::instance->sellMech( (*iter) );
		}


		unsigned long base, color1, color2;
		for ( MECH_LIST::EIterator pIter = prevInventory.Begin(); !pIter.IsDone(); pIter++ )
		{
			(*pIter).getColors(base, color1, color2);
			LogisticsData::instance->addMechToInventory( (*pIter).getVariant(), (*pIter).getPilot(),
				(*pIter).getForceGroup(), true );
		}

	}

	variantListBox.removeAllItems(true);
	inventoryListBox.removeAllItems(true);

	mechDisplay.setMech( NULL );
}
Ejemplo n.º 3
0
EHttpProxyResponse::EHttpProxyResponse(const char* httpVersion,
		const char* statusLine, EMap<EString*, EList<EString*>*>* headers) {
	this->httpVersion = httpVersion;
	this->statusLine = statusLine;

	// parses the status code from the status line
	EString statusLine_(statusLine);
	this->statusCode = statusLine_.charAt(0) == ' ' ? EInteger::parseInt(statusLine_.substring(1, 4).c_str()) : EInteger
			::parseInt(statusLine_.substring(0, 3).c_str());

	this->headers.clear(); // Clear old.

	if (headers) {
		sp<EIterator<EMapEntry<EString*, EList<EString*>*>*> > iter = headers->entrySet()->iterator();
		while (iter->hasNext()) {
			EMapEntry<EString*, EList<EString*>*>* header = iter->next();
			EList<EString*>* v = header->getValue();
			if (v) {
				EArrayList<EString*>* list = new EArrayList<EString*>(1);
				sp<EIterator<EString*> > it = v->iterator();
				while (it->hasNext()) {
					list->add(new EString(it->next()));
				}
				this->headers.put(new EString(header->getKey()->c_str()), list);
			}
			else {
				this->headers.put(new EString(header->getKey()->c_str()), null);
			}
		}
	}
}
Ejemplo n.º 4
0
EString EHttpProxyRequest::toHttpString() {
    EString sb;

    sb.append(getHttpVerb()).append(' ').append(getHttpURI()).append(' ').append(getHttpVersion())
    .append(EHttpProxyConstants_CRLF);

    boolean hostHeaderFound = false;

    if (getHeaders() != null) {
        sp<EIterator<EMapEntry<EString*, EList<EString*>*>*> > iter = getHeaders()->entrySet()->iterator();
        while (iter->hasNext()) {
            EMapEntry<EString*, EList<EString*>*>* header = iter->next();
            if (!hostHeaderFound) {
                hostHeaderFound = header->getKey()->equalsIgnoreCase("host");
            }

            EList<EString*>* values = header->getValue();
            if (values) {
                sp<EIterator<EString*> > iter2 = values->iterator();
                while (iter2->hasNext()) {
                    sb.append(header->getKey()->c_str()).append(": ").append(iter2->next()).append(EHttpProxyConstants_CRLF);
                }
            }
        }

        if (!hostHeaderFound && (eso_strcmp(getHttpVersion(), EHttpProxyConstants_HTTP_1_1) == 0)) {
            sb.append("Host: ").append(getHost()).append(EHttpProxyConstants_CRLF);
        }
    }

    sb.append(EHttpProxyConstants_CRLF);

    return sb;
}
Ejemplo n.º 5
0
static void print_index_sequences(ostream& fout, Ebwt& ebwt)
{
    EList<string>* refnames = &(ebwt.refnames());

    TStr cat_ref;
    ebwt.restore(cat_ref);

    uint32_t curr_ref = 0xffffffff;
    string curr_ref_seq = "";
    uint32_t curr_ref_len = 0xffffffff;
    uint32_t last_text_off = 0;
    size_t orig_len = cat_ref.length();
    uint32_t tlen = 0xffffffff;
    bool first = true;
    for(size_t i = 0; i < orig_len; i++) {
        uint32_t tidx = 0xffffffff;
        uint32_t textoff = 0xffffffff;
        tlen = 0xffffffff;
        bool straddled = false;
        ebwt.joinedToTextOff(1 /* qlen */, (uint32_t)i, tidx, textoff, tlen, true, straddled);

        if (tidx != 0xffffffff && textoff < tlen)
        {
            if (curr_ref != tidx)
            {
                if (curr_ref != 0xffffffff)
                {
                    // Add trailing gaps, if any exist
                    if(curr_ref_seq.length() < curr_ref_len) {
                        curr_ref_seq += string(curr_ref_len - curr_ref_seq.length(), 'N');
                    }
                    print_fasta_record(fout, (*refnames)[curr_ref], curr_ref_seq);
                }
                curr_ref = tidx;
                curr_ref_seq = "";
                curr_ref_len = tlen;
                last_text_off = 0;
                first = true;
            }

            uint32_t textoff_adj = textoff;
            if(first && textoff > 0) textoff_adj++;
            if (textoff_adj - last_text_off > 1)
                curr_ref_seq += string(textoff_adj - last_text_off - 1, 'N');

            curr_ref_seq.push_back(cat_ref[i]);
            last_text_off = textoff;
            first = false;
        }
    }
    if (curr_ref < refnames->size())
    {
        // Add trailing gaps, if any exist
        if(curr_ref_seq.length() < curr_ref_len) {
            curr_ref_seq += string(curr_ref_len - curr_ref_seq.length(), 'N');
        }
        print_fasta_record(fout, (*refnames)[curr_ref], curr_ref_seq);
    }

}
Ejemplo n.º 6
0
EList ListGraph::getAdj(NodeID u) const{
	 EList lst;
	 node* temp = ary[u].next;
	 while(temp != NULL){
		 lst.push_back(temp->p);
		 temp = temp->next;
	 };
	 return lst;
 };
Ejemplo n.º 7
0
void
Client::RemoveEventWorker(EventWorker* p_worker) {
    for(EList::compatibility_iterator it = m_eventWorkers.GetFirst(); it ; it = it->GetNext()) {
        if (it->GetData() == p_worker) {
            //wxLogDebug(wxT("Deleting event worker"));
            delete it->GetData();
            m_eventWorkers.DeleteNode(it);
            return;
        }
    }
}
Ejemplo n.º 8
0
std::list<NWPair> ListGraph::getAdj(NodeID u) const
{
    EList temp;
    EList::const_iterator it;
    for(it = edgeList[u].begin(); it != edgeList[u].end(); it++)
    {
        NWPair theEdge = *it;
        if(theEdge.first != NULL)
            temp.push_back(NWPair(theEdge.first, theEdge.second));
    }
    return temp;

}
Ejemplo n.º 9
0
 EList MatrixGraph::getAdj(NodeID u) const{

	 EList lst;
	 //for the number of nodes
	 for(int i = 0; i < num_nodes; i++){
		 // if they are atached
		 if(ary[u][i] != 0){
			 //add to the vector
			lst.push_back(NWPair(i, ary[u][i]));
		 };
	 };
	 return lst;
 };
Ejemplo n.º 10
0
/**
 * Clip off some of the low-numbered positions.
 */
void Edit::clipLo(EList<Edit>& ed, size_t len, size_t amt) {
	size_t nrm = 0;
	for(size_t i = 0; i < ed.size(); i++) {
		assert_lt(ed[i].pos, len);
		if(ed[i].pos < amt) {
			nrm++;
		} else {
			// Shift everyone else up
			ed[i].pos -= (uint32_t)amt;
		}
	}
	ed.erase(0, nrm);
}
Ejemplo n.º 11
0
   // @note The general idea of this method comes from https://github.com/ScottDVincent/HW05_vincensd_v2/
	std::list<NWPair> MatrixGraph::getAdj(NodeID u) const {
		if (0 <= u < M.size()) {
			EList list; 
			for(int i = 0; i < M.at(u).size(); i++) {
				if (M.at(u).at(i) != 0 ) {
					NWPair pair(i, M.at(u).at(i));
					if (pair.second != 0) 
						list.push_back(pair);
				}
			}
			return list;
		}
	}
Ejemplo n.º 12
0
/**
 * Calculate a vector containing the sizes of all of the patterns in
 * all of the given input files, in order.  Returns the total size of
 * all references combined.  Rewinds each istream before returning.
 */
std::pair<size_t, size_t>
fastaRefReadSizes(
	EList<FileBuf*>& in,
	EList<RefRecord>& recs,
	const RefReadInParams& rparms,
	BitpairOutFileBuf* bpout,
	int& numSeqs)
{
	uint32_t unambigTot = 0;
	uint32_t bothTot = 0;
	RefReadInParams rpcp = rparms;
	assert_gt(in.size(), 0);
	// For each input istream
	for(size_t i = 0; i < in.size(); i++) {
		bool first = true;
		assert(!in[i]->eof());
		// For each pattern in this istream
		while(!in[i]->eof()) {
			RefRecord rec = fastaRefReadSize(*in[i], rparms, first, bpout);
			if((unambigTot + rec.len) < unambigTot) {
				cerr << "Error: Reference sequence has more than 2^32-1 characters!  Please divide the" << endl
				     << "reference into batches or chunks of about 3.6 billion characters or less each" << endl
				     << "and index each independently." << endl;
				throw 1;
			}
			// Add the length of this record.
			if(rec.first) numSeqs++;
			unambigTot += rec.len;
			bothTot += rec.len;
			bothTot += rec.off;
			first = false;
			if(rec.len == 0 && rec.off == 0 && !rec.first) continue;
			recs.push_back(rec);
		}
		// Reset the input stream
		in[i]->reset();
		assert(!in[i]->eof());
#ifndef NDEBUG
		// Check that it's really reset
		int c = in[i]->get();
		assert_eq('>', c);
		in[i]->reset();
		assert(!in[i]->eof());
#endif
	}
	assert_geq(bothTot, 0);
	assert_geq(unambigTot, 0);
	return make_pair(
		unambigTot, // total number of unambiguous DNA characters read
		bothTot); // total number of DNA characters read, incl. ambiguous ones
}
Ejemplo n.º 13
0
/**
 * Given a list of edits and a DNA string representing the query
 * sequence, check that the edits are consistent with respect to the
 * query.
 */
bool Edit::repOk(
	const EList<Edit>& edits,
	const BTDnaString& s,
	bool fw,
	size_t trimBeg,
	size_t trimEnd)
{
	if(!fw) {
		invertPoss(const_cast<EList<Edit>&>(edits), s.length()-trimBeg-trimEnd, false);
		swap(trimBeg, trimEnd);
	}
	for(size_t i = 0; i < edits.size(); i++) {
		const Edit& e = edits[i];
		size_t pos = e.pos;
		if(i > 0) {
			assert_geq(pos, edits[i-1].pos);
		}
		bool del = false, mm = false;
		while(i < edits.size() && edits[i].pos == pos) {
			const Edit& ee = edits[i];
			assert_lt(ee.pos, s.length());
            if(ee.type != EDIT_TYPE_SPL) {
                if(ee.qchr != '-') {
                    assert(ee.isRefGap() || ee.isMismatch());
                    assert_eq((int)ee.qchr, s.toChar(ee.pos+trimBeg));
                }
            }
			if(ee.isMismatch()) {
				assert(!mm);
				mm = true;
				assert(!del);
			} else if(ee.isReadGap()) {
				assert(!mm);
			} else if(ee.isRefGap()) {
				assert(!mm);
				assert(!del);
				del = true;
			} else if(ee.isSpliced()) {
                
            }
			i++;
		}
	}
	if(!fw) {
		invertPoss(const_cast<EList<Edit>&>(edits), s.length()-trimBeg-trimEnd, false);
	}
	return true;
}
void AlignerDriverRootSelector::select(
	const Read& q,
	const Read* qo,
	bool nofw,
	bool norc,
	EList<DescentConfig>& confs,
	EList<DescentRoot>& roots)
{
	// Calculate interval length for both mates
	int interval = rootIval_.f<int>((double)q.length());
	if(qo != NULL) {
		// Boost interval length by 20% for paired-end reads
		interval = (int)(interval * 1.2 + 0.5);
	}
	float pri = 0.0f;
	for(int fwi = 0; fwi < 2; fwi++) {
		bool fw = (fwi == 0);
		if((fw && nofw) || (!fw && norc)) {
			continue;
		}
		// Put down left-to-right roots w/r/t forward and reverse-complement reads
		{
			bool first = true;
			size_t i = 0;
			while(first || (i + landing_ <= q.length())) {
				confs.expand();
				confs.back().cons.init(landing_, consExp_);
				roots.expand();
				roots.back().init(
					i,          // offset from 5' end
					true,       // left-to-right?
					fw,         // fw?
					q.length(), // query length
					pri);       // root priority
				i += interval;
				first = false;
			}
		}
		// Put down right-to-left roots w/r/t forward and reverse-complement reads
		{
			bool first = true;
			size_t i = 0;
			while(first || (i + landing_ <= q.length())) {
				confs.expand();
				confs.back().cons.init(landing_, consExp_);
				roots.expand();
				roots.back().init(
					q.length() - i - 1, // offset from 5' end
					false,              // left-to-right?
					fw,                 // fw?
					q.length(),         // query length
					pri);               // root priority
				i += interval;
				first = false;
			}
		}
	}
}
Ejemplo n.º 15
0
static void resetOptions() {
	gVerbose                = 0;
	gQuiet					= false;
	sanityCheck				= 0;  // enable expensive sanity checks
	seed					= 0; // srandom() seed
	showVersion				= false; // just print version and quit?
	qUpto					= 0xffffffff; // max # of queries to read
	nthreads				= 1;     // number of pthreads operating concurrently
	skipReads				= 0;     // # reads/read pairs to skip
	gGapBarrier				= 4;     // disallow gaps within this many chars of either end of alignment
	bonusMatchType  = DEFAULT_MATCH_BONUS_TYPE;
	bonusMatch      = DEFAULT_MATCH_BONUS;
	penMmcType      = DEFAULT_MM_PENALTY_TYPE;
	penMmcMax       = DEFAULT_MM_PENALTY_MAX;
	penMmcMin       = DEFAULT_MM_PENALTY_MIN;
	penNType        = DEFAULT_N_PENALTY_TYPE;
	penN            = DEFAULT_N_PENALTY;
	penNCatPair     = DEFAULT_N_CAT_PAIR; // concatenate mates before N filtering?
	localAlign      = false;     // do local alignment in DP steps
	penRdGapConst   = DEFAULT_READ_GAP_CONST;
	penRfGapConst   = DEFAULT_REF_GAP_CONST;
	penRdGapLinear  = DEFAULT_READ_GAP_LINEAR;
	penRfGapLinear  = DEFAULT_REF_GAP_LINEAR;
	scoreMin.init  (SIMPLE_FUNC_LINEAR, DEFAULT_MIN_CONST,   DEFAULT_MIN_LINEAR);
	nCeil.init     (SIMPLE_FUNC_LINEAR, 0.0f, std::numeric_limits<double>::max(), 2.0f, 0.1f);
	msIval.init    (SIMPLE_FUNC_LINEAR, 1.0f, std::numeric_limits<double>::max(), DEFAULT_IVAL_B, DEFAULT_IVAL_A);
	enable8            = true;  // use 8-bit SSE where possible?
	cminlen            = 2000;  // longer reads use checkpointing
	cpow2              = 4;     // checkpoint interval log2
	doTri              = false; // do triangular mini-fills?
	ignoreQuals = false;     // all mms incur same penalty, regardless of qual
	queries.clear();         // list of query files
	outfile.clear();         // write output to this file
}
Ejemplo n.º 16
0
/**
 * Create a BitPairReference encapsulating the reference portion of the
 * index at the given basename.  Iterate through the reference
 * sequences, sending each one to print_ref_sequence to print.
 */
static void print_ref_sequences(
    ostream& fout,
    bool color,
    const EList<string>& refnames,
    const uint32_t* plen,
    const string& adjustedEbwtFileBase)
{
    BitPairReference ref(
        adjustedEbwtFileBase, // input basename
        color,                // true -> expect colorspace reference
        false,                // sanity-check reference
        NULL,                 // infiles
        NULL,                 // originals
        false,                // infiles are sequences
        false,                // memory-map
        false,                // use shared memory
        false,                // sweep mm-mapped ref
        verbose,              // be talkative
        verbose);             // be talkative at startup
    assert_eq(ref.numRefs(), refnames.size());
    for(size_t i = 0; i < ref.numRefs(); i++) {
        print_ref_sequence(
            fout,
            ref,
            refnames[i],
            i,
            plen[i] + (color ? 1 : 0));
    }
}
Ejemplo n.º 17
0
void
Client::StartWorker(workMode pMode) {
    int msgsize = 1 + (int) (250000.0 * (rand() / (RAND_MAX + 1.0)));
    char* buf = CreateBuffer(&msgsize);

    //fill data part of buffer with random bytes
    for (int i = 2; i < (msgsize); i++) {
        buf[i] = i % 256;
    }

    if (pMode == THREADS) {
        ThreadWorker* c = new ThreadWorker(m_host,buf,msgsize+2);
        if (c->Create() != wxTHREAD_NO_ERROR) {
            wxLogError(wxT("Cannot create more threads"));
        } else {
            c->Run();
            m_threadWorkers.Append(c);
        }
    } else {
        EventWorker* e = new EventWorker(m_host,buf,msgsize+2);
        e->Run();
        m_eventWorkers.Append(e);
    }
    m_statConnecting++;
}
Ejemplo n.º 18
0
EList *
e_list_duplicate (EList *old)
{
	EList *list = g_object_new (E_TYPE_LIST, NULL);

	list->copy    = old->copy;
	list->free    = old->free;
	list->closure = old->closure;
	list->list    = g_list_copy (old->list);
	if (list->copy) {
		GList *listlist;
		for (listlist = list->list; listlist; listlist = listlist->next) {
			listlist->data = list->copy (listlist->data, list->closure);
		}
	}
	return list;
}
Ejemplo n.º 19
0
int
Client::OnExit()
{
    for(EList::compatibility_iterator it = m_eventWorkers.GetFirst(); it ; it->GetNext()) {
        delete it->GetData();
    }
    return 0;
}
Ejemplo n.º 20
0
/**
 * Clip off some of the high-numbered positions.
 */
void Edit::clipHi(EList<Edit>& ed, size_t len, size_t amt) {
	assert_leq(amt, len);
	size_t max = len - amt;
	size_t nrm = 0;
	for(size_t i = 0; i < ed.size(); i++) {
		size_t ii = ed.size() - i - 1;
		assert_lt(ed[ii].pos, len);
		if(ed[ii].pos > max) {
			nrm++;
		} else if(ed[ii].pos == max && !ed[ii].isReadGap()) {
			nrm++;
		} else {
			break;
		}
	}
	ed.resize(ed.size() - nrm);
}
Ejemplo n.º 21
0
void EHttpDigestAuthLogicHandler::handleResponse(sp<EHttpProxyResponse>& response) {
	this->response = response;

	if (step == 0) {
		if (response->getStatusCode() != 401 && response->getStatusCode() != 407) {
			EString msg("Received unexpected response code (");
			msg << response->getStatusLine() << ").";
			throw EProxyAuthException(__FILE__, __LINE__, msg.c_str());
		}

		// Header should look like this
		// Proxy-Authenticate: Digest still_some_more_stuff
		EString k("Proxy-Authenticate");
		EList<EString*>* values = response->getHeaders()->get(&k);
		EString* challengeResponse = null;

		sp<EIterator<EString*> > iter = values->iterator();
		while (iter->hasNext()) {
			EString* s = iter->next();
			if (s->startsWith("Digest")) {
				challengeResponse = s;
				break;
			}
		}

		if (challengeResponse == null) {
			throw EProxyAuthException(__FILE__, __LINE__, "Server doesn't support digest authentication method !");
		}

		try {
			EString s = challengeResponse->substring(7);
			directives = EStringUtilities::parseDirectives((byte*)s.c_str(), s.length());
		} catch (EException& e) {
			throw EProxyAuthException(__FILE__, __LINE__, "Parsing of server digest directives failed", &e);
		}
		step = 1;
	} else {
		EString msg("Received unexpected response code (");
		msg << response->getStatusLine() << ").";
		throw EProxyAuthException(__FILE__, __LINE__,  msg.c_str());
	}
}
Ejemplo n.º 22
0
void EHttpProxyRequest::setHeaders(EMap<EString*, EList<EString*>*>* headers) {
    if (!headers) return;

    this->headers.clear(); // Clear old.

    sp<EIterator<EMapEntry<EString*, EList<EString*>*>*> > iter = headers->entrySet()->iterator();
    while (iter->hasNext()) {
        EMapEntry<EString*, EList<EString*>*>* header = iter->next();
        EArrayList<EString*>* listCopy = null;
        EList<EString*>* values = header->getValue();
        if (values) {
            listCopy = new EArrayList<EString*>();
            sp<EIterator<EString*> > iter2 = values->iterator();
            while (iter2->hasNext()) {
                listCopy->add(new EString(iter2->next()));
            }
        }
        this->headers.put(new EString(header->getKey()->c_str()), listCopy);
    }
}
Ejemplo n.º 23
0
/**
 * Merge second argument into the first.  Assume both are sorted to
 * begin with.
 */
void Edit::merge(EList<Edit>& dst, const EList<Edit>& src) {
	size_t di = 0, si = 0;
	while(di < dst.size()) {
		if(src[si].pos < dst[di].pos) {
			dst.insert(src[si], di);
			si++; di++;
		} else if(src[si].pos == dst[di].pos) {
			// There can be two inserts at a given position, but we
			// can't merge them because there's no way to know their
			// order
			assert(src[si].isReadGap() != dst[di].isReadGap());
			if(src[si].isReadGap()) {
				dst.insert(src[si], di);
				si++; di++;
			} else if(dst[di].isReadGap()) {
				di++;
			}
		}
	}
	while(si < src.size()) dst.push_back(src[si++]);
}
Ejemplo n.º 24
0
/**
 * Delete all the index files that we tried to create.  For when we had to
 * abort the index-building process due to an error.
 */
static void deleteIdxFiles(
	const string& outfile,
	bool doRef,
	bool justRef)
{
	
	for(size_t i = 0; i < filesWritten.size(); i++) {
		cerr << "Deleting \"" << filesWritten[i].c_str()
		     << "\" file written during aborted indexing attempt." << endl;
		remove(filesWritten[i].c_str());
	}
}
Ejemplo n.º 25
0
/**
 * Bowtie main function.  It is placed in a separate source file to
 * make it slightly easier to compile Bowtie as a library.
 *
 * If the user specifies -A <file> as the first two arguments, main
 * will interpret that file as having one set of command-line arguments
 * per line, and will dispatch each batch of arguments one at a time to
 * bowtie.
 */
int main(int argc, const char **argv) {
	if(argc > 2 && strcmp(argv[1], "-A") == 0) {
		const char *file = argv[2];
		ifstream in;
		in.open(file);
		char buf[4096];
		int lastret = -1;
		while(in.getline(buf, 4095)) {
			EList<string> args;
			args.push_back(string(argv[0]));
			tokenize(buf, " \t", args);
			const char **myargs = (const char**)malloc(sizeof(char*)*args.size());
			for(size_t i = 0; i < args.size(); i++) {
				myargs[i] = args[i].c_str();
			}
			if(args.size() == 1) continue;
			lastret = hisat2((int)args.size(), myargs);
			free(myargs);
		}
		if(lastret == -1) {
			cerr << "Warning: No arg strings parsed from " << file << endl;
			return 0;
		}
		return lastret;
	} else {
		return hisat2(argc, argv);
	}
}
Ejemplo n.º 26
0
/**
 * Check that this Ebwt, when restored via restore(), matches up with
 * the given array of reference sequences.  For sanity checking.
 */
void Ebwt::checkOrigs(
	const EList<SString<char> >& os,
	bool color,
	bool mirror) const
{
	SString<char> rest;
	restore(rest);
	uint32_t restOff = 0;
	size_t i = 0, j = 0;
	if(mirror) {
		// TODO: FIXME
		return;
	}
	while(i < os.size()) {
		size_t olen = os[i].length();
		int lastorig = -1;
		for(; j < olen; j++) {
			size_t joff = j;
			if(mirror) joff = olen - j - 1;
			if((int)os[i][joff] == 4) {
				// Skip over Ns
				lastorig = -1;
				if(!mirror) {
					while(j < olen && (int)os[i][j] == 4) j++;
				} else {
					while(j < olen && (int)os[i][olen-j-1] == 4) j++;
				}
				j--;
				continue;
			}
			if(lastorig == -1 && color) {
				lastorig = os[i][joff];
				continue;
			}
			if(color) {
				assert_neq(-1, lastorig);
				assert_eq(dinuc2color[(int)os[i][joff]][lastorig], rest[restOff]);
			} else {
				assert_eq(os[i][joff], rest[restOff]);
			}
			lastorig = (int)os[i][joff];
			restOff++;
		}
		if(j == os[i].length()) {
			// Moved to next sequence
			i++;
			j = 0;
		} else {
			// Just jumped over a gap
		}
	}
}
Ejemplo n.º 27
0
void TaskManager::setWorkerName(RFSMtreenode* startnode, std::string workName, EList<std::string>& tlist)
{
	std::vector<std::string> linkedTasks = startnode->getLinkedNodes();
	if(linkedTasks.size()>0){
		for(unsigned int i =0; i<linkedTasks.size();i++){
			std::string tName = linkedTasks[i];
			RFSMtreenode* t = m_taskMem->findBehavior(tName);
			if(t == NULL){
				t = m_taskMem->findConnector(tName);
			}

			if(t != NULL && !t->isReferred(workName)){	
				tlist.addTail(t->getName());
				t->addRefTask(workName);
				setWorkerName(t, workName, tlist);
			}
		}
	}
}
Ejemplo n.º 28
0
/**
 * Flip all the edits.pos fields so that they're with respect to
 * the other end of the read (of length 'sz').
 */
void Edit::invertPoss(
	EList<Edit>& edits,
	size_t sz,
	size_t ei,
	size_t en,
	bool sort)
{
	// Invert elements
	size_t ii = 0;
	for(size_t i = ei; i < ei + en/2; i++) {
		Edit tmp = edits[i];
		edits[i] = edits[ei + en - ii - 1];
		edits[ei + en - ii - 1] = tmp;
		ii++;
	}
	for(size_t i = ei; i < ei + en; i++) {
		assert(edits[i].pos < sz ||
			   (edits[i].isReadGap() && edits[i].pos == sz));
		// Adjust pos
        if(edits[i].isReadGap() || edits[i].isSpliced()) {
            edits[i].pos = (uint32_t)(sz - edits[i].pos);
        } else {
            edits[i].pos = (uint32_t)(sz - edits[i].pos - 1);
        }
		// Adjust pos2
		if(edits[i].isReadGap()) {
			int64_t pos2diff = (int64_t)(uint64_t)edits[i].pos2 - (int64_t)((uint64_t)std::numeric_limits<uint32_t>::max() >> 1);
			int64_t pos2new = (int64_t)(uint64_t)edits[i].pos2 - 2*pos2diff;
			assert(pos2diff == 0 || (uint32_t)pos2new != (std::numeric_limits<uint32_t>::max() >> 1));
			edits[i].pos2 = (uint32_t)pos2new;
		}
	}
	if(sort) {
		// Edits might not necessarily be in same order after inversion
		edits.sortPortion(ei, en);
#ifndef NDEBUG
		for(size_t i = ei + 1; i < ei + en; i++) {
			assert_geq(edits[i].pos, edits[i-1].pos);
		}
#endif
	}
}
Ejemplo n.º 29
0
void
Client::StartWorker(workMode pMode, const wxString& pMessage) {
    char* tmpbuf = wxStrdup(pMessage.mb_str());
    int msgsize = strlen(tmpbuf);
    char* buf = CreateBuffer(&msgsize);
    memset(buf+2,0x0,msgsize);
    memcpy(buf+2,tmpbuf,msgsize);
    free(tmpbuf);

    if (pMode == THREADS) {
        ThreadWorker* c = new ThreadWorker(m_host,buf,msgsize+2);
        if (c->Create() != wxTHREAD_NO_ERROR) {
            wxLogError(wxT("Cannot create more threads"));
        } else {
            c->Run();
            m_threadWorkers.Append(c);
        }
    } else {
        EventWorker* e = new EventWorker(m_host,buf,msgsize+2);
        e->Run();
        m_eventWorkers.Append(e);
    }
    m_statConnecting++;
}
Ejemplo n.º 30
0
/**
 * Given the values for all of the various arguments used to specify
 * the read and quality input, create a list of pattern sources to
 * dispense them.
 */
PairedPatternSource* PairedPatternSource::setupPatternSources(
	const EList<string>& si,   // singles, from argv
	const EList<string>& m1,   // mate1's, from -1 arg
	const EList<string>& m2,   // mate2's, from -2 arg
	const EList<string>& m12,  // both mates on each line, from --12 arg
#ifdef USE_SRA
    const EList<string>& sra_accs,
#endif
	const EList<string>& q,    // qualities associated with singles
	const EList<string>& q1,   // qualities associated with m1
	const EList<string>& q2,   // qualities associated with m2
	const PatternParams& p,    // read-in parameters
    size_t nthreads,
	bool verbose)              // be talkative?
{
	EList<PatternSource*>* a  = new EList<PatternSource*>();
	EList<PatternSource*>* b  = new EList<PatternSource*>();
	EList<PatternSource*>* ab = new EList<PatternSource*>();
	// Create list of pattern sources for paired reads appearing
	// interleaved in a single file
	for(size_t i = 0; i < m12.size(); i++) {
		const EList<string>* qs = &m12;
		EList<string> tmp;
		if(p.fileParallel) {
			// Feed query files one to each PatternSource
			qs = &tmp;
			tmp.push_back(m12[i]);
			assert_eq(1, tmp.size());
		}
		ab->push_back(PatternSource::patsrcFromStrings(p, *qs, nthreads));
		if(!p.fileParallel) {
			break;
		}
	}
    
#ifdef USE_SRA
    for(size_t i = 0; i < sra_accs.size(); i++) {
        const EList<string>* qs = &sra_accs;
        EList<string> tmp;
        if(p.fileParallel) {
            // Feed query files one to each PatternSource
            qs = &tmp;
            tmp.push_back(sra_accs[i]);
            assert_eq(1, tmp.size());
        }
        ab->push_back(PatternSource::patsrcFromStrings(p, *qs, nthreads));
        if(!p.fileParallel) {
            break;
        }
    }
#endif

	// Create list of pattern sources for paired reads
	for(size_t i = 0; i < m1.size(); i++) {
		const EList<string>* qs = &m1;
		EList<string> tmpSeq;
		EList<string> tmpQual;
		if(p.fileParallel) {
			// Feed query files one to each PatternSource
			qs = &tmpSeq;
			tmpSeq.push_back(m1[i]);
			assert_eq(1, tmpSeq.size());
		}
		a->push_back(PatternSource::patsrcFromStrings(p, *qs, nthreads));
		if(!p.fileParallel) {
			break;
		}
	}

	// Create list of pattern sources for paired reads
	for(size_t i = 0; i < m2.size(); i++) {
		const EList<string>* qs = &m2;
		EList<string> tmpSeq;
		EList<string> tmpQual;
		if(p.fileParallel) {
			// Feed query files one to each PatternSource
			qs = &tmpSeq;
			tmpSeq.push_back(m2[i]);
			assert_eq(1, tmpSeq.size());
		}
		b->push_back(PatternSource::patsrcFromStrings(p, *qs, nthreads));
		if(!p.fileParallel) {
			break;
		}
	}
	// All mates/mate files must be paired
	assert_eq(a->size(), b->size());

	// Create list of pattern sources for the unpaired reads
	for(size_t i = 0; i < si.size(); i++) {
		const EList<string>* qs = &si;
		PatternSource* patsrc = NULL;
		EList<string> tmpSeq;
		EList<string> tmpQual;
		if(p.fileParallel) {
			// Feed query files one to each PatternSource
			qs = &tmpSeq;
			tmpSeq.push_back(si[i]);
			assert_eq(1, tmpSeq.size());
		}
		patsrc = PatternSource::patsrcFromStrings(p, *qs, nthreads);
		assert(patsrc != NULL);
		a->push_back(patsrc);
		b->push_back(NULL);
		if(!p.fileParallel) {
			break;
		}
	}

	PairedPatternSource *patsrc = NULL;
#ifdef USE_SRA
	if(m12.size() > 0 || sra_accs.size() > 0) {
#else
    if(m12.size() > 0) {
#endif
		patsrc = new PairedSoloPatternSource(ab, p);
		for(size_t i = 0; i < a->size(); i++) delete (*a)[i];
		for(size_t i = 0; i < b->size(); i++) delete (*b)[i];
		delete a; delete b;
	} else {
		patsrc = new PairedDualPatternSource(a, b, p);
		for(size_t i = 0; i < ab->size(); i++) delete (*ab)[i];
		delete ab;
	}
	return patsrc;
}

VectorPatternSource::VectorPatternSource(
	const EList<string>& v,
	const PatternParams& p) :
	PatternSource(p),
	cur_(p.skip),
	skip_(p.skip),
	paired_(false),
	v_(),
	quals_()
{
	for(size_t i = 0; i < v.size(); i++) {
		EList<string> ss;
		tokenize(v[i], ":", ss, 2);
		assert_gt(ss.size(), 0);
		assert_leq(ss.size(), 2);
		// Initialize s
		string s = ss[0];
		int mytrim5 = gTrim5;
		if(gColor && s.length() > 1) {
			// This may be a primer character.  If so, keep it in the
			// 'primer' field of the read buf and parse the rest of the
			// read without it.
			int c = toupper(s[0]);
			if(asc2dnacat[c] > 0) {
				// First char is a DNA char
				int c2 = toupper(s[1]);
				// Second char is a color char
				if(asc2colcat[c2] > 0) {
					mytrim5 += 2; // trim primer and first color
				}
			}
		}
		if(gColor) {
			// Convert '0'-'3' to 'A'-'T'
			for(size_t i = 0; i < s.length(); i++) {
				if(s[i] >= '0' && s[i] <= '4') {
					s[i] = "ACGTN"[(int)s[i] - '0'];
				}
				if(s[i] == '.') s[i] = 'N';
			}
		}
		if(s.length() <= (size_t)(gTrim3 + mytrim5)) {
			// Entire read is trimmed away
			s.clear();
		} else {
			// Trim on 5' (high-quality) end
			if(mytrim5 > 0) {
				s.erase(0, mytrim5);
			}
			// Trim on 3' (low-quality) end
			if(gTrim3 > 0) {
				s.erase(s.length()-gTrim3);
			}
		}
		//  Initialize vq
		string vq;
		if(ss.size() == 2) {
			vq = ss[1];
		}
		// Trim qualities
		if(vq.length() > (size_t)(gTrim3 + mytrim5)) {
			// Trim on 5' (high-quality) end
			if(mytrim5 > 0) {
				vq.erase(0, mytrim5);
			}
			// Trim on 3' (low-quality) end
			if(gTrim3 > 0) {
				vq.erase(vq.length()-gTrim3);
			}
		}
		// Pad quals with Is if necessary; this shouldn't happen
		while(vq.length() < s.length()) {
			vq.push_back('I');
		}
		// Truncate quals to match length of read if necessary;
		// this shouldn't happen
		if(vq.length() > s.length()) {
			vq.erase(s.length());
		}
		assert_eq(vq.length(), s.length());
		v_.expand();
		v_.back().installChars(s);
		quals_.push_back(BTString(vq));
		trimmed3_.push_back(gTrim3);
		trimmed5_.push_back(mytrim5);
		ostringstream os;
		os << (names_.size());
		names_.push_back(BTString(os.str()));
	}
	assert_eq(v_.size(), quals_.size());
}
	
bool VectorPatternSource::nextReadImpl(
	Read& r,
	TReadId& rdid,
	TReadId& endid,
	bool& success,
	bool& done)
{
	// Let Strings begin at the beginning of the respective bufs
	r.reset();
	lock();
	if(cur_ >= v_.size()) {
		unlock();
		// Clear all the Strings, as a signal to the caller that
		// we're out of reads
		r.reset();
		success = false;
		done = true;
		assert(r.empty());
		return false;
	}
	// Copy v_*, quals_* strings into the respective Strings
	r.color = gColor;
	r.patFw  = v_[cur_];
	r.qual = quals_[cur_];
	r.trimmed3 = trimmed3_[cur_];
	r.trimmed5 = trimmed5_[cur_];
	ostringstream os;
	os << cur_;
	r.name = os.str();
	cur_++;
	done = cur_ == v_.size();
	rdid = endid = readCnt_;
	readCnt_++;
	unlock();
	success = true;
	return true;
}