Пример #1
0
OutT matches (std::string const& ws, std::string const& s, OutT dst) {
  typedef std::pair<int, std::deque<char>> acc_t;

  auto step = [](acc_t p, char x) -> acc_t {
    ++p.first;
    p.second.push_front (x);

    return p;
  };

  std::deque<acc_t> buf;
  scan_left (
      step
    , std::make_pair(0, std::deque<char>())
    , s.begin ()
    , s.end ()
    , std::back_inserter(buf));

  std::string sw(ws.rbegin (), ws.rend ());
  auto pred = [&sw] (auto p) -> bool { 
    return prefix (
      sw.begin (), sw.end ()
    , p.second.begin (), p.second.end ()); 
  };
  std::deque<acc_t> temp;
  filter (pred, buf, std::back_inserter (temp));

  return std::transform (
     temp.begin (), temp.end (), dst, 
     [](acc_t const& p) -> int {  return p.first; });
}
Пример #2
0
OutT scan_left (F f, AccT z, InT begin, InT end, OutT out) {
  *out++ = z;
  if (begin == end) return out;
  auto const& x = *begin;

  return scan_left (f, f (z, x), std::next (begin), end, out);
}
Пример #3
0
OutT matches (std::string const& ws, std::string const& s, OutT dst) {
  typedef std::string::const_reverse_iterator it;
  typedef std::pair<it, it> iterator_range;
  typedef std::pair<int, iterator_range> acc_t;

  std::size_t num_chars=s.size();

  auto step = [num_chars,&s](acc_t p, char x) -> acc_t {
    ++p.first;
    std::string::const_reverse_iterator rbegin = s.rbegin ();
    std::advance (rbegin, num_chars - p.first);
    p.second = std::make_pair (rbegin, s.rend ());

    return p;
  };

  std::deque<acc_t> buf1;
  scan_left (
      step
    , std::make_pair (0, std::make_pair (s.rend (), s.rend()))
    , s.begin ()
    , s.end ()
    , std::back_inserter (buf1));

  std::string sw(ws.rbegin (), ws.rend ());
  auto pred = [num_chars, &sw, &s] (auto p) -> bool { 
    return prefix (sw.begin (), sw.end (), p.second.first, p.second.second); 
  };

  std::deque<acc_t> buf2;
  filter (pred, buf1, std::back_inserter (buf2));
  buf2.swap (buf1);

  return std::transform (buf1.begin (), buf1.end (), 
           dst, [](acc_t const& p) -> int {  return p.first; });
}
Пример #4
0
/*
 * Quality clips file 'file', updating the QL and QR records in the process.
 *
 * Returns 0 for success.
 *        -1 for failure.
 */
static int qclip(char *file, params p) {
    SeqInfo *si = NULL;
    int start_pos, right_pos, left_pos;
    FILE *fp;

    if (p.verbose)
	printf("Clipping file %s\n", file);

    /* Read the sequence and confidence */
    if (NULL == (si = read_sequence_details(file, 0))) {
	fprintf(stderr, "Failed to read file '%s'\n", file);
	return -1;
    }

    if (exp_Nentries(si->e, EFLT_SQ) > 0 &&
	!valid_seq(exp_get_entry(si->e, EFLT_SQ), 0)) {
	fprintf(stderr, "File '%s' not allowed in demonstration mode\n", file);
	freeSeqInfo(si);
	return -1;
    }

    if (p.use_conf) {
	int i;
	int1 *conf;

	conf = xmalloc(si->length * sizeof(*conf));
	if (SeqInfo_conf(si, conf, si->length) == -1) {
	    if (p.verbose)
		puts("    Could not load confidence values - using sequence");
	    p.use_conf = 0;
	}

	for (i = 0; i < si->length; i++)
	    if (conf[i] != 0)
		break;
	if (i == si->length) {
	    if (p.verbose)
		puts("    Confidence values are all zero - using sequence");
	    p.use_conf = 0;
	}

	if (p.use_conf) {
	    /* Identify the best location to start from */
	    start_pos = find_highest_conf(p, conf, si->length);

	    /* Scan left, and scan right */
	    left_pos = scan_left(p, conf, start_pos)+1;
	    right_pos = scan_right(p, conf, start_pos, si->length)+1;
	}
	xfree(conf);
    }

    if (!p.use_conf) {
	char *seq = exp_get_entry(si->e, EFLT_SQ);

	left_pos = start_of_good(seq, p.start, p.lwin1, p.lcnt1,
				 p.lwin2, p.lcnt2) - 1;
	right_pos = end_of_good(seq, p.start, p.rwin1, p.rcnt1,
				p.rwin2, p.rcnt2) + 1;
    }
    
    if (left_pos < p.min)
	left_pos = p.min;
    if (right_pos > p.max)
	right_pos = p.max;
    if (left_pos >= right_pos)
	left_pos = right_pos-1;

    if (right_pos - left_pos < p.min_len) {
	fprintf(stderr, "Sequence too short (length=%d)\n",
		right_pos - left_pos);
	freeSeqInfo(si);
	return -1;
    }

    /* Append details onto the end of the Exp File */
    if (!p.test_mode) {
	if (NULL == (fp = fopen(file, "a"))) {
	    fprintf(stderr, "Failed to write file '%s'\n", file);
	    freeSeqInfo(si);
	    return -1;
	}
	fprintf(fp, "QL   %d\n", left_pos);
	fprintf(fp, "QR   %d\n", right_pos);
	fclose(fp);
    } else {
	printf("%-30s QL %4d            QR %4d\n", file, left_pos, right_pos);
    }

    freeSeqInfo(si);
    return 0;
}
Пример #5
0
Status Operators::SNL(const string& result,           // Output relation name
                      const int projCnt,              // Number of attributes in the projection
                      const AttrDesc attrDescArray[], // Projection list (as AttrDesc)
                      const AttrDesc& attrDesc1,      // The left attribute in the join predicate
                      const Operator op,              // Predicate operator
                      const AttrDesc& attrDesc2,      // The left attribute in the join predicate
                      const int reclen)               // The length of a tuple in the result relation
{
  cout << "Algorithm: Simple NL Join" << endl;

  /* Your solution goes here */

    // variables for the output relation
    Status output_constr_status;
    HeapFile output(result, output_constr_status);
    if (output_constr_status != OK) {
        return output_constr_status;
    }
    
    // outer scan on the right relation
    Status scan_right_constr_status;
    HeapFileScan scan_right(attrDesc2.relName, scan_right_constr_status);
    if (scan_right_constr_status != OK) {
        return scan_right_constr_status;
    }
    Status scan_right_start_status = scan_right.startScan(attrDesc2.attrOffset, attrDesc2.attrLen,
                                                          (Datatype)attrDesc2.attrType, NULL,
                                                          (Operator)-1);
    if (scan_right_start_status != OK) {
        return scan_right_start_status;
    }

    // variables for current record from the right relation that we are doing an inner scan on
    Record cur_record;
    RID cur_record_ID;
    Status scan_right_status;
    // variables for the record that goes into the result relation
    Record result_rec;
    RID result_RID;
    while ((scan_right_status = scan_right.scanNext(cur_record_ID, cur_record)) == OK) {
        char *filter = (char *)cur_record.data+attrDesc2.attrOffset;
        // filtered inner scan on the left relation
        Status scan_left_constr_status;
        HeapFileScan scan_left(attrDesc1.relName, attrDesc1.attrOffset, attrDesc1.attrLen,
                               (Datatype)attrDesc1.attrType, filter, op, scan_left_constr_status);
        if (scan_left_constr_status != OK) {
            return scan_left_constr_status;
        }
        Status scan_left_status;
        while ((scan_left_status=scan_left.scanNext(result_RID, result_rec)) == OK) {
            // create the output record
            RID output_RID;
            Record output_record;
            Status join_status = join_project(projCnt, attrDescArray, reclen,
                                              attrDesc1.relName, attrDesc2.relName, result_rec,
                                              cur_record, &output_record);
            Status output_status = output.insertRecord(output_record, output_RID);
            delete [](char *)output_record.data;
            if (output_status != OK) {
                return output_status;
            }
        }
        // end of inner scan
        if (scan_left_status != FILEEOF) {
            return scan_left_status;
        }
        
    }
    // end of outer scan
    if (scan_right_status != FILEEOF) {
        return scan_right_status;
    }

  return OK;
}