int IntersectByMaster(CCdCore* ccd, double rowFraction) { int result = -1; unsigned int masterLen = (ccd) ? ccd->GetSequenceStringByRow(0).length() : 0; if (masterLen == 0) return result; int slaveStart; int nAlignedIBM = 0; unsigned int i, j, nBlocks; unsigned int nRows = ccd->GetNumRows(); // If there is already a consistent block model, do nothing. MultipleAlignment* ma = new MultipleAlignment(ccd); if (ma && ma->isBlockAligned()) { delete ma; return 0; } delete ma; BlockIntersector blockIntersector(masterLen); BlockModel* intersectedBlockModel; //BlockModel* simpleIntersectedBlockModel; BlockModelPair* bmp; vector<BlockModelPair*> blockModelPairs; set<int> forcedCTerminiInIntersection; list< CRef< CSeq_align > >& cdSeqAligns = ccd->GetSeqAligns(); list< CRef< CSeq_align > >::iterator cdSeqAlignIt = cdSeqAligns.begin(), cdSeqAlignEnd = cdSeqAligns.end(); for (i = 0; cdSeqAlignIt != cdSeqAlignEnd; ++cdSeqAlignIt, ++i) { bmp = new BlockModelPair(*cdSeqAlignIt); // We assume # of blocks and all block lengths are same on master and slave. if (bmp && bmp->isValid()) { blockModelPairs.push_back(bmp); blockIntersector.addOneAlignment(bmp->getMaster()); // Find places the intersection can't merge blocks (i.e., where there are // gaps in the slave across a block boundary, but not in the master). BlockModel& slave = bmp->getSlave(); nBlocks = slave.getBlocks().size(); for (j = 0; j < nBlocks - 1; ++j) { // '-1' as I don't care about end of the C-terminal block if (slave.getGapToCTerminal(j) > 0 && bmp->getMaster().getGapToCTerminal(j) == 0) { forcedCTerminiInIntersection.insert(bmp->getMaster().getBlock(j).getEnd()); } } } } // There was a problem creating one of the BlockModelPair objects from a seq_align, // or one or more seq_align was invalid. if (blockModelPairs.size() != cdSeqAligns.size()) { return result; } //simpleIntersectedBlockModel = blockIntersector.getIntersectedAlignment(forcedCTerminiInIntersection); intersectedBlockModel = blockIntersector.getIntersectedAlignment(forcedCTerminiInIntersection, rowFraction); nAlignedIBM = (intersectedBlockModel) ? intersectedBlockModel->getTotalBlockLength() : 0; if (nAlignedIBM == 0) { return result; } /* string testStr, testStr2; string sint = intersectedBlockModel->toString(); string sintsimple = simpleIntersectedBlockModel->toString(); delete simpleIntersectedBlockModel; cout << "rowFraction = 1:\n" << sintsimple << endl; cout << "rowFraction = " << rowFraction << ":\n" << sint << endl; */ // As we have case where every block model isn't identical, // change each seq-align to reflect the common set of aligned columns. nBlocks = intersectedBlockModel->getBlocks().size(); for (i = 0, cdSeqAlignIt = cdSeqAligns.begin(); i < nRows - 1 ; ++i, ++cdSeqAlignIt) { bmp = blockModelPairs[i]; //BlockModelPair seqAlignPair(*cdSeqAlignIt); BlockModel* intersectedSeqAlignSlave = new BlockModel(bmp->getSlave().getSeqId(), false); bmp->reverse(); for (j = 0; j < nBlocks; ++j) { const Block& jthMasterBlock = intersectedBlockModel->getBlock(j); slaveStart = bmp->mapToMaster(jthMasterBlock.getStart()); // since we're dealing w/ an intersection, slaveStart should always be valid assert(slaveStart != -1); Block b(slaveStart, jthMasterBlock.getLen(), jthMasterBlock.getId()); intersectedSeqAlignSlave->addBlock(b); } *cdSeqAlignIt = intersectedSeqAlignSlave->toSeqAlign(*intersectedBlockModel); //testStr = intersectedSeqAlignSlave->toString(); //testStr2 = bmp->getMaster().toString(); // original *slave* alignment delete bmp; } blockModelPairs.clear(); result = nBlocks; delete intersectedBlockModel; return result; }