void GenomeMetaTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); MetaData *ancMeta = ancGenome->getMetaData(); ancMeta->set("Young", "Jeezy"); }
void GenomeCreateTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); Genome *leaf1Genome = alignment->addLeafGenome("Leaf1", "AncGenome", 0.1); Genome *leaf2Genome = alignment->addLeafGenome("Leaf2", "AncGenome", 0.2); Genome *leaf3Genome = alignment->addLeafGenome("Leaf3", "AncGenome", 0.3); MetaData *ancMeta = ancGenome->getMetaData(); ancMeta->set("Young", "Jeezy"); vector<Sequence::Info> seqVec(1); seqVec[0] = Sequence::Info("Sequence", 1000000, 5000, 700000); ancGenome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 1000000, 700000, 0); leaf1Genome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 2000000, 700000, 0); leaf2Genome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 3000000, 700000, 0); leaf3Genome->setDimensions(seqVec); }
void GenomeCopyTest::createCallBack(Alignment *alignment) { hal_size_t alignmentSize = alignment->getNumGenomes(); CuAssertTrue(_testCase, alignmentSize == 0); // Hacky: Need a different alignment to test copying the bottom // segments correctly. (the names of a node's children are used // when copying bottom segments, and two genomes can't have the same // name in the same alignment) _path = getTempFile(); _secondAlignment = AlignmentPtr(getTestAlignmentInstances(alignment->getStorageFormat(), _path, WRITE_ACCESS | CREATE_ACCESS)); Genome *ancGenome = alignment->addRootGenome("AncGenome", 0); Genome *leafGenome = alignment->addLeafGenome("LeafGenome1", "AncGenome", 0); // This genome will test copyDimensions, copyTopSegments, // copyBottomSegments, copySequence, copyMetadata Genome *copyRootGenome = _secondAlignment->addRootGenome("copyRootGenome", 0); Genome *copyLeafGenome = _secondAlignment->addLeafGenome("LeafGenome1", "copyRootGenome", 0); MetaData *ancMeta = ancGenome->getMetaData(); ancMeta->set("Young", "Jeezy"); vector<Sequence::Info> seqVec(1); seqVec[0] = Sequence::Info("Sequence", 1000000, 0, 700000); ancGenome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 1000000, 5000, 0); leafGenome->setDimensions(seqVec); string ancSeq = "CAT"; hal_index_t n = ancGenome->getSequenceLength(); DnaIteratorPtr dnaIt = ancGenome->getDnaIterator(); for (; dnaIt->getArrayIndex() < n; dnaIt->toRight()) { size_t i = dnaIt->getArrayIndex() % ancSeq.size(); dnaIt->setBase(ancSeq[i]); } dnaIt->flush(); n = leafGenome->getSequenceLength(); dnaIt = leafGenome->getDnaIterator(); for (; dnaIt->getArrayIndex() < n; dnaIt->toRight()) { size_t i = dnaIt->getArrayIndex() % ancSeq.size(); dnaIt->setBase(ancSeq[i]); } dnaIt->flush(); TopSegmentIteratorPtr topIt = leafGenome->getTopSegmentIterator(); n = leafGenome->getNumTopSegments(); for (; topIt->getArrayIndex() < n; topIt->toRight()) { topIt->setCoordinates(topIt->getArrayIndex(), 1); topIt->tseg()->setParentIndex(3); topIt->tseg()->setParentReversed(true); topIt->tseg()->setBottomParseIndex(5); if (topIt->getArrayIndex() != 6) { topIt->tseg()->setNextParalogyIndex(6); } else { topIt->tseg()->setNextParalogyIndex(7); } } BottomSegmentIteratorPtr botIt = ancGenome->getBottomSegmentIterator(); n = ancGenome->getNumBottomSegments(); for (; botIt->getArrayIndex() < n; botIt->toRight()) { botIt->setCoordinates(botIt->getArrayIndex(), 1); botIt->bseg()->setChildIndex(0, 3); botIt->bseg()->setChildReversed(0, true); botIt->bseg()->setTopParseIndex(5); } seqVec[0] = Sequence::Info("Sequence", 3300, 0, 1100); copyRootGenome->setDimensions(seqVec); seqVec[0] = Sequence::Info("Sequence", 3300, 2200, 0); copyLeafGenome->setDimensions(seqVec); string copySeq = "TAG"; dnaIt = copyRootGenome->getDnaIterator(); n = copyRootGenome->getSequenceLength(); for (; dnaIt->getArrayIndex() < n; dnaIt->toRight()) { size_t i = dnaIt->getArrayIndex() % copySeq.size(); dnaIt->setBase(copySeq[i]); } dnaIt->flush(); dnaIt = copyLeafGenome->getDnaIterator(); n = copyLeafGenome->getSequenceLength(); for (; dnaIt->getArrayIndex() < n; dnaIt->toRight()) { size_t i = dnaIt->getArrayIndex() % copySeq.size(); dnaIt->setBase(copySeq[i]); } dnaIt->flush(); topIt = copyLeafGenome->getTopSegmentIterator(); n = copyLeafGenome->getNumTopSegments(); for (; topIt->getArrayIndex() < n; topIt->toRight()) { topIt->setCoordinates(7, 8); topIt->tseg()->setParentIndex(9); topIt->tseg()->setParentReversed(false); topIt->tseg()->setBottomParseIndex(11); if (topIt->getArrayIndex() != 12) { topIt->tseg()->setNextParalogyIndex(12); } else { topIt->tseg()->setNextParalogyIndex(7); } } botIt = copyRootGenome->getBottomSegmentIterator(); n = copyRootGenome->getNumBottomSegments(); for (; botIt->getArrayIndex() < n; botIt->toRight()) { botIt->setCoordinates(6, 7); botIt->bseg()->setChildIndex(0, 8); botIt->bseg()->setChildReversed(0, false); botIt->bseg()->setTopParseIndex(10); } ancGenome->copy(copyRootGenome); leafGenome->copy(copyLeafGenome); _secondAlignment->close(); }
int main(int argc, char *argv[]) { CLParserPtr optParser = initParser(); string inPath, bottomAlignmentFile, topAlignmentFile, genomeName; bool noMarkAncestors; try { optParser->parseOptions(argc, argv); inPath = optParser->getArgument<string>("inFile"); bottomAlignmentFile = optParser->getOption<string>("bottomAlignmentFile"); topAlignmentFile = optParser->getOption<string>("topAlignmentFile"); genomeName = optParser->getArgument<string>("genomeName"); noMarkAncestors = optParser->getFlag("noMarkAncestors"); } catch (exception &e) { optParser->printUsage(cerr); return 1; } AlignmentPtr mainAlignment = openHalAlignment(inPath, optParser); AlignmentConstPtr bottomAlignment; AlignmentConstPtr topAlignment; bool useTopAlignment = mainAlignment->getRootName() != genomeName; bool useBottomAlignment = mainAlignment->getChildNames(genomeName).size() != 0; Genome *mainReplacedGenome = mainAlignment->openGenome(genomeName); if (useTopAlignment) { // Not a root genome. Can update using a top alignment. if (topAlignmentFile == "\"\"") { throw hal_exception("Cannot replace non-root genome without a top " "alignment file."); } topAlignment = openHalAlignment(topAlignmentFile, optParser); const Genome *topReplacedGenome = topAlignment->openGenome(genomeName); topReplacedGenome->copyDimensions(mainReplacedGenome); topReplacedGenome->copySequence(mainReplacedGenome); } if (useBottomAlignment) { // Not a leaf genome. Can update using a bottom alignment. if (bottomAlignmentFile == "\"\"") { throw hal_exception("Cannot replace non-leaf genome without a bottom " "alignment file."); } bottomAlignment = openHalAlignment(bottomAlignmentFile, optParser); const Genome *botReplacedGenome = bottomAlignment->openGenome(genomeName); botReplacedGenome->copyDimensions(mainReplacedGenome); botReplacedGenome->copySequence(mainReplacedGenome); } if (!useTopAlignment && !useBottomAlignment) { throw hal_exception("Root genome is also a leaf genome."); } if (useBottomAlignment) { copyFromBottomAlignment(bottomAlignment, mainAlignment, genomeName); } if (useTopAlignment) { copyFromTopAlignment(topAlignment, mainAlignment, genomeName); } // Clear update flag if present, since the genome has just been updated. MetaData *metaData = mainReplacedGenome->getMetaData(); if (metaData->has("needsUpdate")) { metaData->set("needsUpdate", "false"); } if (!noMarkAncestors) { markAncestorsForUpdate(mainAlignment, genomeName); } if (useTopAlignment) { topAlignment->close(); } if (useBottomAlignment) { bottomAlignment->close(); } mainAlignment->close(); }