示例#1
0
void Side2Seq::convertSequence(const SGSequence* seq)
{
  // we exclude the very first and last sides as they don't induce breaks
  // (very first start woult have forward == true, for example..)
  SGSide start = SGSide(SGPosition(seq->getID(), 0), false);
  SGSide end = SGSide(SGPosition(seq->getID(), seq->getLength() - 1), true);
  set<SGSide> cutSides;
  if (seq->getLength() > 1)
  {
    getIncidentJoins(start, end, cutSides);
  }
  if (_chop > 0)
  {
    getChopSides(seq, cutSides);
  }
  cleanCutSides(cutSides);
  
  SGPosition first(seq->getID(), 0);
  int firstIdx = _outGraph->getNumSequences();
  for (set<SGSide>::iterator i = cutSides.begin(); i != cutSides.end(); ++i)
  {
    SGPosition last = i->getBase();
    assert(last.getSeqID() == first.getSeqID());
    if (i->getForward() == true)
    {
      // left side of base: don't include this position
      last.setPos(last.getPos() - 1);
    }
    // add it
    addOutSequence(seq, first, last);
    // add one because segments inclusive
    first.setPos(last.getPos() + 1);
  }

  // need to do one segment at end
  SGPosition last(seq->getID(), seq->getLength() - 1);
  addOutSequence(seq, first, last);

  // chain all the added seqeunces with new joins
  for (int j = firstIdx + 1; j < _outGraph->getNumSequences(); ++j)
  {
    const SGSequence* fs = _outGraph->getSequence(j-1);
    const SGSequence* ts = _outGraph->getSequence(j);
    SGSide side1(SGPosition(fs->getID(), fs->getLength() - 1), false);
    SGSide side2(SGPosition(ts->getID(), 0), true);
    const SGJoin* newJoin = _outGraph->addJoin(new SGJoin(side1, side2));
    verifyOutJoin(newJoin);
  }
}