Esempio n. 1
0
  // 從本文的begin位置到end位置,找到第一個Pattern發生之起始位置
    T1::iterator pMatch(T1::iterator begin, T1::iterator end) {
	    T1::iterator i;
		int j;

		for (i = begin, j = 0; ((i != end) && (j < pat->size())); ) {
			if (*i == (*pat->ch)[j]) {
				i++; j++;
			}
			else {
				if (j == 0)  i++;
				else  j = pat->Fail(j - 1) + 1;
			}
		}
		return ( (j == pat->size()) ? i - pat->size() : end );
	}
Esempio n. 2
0
SearchStates gram::search_read_backwards(const Pattern &read,
                                         const Pattern &kmer,
                                         const KmerIndex &kmer_index,
                                         const PRG_Info &prg_info) {
    // Test if kmer has been indexed
    bool kmer_in_index = kmer_index.find(kmer) != kmer_index.end();
    if (not kmer_in_index)
        return SearchStates{};

    // Test if kmer has been indexed, but has no search states in prg
    auto kmer_index_search_states = kmer_index.at(kmer);
    if (kmer_index_search_states.empty())
        return kmer_index_search_states;


    // Reverse iterator + skipping through indexed kmer in read
    auto read_begin = read.rbegin();
    std::advance(read_begin, kmer.size());

    SearchStates new_search_states = kmer_index_search_states;

    for (auto it = read_begin; it != read.rend(); ++it) { /// Iterates end to start of read
        const Base &pattern_char = *it;
        new_search_states = process_read_char_search_states(pattern_char,
                                                            new_search_states,
                                                            prg_info);
        // Test if no mapping found upon character extension
        auto read_not_mapped = new_search_states.empty();
        if (read_not_mapped)
            break;
    }

    new_search_states = handle_allele_encapsulated_states(new_search_states, prg_info);
    return new_search_states;
}
Esempio n. 3
0
bool Analyzer::convert(Pattern& pattern, vector<string>& items, RowData& row_data){

	// pattern and item size must match
	if (pattern.size() != items.size()) {
		return false;
	}
		
	Pattern::iterator itr_pattern = pattern.begin();
	vector<string>::iterator itr_items = items.begin();

	// process every element using proper element parser
	// return true only if all items are proper handled
	while (itr_pattern != pattern.end()) {
		Element* ele = *(*itr_pattern);
		string str = *itr_items;

		// increase pattern itr and corresponding item itr
		itr_pattern++;
		itr_items++;

		Data data;

		if (ele->convert(str, data)) {
			row_data.push_back(data);
		} else {
			row_data.clear();
			return false;
		}
	}
	return true;
}
Esempio n. 4
0
   void PSU1Rules::BuildCodeSignal(const CodeTupleVector& codeTupleVec,
         const TrTupleVector& trTupleVec, const double bauda)
   {
      std::cout << "BUILDING CODE Signal " << std::endl;

      LocationVector lv = codeTupleVec[0].get<0>();
      const Pattern pattern = codeTupleVec[0].get<1>();
      const uint16_t pre_baud = round(trTupleVec[0].get<1>()/bauda);

      for(uint16_t idx=0; idx<lv.size(); ++idx)
      {
         const uint16_t ch_idx = ChIndex(lv,idx);
         ports_[ch_idx].resize(pre_baud+pattern.size());

         for(uint16_t jdx=0; jdx<pattern.size(); ++jdx) 
         {
            const uint16_t code_offset = pre_baud + jdx;
            ports_[ch_idx][code_offset] = pattern[jdx];
         }
      }
   }
Esempio n. 5
0
Row ClusterRepository::search(Pattern pattern, double threshold){
	std::vector<double> origin(pattern.size());
	Converter<Pattern> converter;

	std::fill(origin.begin(), origin.end(), (double)1);
	double feature = Math::cosSimilarity(origin, converter.convert(pattern));

	//しきい値以下のクラスタ
	std::vector<Row> result = this->sqlite.execute(this->getSelectClusterQuery(feature, threshold));
	
	if(result.empty()) throw std::exception("not found");

	return result[0];
}
Esempio n. 6
0
bool gram::quasimap_read(const Pattern &read,
                         Coverage &coverage,
                         const KmerIndex &kmer_index,
                         const PRG_Info &prg_info,
                         const Parameters &parameters) {
    auto kmer = get_kmer_from_read(parameters.kmers_size, read); // Gets last k bases of read

    auto search_states = search_read_backwards(read, kmer, kmer_index, prg_info);
    auto read_mapped_exactly = not search_states.empty();
    // Test read did not map
    if (not read_mapped_exactly)
        return read_mapped_exactly;
    auto read_length = read.size();

    uint64_t  random_seed = parameters.seed;
    coverage::record::search_states(coverage,
                                    search_states,
                                    read_length,
                                    prg_info,
                                    random_seed);
    return read_mapped_exactly;
}
Esempio n. 7
0
Pattern gram::get_kmer_from_read(const uint32_t &kmer_size, const Pattern &read) {
    Pattern kmer;
    auto kmer_start_it = read.begin() + read.size() - kmer_size;
    kmer.assign(kmer_start_it, read.end());
    return kmer;
}