Esempio n. 1
0
// Deletes the front of the search bar and updates the search matcher
void do_del(){
	del_letter();

	/* Ignore the matcher if the string query is below the threshhold
	   Update and add matches when we delete letters  */
	if(qs_length() < SEARCH_THRESHHOLD){
		draw_information_box("ENTER YOUR SEARCH!");
	}
	if(qs_length() >= SEARCH_THRESHHOLD){
		add_matches();
	}
}
static GtUword front_second_inplace(Frontvalue *midfront,
                                    Frontvalue *lowfront,
                                    GtUword history,
                                    Sequenceobject *useq,
                                    Sequenceobject *vseq)
{
  GtUword alignedlen, maxalignedlen;
  const uint64_t mask = ((uint64_t) 1) << (history-1);

  *(lowfront+1) = *(lowfront+2) = *lowfront;
  lowfront->row++;
  lowfront->backreference = FT_EOP_DELETION;
  UPDATE_MATCH_HISTORY(lowfront->matchhistory_count,lowfront->matchhistory);
  add_matches(midfront,lowfront,mask,useq,vseq);
  maxalignedlen = GT_MULT2(lowfront->row) + FRONT_DIAGONAL(lowfront);

  (lowfront+1)->row++;
  (lowfront+1)->backreference = FT_EOP_REPLACEMENT;
  UPDATE_MATCH_HISTORY((lowfront+1)->matchhistory_count,
                       (lowfront+1)->matchhistory);
  add_matches(midfront,lowfront + 1,mask,useq,vseq);
  alignedlen = GT_MULT2((lowfront+1)->row) + FRONT_DIAGONAL(lowfront + 1);
  if (maxalignedlen < alignedlen)
  {
    maxalignedlen = alignedlen;
  }

  (lowfront+2)->backreference = FT_EOP_INSERTION;
  UPDATE_MATCH_HISTORY((lowfront+2)->matchhistory_count,
                       (lowfront+2)->matchhistory);
  add_matches(midfront,lowfront + 2,mask,useq,vseq);
  alignedlen = GT_MULT2((lowfront+2)->row) + FRONT_DIAGONAL(lowfront + 2);
  if (maxalignedlen < alignedlen)
  {
    maxalignedlen = alignedlen;
  }
  return maxalignedlen;
}
Esempio n. 3
0
// Draws the character on the search bar and updates the search matcher
void do_key(char key){
	add_letter(key);

	/* Ignore the matcher if the string query length is below the threshhold to provide matchings
	   Update and delete matches when we add letters */
	if(qs_length() < SEARCH_THRESHHOLD){
		draw_information_box("ENTER YOUR SEARCH!");
	}
	if(qs_length() > SEARCH_THRESHHOLD && MN_COUNT > 0){
		del_matches();
	}
	if(qs_length() == SEARCH_THRESHHOLD){
		add_matches();
	}
}
Esempio n. 4
0
int main(int argc, char **argv) {
  char **fasta_files;
  int seed_len, i, n_fasta_files;
  ChrTable *chr_tab;
  SeedTable *seed_tab;
  Seq *seq;
  gzFile gzf, out_gzf;
  char *out_filename;
  
  if(argc < 4) {
    fprintf(stderr, "usage: %s <seed_len> <chromInfo.txt> "
	    "<output_seed_index.gz> [chr1.fa.gz [chr2.fa.gz [...]]]\n", 
	    argv[0]);
    exit(2);
  }
  
  
  seed_len = util_parse_long(argv[1]);

  fasta_files = &argv[4];
  n_fasta_files = argc - 4;
  out_filename = argv[3];

  /* read chromosomes and make table containing offsets for both
   * forward and reverse strands (so we can represent genomic
   * coordinates with a single long integer).
   */
  chr_tab = chr_table_read(argv[2]);
  fprintf(stderr, "there are %d chromosomes, total length: %u\n",
	  chr_tab->n_chr, chr_tab->total_chr_len);

  /* create a table to hold seed matches */
  fprintf(stderr, "initializing seed table\n");
  seed_tab = seed_table_new(seed_len);

  /* open an output file to write seed table to */
  if(util_file_exists(out_filename)) {
    my_err("output file %s already exists\n", out_filename);
    exit(2);
  }
  out_gzf = util_must_gzopen(out_filename, "wb");

  /*
   * first pass: count number of matches to each seed 
   */
  seq = seq_new();
  for(i = 0; i < n_fasta_files; i++) {
    fprintf(stderr, "reading sequence from file %s\n", fasta_files[i]);
    gzf = util_must_gzopen(fasta_files[i], "rb");
    while(seq_read_fasta_record(seq, gzf)) {
      fprintf(stderr, "%s %ld\n", seq->name, seq->len);
      fprintf(stderr, "counting seed matches\n");
      count_matches(chr_tab, seed_tab, seq);
    }
    gzclose(gzf);
  }

  /*
   * second pass: store location of each match
   */
  for(i = 0; i < n_fasta_files; i++) {
    fprintf(stderr, "reading sequence from file %s\n", fasta_files[i]);
    gzf = util_must_gzopen(fasta_files[i], "rb");
    while(seq_read_fasta_record(seq, gzf)) {
      fprintf(stderr, "%s %ld\n", seq->name, seq->len);
      fprintf(stderr, "recording seed match positions\n");
      add_matches(chr_tab, seed_tab, seq);
    }
    gzclose(gzf);
  }

  seq_free(seq);

  /* write table to file in binary format */
  fprintf(stderr, "writing seed table to file %s\n", out_filename);
  seed_table_write(seed_tab, out_gzf);
  gzclose(out_gzf);

  chr_table_free(chr_tab);
  seed_table_free(seed_tab);
  
  return 0;
}
GtUword front_prune_edist_inplace(
#ifndef OUTSIDE_OF_GT
                         bool forward,
                         GtAllocatedMemory *frontspace,
#endif
                         Trimstat *trimstat,
                         Polished_point *best_polished_point,
                         Fronttrace *front_trace,
                         const Polishing_info *pol_info,
                         GtUword history,
                         GtUword minmatchnum,
                         GtUword maxalignedlendifference,
                         FTsequenceResources *ufsr,
                         GtUword ustart,
                         GtUword ulen,
                         FTsequenceResources *vfsr,
                         GtUword vstart,
                         GtUword vlen)
{
  const GtUword sumseqlength = ulen + vlen,
                minsizeforshift = sumseqlength/1000,
                minlenforhistorycheck = GT_MULT2(history);
  /* so the space for allocating the fronts is
     sizeof (Frontvalue) * ((m+n)/1000 + maxvalid), where maxvalid is a small
     constant. */
  GtUword distance, trimleft = 0, valid = 1UL, maxvalid = 0, sumvalid = 0;
  const uint64_t mask = ((uint64_t) 1) << (history-1);
  Frontvalue *validbasefront;
  bool diedout = false;
  Sequenceobject useq, vseq;

#ifdef OUTSIDE_OF_GT
  GtAllocatedMemory *frontspace = gt_malloc(sizeof *frontspace);
  frontspace->space = NULL;
  frontspace->allocated = 0;
  frontspace->offset = 0;
  sequenceobject_init(&useq,useqptr,ustart,ulen);
  sequenceobject_init(&vseq,vseqptr,vstart,vlen);
#else
  GtReadmode readmode = forward ? GT_READMODE_FORWARD : GT_READMODE_REVERSE;
  sequenceobject_init(&useq,ufsr->extend_char_access,ufsr->encseq,readmode,
                      ustart,ulen,ufsr->encseq_r,ufsr->sequence_cache,
                      ufsr->totallength);
  sequenceobject_init(&vseq,ufsr->extend_char_access,vfsr->encseq,readmode,
                      vstart,vlen,vfsr->encseq_r,vfsr->sequence_cache,
                      vfsr->totallength);
  frontspace->offset = 0;
#endif
#ifdef TRIM_INFO_OUT
  printf("regionalquality(minmatchnum)=" GT_WU "\n",minmatchnum);
#endif
  for (distance = 0, valid = 1UL; /* Nothing */; distance++, valid += 2)
  {
    GtUword trim, maxalignedlen, minlenfrommaxdiff;

#ifdef TRIM_INFO_OUT
    printf("distance=" GT_WU ",full=" GT_WU ",trimleft=" GT_WU
           ",valid=" GT_WU "\n",distance,
                  GT_MULT2(distance) + 1,
                  trimleft,valid);
#endif
    gt_assert(valid <= GT_MULT2(distance) + 1);
    sumvalid += valid;
    if (maxvalid < valid)
    {
      maxvalid = valid;
    }
    validbasefront = frontspace_allocate(minsizeforshift,trimleft,valid,
                                         frontspace);
    if (distance == 0)
    {
      validbasefront->row = 0;
      validbasefront->matchhistory = 0;
      validbasefront->matchhistory_count = 0;
      validbasefront->backreference = 0; /* No back reference */
      add_matches(validbasefront + distance,validbasefront,mask,&useq,&vseq);
      maxalignedlen = GT_MULT2(validbasefront->row);
    } else
    {
      gt_assert(valid >= 3UL);
      frontspace_check((const Frontvalue *) frontspace->space,
                       ((const Frontvalue *) frontspace->space)
                        + frontspace->allocated - 1,
                       validbasefront + trimleft);
      frontspace_check((const Frontvalue *) frontspace->space,
                       ((const Frontvalue *) frontspace->space)
                         + frontspace->allocated - 1,
                       validbasefront + trimleft + valid - 1);
      if (valid == 3UL)
      {
        maxalignedlen
          = front_second_inplace(validbasefront + distance,
                                 validbasefront + trimleft,
                                 history,
                                 &useq,
                                 &vseq);
      } else
      {
        maxalignedlen
          = front_next_inplace(validbasefront + distance,
                               validbasefront + trimleft,
                               validbasefront + trimleft + valid - 1,
                               history,
                               &useq,
                               &vseq);
      }
    }
    gt_assert(valid > 0);
    minlenfrommaxdiff = maxalignedlen >= maxalignedlendifference
                          ? maxalignedlen - maxalignedlendifference
                          : 0;
#ifdef TRIM_INFO_OUT
    printf("maxalignedlen=" GT_WU ",maxlenfrommaxdiff=" GT_WU "\n",
           maxalignedlen,minlenfrommaxdiff);
#endif
    trim = trim_front(true,
#ifdef TRIM_INFO_OUT
                      distance,
#endif
                      ulen,
                      vlen,
                      minmatchnum,
                      minlenforhistorycheck,
                      minlenfrommaxdiff,
                      validbasefront + distance,
                      validbasefront + trimleft,
                      validbasefront + trimleft + valid);
#ifdef TRIM_INFO_OUT
    printf("trim on left=" GT_WU "\n",trim);
#endif
    if (trim > 0)
    {
      trimleft += trim;
      gt_assert(valid >= trim);
      valid -= trim;
    }
    if (valid > 0)
    {
      trim = trim_front(false,
#ifdef TRIM_INFO_OUT
                        distance,
#endif
                        ulen,
                        vlen,
                        minmatchnum,
                        minlenforhistorycheck,
                        minlenfrommaxdiff,
                        validbasefront + distance,
                        validbasefront + trimleft + valid - 1,
                        validbasefront + trimleft - 1);
#ifdef TRIM_INFO_OUT
      printf("trim on right=" GT_WU "\n",trim);
#endif
      gt_assert(trim < valid);
      if (trim > 0)
      {
        gt_assert(valid >= trim);
        valid -= trim;
      }
    }
    if (valid == 0)
    {
      diedout = true;
      break;
    }
    if (front_trace != NULL)
    {
      front_trace_add_gen(front_trace,trimleft,valid);
    }
    update_trace_and_polished(best_polished_point,
#ifndef OUTSIDE_OF_GT
                              &useq.min_access_pos,
                              &vseq.min_access_pos,
#endif
                              front_trace,
                              pol_info,
                              distance,
                              trimleft,
                              validbasefront + distance,
                              validbasefront + trimleft,
                              validbasefront + trimleft + valid - 1);
    if ((vlen > ulen && vlen - ulen <= distance) ||
        (vlen <= ulen && ulen - vlen <= distance))
    {
      if (distance + vlen - ulen >= trimleft &&
          distance + vlen - ulen <= trimleft + valid - 1 &&
          validbasefront[distance + vlen - ulen].row == ulen)
      {
        break;
      }
    }
    if (distance >= sumseqlength)
    {
      break;
    }
  }
  trimstat_add(trimstat,diedout,sumvalid,maxvalid,distance,
               sizeof (Frontvalue) * frontspace->allocated,
#ifndef OUTSIDE_OF_GT
               useq.sequence_cache != NULL &&
               vseq.sequence_cache != NULL ? MAX(useq.sequence_cache->allocated,
                                                 vseq.sequence_cache->allocated)
                                           : 0
#else
               0
#endif
              );
  return diedout ? sumseqlength + 1 : distance;
}
static GtUword front_next_inplace(Frontvalue *midfront,
                                  Frontvalue *lowfront,
                                  Frontvalue *highfront,
                                  GtUword history,
                                  Sequenceobject *useq,
                                  Sequenceobject *vseq)
{
  GtUword alignedlen, maxalignedlen;
  const uint64_t mask = ((uint64_t) 1) << (history-1);
  Frontvalue bestfront, insertion_value, replacement_value, *frontptr;

  insertion_value = *lowfront; /* from previous diag -(d-1) => -d => DELETION */
  bestfront = insertion_value;
  bestfront.row++;
  UPDATE_MATCH_HISTORY(bestfront.matchhistory_count,bestfront.matchhistory);
  *lowfront = bestfront;
  lowfront->backreference = FT_EOP_DELETION;
  add_matches(midfront,lowfront,mask,useq,vseq);
  maxalignedlen = GT_MULT2(lowfront->row) + FRONT_DIAGONAL(lowfront);

  replacement_value = *(lowfront+1);
  if (bestfront.row < replacement_value.row + 1)
  {
    bestfront = replacement_value;
    bestfront.backreference = FT_EOP_DELETION;
    bestfront.row++;
    UPDATE_MATCH_HISTORY(bestfront.matchhistory_count,bestfront.matchhistory);
  } else
  {
    bestfront.backreference = FT_EOP_REPLACEMENT;
    if (bestfront.row == replacement_value.row + 1)
    {
      bestfront.backreference |= FT_EOP_DELETION;
    }
  }
  *(lowfront+1) = bestfront;
  add_matches(midfront,lowfront + 1,mask,useq,vseq);
  alignedlen = GT_MULT2((lowfront+1)->row) + FRONT_DIAGONAL(lowfront + 1);
  if (maxalignedlen < alignedlen)
  {
    maxalignedlen = alignedlen;
  }
  for (frontptr = lowfront+2; frontptr <= highfront; frontptr++)
  {
    bestfront = insertion_value;
    bestfront.backreference = FT_EOP_INSERTION;
    if (frontptr <= highfront - 1)
    {
      if (bestfront.row < replacement_value.row + 1)
      {
        bestfront = replacement_value;
        bestfront.backreference = FT_EOP_REPLACEMENT;
        bestfront.row++;
      } else
      {
        if (bestfront.row == replacement_value.row + 1)
        {
          bestfront.backreference |= FT_EOP_REPLACEMENT;
        }
      }
    }
    if (frontptr <= highfront - 2)
    {
      if (bestfront.row < frontptr->row + 1)
      {
        bestfront = *frontptr;
        bestfront.backreference = FT_EOP_DELETION;
        bestfront.row++;
      } else
      {
        if (bestfront.row == frontptr->row + 1)
        {
          bestfront.backreference |= FT_EOP_DELETION;
        }
      }
    }
    UPDATE_MATCH_HISTORY(bestfront.matchhistory_count,bestfront.matchhistory);
    if (frontptr < highfront)
    {
      insertion_value = replacement_value;
      replacement_value = *frontptr;
    }
    *frontptr = bestfront;
    add_matches(midfront,frontptr,mask,useq,vseq);
    alignedlen = GT_MULT2(frontptr->row) + FRONT_DIAGONAL(frontptr);
    if (maxalignedlen < alignedlen)
    {
      maxalignedlen = alignedlen;
    }
  }
  return maxalignedlen;
}
bool MatchesProto::MergePartialFromCodedStream(
    ::google::protobuf::io::CodedInputStream* input) {
#define DO_(EXPRESSION) if (!(EXPRESSION)) return false
  ::google::protobuf::uint32 tag;
  while ((tag = input->ReadTag()) != 0) {
    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
      // optional fixed64 imageLseq = 1;
      case 1: {
        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
            ::google::protobuf::internal::WireFormatLite::WIRETYPE_FIXED64) {
          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_FIXED64>(
                 input, &imagelseq_)));
          set_has_imagelseq();
        } else {
          goto handle_uninterpreted;
        }
        if (input->ExpectTag(17)) goto parse_imageRseq;
        break;
      }
      
      // optional fixed64 imageRseq = 2;
      case 2: {
        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
            ::google::protobuf::internal::WireFormatLite::WIRETYPE_FIXED64) {
         parse_imageRseq:
          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
                   ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_FIXED64>(
                 input, &imagerseq_)));
          set_has_imagerseq();
        } else {
          goto handle_uninterpreted;
        }
        if (input->ExpectTag(26)) goto parse_matches;
        break;
      }
      
      // repeated .sfm.DMatches matches = 3;
      case 3: {
        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
            ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
         parse_matches:
          DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
                input, add_matches()));
        } else {
          goto handle_uninterpreted;
        }
        if (input->ExpectTag(26)) goto parse_matches;
        if (input->ExpectAtEnd()) return true;
        break;
      }
      
      default: {
      handle_uninterpreted:
        if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
            ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
          return true;
        }
        DO_(::google::protobuf::internal::WireFormat::SkipField(
              input, tag, mutable_unknown_fields()));
        break;
      }
    }
  }
  return true;
#undef DO_
}
Esempio n. 8
0
int main(int argc, char *argv[]) {
        int r;
        sd_journal *j = NULL;
        unsigned line = 0;
        bool need_seek = false;
        sd_id128_t previous_boot_id;
        bool previous_boot_id_valid = false;
        bool have_pager;

        log_parse_environment();
        log_open();

        r = parse_argv(argc, argv);
        if (r <= 0)
                goto finish;

        if (arg_new_id128) {
                r = generate_new_id128();
                goto finish;
        }

#ifdef HAVE_ACL
        if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0)
                log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this message off.");
#endif

        if (arg_directory)
                r = sd_journal_open_directory(&j, arg_directory, 0);
        else
                r = sd_journal_open(&j, arg_local ? SD_JOURNAL_LOCAL_ONLY : 0);

        if (r < 0) {
                log_error("Failed to open journal: %s", strerror(-r));
                goto finish;
        }

        if (arg_print_header) {
                journal_print_header(j);
                r = 0;
                goto finish;
        }

        r = add_this_boot(j);
        if (r < 0)
                goto finish;

        r = add_matches(j, argv + optind);
        if (r < 0)
                goto finish;

        if (!arg_quiet) {
                usec_t start, end;
                char start_buf[FORMAT_TIMESTAMP_MAX], end_buf[FORMAT_TIMESTAMP_MAX];

                r = sd_journal_get_cutoff_realtime_usec(j, &start, &end);
                if (r < 0) {
                        log_error("Failed to get cutoff: %s", strerror(-r));
                        goto finish;
                }

                if (r > 0) {
                        if (arg_follow)
                                printf("Logs begin at %s.\n", format_timestamp(start_buf, sizeof(start_buf), start));
                        else
                                printf("Logs begin at %s, end at %s.\n",
                                       format_timestamp(start_buf, sizeof(start_buf), start),
                                       format_timestamp(end_buf, sizeof(end_buf), end));
                }
        }

        if (arg_lines >= 0) {
                r = sd_journal_seek_tail(j);
                if (r < 0) {
                        log_error("Failed to seek to tail: %s", strerror(-r));
                        goto finish;
                }

                r = sd_journal_previous_skip(j, arg_lines);
        } else {
                r = sd_journal_seek_head(j);
                if (r < 0) {
                        log_error("Failed to seek to head: %s", strerror(-r));
                        goto finish;
                }

                r = sd_journal_next(j);
        }

        if (r < 0) {
                log_error("Failed to iterate through journal: %s", strerror(-r));
                goto finish;
        }

        have_pager = !arg_no_pager && !arg_follow;
        if (have_pager) {
                columns();
                pager_open();
        }

        if (arg_output == OUTPUT_JSON) {
                fputc('[', stdout);
                fflush(stdout);
        }

        for (;;) {
                for (;;) {
                        sd_id128_t boot_id;
                        int flags = (arg_show_all*OUTPUT_SHOW_ALL |
                                     have_pager*OUTPUT_FULL_WIDTH);

                        if (need_seek) {
                                r = sd_journal_next(j);
                                if (r < 0) {
                                        log_error("Failed to iterate through journal: %s", strerror(-r));
                                        goto finish;
                                }
                        }

                        if (r == 0)
                                break;

                        r = sd_journal_get_monotonic_usec(j, NULL, &boot_id);
                        if (r >= 0) {
                                if (previous_boot_id_valid &&
                                    !sd_id128_equal(boot_id, previous_boot_id))
                                        printf(ANSI_HIGHLIGHT_ON "----- Reboot -----" ANSI_HIGHLIGHT_OFF "\n");

                                previous_boot_id = boot_id;
                                previous_boot_id_valid = true;
                        }

                        line ++;

                        r = output_journal(j, arg_output, line, 0, flags);
                        if (r < 0)
                                goto finish;

                        need_seek = true;
                }

                if (!arg_follow)
                        break;

                r = sd_journal_wait(j, (uint64_t) -1);
                if (r < 0) {
                        log_error("Couldn't wait for log event: %s", strerror(-r));
                        goto finish;
                }
        }

        if (arg_output == OUTPUT_JSON)
                fputs("\n]\n", stdout);

finish:
        if (j)
                sd_journal_close(j);

        pager_close();

        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}