Пример #1
0
void Liftover::liftInterval()
{  
  PositionMap posCacheMap;
  _colIt = _srcSequence->getColumnIterator(&_tgtSet, 0, _inStart, _inEnd - 1);
  while (true) 
  {
    const ColumnMap* cMap = _colIt->getColumnMap();
    for (ColumnMap::const_iterator i = cMap->begin(); i != cMap->end(); ++i)
    {
      if (i->first->getGenome() == _tgtGenome)
      {
        const DNASet* dSet = i->second;
        const Sequence* seq = i->first;
        // if we're not adding the column, don't bother keeping track
        hal_size_t paralogyFactor = _addDupeColumn ? dSet->size() : 0;
        SeqIndex seqIdx(seq, paralogyFactor);
        for (DNASet::const_iterator j = dSet->begin(); j != dSet->end(); ++j)
        {
          pair<PositionMap::iterator, bool> res =
             posCacheMap.insert(pair<SeqIndex, PositionCache*>(seqIdx, NULL));
          if (res.second == true)
          {
            res.first->second = new PositionCache();
          }
          res.first->second->insert((*j)->getArrayIndex());
        }
      }
    }
    if (_colIt->lastColumn() == true)
    {
      break;
    }
    _colIt->toRight();
  } 

  PositionMap::iterator pcmIt;
  for (pcmIt = posCacheMap.begin(); pcmIt != posCacheMap.end(); ++pcmIt)
  {
    const Sequence* seq = pcmIt->first.first;
    _outParalogy = pcmIt->first.second;
    hal_size_t seqStart = seq->getStartPosition();
    PositionCache* posCache = pcmIt->second;
    const IntervalSet* iSet = posCache->getIntervalSet();
    _outName = seq->getName();
    for (IntervalSet::const_iterator k = iSet->begin(); k != iSet->end(); ++k)
    {
      _outStart = k->second - seqStart;
      _outEnd = k->first + 1 - seqStart;
      writeBedLine();
    }
    delete posCache;
  }
}
Пример #2
0
void ColumnLiftover::liftInterval(BedList& mappedBedLines)
{  
  PositionMap posCacheMap;
  PositionMap revCacheMap;
  _colIt = _srcSequence->getColumnIterator(&_tgtSet, 0, _bedLine._start, 
                                           _bedLine._end - 1,
                                           !_traverseDupes,
                                           false,
                                           _bedLine._strand == '-');
  while (true) 
  {
    const ColumnMap* cMap = _colIt->getColumnMap();
    for (ColumnMap::const_iterator i = cMap->begin(); i != cMap->end(); ++i)
    {
      if (i->first->getGenome() == _tgtGenome)
      {
        const DNASet* dSet = i->second;
        const Sequence* seq = i->first;
        // if we're not adding the column, don't bother keeping track
        SeqIndex seqIdx(seq, 0);
        for (DNASet::const_iterator j = dSet->begin(); j != dSet->end(); ++j)
        {
          pair<PositionMap::iterator, bool> res;
          if ((*j)->getReversed() == false)
          {
            res =
               posCacheMap.insert(pair<SeqIndex, PositionCache*>(seqIdx, NULL));
          }
          else
          {
            res =
               revCacheMap.insert(pair<SeqIndex, PositionCache*>(seqIdx, NULL));
          }
          if (res.second == true)
          {
            res.first->second = new PositionCache();
          }
          res.first->second->insert((*j)->getArrayIndex());
        }
      }
    }
    if (_colIt->lastColumn() == true)
    {
      break;
    }
    _colIt->toRight();
  } 

  PositionMap::iterator pcmIt;
  for (pcmIt = posCacheMap.begin(); pcmIt != posCacheMap.end(); ++pcmIt)
  {
    const Sequence* seq = pcmIt->first.first;
    _outParalogy = pcmIt->first.second;
    hal_size_t seqStart = seq->getStartPosition();
    PositionCache* posCache = pcmIt->second;
    const IntervalSet* iSet = posCache->getIntervalSet();
    for (IntervalSet::const_iterator k = iSet->begin(); k != iSet->end(); ++k)
    {
      mappedBedLines.push_back(_bedLine);
      BedLine& outBedLine = mappedBedLines.back();
      outBedLine._blocks.clear();
      outBedLine._chrName = seq->getName();
      outBedLine._start = k->second - seqStart;
      outBedLine._end = k->first + 1 - seqStart;
      outBedLine._strand = _bedLine._strand == '.' ? '.' : '+';
      outBedLine._srcStart = NULL_INDEX; // not available from posMap
    }
    delete posCache;
  }

  for (pcmIt = revCacheMap.begin(); pcmIt != revCacheMap.end(); ++pcmIt)
  {
    const Sequence* seq = pcmIt->first.first;
    _outParalogy = pcmIt->first.second;
    hal_size_t seqStart = seq->getStartPosition();
    PositionCache* posCache = pcmIt->second;
    const IntervalSet* iSet = posCache->getIntervalSet();
    for (IntervalSet::const_iterator k = iSet->begin(); k != iSet->end(); ++k)
    {
      mappedBedLines.push_back(_bedLine);
      BedLine& outBedLine = mappedBedLines.back();
      outBedLine._blocks.clear();
      outBedLine._chrName = seq->getName();
      outBedLine._start = k->second - seqStart;
      outBedLine._end = k->first + 1 - seqStart;
      outBedLine._strand = _bedLine._strand == '.' ? '.' : '-';
      outBedLine._srcStart = NULL_INDEX; // not available from posMap
    }
    delete posCache;
  }

}
Пример #3
0
void csMeshGenerator::GeneratePositions (int cidx, csMGCell& cell,
                                         csMGPositionBlock* block)
{
  random.Initialize ((unsigned int)cidx); // @@@ Consider using a better seed?

  block->positions.Empty ();
  cell.needPositions = false;

  const csBox2& box = cell.box;
  float box_area = box.Area ();
  
  CS_ALLOC_STACK_ARRAY(float, geoRadii, geometries.GetSize ());
  for (size_t i = 0 ; i < geometries.GetSize () ; i++)
    geoRadii[i] = geometries[i]->GetRadius();
  PositionMap positionMap (geoRadii, geometries.GetSize (),
			   box, cidx);

  if(minRadius < 0.0f)
  {
    for (size_t i = 0 ; i < geometries.GetSize () ; i++)
    {
      if(geometries[i]->GetRadius() < minRadius || minRadius < 0.0f)
      {
        minRadius = geometries[i]->GetRadius();
      }
    }
  }

  size_t i, j;
  for (size_t g = 0 ; g < geometries.GetSize () ; g++)
  {
    csMGPosition pos;
    pos.geom_type = g;
    size_t mpos_count = geometries[g]->GetManualPositionCount (cidx);

    float density = geometries[g]->GetDensity () * default_density_factor;

    size_t count = (mpos_count > 0)? mpos_count : size_t (density * box_area);

    /* Estimation of actual number of generated positions
     * Count how many of the generated positions have actually caused a mesh
     * to be placed (densities < 1 will cause some position to be rejected...).
     * After generating minSamples positions, estimate the total number
     * of actually used positions, and break if that is reached. */
    size_t minSamples = ceil (sqrtf (count));
    size_t positionsUsed = 0;

    const csArray<csMGDensityMaterialFactor>& mftable
      = geometries[g]->GetDensityMaterialFactors ();
    float default_material_factor
      = geometries[g]->GetDefaultDensityMaterialFactor ();
    bool do_material = mftable.GetSize () > 0;
    for (j = 0 ; j < count ; j++)
    {
      float pos_factor;
      float r = geometries[g]->csMeshGeneratorGeometry::GetRadius();
      float x;
      float z;
      PositionMap::AreaID area;
      if (mpos_count == 0)
      {
        if(!positionMap.GetRandomPosition (r, x, z, area))
        {
          // Ran out of room in this cell.
          return;
        }
        geometries[g]->GetDensityMapFactor (x, z, pos_factor);
      }
      else
      {
        csVector2 mpos = geometries[g]->GetManualPosition (cidx,j);
        x = mpos.x; 
        z = mpos.y;
        pos_factor = 1.0f;
      }
      
      if (!((pos_factor < 0.0001) ||
        (pos_factor < 0.9999 && random.Get () > pos_factor)))
      {
        csVector3 start (x, samplebox.MaxY (), z);
        csVector3 end = start;
        end.y = samplebox.MinY ();
        bool hit = false;
        iMaterialWrapper* hit_material = 0;
        for (i = 0 ; i < cell.meshes.GetSize () ; i++)
        {
          csHitBeamResult rc = cell.meshes[i]->HitBeam (start, end,
            do_material);
          if (rc.hit)
          {
            pos.position = rc.isect;
            end.y = rc.isect.y + 0.0001;
            hit_material = rc.material;
            hit = true;
          }
        }
        if (hit)
        {
          if (do_material)
          {
            // We use material density tables.
            float factor = default_material_factor;
	    for (size_t mi = 0 ; mi < mftable.GetSize () ; mi++)
	    {
	      if (mftable[mi].material == hit_material)
	      {
		factor = mftable[mi].factor;
		break;
	      }
	    }

            if (factor < 0.0001 || (factor < 0.9999 && random.Get () > factor))
            {
              hit = false;
            }
          }
          if (hit)
          {
            int rot = int (random.Get (CS_GEOM_MAX_ROTATIONS));
            if (rot < 0) rot = 0;
            else if (rot >= CS_GEOM_MAX_ROTATIONS) rot = CS_GEOM_MAX_ROTATIONS-1;
            pos.rotation = rot;
            block->positions.Push (new csMGPosition (pos));
	    positionsUsed++;
	    
	    if (mpos_count == 0)
	      positionMap.MarkAreaUsed (area, r, x, z);
          }
        }
      }

      /* Estimate how many positions will actually be used based on the
       * running count of used positions. */
      size_t estimatedCount = ceil (count * (float (positionsUsed) / (j+1)));
      // If enough samples have been collected...
      if (j >= minSamples)
      {
	// ... and the estimated count has been hit, exit early.
	if (positionsUsed >= estimatedCount)
	  break;
      }
    }
  }
}