示例#1
0
std::string
Individual::getChromosomeString (void) {
  std::string result;
  std::vector < bool > ch = getChromosome();
  for (bool alel : ch) {
    result.push_back ( alel?'1':'0' );
  }
  return result;
}
示例#2
0
std::vector < Individual >
Individual::cruzaAcentuada (Individual& spouse) {
  std::vector < Individual > result;
  std::vector < bool > parent1 = getChromosome();
  std::vector < bool > parent2 = spouse.getChromosome();
  size_t size = parent1.size();
  size_t genNumber = chromosome.size();
  std::vector < bool > child1_ch, child2_ch, child1_marks(size, false), child2_marks(size, false);
  bool cross = false;
  std::vector <bool>::iterator mark_it = crossPoints.begin();
  std::vector <bool>::iterator mark_spouse_it = spouse.crossPoints.begin();
  for( size_t i = 0; i < size; i++, mark_it++, mark_spouse_it++ ) {
    if (*mark_it || *mark_spouse_it) {
      cross = !cross;
    }
    if(!cross) {
      if(*mark_it) {
        child2_marks.at(i) = true;
      } if (*mark_spouse_it) {
        child1_marks.at(i) = true;
      }
      child1_ch.push_back( parent1.at(i) );
      child2_ch.push_back( parent2.at(i) );
    } else {
      if(*mark_it) {
        child1_marks.at(i) = true;
      } if (*mark_spouse_it) {
        child2_marks.at(i) = true;
      }
      child1_ch.push_back( parent2.at(i) );
      child2_ch.push_back( parent1.at(i) );
    }
  }
  Individual child1 (child1_ch,genNumber);
  Individual child2 (child2_ch,genNumber);
  child1.crossPoints = child1_marks;
  child2.crossPoints = child2_marks;
  result.push_back( child1 );
  result.push_back( child2 );
  return result;
}
示例#3
0
std::vector < Individual >
Individual::cruzaUnPunto (Individual& spouse, size_t p) {
  std::vector < Individual > result;
  std::vector < bool > parent1 = getChromosome();
  std::vector < bool > parent2 = spouse.getChromosome();
  std::vector < bool > child1, child2;
  size_t size = parent1.size();
  size_t genNumber = chromosome.size();
  for( size_t i = 0; i < size; i++ ) {
    if (i < p) {
      child1.push_back( parent1.at(i) );
      child2.push_back( parent2.at(i) );
    } else {
      child1.push_back( parent2.at(i) );
      child2.push_back( parent1.at(i) );
    }
  }
  result.push_back( Individual(child1,genNumber) );
  result.push_back( Individual(child2,genNumber) );
  return result;
}
示例#4
0
std::vector < Individual >
Individual::cruzaDosPuntos (Individual& spouse, size_t x, size_t y) {
  std::vector < Individual > result;
  std::vector < bool > parent1 = getChromosome();
  std::vector < bool > parent2 = spouse.getChromosome();
  std::vector < bool > child1, child2;
  size_t size = parent1.size();
  size_t genNumber = chromosome.size();
  size_t t = x;
  x = x<y?x:y;
  y = y<t?t:y;
  for( size_t i = 0; i < size; i++ ) {
    if (i < x || i >= y) {
      child1.push_back( parent1.at(i) );
      child2.push_back( parent2.at(i) );
    } else {
      child1.push_back( parent2.at(i) );
      child2.push_back( parent1.at(i) );
    }
  }
  result.push_back( Individual(child1,genNumber) );
  result.push_back( Individual(child2,genNumber) );
  return result;
}
示例#5
0
文件: ea.cpp 项目: veimox/locokit69
void Chromosome<T>::copyChromosome(std::vector<T>& chromosome)
{
    chromosome.clear();
    for (unsigned int gen = 0; gen < size; ++gen)
        chromosome.push_back(getChromosome()[gen]);
}
示例#6
0
inline bool GenabelSnp::operator < (const GenabelSnp& snp) const {
	int c1 = getChromosome();
	int c2 = snp.getChromosome();
	return c1 < c2 ? true : (  c1 > c2 ? false : getPosition() < snp.getPosition() );
}
示例#7
0
void PileupElementBaseQual::analyze()
{
    if(getRefPosition() != UNSET_POSITION && myIndex != -1)
    {
    	char tempCStr[11];
    	std::string tempStr;
    	tempStr.append(getChromosome());
    	tempStr.append("\t");
    	sprintf(tempCStr, "%d", getRefPosition()+1 );
    	tempStr.append(tempCStr);
    	tempStr.append("\t.\t");
    	tempStr.append(getRefAllele());
    	tempStr.append("\t.\t.\t.\t.\t");
         
        tempStr.append("N:BASE:MAPQ:BASEQ:STRAND:CYCLE:GL\t");
        
        sprintf(tempCStr, "%d", myIndex+1 );
    	tempStr.append(tempCStr);
    	tempStr.append(":");
        
        sprintf(tempCStr, "%c", myBases[0]);
        tempStr.append(tempCStr);
        for (int i=1; i<=myIndex; ++i)
        {
            sprintf(tempCStr, ",%c", myBases[i]);
            tempStr.append(tempCStr);
        }
        tempStr.append(":");	
		
        sprintf(tempCStr, "%d", myMapQualities[0]);
        tempStr.append(tempCStr);
        for (int i=1; i<=myIndex; ++i)
        {
            sprintf(tempCStr, ",%d", myMapQualities[i]);
            tempStr.append(tempCStr);
        }
        tempStr.append(":");

        sprintf(tempCStr, "%d", myQualities[0]);
        tempStr.append(tempCStr);    
        for (int i=1; i<=myIndex; ++i)
        {
            sprintf(tempCStr, ",%d", myQualities[i]);
            tempStr.append(tempCStr);
        }
        tempStr.append(":");
 
        sprintf(tempCStr, "%c", myStrands[0]);
        tempStr.append(tempCStr);
        for (int i=1; i<=myIndex; ++i)
        {
            sprintf(tempCStr, ",%c", myStrands[i]);
            tempStr.append(tempCStr);
        }
        tempStr.append(":");
 
        sprintf(tempCStr, "%d", myCycles[0]);
        tempStr.append(tempCStr); 
        for (int i=1; i<=myIndex; ++i)
        {
            sprintf(tempCStr, ",%d", myCycles[i]);
            tempStr.append(tempCStr);        	
        }
        tempStr.append(":");
         
        computeGLScores(myIndex, myGLScores, myBases, myQualities);
        
        sprintf(tempCStr, "%d", myGLScores[0]);
        tempStr.append(tempCStr);    
        for (int i=1; i<=9; ++i)
        {
            sprintf(tempCStr, ",%d", myGLScores[i]);
            tempStr.append(tempCStr);
        }
        
        tempStr.append("\n");  	
       	myVcfOutFile->ifwrite(tempStr.c_str(), tempStr.length());
    }
    
    //to ensure this does not print when reflushed
    myIndex=-1;
}
示例#8
0
// Add an entry to this pileup element.  
void PileupElementBaseQual::addEntry(SamRecord& record)
{
    // Call the base class:
    PileupElement::addEntry(record);

    if(myRefAllele.empty())
    {
    	genomeIndex_t markerIndex = (*myRefSeq).getGenomePosition(getChromosome(), static_cast<uint32_t>(getRefPosition()+1));
        myRefAllele = (*myRefSeq)[markerIndex];
    }

    // Increment the index
    ++myIndex;
    
    // if the index has gone beyond the allocated space, double the size.
    if(myIndex >= myAllocatedSize)
    {
        char* tempBuffer = (char*)realloc(myBases, myAllocatedSize * 2);
        if(tempBuffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myBases = tempBuffer;
        int8_t* tempInt8Buffer = (int8_t*)realloc(myMapQualities, myAllocatedSize * 2 * sizeof(int8_t));
        if(tempInt8Buffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myMapQualities = tempInt8Buffer; 
        tempInt8Buffer = (int8_t*)realloc(myQualities, myAllocatedSize * 2 * sizeof(int8_t));
        if(tempInt8Buffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myQualities = tempInt8Buffer;
        tempBuffer = (char*)realloc(myStrands, myAllocatedSize * 2);
        if(tempBuffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myStrands = tempBuffer;
        tempInt8Buffer = (int8_t*)realloc(myCycles, myAllocatedSize * 2 * sizeof(int8_t));
        if(tempInt8Buffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myCycles = tempInt8Buffer; 
        int16_t* tempInt16Buffer = (int16_t*)realloc(myGLScores, myAllocatedSize * 2 * sizeof(int16_t));
        if(tempInt8Buffer == NULL)
        {
            std::cerr << "Memory Allocation Failure\n";
            // TODO
            return;
        }
        myGLScores = tempInt16Buffer;
        myAllocatedSize = myAllocatedSize * 2;
    }

    Cigar* cigar = record.getCigarInfo();
    
    if(cigar == NULL)
    {
        throw std::runtime_error("Failed to retrieve cigar info from the record.");
    }

    int32_t readIndex = 
        cigar->getQueryIndex(getRefPosition(), record.get0BasedPosition());

    // If the readPosition is N/A, this is a deletion.
    if(readIndex != CigarRoller::INDEX_NA)
    {
        char base = record.getSequence(readIndex);
        int8_t mapQual = record.getMapQuality();
        //-33 to obtain the PHRED base quality
        char qual = record.getQuality(readIndex) - 33;
        if(qual == UNSET_QUAL)
        {
            qual = ' ';
        }
        char strand = (record.getFlag() & 0x0010) ? 'R' : 'F';
        int cycle = strand == 'F' ? readIndex + 1 : record.getReadLength() -  readIndex;
        myBases[myIndex] = base;
        myMapQualities[myIndex] = mapQual;
        myQualities[myIndex] = qual;
        myStrands[myIndex] = strand;
        myCycles[myIndex] = cycle;
    }
    else if(myAddDelAsBase)
    {
        int8_t mapQual = record.getMapQuality();
        char strand = (record.getFlag() & 0x0010) ? 'R' : 'F';
        myBases[myIndex] = '-';
        myMapQualities[myIndex] = mapQual;
        myQualities[myIndex] = -1;
        myStrands[myIndex] = strand;
        myCycles[myIndex] = -1;
    }
    else
    {
        // Do not add a deletion.
        // Did not add any entries, so decrement the index counter since the
        // index was not used.
        --myIndex;
    }
}