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


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

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


在下文中一共展示了StringArray::Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: printArrayDoubleJoin

void VcfHelper::printArrayDoubleJoin(IFILE oFile, const StringArray& arr1, const StringArray& arr2, const char* sep1, const char* sep2, const char* empty) {
  int len1 = arr1.Length();
  int len2 = arr2.Length();

  if ( len1 == len2 ) {
    printArrayDoubleJoin(oFile, arr1, arr2, sep1, sep2, empty, 0, len1);
  }
  else {
    throw VcfFileException("Inconsistency between arr1.Length() == %d and arr2.Length() == %d", len1, len2);
  }
}
开发者ID:aminzia,项目名称:statgen,代码行数:11,代码来源:VcfFile.cpp

示例3: addLineFromVcf

void GroupFromAnnotation::addLineFromVcf( String & buffer )
{
// sample:
// ANNO=Nonsynonymous:ASB16;
// ANNOFULL=ASB16/NM_080863:+:Nonsynonymous(CCC/Pro/P->ACC/Thr/T:Base1310/1362:Codon437/454:Exon5/5):Exon
//	|C17orf65/NM_178542:-:Intron

	StringArray vfield;
	vfield.AddTokens(buffer, "\t");
	if ( vfield.Length() < 8 )
		error("Annotation vcf only has %d columns!\n", vfield.Length());
	StringArray info_semicolon;
	info_semicolon.AddTokens( vfield[7],";" );
	
// find ANNOFULL first
	int annofull_index = -1;
	for( int i=0; i<info_semicolon.Length(); i++ ) {
		String iheader = info_semicolon[i].SubStr(0,8);
		if (iheader == "ANNOFULL") {
			annofull_index = i;
			break;
		}
	}
	if (annofull_index == -1) {
		printf("warning: no ANNOFULL field at chr%s:%s. Variant won't included in groups!\n", info_semicolon[0].c_str(), info_semicolon[1].c_str());
		return;
	}

// remove ANNOFULL=
	String anno_full_str = info_semicolon[annofull_index].SubStr(9);

// check each alternative field
	StringArray alts;
	alts.AddTokens( anno_full_str, "|" );
	for( int a=0; a<alts.Length(); a++ ) {
		StringArray sub;
		sub.AddTokens( alts[a], ":/=");
		if (func_upper.Length() != 0) { // match before add
			for(int f =0;f<func_upper.Length();f++) {
				bool pattern_match = checkPatternMatch( sub, func_upper[f] );
				if ( pattern_match ) {
					addGeneFromVcf( vfield, sub[0] );
					break;
				}
			}
		}
		else { // no pattern to match: check if intergenic first
			String upper_name = sub[0].ToUpper();
			if ( !upper_name.SlowFind( "INTERGENIC" ) )
				addGeneFromVcf( vfield, sub[0] );
		}
	}	
}
开发者ID:traxexx,项目名称:Raremetal,代码行数:53,代码来源:GroupFromAnnotation.cpp

示例4: StringToArray

void StringToArray(const String & input, IntArray & values, int desired)
   {
   StringArray tokens;
   tokens.AddTokens(input, ',');

   values.Dimension(desired);
   values.Zero();

   if (tokens.Length())
      for (int i = 0; i < desired; i++)
         values[i] = tokens[i % tokens.Length()].AsInteger();
   }
开发者ID:aminzia,项目名称:statgen,代码行数:12,代码来源:Main.cpp

示例5: LoadRegionList

void GenomeRegionSeqStats::LoadRegionList(String &inputList)
{
  FILE *in = fopen(inputList.c_str(), "r");
  if(in==NULL) error("Open region input file %s failed!\n", inputList.c_str());
  StringArray tokens;
  String buffer;
  while(!feof(in))
    {
      buffer.ReadLine(in);
      if (buffer.IsEmpty() || buffer[0] == '#') continue;
      tokens.ReplaceTokens(buffer);
      if(tokens.Length()<3)
	error("Too few columns: %s\n", buffer.c_str());
      
      String CSE = tokens[0]+":"+tokens[1]+":"+tokens[2];
      std::pair<int, int> start_end;
      start_end.first = tokens[1].AsInteger();
      start_end.second = tokens[2].AsInteger();
      if(start_end.first>=start_end.second) // positions are 0-based. Otherwise == is valid
      	error("Region end is equal or smaller than the start: %s!\n", buffer.c_str());      
      genomeRegions_lines[tokens[0]].push_back(buffer);
      genomeRegions[tokens[0]].push_back(start_end);
      genomeRegions_currentIndex[tokens[0]] = 0; 

      if(tokens.Length()>3) {
	groupStats[tokens[3]].segCount++;
	groupStats[tokens[3]].totalLen += (start_end.second - start_end.first);
	genomeRegionGroups[CSE].push_back(tokens[3]);
      }
    }
  
  fclose(in);
  
  // Chromosome info
  contigs.clear();
  std::map<String, vector<std::pair<int, int> > >::iterator p;
  for(p=genomeRegions.begin(); p!=genomeRegions.end(); p++)
    {
      contigs.push_back(p->first);
      for(unsigned int i=1; i<genomeRegions[p->first].size(); i++)
	if(genomeRegions[p->first][i].first<genomeRegions[p->first][i-1].first)
	  error("Input coordinates are not in order: %s %d %d!\n", p->first.c_str(),genomeRegions[p->first][i].first,genomeRegions[p->first][i].second);
    }
  // Group info such as gene names
  groups.clear();
  std::map<String, Stats>::iterator p2;
  for(p2=groupStats.begin(); p2!=groupStats.end(); p2++)
    groups.push_back(p2->first);
}
开发者ID:aminzia,项目名称:statgen,代码行数:49,代码来源:GenomeRegionSeqStats.cpp

示例6: 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

示例7: 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

示例8: printArrayJoin

void VcfHelper::printArrayJoin(IFILE oFile, const StringArray& arr, const char* sep, const char* empty) {
  int len = arr.Length();
  if ( len == 0 ) {
    ifprintf(oFile,"%s",empty);
  }
  else if ( len == 1 ) {
    ifprintf(oFile,"%s",arr[0].c_str());
  }
  else {
    printArrayJoin(oFile,arr,sep,empty,0,len);
  }
}
开发者ID:aminzia,项目名称:statgen,代码行数:12,代码来源:VcfFile.cpp

示例9: ReadCrossoverRates

bool MarkovParameters::ReadCrossoverRates(const char * filename)
   {
   StringArray tokens;
   StringArray rec;
   rec.Read(filename);

   // Load estimated per marker error rates
   if (rec.Length() == markers)
      {
      printf("  Updating error rates using data in %s ...\n", (const char *) filename);
      for (int i = 0; i < markers; i++)
         {
         tokens.ReplaceTokens(rec[i+1]);

         if (tokens.Length() >= 2) R[i] = tokens[1].AsDouble();
         }

      return true;
      }

   return false;
   }
开发者ID:cfuchsberger,项目名称:minimac,代码行数:22,代码来源:MarkovParameters.cpp

示例10: checkPatternMatch

bool GroupFromAnnotation::checkPatternMatch( StringArray & sub, String & func )
{
	int result = -1;
	for( int i=0; i<sub.Length(); i++ ) {
		if ( sub[i].Length() < func.Length() )
			continue;
		String str = sub[i];
		String upper_sub = str.ToUpper();
		result = upper_sub.SlowFind( func );
		if ( result == 0 )
			break;
	}
	if ( result == 0 )
		return 1;
	else
		return 0;
}
开发者ID:traxexx,项目名称:Raremetal,代码行数:17,代码来源:GroupFromAnnotation.cpp

示例11: setFields

// Set the fields from the passed in line.
// Return true if successfully set.
bool SamHeaderRecord::setFields(const StringArray& tokens)
{
    bool status = true;

    // Loop through the tags for this type.
    // The tags start in column 1 since column 0 contains the type.
    for(int columnIndex = 1; columnIndex < tokens.Length(); columnIndex++)
    {
        // Validate that the tag is at least 3 characters. Two for the token,
        // one for the ':'.
        if((tokens[columnIndex].Length() < 3) ||
                (tokens[columnIndex][2] != ':'))
        {
            // Continue to the next tag, this one is too small/invalid.
            status = false;
            std::cerr << "ERROR: Poorly formatted tag in header: "
                      << tokens[columnIndex] << std::endl;
            continue;
        }

        // Get the tag from the token.
        char tag[3];
        tag[0] = tokens[columnIndex][0];
        tag[1] = tokens[columnIndex][1];
        tag[2] = 0;

        // The tag value is the rest of the substring.
        String tagValue = (tokens[columnIndex]).SubStr(3);

        // Set the tag.
        status &= setTag(tag, tagValue.c_str());
    }

    status &= isValid();

    return(status);
}
开发者ID:luyi0629,项目名称:Minimac3,代码行数:39,代码来源:SamHeaderRecord.cpp

示例12: execute

int VcfMac::execute(int argc, char **argv)
{
    String inputVcf = "";
    int minAC = -1;
    String sampleSubset = "";
    String filterList = "";
    bool params = false;

    IntervalTree<int> regions;
    std::vector<int> intersection;
    
    // Read in the parameters.    
    ParameterList inputParameters;
    BEGIN_LONG_PARAMETERS(longParameterList)
        LONG_PARAMETER_GROUP("Required Parameters")
        LONG_STRINGPARAMETER("in", &inputVcf)
        LONG_PARAMETER_GROUP("Optional Parameters")
        LONG_STRINGPARAMETER("sampleSubset", &sampleSubset)
        LONG_INTPARAMETER("minAC", &minAC)
        LONG_STRINGPARAMETER("filterList", &filterList)
        LONG_PARAMETER("params", &params)
        LONG_PHONEHOME(VERSION)
        END_LONG_PARAMETERS();
   
    inputParameters.Add(new LongParameters ("Input Parameters", 
                                            longParameterList));
    
    inputParameters.Read(argc-1, &(argv[1]));
    
    // Check that all files were specified.
    if(inputVcf == "")
    {
        usage();
        inputParameters.Status();
        std::cerr << "Missing \"--in\", a required parameter.\n\n";
        return(-1);
    }

    if(params)
    {
        inputParameters.Status();
    }

    // Open the two input files.
    VcfFileReader inFile;
    VcfHeader header;
    VcfRecord record;

    // Open the file
    if(sampleSubset.IsEmpty())
    {
        inFile.open(inputVcf, header);        
    }
    else
    {
        inFile.open(inputVcf, header, sampleSubset, NULL, NULL);
    }
    
    // Add the discard rule for minor allele count.
    if(minAC >= 0)
    {
        inFile.addDiscardMinMinorAlleleCount(minAC, NULL);
    }
    
    if(!filterList.IsEmpty())
    {
        // Open the filter list.
        IFILE regionFile = ifopen(filterList, "r");
        String regionLine;
        StringArray regionColumn;
        int start;
        int end;
        int intervalVal = 1;
        if(regionFile == NULL)
        {
            std::cerr << "Failed to open " << filterList 
                      << ", so keeping all positions\n";
            filterList.Clear();
        }
        else
        {
            while( regionFile->isOpen() && !regionFile->ifeof())
            {
                // Read the next interval
                regionLine.Clear();
                regionLine.ReadLine(regionFile);
                if(regionLine.IsEmpty())
                {
                    // Nothing on this line, continue to the next.
                    continue;
                }
                regionColumn.ReplaceColumns(regionLine, ' ');
                if(regionColumn.Length() != 2)
                {
                    std::cerr << "Improperly formatted region line: " 
                              << regionLine << "; skipping to the next line.\n";
                    continue;
                }
                // Convert the columns to integers.
                if(!regionColumn[0].AsInteger(start))
//.........这里部分代码省略.........
开发者ID:statgen,项目名称:vcfUtil,代码行数:101,代码来源:VcfMac.cpp

示例13: CalcRegionStats

void GenomeRegionSeqStats::CalcRegionStats(StringArray &bamFiles)
{
 for(int i=0; i<bamFiles.Length(); i++) 
   CalcRegionStats(bamFiles[i]);
}
开发者ID:aminzia,项目名称:statgen,代码行数:5,代码来源:GenomeRegionSeqStats.cpp

示例14: CalcClusters

void GenomeRegionSeqStats::CalcClusters(StringArray &bamFiles, int minMapQuality)
{
 for(int i=0; i<bamFiles.Length(); i++) 
   CalcClusters(bamFiles[i], minMapQuality);
}
开发者ID:aminzia,项目名称:statgen,代码行数:5,代码来源:GenomeRegionSeqStats.cpp

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