Esempio n. 1
0
void
GLScreenBuffer::DeprecatedReadback(SharedSurface_GL* src, gfxImageSurface* dest)
{
    MOZ_ASSERT(src && dest);
    MOZ_ASSERT(ToIntSize(dest->GetSize()) == src->Size());
    MOZ_ASSERT(dest->Format() == (src->HasAlpha() ? gfxImageFormat::ARGB32
                                                  : gfxImageFormat::RGB24));

    mGL->MakeCurrent();

    bool needsSwap = src != SharedSurf();
    if (needsSwap) {
        SharedSurf()->UnlockProd();
        src->LockProd();
    }

    ReadBuffer* buffer = CreateRead(src);
    MOZ_ASSERT(buffer);

    ScopedBindFramebuffer autoFB(mGL, buffer->FB());
    ReadPixelsIntoImageSurface(mGL, dest);

    delete buffer;

    if (needsSwap) {
        src->UnlockProd();
        SharedSurf()->LockProd();
    }
}
int main(int argc, char *argv[]){

  Read *Read = CreateRead(65536+GUARD, 65535+GUARD);
  int32_t seqSize = 0, x, n;
  uint64_t cutted = 0, totalReads = 0;

  if(argc < 2 || ArgBin(0, argv, argc, "-h") || ArgBin(0, argv, argc, "?")){
    PrintArgs(argv[0]);
    return EXIT_SUCCESS;
    }
  
  int k             = ArgNum(5,  argv, argc, "-k", 0, 9999999);
  int min_QS_window = ArgNum(25, argv, argc, "-w", 0, 9999999);
  int min_QS        = ArgNum(33, argv, argc, "-m", 0, 9999999);

  fprintf(stderr, "Minimum QS: %d\n", min_QS);
 
  uint32_t position = 0;
  while(GetRead(stdin, Read)){

    seqSize = strlen((char *) Read->bases) - 1;

    for(x = seqSize ; x >= 0 ; x--){
      if(x >= k){

        int tmp_QS = 0;
        for(n = 0 ; n < k ; ++n){
          tmp_QS += ((int) Read->scores[x - 1 - n]) - min_QS;
          }

        if(((double) tmp_QS / k) < (double) min_QS_window){
          ++cutted;
          position = x;
          break;
          }
        }
      }

    ++totalReads;

    if(x > seqSize - k) continue;

    // PRINT READ
    fprintf(stdout, "@");
    for(n = 0 ; n < strlen((char *) Read->header1) ; ++n)
      fprintf(stdout, "%c", Read->header1[n]);
    for(n = position ; n < seqSize ; ++n)
      fprintf(stdout, "%c", Read->bases[n]);
    fprintf(stdout, "\n+\n");
    for(n = position ; n < seqSize ; ++n)
      fprintf(stdout, "%c", Read->scores[n]);
    fprintf(stdout, "\n");
    }

  fprintf(stderr, "Total reads    : %"PRIu64"\n", totalReads);
  fprintf(stderr, "Trimmed reads  : %"PRIu64"\n", cutted);

  FreeRead(Read);
  return EXIT_SUCCESS;
  }
Esempio n. 3
0
File: QSMax.c Progetto: pratas/goose
int main(int argc, char *argv[]){

  Read *Read = CreateRead(65536+GUARD, 65535+GUARD);
  int32_t  seqSize = 0, x;
  uint64_t *QS = (uint64_t *) Calloc(65536, sizeof(uint64_t));
  
  if(ArgBin(0, argv, argc, "-h") || ArgBin(0, argv, argc, "?")){
    PrintArgs(argv[0]);
    return EXIT_SUCCESS;
    }

  while(GetRead(stdin, Read)){
    seqSize = strlen((char *) Read->bases) - 1;
    for(x = 0 ; x < seqSize ; ++x){
      int tmp_QS = (int) Read->scores[x];
      if(QS[x] < tmp_QS)
      QS[x] = tmp_QS;
      if(x == 65535){
        fprintf(stderr, "Error: read to long. Increase buffer!\n");
        exit(1);
        }
      }
    }

  int maxs = atoi(argv[argc-1]);

  for(x = 0 ; x < maxs ; ++x)
    fprintf(stdout, "%2d ", x+1);
  fprintf(stdout, "\n");
  for(x = 0 ; x < maxs ; ++x)
    fprintf(stdout, "--+");
  fprintf(stdout, "\n");
  for(x = 0 ; x < maxs ; ++x)
    fprintf(stdout, "%2d ", (int) QS[x]);
  fprintf(stdout, "\n");

  Free(QS, 0);
  FreeRead(Read);
  return EXIT_SUCCESS;
  }
Esempio n. 4
0
void
GLScreenBuffer::Attach(SharedSurface* surface, const gfx::IntSize& size)
{
    ScopedBindFramebuffer autoFB(mGL);

    SharedSurface_GL* surf = SharedSurface_GL::Cast(surface);
    if (mRead && SharedSurf())
        SharedSurf()->UnlockProd();

    surf->LockProd();

    if (mRead &&
        surf->AttachType() == SharedSurf()->AttachType() &&
        size == Size())
    {
        // Same size, same type, ready for reuse!
        mRead->Attach(surf);
    } else {
        // Else something changed, so resize:
        DrawBuffer* draw = CreateDraw(size);  // Can be null.
        ReadBuffer* read = CreateRead(surf);
        MOZ_ASSERT(read); // Should never fail if SwapProd succeeded.

        delete mDraw;
        delete mRead;

        mDraw = draw;
        mRead = read;
    }

    // Check that we're all set up.
    MOZ_ASSERT(SharedSurf() == surf);

    if (!PreserveBuffer()) {
        // DiscardFramebuffer here could help perf on some mobile platforms.
    }
}
Esempio n. 5
0
int main(int argc, char *argv[]){

  Read *Read = CreateRead(65536+GUARD, 65535+GUARD);
  uint32_t seqSize = 0, totalQS = 0, N = 0, x, n;
  uint64_t okReads = 0, totalReads = 0;

  if(ArgBin(0, argv, argc, "-h") || ArgBin(0, argv, argc, "?")){
    PrintArgs(argv[0]);
    return EXIT_SUCCESS;
    }
  
  int max_n         = ArgNum(0,  argv, argc, "-n", 0, 9999999);
  int k             = ArgNum(5,  argv, argc, "-k", 0, 9999999);
  int min_QS_window = ArgNum(25, argv, argc, "-w", 0, 9999999);
  int min_avg_qs    = ArgNum(25, argv, argc, "-a", 0, 9999999);
  int min_read_size = ArgNum(35, argv, argc, "-m", 0, 9999999);
 
  // LOAD PARAMETERS
 
  while(GetRead(stdin, Read)){

    seqSize = strlen((char *) Read->bases) - 1;
    totalQS = 0;
    N       = 0;

    for(x = 0 ; x < seqSize ; ++x){
      if(Read->bases[x] == 'N'){
        ++N;
        }
      totalQS += ((int) Read->scores[x]) - 33; // PHRED +33

      if(x < seqSize - k){
        int tmp_QS = 0;
        for(n = 0 ; n < k ; ++n)
          tmp_QS += ((int) Read->scores[x + n]) - 33;
        if(tmp_QS / k < min_QS_window)
          break;
        }
      }

    ++totalReads;

    // EVALUATE TO DISCARD:
    if(N > max_n)                        continue;
    if((totalQS / seqSize) < min_avg_qs) continue;
    if(x < min_read_size)                continue;


    // PRINT READ
    for(n = 0 ; n < strlen((char *) Read->header1) ; ++n)
      fprintf(stdout, "%c", Read->header1[n]);
    for(n = 0 ; n < x ; ++n)
      fprintf(stdout, "%c", Read->bases[n]);
    fprintf(stdout, "\n+\n");
    for(n = 0 ; n < x ; ++n)
      fprintf(stdout, "%c", Read->scores[n]);
    fprintf(stdout, "\n");

    ++okReads;
    }

  fprintf(stderr, "Total reads    : %"PRIu64"\n", totalReads);
  fprintf(stderr, "Filtered reads : %"PRIu64"\n", totalReads-okReads);

  FreeRead(Read);
  return EXIT_SUCCESS;
  }
Esempio n. 6
0
/*
 * This application filters the FASTQ reads with the length higher than the value defined
 */
int main(int argc, char *argv[])
{
  Read *Read = CreateRead(65536+GUARD, 65535+GUARD);
  uint32_t sequenceSize = 0, index;
  uint64_t okReads = 0, totalReads = 0;
  int min_read_size = 0;

  char *programName = argv[0];
  struct argparse_option options[] = {
        OPT_HELP(),
        OPT_GROUP("Basic options"),
        OPT_INTEGER('s', "size", &min_read_size, "The maximum read length"),
        OPT_BUFF('<', "input.fastq", "Input FASTQ file format (stdin)"),
        OPT_BUFF('>', "output", "Output read information (stdout)"),
        OPT_END(),
  };
  struct argparse argparse;

  char usage[250] = "\nExample: "; 
  strcat(usage, programName);
  strcat(usage, " < input.fastq > output\n"
    "\nOutput example :\n"
    "<FASTQ non-filtered reads>\n"
    "Total reads    : value\n"
    "Filtered reads : value\n");

  argparse_init(&argparse, options, NULL, programName, 0);
  argparse_describe(&argparse, "\nIt filters the FASTQ reads with the length higher than the value defined. "
    "If present, it will erase the second header (after +).", usage);
  argc = argparse_parse(&argparse, argc, argv);

  if(argc != 0)
    argparse_help_cb(&argparse, options);

  if(min_read_size <= 0 || min_read_size > UINT_MAX)
  {
    fprintf(stderr, "\nERROR: The size value most be a positive unsigned int!\n");
    argparse_help_cb(&argparse, options);
    exit(1);
  }
 
  while(GetRead(stdin, Read))
  {
    sequenceSize = strlen((char *) Read->bases) - 1;
    ++totalReads;

    // Evaluate to discard
    if(sequenceSize > min_read_size) continue;

    // Print the read
    fprintf(stdout, "@");
    for(index = 0 ; index < strlen((char *) Read->header1) ; ++index)
      fprintf(stdout, "%c", Read->header1[index]);
    for(index = 0 ; index < sequenceSize ; ++index)
      fprintf(stdout, "%c", Read->bases[index]);
    fprintf(stdout, "\n+\n");
    for(index = 0 ; index < sequenceSize ; ++index)
      fprintf(stdout, "%c", Read->scores[index]);
    fprintf(stdout, "\n");

    ++okReads;
  }

  fprintf(stderr, "Total reads    : %"PRIu64"\n", totalReads);
  fprintf(stderr, "Filtered reads : %"PRIu64"\n", totalReads-okReads);

  FreeRead(Read);
  return EXIT_SUCCESS;
}
Esempio n. 7
0
/*
 * This application discards the FASTQ reads with the minimum number of \"N\" symbols. 
 * If present, it will erase the second header (after +).
 */
int main(int argc, char *argv[])
{
  Read *Read = CreateRead(65536+GUARD, 65535+GUARD);
  uint32_t sequenceSize = 0, N_counter = 0, globalIndex, index;
  uint64_t okReads = 0, totalReads = 0;
  int max_n_read = 0;

  char *programName = argv[0];
  struct argparse_option options[] = {
        OPT_HELP(),
        OPT_GROUP("Basic options"),
        OPT_INTEGER('m', "max", &max_n_read, "The maximum of of \"N\" symbols in the read"),
        OPT_BUFF('<', "input.fastq", "Input FASTQ file format (stdin)"),
        OPT_BUFF('>', "output", "Output read information (stdout)"),
        OPT_END(),
  };
  struct argparse argparse;

  char usage[250] = "\nExample: "; 
  strcat(usage, programName);
  strcat(usage, " < input.fastq > output\n"
    "\nOutput example :\n"
    "<FASTQ non-filtered reads>\n"
    "Total reads    : value\n"
    "Filtered reads : value\n");

  argparse_init(&argparse, options, NULL, programName, 0);
  argparse_describe(&argparse, "\nIt discards the FASTQ reads with the minimum number of \"N\" symbols."
    "If present, it will erase the second header (after +).", usage);
  argc = argparse_parse(&argparse, argc, argv);

  if(argc != 0)
    argparse_help_cb(&argparse, options);

  if(max_n_read <= 0 || max_n_read > UINT_MAX)
  {
    fprintf(stderr, "\nERROR: The number of \"N\" symbols most be a positive unsigned int!\n");
    argparse_help_cb(&argparse, options);
    exit(1);
  }
 
  // LOAD PARAMETERS
  while(GetRead(stdin, Read))
  {
    sequenceSize = strlen((char *) Read->bases) - 1;
    N_counter = 0;
    for(globalIndex = 0 ; globalIndex < sequenceSize ; ++globalIndex)
      if(Read->bases[globalIndex] == 'N')
        ++N_counter;

    ++totalReads;

    // Evaluate to discard
    if(N_counter > max_n_read) continue;

    // Print read
    fprintf(stdout, "@");
    for(index = 0 ; index < strlen((char *) Read->header1) ; ++index)
      fprintf(stdout, "%c", Read->header1[index]);
    for(index = 0 ; index < globalIndex ; ++index)
      fprintf(stdout, "%c", Read->bases[index]);
    fprintf(stdout, "\n+\n");
    for(index = 0 ; index < globalIndex ; ++index)
      fprintf(stdout, "%c", Read->scores[index]);
    fprintf(stdout, "\n");

    ++okReads;
  }

  fprintf(stderr, "Total reads    : %"PRIu64"\n", totalReads);
  fprintf(stderr, "Filtered reads : %"PRIu64"\n", totalReads-okReads);

  FreeRead(Read);
  return EXIT_SUCCESS;
}