コード例 #1
0
ファイル: strtonum-tests.c プロジェクト: SSSD/sssd
END_TEST

START_TEST (test_strtouint32_mixed_alphanumeric_base_10)
{
    uint32_t result;
    const char *input = "12b13";
    uint32_t expected = 12;
    char *endptr;
    const char *expected_endptr = input+2;
    errno_t error;

    result = strtouint32(input, &endptr, 10);
    error = errno;

    EXPECT_UNSET_ERRNO(error);
    CHECK_ENDPTR(expected_endptr, endptr);
    CHECK_RESULT(expected, result);
}
コード例 #2
0
ファイル: strtonum-tests.c プロジェクト: SSSD/sssd
END_TEST

START_TEST (test_strtouint32_emptystring_base_10)
{
    uint32_t result;
    const char *input = "";
    uint32_t expected = 0;
    char *endptr;
    const char *expected_endptr = input;
    errno_t error;

    result = strtouint32(input, &endptr, 10);
    error = errno;

    EXPECT_UNSET_ERRNO(error);
    CHECK_ENDPTR(expected_endptr, endptr);
    CHECK_RESULT(expected, result);
}
コード例 #3
0
ファイル: strtonum-tests.c プロジェクト: SSSD/sssd
END_TEST


START_TEST (test_strtouint32_pos_integer_overflow_base_10)
{
    uint32_t result;
    const char *input = "8589934592";
    uint32_t expected = UINT32_MAX;
    char *endptr;
    errno_t error;

    result = strtouint32(input, &endptr, 10);
    error = errno;

    CHECK_ERRNO(ERANGE, error);
    CHECK_ZERO_ENDPTR(endptr);
    CHECK_RESULT(expected, result);
}
コード例 #4
0
ファイル: usertools.c プロジェクト: 3van/sssd
errno_t sss_user_by_name_or_uid(const char *input, uid_t *_uid, gid_t *_gid)
{
    uid_t uid;
    errno_t ret;
    char *endptr;
    struct passwd *pwd;

    /* Try if it's an ID first */
    errno = 0;
    uid = strtouint32(input, &endptr, 10);
    if (errno != 0 || *endptr != '\0') {
        ret = errno;
        if (ret == ERANGE) {
            DEBUG(SSSDBG_OP_FAILURE,
                  "UID [%s] is out of range.\n", input);
            return ret;
        }

        /* Nope, maybe a username? */
        pwd = getpwnam(input);
    } else {
        pwd = getpwuid(uid);
    }

    if (pwd == NULL) {
        DEBUG(SSSDBG_OP_FAILURE,
              "[%s] is neither a valid UID nor a user name which could be "
              "resolved by getpwnam().\n", input);
        return EINVAL;
    }

    if (_uid) {
        *_uid = pwd->pw_uid;
    }

    if (_gid) {
        *_gid = pwd->pw_gid;
    }
    return EOK;
}
コード例 #5
0
ファイル: strtonum-tests.c プロジェクト: SSSD/sssd
END_TEST

/*******************
 * strtouint tests *
 *******************/

/* Base-10 */
START_TEST (test_strtouint32_pos_integer_base_10)
{
    uint32_t result;
    const char *input = "123";
    uint32_t expected = 123;
    char *endptr;
    errno_t error;

    result = strtouint32(input, &endptr, 10);
    error = errno;

    EXPECT_UNSET_ERRNO(error);
    CHECK_ZERO_ENDPTR(endptr);
    CHECK_RESULT(expected, result);
}
コード例 #6
0
ファイル: test-line-buffer.c プロジェクト: 1tgr/git
int cmd_main(int argc, const char **argv)
{
	struct line_buffer stdin_buf = LINE_BUFFER_INIT;
	struct line_buffer file_buf = LINE_BUFFER_INIT;
	struct line_buffer *input = &stdin_buf;
	const char *filename;
	char *s;

	if (argc == 1)
		filename = NULL;
	else if (argc == 2)
		filename = argv[1];
	else
		usage("test-line-buffer [file | &fd] < script");

	if (buffer_init(&stdin_buf, NULL))
		die_errno("open error");
	if (filename) {
		if (*filename == '&') {
			if (buffer_fdinit(&file_buf, strtouint32(filename + 1)))
				die_errno("error opening fd %s", filename + 1);
		} else {
			if (buffer_init(&file_buf, filename))
				die_errno("error opening %s", filename);
		}
		input = &file_buf;
	}

	while ((s = buffer_read_line(&stdin_buf)))
		handle_line(s, input);

	if (filename && buffer_deinit(&file_buf))
		die("error reading from %s", filename);
	if (buffer_deinit(&stdin_buf))
		die("input error");
	if (ferror(stdout))
		die("output error");
	return 0;
}
コード例 #7
0
int
main(int argc, char **argv) {
  size_t   lw;
  uint32  *ww = 0L;
  uint32   idx = 0;
  uint32   err = 0;
  FILE    *out;
  uint32   blockSize = 1048576;
  uint32   numBlocks = 32;

  if (argc == 2)
    numBlocks = strtouint32(argv[1], 0L);

  //  The file must exist, and it must be large enough to contain all
  //  that we want to write.  So, we create the file and fill it with
  //  junk.
  //
  ww  = (uint32 *)malloc(sizeof(uint32) * blockSize);
  if (ww == NULL) {
    fprintf(stderr, "can't allocate %d uint32's for clearing the file.\n", blockSize);
    exit(1);
  }
  errno = 0;
  out = fopen("mmap.test.junk", "w");
  if (errno) {
    fprintf(stderr, "can't open 'mmap.test.junk' to fill with junk: %s\n", strerror(errno));
    exit(1);
  }
  for (idx=0; idx<numBlocks; idx++) {
    fprintf(stderr, "Writing initial blocks: "uint32FMT"/"uint32FMT"\r", idx, numBlocks), fflush(stderr);
    fwrite(ww, sizeof(uint32), 1048576, out);
    if (errno) {
      fprintf(stderr, "can't write to 'mmap.test.junk': %s\n", strerror(errno));
      exit(1);
    }
  }
  fclose(out);
  free(ww);
  fprintf(stderr, "\n");

  //  Now, map it, and fill it with real data.
  //
  ww = (uint32 *)mapFile("mmap.test.junk", &lw, 'w');
  for (idx=0; idx<numBlocks * blockSize; idx++) {
    if ((idx & 0xfff) == 0)
      fprintf(stderr, "Writing: "uint32FMT"/"uint32FMT"\r", idx, numBlocks * blockSize), fflush(stderr);
    ww[idx] = idx;
  }
  unmapFile(ww, lw);
  fprintf(stderr, "\n");

  //  Map again, and check the data.
  //
  ww = mapFile("mmap.test.junk", &lw, 'r');
  for (idx=0; idx<numBlocks * blockSize; idx++) {
    if ((idx & 0xfff) == 0)
      fprintf(stderr, "Verifying: "uint32FMT"/"uint32FMT"\r", idx, numBlocks * blockSize), fflush(stderr);
    if (ww[idx] != idx)
      err++;
  }
  unmapFile(ww, lw);
  fprintf(stderr, "\n");

  unlink("mmap.test.junk");

  return (err != 0);  
}
コード例 #8
0
int
main(int argc, char **argv) {
  uint32                  covMax    = 0;
  intervalList<uint64>  **cov       = 0L;
  uint32                 *len       = 0L;

  uint32                  lastIID   = 0;

  bool                    isRaw     = false;
  bool                    isBlast   = false;

  char                   *fastaname = 0L;
  char                   *covname   = 0L;

  seqCache               *F = 0L;

  FILE                   *C = stdout;

  int arg=1;
  int err=0;
  while (arg < argc) {
    if        (strcmp(argv[arg], "-mask") == 0) {
      fastaname = argv[++arg];

    } else if (strcmp(argv[arg], "-cov") == 0) {
      covname   = argv[++arg];

    } else if (strcmp(argv[arg], "-raw") == 0) {
      isRaw = true;

    } else if (strcmp(argv[arg], "-blast") == 0) {
      isBlast = true;

    } else {
      fprintf(stderr, "unknown arg: '%s'\n", argv[arg]);
      err++;
    }
    arg++;
  }
  if ((err) || (isatty(fileno(stdin)))) {
    fprintf(stderr, "usage: %s [-mask in.fasta] [-cov dat] [-raw | -blast] < sim4db-results\n", argv[0]);
    fprintf(stderr, "       -mask    Read sequences from in.fasta, lower-case mask\n");
    fprintf(stderr, "                any base with an alignment, write to out.fasta\n");
    fprintf(stderr, "       -cov     Write coverage statistics to 'dat' instead of stdout\n");
    fprintf(stderr, "       -raw     If present, assume the 'sim4db-results' are\n");
    fprintf(stderr, "                a space-separated list of 'iid begin end', one per line\n");
    fprintf(stderr, "       -blast   Same idea as raw, expects 'UID.IID' for query id,\n");
    fprintf(stderr, "                blast format (-m) 9.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "Output on stdout is the masked sequence if -mask is specified,\n");
    fprintf(stderr, "otherwise, it is the coverage statistics.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "-mask is almost a required option - we need it to get the length.\n");
    fprintf(stderr, "of sequences with no mapping (100%% uncovered) and to get the\n");
    fprintf(stderr, "number of sequences.\n");
    fprintf(stderr, "\n");
    if (isatty(fileno(stdin)))
      fprintf(stderr, "error: I cannot read polishes from the terminal!\n\n");
  }

  if (fastaname) {
    C = 0L;
    F = new seqCache(fastaname);
  }

  if (covname) {
    errno = 0;
    C     = fopen(covname, "w");
    if (errno)
      fprintf(stderr, "Failed to open '%s' for write: %s\n", covname, strerror(errno)), exit(1);
  }

  covMax   = 1024 * 1024;
  if (F)
    covMax = F->getNumberOfSequences();
  cov      = new intervalList<uint64> * [covMax];
  len      = new uint32 [covMax];

  fprintf(stderr, "Found "uint32FMT" sequences in the input file.\n", covMax);

  for (uint32 i=0; i<covMax; i++) {
    cov[i] = 0L;
    len[i] = 0;
  }

  if (isRaw || isBlast) {
    char          inLine[1024];
    splitToWords  S;

    while (!feof(stdin)) {
      fgets(inLine, 1024, stdin);
      S.split(inLine);

      uint32  iid=0, beg=0, end=0;

      if (isRaw) {
        iid = strtouint32(S[0], 0L);
        beg = strtouint32(S[1], 0L) - 1;   //  Convert to space-based
        end = strtouint32(S[2], 0L);
      }
      if (isBlast) {
        char *iii = S[0];
        while ((*iii != '.') && (*iii))
          iii++;
        iii++;
        if (*iii == 0)
          fprintf(stderr, "UID.IID error: '%s'\n", S[0]);

        iid = strtouint32(iii, 0L);
        beg = strtouint32(S[6], 0L) - 1;   //  Convert to space-based
        end = strtouint32(S[7], 0L);
      }

      if (iid >= covMax) {
        fprintf(stderr, "ERROR:  Found iid "uint32FMT", but only allocated "uint32FMT" places!\n",
                iid, covMax);
        exit(1);
      }
      if (cov[iid] == 0L) {
        cov[iid] = new intervalList<uint64>;
        len[iid] = 0;
      }
      if (iid >= lastIID) {
        lastIID = iid + 1;
      }
      cov[iid]->add(beg, end-beg);
    }

  } else {
    sim4polishReader *R = new sim4polishReader("-");
    sim4polish       *p = 0L;

    while (R->nextAlignment(p)) {
      if (p->_estID > covMax)
        fprintf(stderr, "DIE!  You have more sequences in your polishes than in your source!\n"), exit(1);

      if (p->_estID >= covMax) {
        fprintf(stderr, "ERROR:  Found iid "uint32FMT", but only allocated "uint32FMT" places!\n",
                p->_estID, covMax);
        exit(1);
      }
      if (cov[p->_estID] == 0L) {
        cov[p->_estID] = new intervalList<uint64>;
        len[p->_estID] = p->_estLen;
      }
      if (p->_estID >= lastIID) {
        lastIID = p->_estID + 1;
      }

      for (uint32 e=0; e<p->_numExons; e++) {
        p->_exons[e]._estFrom--;        //  Convert to space-based

        if (p->_matchOrientation == SIM4_MATCH_FORWARD)
          cov[p->_estID]->add(p->_exons[e]._estFrom,
                              p->_exons[e]._estTo - p->_exons[e]._estFrom);
        else
          cov[p->_estID]->add(p->_estLen - p->_exons[e]._estTo,
                              p->_exons[e]._estTo - p->_exons[e]._estFrom);
      }
    }
  }


  //  Scan the list of intervalLists, compute the amount covered, print.
  //
  for (uint32 iid=0; iid<lastIID; iid++) {

    //  Argh!  If there are no intervals, we need to report the whole
    //  sequence is uncovered!

    uint32  numRegions  = 0;
    uint32  sumLengths  = 0;
    uint32  l, h;

    //  Save the number of regions and the sum of their lengths,
    //  then merge regions
    //
    if (cov[iid]) {
      numRegions = cov[iid]->numberOfIntervals();
      sumLengths = cov[iid]->sumOfLengths();
      cov[iid]->merge();
    }

    if (F) {
      seqInCore *S = F->getSequenceInCore(iid);

      if (len[iid] == 0)
        len[iid] = S->sequenceLength();

      assert(len[iid] == S->sequenceLength());

      char   *seq = new char [len[iid] + 1];
      strcpy(seq, S->sequence());

      for (uint32 p=0; p<len[iid]; p++)
        seq[p] = toUpper[seq[p]];

      if (cov[iid]) {
        for (uint32 c=0; c<cov[iid]->numberOfIntervals(); c++) {
          l = cov[iid]->lo(c);
          h = cov[iid]->hi(c);

          if (h > len[iid]) {
            fprintf(stderr, "ERROR:  range "uint32FMT"-"uint32FMT" out of bounds (seqLen = "uint32FMT")\n",
                    l, h, len[iid]);
            assert(h <= len[iid]);
          }

          for (uint32 p=l; p<h; p++)
            //seq[p] = toLower[seq[p]];
            seq[p] = 'N';
        }
      }

      fprintf(stdout, "%s\n%s\n", S->header(), seq);

      delete [] seq;
      delete    S;
    }

    if (C) {
      double  percentCovered = 0.00;

      if (cov[iid])
        percentCovered = cov[iid]->sumOfLengths() / (double)len[iid];

      fprintf(C, uint32FMT"\t"uint32FMT"\t%5.3f\t"uint32FMT"\t"uint32FMT"\n",
              iid,
              len[iid],
              percentCovered,
              numRegions,
              sumLengths);
    }
  }
}
コード例 #9
0
ファイル: leaff.C プロジェクト: ondovb/canu
void
processArray(int argc, char **argv) {

  int arg = 1;
  while (arg < argc) {

    if       ((strcmp(argv[arg], "-f") == 0) ||
              (strcmp(argv[arg], "-F") == 0)) {
      delete fasta;
      fasta = new seqCache(argv[++arg]);

    } else if (strcmp(argv[arg], "-i") == 0) {

      failIfNoSource();

      ++arg;
      if ((argv[arg] == 0L) || (argv[arg][0] == '-'))
        fprintf(stderr, "ERROR: next arg to -i should be 'name', I got '%s'\n",
                (argv[arg] == 0L) ? "(nullpointer)" : argv[arg]), exit(1);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        fprintf(stdout, "G\tseq\t%s:"F_U32"\t"F_U32"\t%s\n",
                argv[arg], s, fasta->getSequenceLength(s), ">unimplemented");

    } else if (strcmp(argv[arg], "-d") == 0) {
      failIfNoSource();
      printf(F_U32"\n", fasta->getNumberOfSequences());

    } else if (strcmp(argv[arg], "-L") == 0) {
      uint32 small = strtouint32(argv[++arg]);
      uint32 large = strtouint32(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        if ((small <= fasta->getSequenceLength(s)) && (fasta->getSequenceLength(s) < large))
          printSequence(s);

    } else if (strcmp(argv[arg], "-N") == 0) {
      double small = atof(argv[++arg]);
      double large = atof(argv[++arg]);

      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S   = fasta->getSequenceInCore(s);
        uint32     Ns  = 0;
        uint32     len = S->sequenceLength();
        char      *seq = S->sequence();

        for (uint32 i=begPos; i<len && i<endPos; i++)
          if ((seq[i] == 'n') || (seq[i] == 'N'))
            Ns++;

        double Np = 100.0 * Ns / len;

        if ((small <= Np) && (Np < large))
          printSequence(S);

        delete S;
      }

    } else if (strcmp(argv[arg], "-W") == 0) {
      failIfNoSource();

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-G") == 0) {
      uint32 n = strtouint32(argv[++arg]);
      uint32 s = strtouint32(argv[++arg]);
      uint32 l = strtouint32(argv[++arg]);

      char      bases[4] = {'A', 'C', 'G', 'T'};
      char     *def      = new char [1024];
      char     *seq      = new char [l + 1];

      if (s == 0)
        s = 1;
      if (s > l)
        fprintf(stderr, "leaff: usage: -G num-seqs min-length max-length\n"), exit(1);

      for (uint32 i=0; i<n; i++) {
        uint32 j = s + ((l-s == 0) ? 0 : (MT.mtRandom32() % (l-s)));
        uint32 p = 0;

        while (p < j)
          seq[p++] = bases[MT.mtRandom32() & 0x3];
        seq[p] = 0;

        sprintf(def, "random%06"F_U32P, i);

        printSequence(def, seq, 0, j);
      }

      delete [] seq;
      delete [] def;

    } else if (strcmp(argv[arg], "-s") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences
      printSequence(argv[++arg]);

    } else if (strcmp(argv[arg], "-S") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Easy to fix, just read the first N sequences

      uint32 lowID  = fasta->getSequenceIID(argv[++arg]);
      uint32 highID = fasta->getSequenceIID(argv[++arg]);

      if (lowID > highID) {
        uint32 t = lowID;
        lowID    = highID;
        highID   = t;
      }

      for (uint32 s=lowID; (s <= highID) && (s <= fasta->getNumberOfSequences()); s++)
        printSequence(s);

    } else if (strcmp(argv[arg], "-r") == 0) {
      uint32 num = strtouint32(argv[++arg]);

      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory

      if (num >= fasta->getNumberOfSequences())
        num = fasta->getNumberOfSequences();

      uint32  *seqs = new uint32 [fasta->getNumberOfSequences()];

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++)
        seqs[i] = i;

      for (uint32 i=0; i<fasta->getNumberOfSequences(); i++) {
        uint32 j = MT.mtRandom32() % (fasta->getNumberOfSequences() - i) + i;
        uint32 t = seqs[j];
        seqs[j] = seqs[i];
        seqs[i] = t;
      }

      for (uint32 i=0; i<num; i++)
        printSequence(seqs[i]);

      delete [] seqs;

    } else if (strcmp(argv[arg], "-q") == 0) {
      failIfNoSource();
      failIfNotRandomAccess();  //  Impossible to fix, or load whole thing into memory
      printIDsFromFile(argv[++arg]);

    } else if (strcmp(argv[arg], "-6") == 0) {
      withLineBreaks = 60;
      if ((argv[arg+1] != 0L) && (argv[arg+1][0] != '-'))
        withLineBreaks = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-w") == 0) {
      toUppercase = !toUppercase;
      for (int z=0; z<256; z++)
        translate[z] = (toUppercase) ? alphabet.toUpper(z) : (char)z;

    } else if (strcmp(argv[arg], "-R") == 0) {
      doReverse = !doReverse;

    } else if (strcmp(argv[arg], "-C") == 0) {
      doComplement = !doComplement;

    } else if (strcmp(argv[arg], "-H") == 0) {
      withDefLine    = !withDefLine;
      specialDefLine = 0L;

    } else if (strcmp(argv[arg], "-h") == 0) {
      withDefLine    = true;
      specialDefLine = argv[++arg];

    } else if (strcmp(argv[arg], "-e") == 0) {
      begPos = strtouint32(argv[++arg]);
      endPos = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-ends") == 0) {
      endExtract = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-A") == 0) {
      processFile(argv[++arg]);



    } else if (strcmp(argv[arg], "--findduplicates") == 0) {
      findDuplicates(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--mapduplicates") == 0) {
      mapDuplicates(argv[arg+1], argv[arg+2]);
      exit(0);

    } else if (strcmp(argv[arg], "--md5") == 0) {
      md5_s     md5;
      char      sum[33];

      fasta = new seqCache(argv[++arg]);

      for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) {
        seqInCore *S = fasta->getSequenceInCore(s);
        fprintf(stdout, "%s %s\n",
                md5_toascii(md5_string(&md5, S->sequence(), S->sequenceLength()), sum),
                S->header());
        delete S;
      }
      delete fasta;
      exit(0);

    } else if ((strcmp(argv[arg], "--partition") == 0) ||
               (strcmp(argv[arg], "--partitionmap") == 0)) {

      char *prefix = 0L;
      if (strcmp(argv[arg], "--partition") == 0)
        prefix = argv[++arg];

      //  does the next arg end with gbp, mbp, kbp or bp?  If so,
      //  partition by length, else partition into buckets.
      //
      int     al = strlen(argv[arg+1]);
      uint64  ps = strtouint64(argv[arg+1]);

      char a3 = (al<3) ? '0' : alphabet.toLower(argv[arg+1][al-3]);
      char a2 = (al<2) ? '0' : alphabet.toLower(argv[arg+1][al-2]);
      char a1 = (al<1) ? '0' : alphabet.toLower(argv[arg+1][al-1]);

      //  partition!

      if (!isdigit(a1) || !isdigit(a2) || !isdigit(a3)) {
        if        ((a3 == 'g') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000000;
        } else if ((a3 == 'm') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000000;
        } else if ((a3 == 'k') && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1000;
        } else if (isdigit(a3) && (a2 == 'b') && (a1 == 'p')) {
          ps *= 1;
        } else {
          fprintf(stderr, "Unknown partition size option '%s'\n", argv[arg+1]), exit(1);
        }

        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionBySize(prefix, ps, argv[arg+2]);
      } else {
        if (ps == 0)
          fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1);
        partitionByBucket(prefix, ps, argv[arg+2]);
      }
      exit(0);

    } else if (strcmp(argv[arg], "--segment") == 0) {
      partitionBySegment(argv[arg+1], strtouint32(argv[arg+2]), argv[arg+3]);
      exit(0);

    } else if (strcmp(argv[arg], "--gccontent") == 0) {
      computeGCcontent(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--dumpblocks") == 0) {
      dumpBlocks(argv[++arg]);
      exit(0);

    } else if (strcmp(argv[arg], "--stats") == 0) {
      stats(argv[arg+1], (argv[arg+2] != 0L) ? strtouint64(argv[arg+2]) : 0);
      exit(0);

    } else if (strcmp(argv[arg], "--errors") == 0) {
      int    L = strtouint32(argv[++arg]);     //  Desired length
      int    l = 0;                            //  min of desired length, length of sequence
      int    N = strtouint32(argv[++arg]);     //  number of copies per sequence
      int    C = strtouint32(argv[++arg]);     //  number of mutations per copy
      double P = atof(argv[++arg]);            //  probability of mutation
      uint32 i = 0;

      fasta = new seqCache(argv[++arg]);

      seqInCore *S = fasta->getSequenceInCore(i++);
      while (S) {
        char   *seq = S->sequence();
        char   *hdr = S->header();
        int     len = S->sequenceLength();

        l = len;
        if ((L > 0) && (L < len))
          l = L;

        simseq(seq, hdr, len, N, l, C, P);

        delete S;
        S = fasta->getSequenceInCore(i++);
      }
      delete fasta;
      exit(0);

    } else if (strcmp(argv[arg], "--seqstore") == 0) {
      constructSeqStore(argv[++arg], fasta);
      exit(0);

    } else if (strcmp(argv[arg], "-help") == 0) {
      if      ((argv[arg+1]) && (strcmp(argv[arg+1], "analysis") == 0))
        helpAnalysis(argv[0]);
      else if ((argv[arg+1]) && (strcmp(argv[arg+1], "examples") == 0))
        helpExamples(argv[0]);
      else
        helpStandard(argv[0]);
      exit(0);

    } else {
      helpStandard(argv[0]);
      fprintf(stderr, "Unknown option '%s'\n", argv[arg]);
      exit(1);
    }

    arg++;
  }

  delete fasta;
  fasta = 0L;
}
コード例 #10
0
ファイル: proxy_id.c プロジェクト: abbra/sssd
void proxy_get_account_info(struct be_req *breq)
{
    struct be_ctx *be_ctx = be_req_get_be_ctx(breq);
    struct be_acct_req *ar;
    struct proxy_id_ctx *ctx;
    struct sysdb_ctx *sysdb;
    struct sss_domain_info *domain;
    uid_t uid;
    gid_t gid;
    int ret;
    char *endptr;

    ar = talloc_get_type(be_req_get_data(breq), struct be_acct_req);
    ctx = talloc_get_type(be_ctx->bet_info[BET_ID].pvt_bet_data,
                          struct proxy_id_ctx);
    sysdb = be_ctx->domain->sysdb;
    domain = be_ctx->domain;

    if (be_is_offline(be_ctx)) {
        return be_req_terminate(breq, DP_ERR_OFFLINE, EAGAIN, "Offline");
    }

    /* for now we support only core attrs */
    if (ar->attr_type != BE_ATTR_CORE) {
        return be_req_terminate(breq, DP_ERR_FATAL, EINVAL, "Invalid attr type");
    }

    /* proxy provider does not support security ID lookups */
    if (ar->filter_type == BE_FILTER_SECID) {
        return be_req_terminate(breq, DP_ERR_FATAL, ENOSYS,
                                "Invalid filter type");
    }

    switch (ar->entry_type & BE_REQ_TYPE_MASK) {
    case BE_REQ_USER: /* user */
        switch (ar->filter_type) {
        case BE_FILTER_ENUM:
            ret = enum_users(breq, ctx, sysdb, domain);
            break;

        case BE_FILTER_NAME:
            ret = get_pw_name(ctx, domain, ar->filter_value);
            break;

        case BE_FILTER_IDNUM:
            uid = (uid_t) strtouint32(ar->filter_value, &endptr, 10);
            if (errno || *endptr || (ar->filter_value == endptr)) {
                return be_req_terminate(breq, DP_ERR_FATAL,
                                        EINVAL, "Invalid attr type");
            }
            ret = get_pw_uid(ctx, domain, uid);
            break;
        default:
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    EINVAL, "Invalid filter type");
        }
        break;

    case BE_REQ_GROUP: /* group */
        switch (ar->filter_type) {
        case BE_FILTER_ENUM:
            ret = enum_groups(breq, ctx, sysdb, domain);
            break;
        case BE_FILTER_NAME:
            ret = get_gr_name(ctx, sysdb, domain, ar->filter_value);
            break;
        case BE_FILTER_IDNUM:
            gid = (gid_t) strtouint32(ar->filter_value, &endptr, 10);
            if (errno || *endptr || (ar->filter_value == endptr)) {
                return be_req_terminate(breq, DP_ERR_FATAL,
                                        EINVAL, "Invalid attr type");
            }
            ret = get_gr_gid(breq, ctx, sysdb, domain, gid, 0);
            break;
        default:
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    EINVAL, "Invalid filter type");
        }
        break;

    case BE_REQ_INITGROUPS: /* init groups for user */
        if (ar->filter_type != BE_FILTER_NAME) {
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    EINVAL, "Invalid filter type");
        }
        if (ctx->ops.initgroups_dyn == NULL) {
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    ENODEV, "Initgroups call not supported");
        }
        ret = get_initgr(breq, ctx, sysdb, domain, ar->filter_value);
        break;

    case BE_REQ_NETGROUP:
        if (ar->filter_type != BE_FILTER_NAME) {
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    EINVAL, "Invalid filter type");
        }
        if (ctx->ops.setnetgrent == NULL || ctx->ops.getnetgrent_r == NULL ||
                ctx->ops.endnetgrent == NULL) {
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    ENODEV, "Netgroups are not supported");
        }

        ret = get_netgroup(ctx, domain, ar->filter_value);
        break;

    case BE_REQ_SERVICES:
        switch (ar->filter_type) {
        case BE_FILTER_NAME:
            if (ctx->ops.getservbyname_r == NULL) {
                return be_req_terminate(breq, DP_ERR_FATAL,
                                        ENODEV, "Services are not supported");
            }
            ret = get_serv_byname(ctx, domain,
                                  ar->filter_value,
                                  ar->extra_value);
            break;
        case BE_FILTER_IDNUM:
            if (ctx->ops.getservbyport_r == NULL) {
                return be_req_terminate(breq, DP_ERR_FATAL,
                                        ENODEV, "Services are not supported");
            }
            ret = get_serv_byport(ctx, domain,
                                  ar->filter_value,
                                  ar->extra_value);
            break;
        case BE_FILTER_ENUM:
            if (!ctx->ops.setservent
                    || !ctx->ops.getservent_r
                    || !ctx->ops.endservent) {
                return be_req_terminate(breq, DP_ERR_FATAL,
                                        ENODEV, "Services are not supported");
            }
            ret = enum_services(ctx, sysdb, domain);
            break;
        default:
            return be_req_terminate(breq, DP_ERR_FATAL,
                                    EINVAL, "Invalid filter type");
        }
        break;

    default: /*fail*/
        return be_req_terminate(breq, DP_ERR_FATAL,
                                EINVAL, "Invalid request type");
    }

    if (ret) {
        if (ret == ENXIO) {
            DEBUG(SSSDBG_OP_FAILURE,
                  "proxy returned UNAVAIL error, going offline!\n");
            be_mark_offline(be_ctx);
        }
        be_req_terminate(breq, DP_ERR_FATAL, ret, NULL);
        return;
    }
    be_req_terminate(breq, DP_ERR_OK, EOK, NULL);
}
コード例 #11
0
ファイル: proxy_id.c プロジェクト: celestian/sssd
static struct dp_reply_std
proxy_account_info(TALLOC_CTX *mem_ctx,
                   struct proxy_id_ctx *ctx,
                   struct dp_id_data *data,
                   struct be_ctx *be_ctx,
                   struct sss_domain_info *domain)
{
    struct dp_reply_std reply;
    struct sysdb_ctx *sysdb;
    uid_t uid;
    gid_t gid;
    errno_t ret;
    char *endptr;

    sysdb = domain->sysdb;

    /* For now we support only core attrs. */
    if (data->attr_type != BE_ATTR_CORE) {
        dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL, "Invalid attr type");
        return reply;
    }

    /* Proxy provider does not support security ID lookups. */
    if (data->filter_type == BE_FILTER_SECID) {
        dp_reply_std_set(&reply, DP_ERR_FATAL, ENOSYS,
                         "Security lookups are not supported");
        return reply;
    }

    switch (data->entry_type & BE_REQ_TYPE_MASK) {
    case BE_REQ_USER: /* user */
        switch (data->filter_type) {
        case BE_FILTER_ENUM:
            ret = enum_users(mem_ctx, ctx, sysdb, domain);
            break;

        case BE_FILTER_NAME:
            ret = get_pw_name(ctx, domain, data->filter_value);
            break;

        case BE_FILTER_IDNUM:
            uid = (uid_t) strtouint32(data->filter_value, &endptr, 10);
            if (errno || *endptr || (data->filter_value == endptr)) {
                dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                                 "Invalid attr type");
                return reply;
            }
            ret = get_pw_uid(ctx, domain, uid);
            break;
        default:
            dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                             "Invalid filter type");
            return reply;
        }
        break;

    case BE_REQ_GROUP: /* group */
        switch (data->filter_type) {
        case BE_FILTER_ENUM:
            ret = enum_groups(mem_ctx, ctx, sysdb, domain);
            break;
        case BE_FILTER_NAME:
            ret = get_gr_name(ctx, sysdb, domain, data->filter_value);
            break;
        case BE_FILTER_IDNUM:
            gid = (gid_t) strtouint32(data->filter_value, &endptr, 10);
            if (errno || *endptr || (data->filter_value == endptr)) {
                dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                                 "Invalid attr type");
                return reply;
            }
            ret = get_gr_gid(mem_ctx, ctx, sysdb, domain, gid, 0);
            break;
        default:
            dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                             "Invalid filter type");
            return reply;
        }
        break;

    case BE_REQ_INITGROUPS: /* init groups for user */
        if (data->filter_type != BE_FILTER_NAME) {
            dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                             "Invalid filter type");
            return reply;
        }
        if (ctx->ops.initgroups_dyn == NULL) {
            dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
                             "Initgroups call not supported");
            return reply;
        }
        ret = get_initgr(mem_ctx, ctx, sysdb, domain, data->filter_value);
        break;

    case BE_REQ_NETGROUP:
        if (data->filter_type != BE_FILTER_NAME) {
            dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                             "Invalid filter type");
            return reply;
        }
        if (ctx->ops.setnetgrent == NULL || ctx->ops.getnetgrent_r == NULL ||
            ctx->ops.endnetgrent == NULL) {
            dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
                             "Netgroups are not supported");
            return reply;
        }

        ret = get_netgroup(ctx, domain, data->filter_value);
        break;

    case BE_REQ_SERVICES:
        switch (data->filter_type) {
        case BE_FILTER_NAME:
            if (ctx->ops.getservbyname_r == NULL) {
                dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
                                 "Services are not supported");
                return reply;
            }
            ret = get_serv_byname(ctx, domain,
                                  data->filter_value,
                                  data->extra_value);
            break;
        case BE_FILTER_IDNUM:
            if (ctx->ops.getservbyport_r == NULL) {
                dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
                                 "Services are not supported");
                return reply;
            }
            ret = get_serv_byport(ctx, domain,
                                  data->filter_value,
                                  data->extra_value);
            break;
        case BE_FILTER_ENUM:
            if (!ctx->ops.setservent
                    || !ctx->ops.getservent_r
                    || !ctx->ops.endservent) {
                dp_reply_std_set(&reply, DP_ERR_FATAL, ENODEV,
                                 "Services are not supported");
                return reply;
            }
            ret = enum_services(ctx, sysdb, domain);
            break;
        default:
            dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                             "Invalid filter type");
            return reply;
        }
        break;

    default: /*fail*/
        dp_reply_std_set(&reply, DP_ERR_FATAL, EINVAL,
                         "Invalid filter type");
        return reply;
    }

    if (ret) {
        if (ret == ENXIO) {
            DEBUG(SSSDBG_OP_FAILURE,
                  "proxy returned UNAVAIL error, going offline!\n");
            be_mark_offline(be_ctx);
        }

        dp_reply_std_set(&reply, DP_ERR_FATAL, ret, NULL);
        return reply;
    }

    dp_reply_std_set(&reply, DP_ERR_OK, EOK, NULL);
    return reply;
}
コード例 #12
0
ファイル: mapMers-depth.C プロジェクト: ondovb/canu
int
main(int argc, char **argv) {
  uint32    merSize    = 16;
  char     *merylFile  = 0L;
  char     *fastaFile  = 0L;
  bool      beVerbose  = false;
  uint32    loCount    = 0;
  uint32    hiCount    = ~uint32ZERO;
  uint32    windowsize = 0;
  uint32    skipsize   = 0;

  int arg=1;
  while (arg < argc) {
    if        (strcmp(argv[arg], "-m") == 0) {
      merSize = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-mers") == 0) {
      merylFile = argv[++arg];

    } else if (strcmp(argv[arg], "-seq") == 0) {
      fastaFile = argv[++arg];

    } else if (strcmp(argv[arg], "-v") == 0) {
      beVerbose = true;

    } else if (strcmp(argv[arg], "-lo") == 0) {
      loCount = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-hi") == 0) {
      hiCount = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-w") == 0) {
      windowsize = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-s") == 0) {
      skipsize = strtouint32(argv[++arg]);

    } else {
      fprintf(stderr, "unknown option '%s'\n", argv[arg]);
    }
    arg++;
  }

  if ((merylFile == 0L) || (fastaFile == 0L)) {
    fprintf(stderr, "usage: %s -m mersize -mers mers -seq fasta > output\n", argv[0]);
    exit(1);
  }

  existDB       *E = new existDB(merylFile, merSize, existDBcounts | existDBcompressCounts | existDBcompressBuckets, loCount, hiCount);
  seqCache      *F = new seqCache(fastaFile);

  for (uint32 Sid=0; Sid < F->getNumberOfSequences(); Sid++) {
    seqInCore  *S  = F->getSequenceInCore(Sid);
    merStream  *MS = new merStream(new kMerBuilder(merSize),
                                   new seqStream(S->sequence(), S->sequenceLength()),
                                   true, true);

    uint32                         idlen = 0;
    intervalDepthRegions<uint64>  *id    = new intervalDepthRegions<uint64> [S->sequenceLength() * 2 + 2];

    while (MS->nextMer()) {
      int32   cnt = (int32)E->count(MS->theFMer()) + (int32)E->count(MS->theRMer());

      //  Old intervalDepth was to add 'cnt' in the first and subtract 'cnt' in the second.
      //  Then to use the 'ct' field below.
      //  New intervalDepth is the same, but uses the value field.
      //  Count is now the number of intervals that are represented in this block.

      id[idlen].pos     = MS->thePositionInSequence();
      id[idlen].change  = cnt;
      id[idlen].open    = true;
      idlen++;

      id[idlen].pos     = MS->thePositionInSequence() + merSize;
      id[idlen].change  = cnt;
      id[idlen].open    = false;
      idlen++;
    }

    intervalList<uint64>  ID(id, idlen);
    uint32                x = 0;

    uint32                len = S->sequenceLength();

    //  Default case, report un-averaged depth at every single location.
    //
    if ((windowsize == 0) && (skipsize == 0)) {
      for (uint32 i=0; i < ID.numberOfIntervals(); i++) {
        for (; x < ID.lo(i); x++)
          fprintf(stdout, uint32FMTW(7)"\t"uint32FMTW(6)"\n", x, 0);
        for (; x < ID.hi(i); x++)
          fprintf(stdout, uint32FMTW(7)"\t"uint32FMTW(6)"\n", x, ID.value(i));
      }
      for (; x < len; x++)
        fprintf(stdout, uint32FMTW(7)"\t"uint32FMTW(6)"\n", x, 0);

    } else {
      uint32  *depth = new uint32 [len];
      for (x=0; x < len; x++)
        depth[x] = 0;

      for (uint32 i=0; i < ID.numberOfIntervals(); i++)
        for (x=ID.lo(i); x < ID.hi(i); x++)
          depth[x] = ID.count(i);

      uint32   avedepth = 0;

      for (x=0; x < windowsize; x++)
        avedepth += depth[x];

      while (x < len) {
        uint32  avepos = (x - 1) - (windowsize - 1) / 2;
        if ((avepos % skipsize) == 0)
          fprintf(stdout, uint32FMT"\t%.4f\n",
                  avepos,
                  (double)avedepth / (double)windowsize);

        avedepth = avedepth + depth[x] - depth[x-windowsize];

        x++;
      }

      delete [] depth;
    }

    delete [] id;

    delete MS;
    delete S;
  }


  delete F;
  delete E;
}
コード例 #13
0
ファイル: tapper.C プロジェクト: liutanqiu/wgs-assembler
int
main(int argc, char **argv) {
  tapperGlobalData  *g = new tapperGlobalData();

  fprintf(stderr, "sizeof(tapperResultIndex) --       "sizetFMT"\n", sizeof(tapperResultIndex));
  fprintf(stderr, "sizeof(tapperResultQV) --          "sizetFMT"\n", sizeof(tapperResultQV));
  fprintf(stderr, "sizeof(tapperResultFragment) --    "sizetFMT"\n", sizeof(tapperResultFragment));
  fprintf(stderr, "sizeof(tapperResultMated) --       "sizetFMT"\n", sizeof(tapperResultMated));
  fprintf(stderr, "sizeof(tapperResultTangled) --     "sizetFMT"\n", sizeof(tapperResultTangled));
  fprintf(stderr, "sizeof(tapperHit) --               "sizetFMT"\n", sizeof(tapperHit));
  fprintf(stderr, "sizeof(tapperTag) --               "sizetFMT"\n", sizeof(tapperTag));

  int arg=1;
  int err=0;
  while (arg < argc) {
    if        (strncmp(argv[arg], "-genomic", 2) == 0) {
      g->genName = argv[++arg];
    } else if (strncmp(argv[arg], "-queries", 2) == 0) {
      g->qryName = argv[++arg];
    } else if (strncmp(argv[arg], "-output", 2) == 0) {
      g->outName = argv[++arg];

    } else if (strncmp(argv[arg], "-begin", 2) == 0) {
      g->bgnRead = strtouint32(argv[++arg], 0L);
      g->thisPartition = 0;
      g->numPartitions = 1;

    } else if (strncmp(argv[arg], "-end", 2) == 0) {
      g->endRead = strtouint32(argv[++arg], 0L);
      g->thisPartition = 0;
      g->numPartitions = 1;

    } else if (strncmp(argv[arg], "-partition", 2) == 0) {
      g->thisPartition = strtouint32(argv[++arg], 0L);
      g->numPartitions = strtouint32(argv[++arg], 0L);

    } else if (strncmp(argv[arg], "-repeatthreshold", 2) == 0) {
      g->repeatThreshold = strtouint32(argv[++arg], 0L);

    } else if (strncmp(argv[arg], "-maxcolorerror", 5) == 0) {
      g->maxColorError = strtouint32(argv[++arg], 0L);

    } else if (strncmp(argv[arg], "-maxbaseerror", 5) == 0) {
      g->maxBaseError = strtouint32(argv[++arg], 0L);

    } else if (strncmp(argv[arg], "-maxmemory", 5) == 0) {
      g->maxMemory = atoi(argv[++arg]);

    } else if (strncmp(argv[arg], "-threads", 2) == 0) {
      g->numThreads = atoi(argv[++arg]);

    } else if (strncmp(argv[arg], "-verbose", 2) == 0) {
      g->beVerbose = true;
    } else {
      fprintf(stderr, "%s: unknown option '%s'\n", argv[0], argv[arg]);
      err++;
    }
    arg++;
  }
  if ((err > 0) || (g->genName == 0L) || (g->qryName == 0L) || (g->outName == 0L)) {
    fprintf(stderr, "usage: %s [opts]\n", argv[0]);
    fprintf(stderr, "\n");
    fprintf(stderr, "  MANDATORY\n");
    fprintf(stderr, "          -genomic genomic.fasta\n");
    fprintf(stderr, "          -queries tags.tapperTags\n");
    fprintf(stderr, "          -output  tapperResultFile directory path\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "  OPTIONAL\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "          -begin b               Start aligning at read b (or mate pair b)\n");
    fprintf(stderr, "          -end   e               Stop aligning at read e (or mate pair e)\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "          -partition n m         Run partition n out of m total partitions.\n");
    fprintf(stderr, "                                 This sets -b and -e so that the reads/mate pairs\n");
    fprintf(stderr, "                                 are in m partitions.  Partitions start at 0 and\n");
    fprintf(stderr, "                                 end at m-1.\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "          -repeatthreshold x     Do not report fragment alignments for tags\n");
    fprintf(stderr, "                                 with more than x alignments.  Singletons, mated\n");
    fprintf(stderr, "                                 tags and are still reported and computed using\n");
    fprintf(stderr, "                                 all alignments.  The default is "uint32FMT".\n", g->repeatThreshold);
    fprintf(stderr, "\n");
    fprintf(stderr, "          -maxcolorerror  n\n");
    fprintf(stderr, "          -maxbaseerror   n\n");
    fprintf(stderr, "\n");
    fprintf(stderr, "          -maxmemory      m (MB)\n");
    fprintf(stderr, "          -threads        n\n");
    fprintf(stderr, "          -verbose\n");

    exit(1);
  }

  g->initialize();

  sweatShop *ss = new sweatShop(tapperReader, tapperWorker, tapperWriter);

  ss->setLoaderQueueSize(16384);
  ss->setLoaderBatchSize(512);
  ss->setWorkerBatchSize(1024);
  ss->setWriterQueueSize(65536);

  ss->setNumberOfWorkers(g->numThreads);

  for (uint32 w=0; w<g->numThreads; w++)
    ss->setThreadData(w, new tapperThreadData(g));

  ss->run(g, g->beVerbose);

  delete g;
  delete ss;

  fprintf(stderr, "\nSuccess!  Bye.\n");
  return(0);
}
コード例 #14
0
int
main(int argc, char **argv) {
  uint32       pNum   = 0;
  uint32       pAlloc = 8388608;
  uint32       estID  = ~uint32ZERO;

  bool        *found  = 0L;

  //  From fixPolishesIID.c
  IIDdict = 0L;
  SEQdict = 0L;
  GENdict = 0L;

  //  Incorporated from sortPolishes
  mergeFilesLen   = 0;
  mergeFilesMax   = sysconf(_SC_OPEN_MAX);
  mergeFiles      = new FILE *       [mergeFilesMax];
  mergeNames      = new char *       [mergeFilesMax];
  mergePolishes   = new sim4polish * [mergeFilesMax];

  //  Default to printing stats on stdout.
  sFile = stdout;

  int arg = 1;
  while (arg < argc) {
    if        (strcmp(argv[arg], "-n") == 0) {
      pAlloc = strtouint32(argv[++arg], 0L);

    } else if (strcmp(argv[arg], "-fpart") == 0) {
      arg++;
      fprintf(stderr, "reading query deflines from '%s'\n", argv[arg]);
      IIDdict = dict_create(DICTCOUNT_T_MAX, headerCompare);
      addToDict(IIDdict, argv[arg]);
    } else if (strcmp(argv[arg], "-g") == 0) {
      ++arg;
      fprintf(stderr, "reading genomic deflines from '%s'\n", argv[arg]);
      GENdict = dict_create(DICTCOUNT_T_MAX, headerCompare);
      addToDict(GENdict, argv[arg]);
    } else if (strcmp(argv[arg], "-F") == 0) {
      ++arg;
      fprintf(stderr, "reading query deflines from '%s'\n", argv[arg]);
      SEQdict = dict_create(DICTCOUNT_T_MAX, headerCompare);
      addToDict(SEQdict, argv[arg]);
    } else if (strcmp(argv[arg], "-f") == 0) {
      ++arg;
      SEQ = new seqCache(argv[arg]);
    } else if (strcmp(argv[arg], "-q") == 0) {
      ++arg;
      QLT = new seqCache(argv[arg]);

    } else if (strcmp(argv[arg], "-filter") == 0) {
      filter = atof(argv[++arg]);
      doFiltering = true;
    } else if (strcmp(argv[arg], "-output") == 0) {
      char  cmd[1024] = {0};
      errno = 0;
      ++arg;
      if (strcmp(argv[arg] + strlen(argv[arg]) - 4, ".bz2") == 0) {
        sprintf(cmd, "bzip2 -1c > %s", argv[arg]);
        oFile = popen(cmd, "w");
        oFileIsPipe = 1;
      } else if (strcmp(argv[arg] + strlen(argv[arg]) - 3, ".gz") == 0) {
        sprintf(cmd, "gzip -1c > %s", argv[arg]);
        oFile = popen(cmd, "w");
        oFileIsPipe = 1;
      } else {
        fprintf(stderr, "Got %s, not .bz2 not .gz!\n", argv[arg]);
        exit(1);
      }
      if (errno)
        fprintf(stderr, "Failed to open '%s': %s\n", cmd, strerror(errno));
      doFiltering = true;
    } else if (strcmp(argv[arg], "-scores") == 0) {
      errno = 0;
      sFile = fopen(argv[++arg], "w");
      if (errno)
        fprintf(stderr, "Failed to open '%s': %s\n", argv[arg-1], strerror(errno));
      doFiltering = true;
    } else if (strcmp(argv[arg], "-unique") == 0) {
      char  cmd[1024] = {0};
      errno = 0;
      arg++;
      if (strcmp(argv[arg] + strlen(argv[arg]) - 4, ".bz2") == 0)
        sprintf(cmd, "bzip2 -1c > %s", argv[arg]);
      else if (strcmp(argv[arg] + strlen(argv[arg]) - 3, ".gz") == 0)
        sprintf(cmd, "gzip -1c > %s", argv[arg]);
      else
        sprintf(cmd, "cat > %s", argv[arg]);
      uFile = popen(cmd, "w");
      if (errno)
        fprintf(stderr, "Failed to open '%s': %s\n", cmd, strerror(errno));
      doFiltering = true;

    } else if (strncmp(argv[arg], "-M", 2) == 0) {
      arg++;
      while ((arg < argc) && (fileExists(argv[arg]))) {
        if (mergeFilesLen >= mergeFilesMax) {
          fprintf(stderr, "%s: ERROR!  Too many input files!  Should be less than %d\n", argv[0], mergeFilesMax);
          exit(1);
        }
        mergeNames[mergeFilesLen]   = argv[arg];
        mergeFiles[mergeFilesLen++] = openFile(argv[arg], "r");
        arg++;
      }
      arg--;

    } else {
      fprintf(stderr, "unknown option: %s\n", argv[arg]);
    }
    arg++;
  }


  if (doFiltering) {
    if (uFile == 0L)
      fprintf(stderr, "ERROR:  -unique is required\n"), exit(1);
    if (sFile == 0L)
      fprintf(stderr, "ERROR:  -scores is required\n"), exit(1);
    if ((filter < 0.0) || (filter > 1.0))
      fprintf(stderr, "ERROR:  -filter value of %f invalid.  0 <= F <= 100.\n", filter), exit(1);
  }


  if ((IIDdict == 0L) || (SEQdict == 0L) || (GENdict == 0L)) {
    fprintf(stderr, "WARNING!  No sequence dictionaries, NOT FIXING IIDs!  (supply -fpart, -f and -g)\n");
  }


  if ((SEQ == 0L) || (QLT == 0L)) {
    fprintf(stderr, "I need -f and -q\n");
    exit(1);
  }

  //  We no longer require that input polishes be sorted increasingly;
  //  now they only must be grouped.  This remembers if we've seen a
  //  match or not.  At the end, we'll analyze() those we haven't done
  //  already.
  //
  found = new bool [ SEQ->getNumberOfSequences() ];
  for (uint32 i=0; i<SEQ->getNumberOfSequences(); i++)
    found[i] = false;


  //  Initialize the merge -- if no merge files, nothing done!
  //
  for (int i=0; i<mergeFilesLen; i++) {
    mergePolishes[i] = new sim4polish(mergeFiles[i]);
    fixIID(mergePolishes[i], IIDdict);
  }


  //  Read polishes, picking the best when we see a change in the
  //  estID.

  sim4polish **p = new sim4polish * [pAlloc];
  sim4polish  *q;

  while ((q = nextPolish()) != 0L) {

    if ((q->_estID != estID) && (pNum > 0)) {
      //fprintf(stderr, "PickBest for estID "uint32FMT"\n", estID);

      found[estID] = true;
      pickBest(p, pNum);
      pNum  = 0;
    }

    if (pNum >= pAlloc) {
      sim4polish **P = new sim4polish * [pAlloc * 2];
      memcpy(p, P, sizeof(sim4polish *) * pAlloc);
      delete [] p;
      p = P;
      pAlloc *= 2;
    }

    p[pNum++] = q;
    estID     = q->_estID;
  }

  if (pNum > 0) {
    found[estID] = true;
    pickBest(p, pNum);
  }

  //  Attempt cleanup
  //
  for (int i=0; i<mergeFilesLen; i++)
    closeFile(mergeFiles[i], mergeNames[i]);

  for (estID=0; estID < SEQ->getNumberOfSequences(); estID++)
    if (found[estID] == false)
      analyze(estID, 0, SEQ->getSequenceLength(estID), SEQ->getSequenceLength(estID), true, 'M');

  delete [] mergeFiles;
  delete [] mergeNames;
  delete [] mergePolishes;

  if (oFile)  pclose(oFile);
  if (uFile)  pclose(uFile);
  if (sFile)  fclose(sFile);

  fprintf(stderr, "Uni:"uint32FMTW(8)" Con:"uint32FMTW(8)" (T:"uint32FMTW(8)" M:"uint32FMTW(8)" I:"uint32FMTW(8)" S:"uint32FMTW(8)" N:"uint32FMTW(8)") Inc:"uint32FMTW(8)" -- Save:"uint32FMTW(8)" Lost:"uint32FMTW(8)"\n",
          statOneMatch,
          statConsistent, consistentTie, consistentMatches, consistentIdentity, consistentTooShort, consistentNot,
          statInconsistent,
          statUnique, statLost);
  fprintf(stderr, "total:  LQ:"uint32FMT" MQ:"uint32FMT" RQ:"uint32FMT"\n",
          totLQ, totMQ, totRQ);

  return(0);
}
コード例 #15
0
ファイル: ifpsrv.c プロジェクト: 3van/sssd
int ifp_process_init(TALLOC_CTX *mem_ctx,
                     struct tevent_context *ev,
                     struct confdb_ctx *cdb)
{
    struct resp_ctx *rctx;
    struct sss_cmd_table *ifp_cmds;
    struct ifp_ctx *ifp_ctx;
    struct be_conn *iter;
    int ret;
    int max_retries;
    char *uid_str;
    char *attr_list_str;
    char *wildcard_limit_str;

    ifp_cmds = get_ifp_cmds();
    ret = sss_process_init(mem_ctx, ev, cdb,
                           ifp_cmds,
                           NULL, -1, NULL, -1,
                           CONFDB_IFP_CONF_ENTRY,
                           SSS_IFP_SBUS_SERVICE_NAME,
                           SSS_IFP_SBUS_SERVICE_VERSION,
                           &monitor_ifp_methods,
                           "InfoPipe",
                           &ifp_dp_methods.vtable,
                           &rctx);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "sss_process_init() failed\n");
        return ret;
    }

    ifp_ctx = talloc_zero(rctx, struct ifp_ctx);
    if (ifp_ctx == NULL) {
        DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing ifp_ctx\n");
        ret = ENOMEM;
        goto fail;
    }

    ifp_ctx->rctx = rctx;
    ifp_ctx->rctx->pvt_ctx = ifp_ctx;

    ret = sss_names_init_from_args(ifp_ctx,
                                   "(?P<name>[^@]+)@?(?P<domain>[^@]*$)",
                                   "%1$s@%2$s", &ifp_ctx->snctx);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing regex data\n");
        goto fail;
    }

    ret = confdb_get_string(ifp_ctx->rctx->cdb, ifp_ctx->rctx,
                            CONFDB_IFP_CONF_ENTRY, CONFDB_SERVICE_ALLOWED_UIDS,
                            DEFAULT_ALLOWED_UIDS, &uid_str);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "Failed to get allowed UIDs.\n");
        goto fail;
    }

    ret = csv_string_to_uid_array(ifp_ctx->rctx, uid_str, true,
                                  &ifp_ctx->rctx->allowed_uids_count,
                                  &ifp_ctx->rctx->allowed_uids);
    talloc_free(uid_str);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "Failed to set allowed UIDs.\n");
        goto fail;
    }

    ret = confdb_get_string(ifp_ctx->rctx->cdb, ifp_ctx->rctx,
                            CONFDB_IFP_CONF_ENTRY, CONFDB_IFP_USER_ATTR_LIST,
                            NULL, &attr_list_str);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE, "Failed to get user attribute list.\n");
        goto fail;
    }

    ifp_ctx->user_whitelist = ifp_parse_user_attr_list(ifp_ctx, attr_list_str);
    talloc_free(attr_list_str);
    if (ifp_ctx->user_whitelist == NULL) {
        DEBUG(SSSDBG_FATAL_FAILURE,
              "Failed to parse the allowed attribute list\n");
        goto fail;
    }

    /* Enable automatic reconnection to the Data Provider */
    ret = confdb_get_int(ifp_ctx->rctx->cdb,
                         CONFDB_IFP_CONF_ENTRY,
                         CONFDB_SERVICE_RECON_RETRIES,
                         3, &max_retries);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE,
              "Failed to set up automatic reconnection\n");
        goto fail;
    }

    /* A bit convoluted way until we have a confdb_get_uint32 */
    ret = confdb_get_string(ifp_ctx->rctx->cdb,
                            ifp_ctx->rctx,
                            CONFDB_IFP_CONF_ENTRY,
                            CONFDB_IFP_WILDCARD_LIMIT,
                            NULL, /* no limit by default */
                            &wildcard_limit_str);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE,
              "Failed to retrieve limit for a wildcard search\n");
        goto fail;
    }

    if (wildcard_limit_str) {
        ifp_ctx->wildcard_limit = strtouint32(wildcard_limit_str, NULL, 10);
        ret = errno;
        if (ret != EOK) {
            goto fail;
        }
    }

    for (iter = ifp_ctx->rctx->be_conns; iter; iter = iter->next) {
        sbus_reconnect_init(iter->conn, max_retries,
                            ifp_dp_reconnect_init, iter);
    }

    /* Connect to the D-BUS system bus and set up methods */
    ret = sysbus_init(ifp_ctx, ifp_ctx->rctx->ev,
                      IFACE_IFP,
                      ifp_ctx, &ifp_ctx->sysbus);
    if (ret == ERR_NO_SYSBUS) {
        DEBUG(SSSDBG_MINOR_FAILURE,
              "The system bus is not available..\n");
        /* Explicitly ignore, the D-Bus daemon will start us */
    } else if (ret != EOK) {
        DEBUG(SSSDBG_CRIT_FAILURE,
              "Failed to connect to the system message bus\n");
        talloc_free(ifp_ctx);
        return EIO;
    }

    ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
    if (ret != EOK) {
        DEBUG(SSSDBG_FATAL_FAILURE,
              "schedule_get_domains_tasks failed.\n");
        goto fail;
    }

    DEBUG(SSSDBG_TRACE_FUNC, "InfoPipe Initialization complete\n");
    return EOK;

fail:
    talloc_free(rctx);
    return ret;
}
コード例 #16
0
ファイル: mapMers.C プロジェクト: ondovb/canu
int
main(int argc, char **argv) {
  uint32    merSize    = 16;
  char     *merylFile  = 0L;
  char     *fastaFile  = 0L;
  bool      beVerbose  = false;
  uint32    loCount    = 0;
  uint32    hiCount    = ~uint32ZERO;
  uint32    operation  = OP_NONE;

  //  For OP_STATS

  uint32         Clen = 0;
  uint32         Cmax = 4 * 1024 * 1024;
  uint32        *C    = new uint32 [Cmax];

  int arg=1;
  while (arg < argc) {
    if        (strcmp(argv[arg], "-m") == 0) {
      merSize = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-mers") == 0) {
      merylFile = argv[++arg];

    } else if (strcmp(argv[arg], "-seq") == 0) {
      fastaFile = argv[++arg];

    } else if (strcmp(argv[arg], "-v") == 0) {
      beVerbose = true;

    } else if (strcmp(argv[arg], "-lo") == 0) {
      loCount = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-hi") == 0) {
      hiCount = strtouint32(argv[++arg]);

    } else if (strcmp(argv[arg], "-stats") == 0) {
      operation = OP_STATS;

    } else if (strcmp(argv[arg], "-regions") == 0) {
      operation = OP_REGIONS;

    } else if (strcmp(argv[arg], "-details") == 0) {
      operation = OP_DETAILS;

    } else {
      fprintf(stderr, "unknown option '%s'\n", argv[arg]);
    }
    arg++;
  }

  if ((operation == OP_NONE) || (merylFile == 0L) || (fastaFile == 0L)) {
    fprintf(stderr, "usage: %s [-stats | -regions | -details] -m mersize -mers mers -seq fasta > output\n", argv[0]);
    exit(1);
  }

#if 0
  existDB       *E = NULL;

  if (fileExists("junk.existDB")) {
    fprintf(stderr, "loading from junk.existDB\n");
    E = new existDB("junk.existDB");
    fprintf(stderr, "loaded\n");
  } else {
    exit(1);
    E = new existDB(merylFile, merSize, existDBcounts, loCount, hiCount);
    E->saveState("junk.existDB");
  }
#endif

  existDB  *E = new existDB(merylFile, merSize, existDBcounts, loCount, hiCount);
  seqCache *F = new seqCache(fastaFile);

  fprintf(stderr, "Begin.\n");


  for (uint32 Sid=0; Sid < F->getNumberOfSequences(); Sid++) {
    seqInCore  *S  = F->getSequenceInCore(Sid);
    merStream  *MS = new merStream(new kMerBuilder(merSize),
                                   new seqStream(S->sequence(), S->sequenceLength()),
                                   true, true);

    //  with counts, report mean, mode, median, min, max for each frag.
    if (operation == OP_STATS) {

      Clen = 0;

      while (MS->nextMer())
        C[Clen++] = E->count(MS->theFMer()) + E->count(MS->theRMer());

      uint64         mean     = uint64ZERO;
      uint64         min      = ~uint64ZERO;
      uint64         max      = uint64ZERO;
      uint64         hist[16]  = { 0 };

      //  Histogram values are powers of two, e.g., <=1, <=2, <=4, <=8, <=16, <=32, <=64, <=128, <=256, <=512, <=1024, <=4096, <=8192, <=328768

      for (uint32 i=0; i<Clen; i++) {
        mean += C[i];

        if (min > C[i])
          min = C[i];
        if (max < C[i])
          max = C[i];

        hist[ logBaseTwo64(C[i]) ]++;
      }

      if (Clen > 0) {
        mean /= Clen;

      } else {
        mean = uint64ZERO;
        min  = uint64ZERO;
        max  = uint64ZERO;
      }

      fprintf(stdout,
              "%s\t"
              uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"
              uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"
              uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\n",
              S->header(),
              mean, min, max,
              hist[ 0], hist[ 1], hist[ 2], hist[ 3], hist[ 4], hist[ 5], hist[ 6], hist[ 7],
              hist[ 8], hist[ 9], hist[10], hist[11], hist[12], hist[13], hist[14], hist[15]);
    }


    //  without counts, reports regions with mer coverage.
    //  Orientation tells us nothing, since the mers are probably canonical
    if (operation == OP_REGIONS) {
      uint64    beg = ~uint64ZERO;
      uint64    end = ~uint64ZERO;
      uint64    pos = ~uint64ZERO;

      uint64    numCovReg = 0;
      uint64    lenCovReg = 0;

      while (MS->nextMer()) {
        if (E->exists(MS->theFMer()) || E->exists(MS->theRMer())) {
          pos = MS->thePositionInSequence();

          if (beg == ~uint64ZERO)
            beg = end = pos;

          if (pos <= end + merSize) {
            end = pos;
          } else {
            fprintf(stdout, "%s\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\n", S->header(), beg, end+merSize, end+merSize - beg);
            numCovReg++;
            lenCovReg += end+merSize - beg;
            beg = end = pos;
          }
        } else {
          fprintf(stdout, "%s\t"uint64FMT"\tuncovered\n", S->header(), MS->thePositionInSequence());
        }
      }

      if (beg != ~uint64ZERO)
        fprintf(stdout, "%s\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\n", S->header(), beg, end+merSize, end+merSize - beg);

      fprintf(stderr, "numCovReg: "uint64FMT"\n", numCovReg);
      fprintf(stderr, "lenCovReg: "uint64FMT"\n", lenCovReg);
    }



    if (operation == OP_DETAILS) {
      char  merString[256];

      while (MS->nextMer()) {
        uint64 beg = MS->thePositionInSequence();
        uint64 end = beg + merSize;
        uint64 fnt = E->count(MS->theFMer());
        uint64 rnt = E->count(MS->theRMer());

        fprintf(stdout, "%s\t%s\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\t"uint64FMT"\n",
                S->header(),
                MS->theFMer().merToString(merString),
                beg,
                end,
                fnt,
                rnt,
                fnt + rnt);
      }
    }


    delete MS;
    delete S;
  }


  delete F;
  delete E;
}