当前位置: 首页>>代码示例>>C++>>正文


C++ StringArray::Clear方法代码示例

本文整理汇总了C++中StringArray::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ StringArray::Clear方法的具体用法?C++ StringArray::Clear怎么用?C++ StringArray::Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringArray的用法示例。


在下文中一共展示了StringArray::Clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadMatrix

int loadMatrix(Matrix& a, String& fileName) {
  a.Zero();

  IFILE ifile(fileName.c_str(), "r");
  String line;
  StringArray array;
  int lineNo = 0;
  while (!ifeof(ifile)) {
    line.ReadLine(ifile);
    lineNo++;
    if (line.Length() == 0) continue;
    array.Clear();
    array.AddTokens(line);
    if (a.cols != 0 && a.cols != array.Length() && line.Length() > 0) {
      fprintf(stderr, "Wrong column size at line %d!\n", lineNo);
      array.Print();
      line.Write(stdout);
      return -1;
    } else {
      a.GrowTo(a.rows, array.Length());
    }
    if (a.rows < lineNo) {
      a.GrowTo(a.rows + 1, a.cols);
    }
    for (int i = 0; i < array.Length(); i++) {
      a[lineNo - 1][i] = atol(array[i]);
    }
  }

  // a.Print(stdout);
  return 0;
};
开发者ID:gpcr,项目名称:rvtests,代码行数:32,代码来源:Main.cpp

示例2: loadVector

int loadVector(Vector& a, String& fileName) {
  a.Zero();

  IFILE ifile(fileName.c_str(), "r");
  String line;
  StringArray array;
  int lineNo = 0;
  while (!ifeof(ifile)) {
    line.ReadLine(ifile);
    lineNo++;
    if (line.Length() == 0) continue;
    array.Clear();
    array.AddTokens(line);
    if (array.Length() > 1 && line.Length() > 0) {
      fprintf(stderr, "Warning: column size at line %d!\n", lineNo);
      array.Print();
      line.Write(stdout);
      return -1;
    }
    if (a.dim < lineNo) {
      a.GrowTo(a.dim + 1);
    }
    a[lineNo - 1] = atol(array[0]);
  }

  // a.Print(stdout);

  return 0;
};
开发者ID:gpcr,项目名称:rvtests,代码行数:29,代码来源:Main.cpp

示例3: LoadRegions

void GCContent::LoadRegions(String & regionsFile, GenomeSequence &genome, bool invertRegion)
{
    if(regionsFile.Length()==0) return;
    if(genome.sequenceLength()==0) error("No reference genome loaded!\n");

    IFILE fhRegions;
    fhRegions = ifopen(regionsFile.c_str(),"r");
    if(fhRegions==NULL)
        error("Open regions file %s failed!\n", regionsFile.c_str());

    regionIndicator.resize(genome.sequenceLength());

    StringArray tokens;
    String buffer;
    int len;

    fprintf(stderr, "Loading region list...");

    while (!ifeof(fhRegions)){
        buffer.ReadLine(fhRegions);
        if (buffer.IsEmpty() || buffer[0] == '#') continue;

        tokens.AddTokens(buffer, WHITESPACE);
        if(tokens.Length() < 3) continue;

        genomeIndex_t startGenomeIndex = 0;
        int chromosomeIndex = tokens[1].AsInteger();

        // use chromosome name (token[0]) and position (token[1]) to query genome index.
        startGenomeIndex = genome.getGenomePosition(tokens[0].c_str(), chromosomeIndex);

        if(startGenomeIndex >= regionIndicator.size() ) {
            //fprintf(stderr, "WARNING: region list section %s position %u is not found in the reference and skipped...\n", tokens[0].c_str(), chromosomeIndex);
            continue;
        }

        len = tokens[2].AsInteger() - tokens[1].AsInteger() + 1;
        for(uint32_t i=startGenomeIndex; i<startGenomeIndex+len; i++)
            regionIndicator[i] = true;

        tokens.Clear();
        buffer.Clear();
    }

    if (invertRegion) {
        fprintf(stderr, " invert region...");
        for (uint32_t i = 0; i < regionIndicator.size(); i++) {
            regionIndicator[i] = !regionIndicator[i];
        }
    }

    ifclose(fhRegions);
    fprintf(stderr, "DONE!\n");
}
开发者ID:BioInfoTools,项目名称:qplot,代码行数:54,代码来源:GCContent.cpp

示例4: execute


//.........这里部分代码省略.........
            StringArray tokens;
            String buffer;
            int position = 0;
            int refID = 0;

            // Loop til the end of the file.
            while (!ifeof(fdbSnp))
            {
                // Read the next line.
                buffer.ReadLine(fdbSnp);
                // If it does not have at least 2 columns, 
                // continue to the next line.
                if (buffer.IsEmpty() || buffer[0] == '#') continue;
                tokens.AddTokens(buffer);
                if(tokens.Length() < 2) continue;

                if(!tokens[1].AsInteger(position))
                {
                    std::cerr << "Improperly formatted region line, start position "
                              << "(2nd column) is not an integer: "
                              << tokens[1]
                              << "; Skipping to the next line.\n";         
                    continue;
                }

                // Look up the reference name.
                refID = samHeader.getReferenceID(tokens[0]);
                if(refID != SamReferenceInfo::NO_REF_ID)
                {
                    // Reference id was found, so add it to the dbsnp
                    dbsnpListPtr->addPosition(refID, position);
                }
        
                tokens.Clear();
                buffer.Clear();
            }
        }
        ifclose(fdbSnp);
    }

    // Read the sam records.
    SamRecord samRecord;

    int numReads = 0;

    //////////////////////
    // Setup in case doing a quality count.
    // Quality histogram.
    const int MAX_QUAL = 126;
    const int START_QUAL = 33;
    uint64_t qualCount[MAX_QUAL+1];
    for(int i = 0; i <= MAX_QUAL; i++)
    {
        qualCount[i] = 0;
    }
    
    const int START_PHRED = 0;
    const int PHRED_DIFF = START_QUAL - START_PHRED;
    const int MAX_PHRED = MAX_QUAL - PHRED_DIFF;
    uint64_t phredCount[MAX_PHRED+1];
    for(int i = 0; i <= MAX_PHRED; i++)
    {
        phredCount[i] = 0;
    }
    
    int refPos = 0;
开发者ID:BioScripts,项目名称:bamUtil,代码行数:67,代码来源:Stats.cpp

示例5: ReadModelsFromFile

bool RegressionAnalysis::ReadModelsFromFile()
   {
   StringArray models;
   models.Read(modelsFile);

   if (models.Length() == 0)
      return false;

   regress = new FancyRegression[models.Length()];

   printf("Retrieving analysis models from file [%s]...\n",
          (const char *) modelsFile);

   modelCount = 0;

   StringArray tokens;
   for (int i = 0, line = 0; i < models.Length(); i++)
      {
      models[i].Trim();

      // Skip comments
      if (models[i][0] == '#') continue;

      // Divide each line into tokens
      tokens.Clear();
      tokens.AddTokens(models[i]);

      // Skip blank lines
      if (tokens.Length() == 0) continue;

      // Print message for tracing...
      printf("   Input: %s\n", (const char *) models[i], line++);

      // Need a minimum of four tokens per line
      if (tokens.Length() < 4)
         {
         printf(" Skipped: Trait name, mean, variance and heritability required.\n");
         continue;
         }

      regress[modelCount].trait = ped.LookupTrait(tokens[0]);

      if (regress[modelCount].trait < 0)
         {
         printf(line == 1 ? " Skipped: Appears to be a header line\n" :
                            " Skipped: Trait %s not listed in the data file\n",
                            (const char *) tokens[0]);
         continue;
         }

      // First check that mean, variance and heritability are valid numbers
      bool fail = false;
      for (int j = 1; j <= 3; j++)
         {
         char * ptr = NULL;
         strtod(tokens[j], &ptr);
         fail |= ptr[0] != 0;
         }

      // If one of the values is not a valid number, skip
      if (fail)
         {
         printf(line == 1 ? " Skipped: Appears to be a header line\n" :
                            " Skipped: Invalid numeric format\n");
         continue;
         }

      regress[modelCount].mean = tokens[1];
      regress[modelCount].variance = tokens[2];
      regress[modelCount].heritability = tokens[3];

      if (tokens.Length() > 4)
         {
         regress[modelCount].label = tokens[4];

         for (int j = 5; j < tokens.Length(); j++)
            {
            regress[modelCount].label += " ";
            regress[modelCount].label += tokens[j];
            }
         }
      else
         regress[modelCount].label.printf("Model %d", modelCount + 1);

      regress[modelCount].shortLabel = regress[modelCount].label;
      regress[modelCount].testRetestCorrel = testRetestCorrel;
      regress[modelCount].bounded = !unrestricted;

      printf("        Model loaded and labelled %s\n", (const char *) regress[modelCount].label);

      modelCount++;
      }

   if (modelCount == 0)
      {
      printf("No valid models, default model will be used\n\n");
      return false;
      }

   printf("Table processed. %d models recognized\n\n", modelCount);
//.........这里部分代码省略.........
开发者ID:hilarymartin,项目名称:MAE_project,代码行数:101,代码来源:RegressAnalysis.cpp

示例6: GetGroupFromFile

void GroupFromAnnotation::GetGroupFromFile(FILE * log)
{
   //Fill in annoGroups.
   StringArray tmp;
   FILE * file = fopen(groupFile,"r");
   if(file==NULL)
   {
      printf("ERROR! Cannot open group file %s.\n",groupFile.c_str());
      error("ERROR! Cannot open group file %s.\n",groupFile.c_str());
   }
   String buffer;
   int line = 0;
   while (!feof(file))
   {
      buffer.ReadLine(file);
      tmp.Clear();
      tmp.AddTokens(buffer, SEPARATORS);
      if(tmp.Length()==0)
	 continue;
      annoGroups.Push(tmp[0]);
      chrom.Push(tmp[1]);
      line++;
   }
   fclose(file);

   //Fill in SNPlist.
   SNPlist = new StringArray [line];
   SNPNoAllele = new StringArray [line];
   FILE * samefile = fopen(groupFile,"r");
   line = 0;
   Vector pos;
   while (!feof(samefile))
   {
      buffer.ReadLine(samefile);
      tmp.Clear();
      pos.Clear();
      tmp.AddTokens(buffer, "\t ");
      SNPlist[line].Dimension(0);
      SNPNoAllele[line].Dimension(0);
      for(int i=1;i<tmp.Length();i++)
      {
	 SNPlist[line].Push(tmp[i]);
	 StringArray sub;
	 sub.Clear();
	 sub.AddTokens(tmp[i],":_/");
	 if(sub.Length()!=4)
	 {
	    printf("Warning: group %s has a variant %s that has invalid format. The correct format should be chr:pos:allele1:allele2.\n",tmp[0].c_str(),tmp[i].c_str());
	    fprintf(log,"Warning: group %s has a variant %s that has invalid format. The correct format should be chr:pos:allele1:allele2.\n",tmp[0].c_str(),tmp[i].c_str());
	    continue;
	 }
	 pos.Push(sub[1].AsInteger());
	 SNPNoAllele[line].Push(sub[0] + ":" + sub[1]);
      }
      //sort SNPlist[line] and SNPNoAllele[line]
      if(SNPlist[line].Length()>1)
      {
	 Vector sorted_pos,order;
	 sorted_pos.Copy(pos);
	 sorted_pos.Sort();
	 order.Dimension(pos.Length());
	 for(int i=0;i<sorted_pos.Length();i++)
	 {
	    for(int j=0;j<pos.Length();j++)
	    {
	       if(sorted_pos[i]==pos[j])
	       {
		  order[i]=j; 
		  break;
	       }
	    }
	 }

	 StringArray cp_SNPlist,cp_SNPNoAllele;
	 cp_SNPlist.Dimension(SNPlist[line].Length());
	 cp_SNPNoAllele.Dimension(SNPNoAllele[line].Length());
	 for(int l=0;l<SNPlist[line].Length();l++)
	 {
	    cp_SNPlist[l] = SNPlist[line][l];
	    cp_SNPNoAllele[l] = SNPNoAllele[line][l];
	 }
	 for(int i=0;i<order.Length();i++)
	 {
	    SNPlist[line][i] = cp_SNPlist[order[i]];
	    //printf("%s\t",SNPlist[line][i].c_str());
	    SNPNoAllele[line][i] = cp_SNPNoAllele[order[i]] ;
	 }
	 //printf("\n");
      }
      line++;
   }
   fclose(samefile);
}
开发者ID:traxexx,项目名称:Raremetal,代码行数:93,代码来源:GroupFromAnnotation.cpp


注:本文中的StringArray::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。