diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index c4f951f1..5738f1ad 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 219C1DE01552C4BD004209F9 /* newcommandtemplate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219C1DDF1552C4BD004209F9 /* newcommandtemplate.cpp */; }; 219C1DE41559BCCF004209F9 /* getcoremicrobiomecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219C1DE31559BCCD004209F9 /* getcoremicrobiomecommand.cpp */; }; + 480D1E2A1EA681D100BF9C77 /* testclustercalcs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 480D1E281EA681D100BF9C77 /* testclustercalcs.cpp */; }; + 480D1E311EA92D5500BF9C77 /* fakeoptimatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 480D1E2F1EA92D5500BF9C77 /* fakeoptimatrix.cpp */; }; 480E8DB11CAB12ED00A0D137 /* testfastqread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 480E8DAF1CAB12ED00A0D137 /* testfastqread.cpp */; }; 480E8DB21CAB1F5E00A0D137 /* vsearchfileparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 489B55701BCD7F0100FB7DC8 /* vsearchfileparser.cpp */; }; 481623E21B56A2DB004C60B7 /* pcrseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 481623E11B56A2DB004C60B7 /* pcrseqscommand.cpp */; }; @@ -33,7 +35,6 @@ 481FB53B1AC1B5EF0076CFF3 /* boneh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66612D37EC400DA6239 /* boneh.cpp */; }; 481FB53C1AC1B5F10076CFF3 /* bootstrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66812D37EC400DA6239 /* bootstrap.cpp */; }; 481FB53D1AC1B5F80076CFF3 /* bstick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66C12D37EC400DA6239 /* bstick.cpp */; }; - 481FB53E1AC1B5FC0076CFF3 /* calculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66E12D37EC400DA6239 /* calculator.cpp */; }; 481FB53F1AC1B6000076CFF3 /* canberra.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B67012D37EC400DA6239 /* canberra.cpp */; }; 481FB5401AC1B6030076CFF3 /* chao1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B67612D37EC400DA6239 /* chao1.cpp */; }; 481FB5411AC1B6070076CFF3 /* coverage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B6BB12D37EC400DA6239 /* coverage.cpp */; }; @@ -287,9 +288,6 @@ 481FB6411AC1B7EA0076CFF3 /* sequenceparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7F9F5CE141A5E500032F693 /* sequenceparser.cpp */; }; 481FB6421AC1B7EA0076CFF3 /* sharedlistvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80412D37EC400DA6239 /* sharedlistvector.cpp */; }; 481FB6431AC1B7EA0076CFF3 /* sharedordervector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */; }; - 481FB6441AC1B7EA0076CFF3 /* sharedrabundfloatvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80F12D37EC400DA6239 /* sharedrabundfloatvector.cpp */; }; - 481FB6451AC1B7EA0076CFF3 /* sharedrabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81112D37EC400DA6239 /* sharedrabundvector.cpp */; }; - 481FB6461AC1B7EA0076CFF3 /* sharedsabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81312D37EC400DA6239 /* sharedsabundvector.cpp */; }; 481FB6471AC1B7EA0076CFF3 /* sparsematrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B83912D37EC400DA6239 /* sparsematrix.cpp */; }; 481FB6481AC1B7EA0076CFF3 /* sparsedistancematrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E0243C15B4520A00A5F046 /* sparsedistancematrix.cpp */; }; 481FB6491AC1B7F40076CFF3 /* suffixdb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B85112D37EC400DA6239 /* suffixdb.cpp */; }; @@ -369,6 +367,8 @@ 48576EA21D05DBCD00BBC9C0 /* vsearchfileparser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 489B55701BCD7F0100FB7DC8 /* vsearchfileparser.cpp */; }; 48576EA51D05E8F600BBC9C0 /* testoptimatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48576EA31D05E8F600BBC9C0 /* testoptimatrix.cpp */; }; 48576EA81D05F59300BBC9C0 /* distpdataset.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48576EA61D05F59300BBC9C0 /* distpdataset.cpp */; }; + 485B0E081F264F2E00CA5F57 /* sharedrabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 485B0E061F264F2E00CA5F57 /* sharedrabundvector.cpp */; }; + 485B0E0E1F27C40500CA5F57 /* sharedrabundfloatvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 485B0E0C1F27C40500CA5F57 /* sharedrabundfloatvector.cpp */; }; 48705AC419BE32C50075E977 /* getmimarkspackagecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48705ABB19BE32C50075E977 /* getmimarkspackagecommand.cpp */; }; 48705AC519BE32C50075E977 /* oligos.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48705ABD19BE32C50075E977 /* oligos.cpp */; }; 48705AC619BE32C50075E977 /* mergesfffilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48705ABF19BE32C50075E977 /* mergesfffilecommand.cpp */; }; @@ -379,6 +379,7 @@ 488841621CC515A000C5E972 /* (null) in Sources */ = {isa = PBXBuildFile; }; 488841651CC6C34900C5E972 /* renamefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 488841631CC6C34900C5E972 /* renamefilecommand.cpp */; }; 488841661CC6C35500C5E972 /* renamefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 488841631CC6C34900C5E972 /* renamefilecommand.cpp */; }; + 4889EA221E8962D50054E0BB /* summary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4889EA201E8962D50054E0BB /* summary.cpp */; }; 48910D431D5243E500F60EDB /* mergecountcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48910D411D5243E500F60EDB /* mergecountcommand.cpp */; }; 48910D441D5243E500F60EDB /* mergecountcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48910D411D5243E500F60EDB /* mergecountcommand.cpp */; }; 48910D461D58CAD700F60EDB /* opticluster.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48910D451D58CAD700F60EDB /* opticluster.cpp */; }; @@ -389,6 +390,12 @@ 48A11C6E1CDA40F0003481D8 /* testrenamefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48A11C6C1CDA40F0003481D8 /* testrenamefilecommand.cpp */; }; 48A85BAD18E1AF2000199B6F /* (null) in Sources */ = {isa = PBXBuildFile; }; 48B662031BBB1B6600997EE4 /* testrenameseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48B662011BBB1B6600997EE4 /* testrenameseqscommand.cpp */; }; + 48BDDA711EC9D31400F0F6C0 /* sharedrabundvectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA6F1EC9D31400F0F6C0 /* sharedrabundvectors.cpp */; }; + 48BDDA721EC9D31400F0F6C0 /* sharedrabundvectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA6F1EC9D31400F0F6C0 /* sharedrabundvectors.cpp */; }; + 48BDDA751ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA731ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp */; }; + 48BDDA761ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA731ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp */; }; + 48BDDA791ECA3B8E00F0F6C0 /* rabundfloatvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA771ECA3B8E00F0F6C0 /* rabundfloatvector.cpp */; }; + 48BDDA7A1ECA3B8E00F0F6C0 /* rabundfloatvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48BDDA771ECA3B8E00F0F6C0 /* rabundfloatvector.cpp */; }; 48C1DDC61D25C1BC00B5BA9D /* (null) in Sources */ = {isa = PBXBuildFile; }; 48C1DDC71D25C1BC00B5BA9D /* (null) in Sources */ = {isa = PBXBuildFile; }; 48C51DF01A76B888004ECDF1 /* fastqread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48C51DEF1A76B888004ECDF1 /* fastqread.cpp */; }; @@ -405,6 +412,45 @@ 48DB37B31B3B27E000C372A4 /* makefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48DB37B11B3B27E000C372A4 /* makefilecommand.cpp */; }; 48DB37B41B3B27E000C372A4 /* makefilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48DB37B11B3B27E000C372A4 /* makefilecommand.cpp */; }; 48E418561D08893A004C36AB /* (null) in Sources */ = {isa = PBXBuildFile; }; + 48E543EB1E8F15A500FF6AB8 /* summary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4889EA201E8962D50054E0BB /* summary.cpp */; }; + 48E543EC1E8F15B800FF6AB8 /* opticluster.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48910D451D58CAD700F60EDB /* opticluster.cpp */; }; + 48E543ED1E8F15C800FF6AB8 /* optimatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48910D491D58CBA300F60EDB /* optimatrix.cpp */; }; + 48E543EE1E92B91100FF6AB8 /* chimeravsearchcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48EDB76A1D1320DD00F76E93 /* chimeravsearchcommand.cpp */; }; + 48E544341E92C49700FF6AB8 /* gtest-port.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544131E92C49700FF6AB8 /* gtest-port.cc */; }; + 48E544361E92C49700FF6AB8 /* gtest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544151E92C49700FF6AB8 /* gtest.cc */; }; + 48E544371E92C49700FF6AB8 /* gtest-death-test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544161E92C49700FF6AB8 /* gtest-death-test.cc */; }; + 48E544381E92C49700FF6AB8 /* gtest-test-part.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544171E92C49700FF6AB8 /* gtest-test-part.cc */; }; + 48E5443A1E92C49700FF6AB8 /* gtest-filepath.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E5441E1E92C49700FF6AB8 /* gtest-filepath.cc */; }; + 48E5443B1E92C49700FF6AB8 /* gtest-printers.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544291E92C49700FF6AB8 /* gtest-printers.cc */; }; + 48E5443C1E92C49700FF6AB8 /* gtest-typed-test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 48E544321E92C49700FF6AB8 /* gtest-typed-test.cc */; }; + 48E544411E9C292900FF6AB8 /* mcc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5443F1E9C292900FF6AB8 /* mcc.cpp */; }; + 48E544421E9C292900FF6AB8 /* mcc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5443F1E9C292900FF6AB8 /* mcc.cpp */; }; + 48E544451E9C2B1000FF6AB8 /* sensitivity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544431E9C2B1000FF6AB8 /* sensitivity.cpp */; }; + 48E544461E9C2B1000FF6AB8 /* sensitivity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544431E9C2B1000FF6AB8 /* sensitivity.cpp */; }; + 48E544491E9C2BE100FF6AB8 /* specificity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544471E9C2BE100FF6AB8 /* specificity.cpp */; }; + 48E5444A1E9C2BE100FF6AB8 /* specificity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544471E9C2BE100FF6AB8 /* specificity.cpp */; }; + 48E5444D1E9C2C8F00FF6AB8 /* tptn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5444B1E9C2C8F00FF6AB8 /* tptn.cpp */; }; + 48E5444E1E9C2C8F00FF6AB8 /* tptn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5444B1E9C2C8F00FF6AB8 /* tptn.cpp */; }; + 48E544511E9C2CFD00FF6AB8 /* tp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5444F1E9C2CFD00FF6AB8 /* tp.cpp */; }; + 48E544521E9C2CFD00FF6AB8 /* tp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5444F1E9C2CFD00FF6AB8 /* tp.cpp */; }; + 48E544551E9C2DF500FF6AB8 /* tn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544531E9C2DF500FF6AB8 /* tn.cpp */; }; + 48E544561E9C2DF500FF6AB8 /* tn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544531E9C2DF500FF6AB8 /* tn.cpp */; }; + 48E544591E9C2E6500FF6AB8 /* fp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544571E9C2E6500FF6AB8 /* fp.cpp */; }; + 48E5445A1E9C2E6500FF6AB8 /* fp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544571E9C2E6500FF6AB8 /* fp.cpp */; }; + 48E5445D1E9C2F0F00FF6AB8 /* fn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5445B1E9C2F0F00FF6AB8 /* fn.cpp */; }; + 48E5445E1E9C2F0F00FF6AB8 /* fn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5445B1E9C2F0F00FF6AB8 /* fn.cpp */; }; + 48E544611E9C2FB800FF6AB8 /* fpfn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5445F1E9C2FB800FF6AB8 /* fpfn.cpp */; }; + 48E544621E9C2FB800FF6AB8 /* fpfn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5445F1E9C2FB800FF6AB8 /* fpfn.cpp */; }; + 48E5446C1E9D3A8C00FF6AB8 /* f1score.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5446A1E9D3A8C00FF6AB8 /* f1score.cpp */; }; + 48E5446D1E9D3A8C00FF6AB8 /* f1score.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5446A1E9D3A8C00FF6AB8 /* f1score.cpp */; }; + 48E544701E9D3B2D00FF6AB8 /* accuracy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5446E1E9D3B2D00FF6AB8 /* accuracy.cpp */; }; + 48E544711E9D3B2D00FF6AB8 /* accuracy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5446E1E9D3B2D00FF6AB8 /* accuracy.cpp */; }; + 48E544741E9D3C1200FF6AB8 /* ppv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544721E9D3C1200FF6AB8 /* ppv.cpp */; }; + 48E544751E9D3C1200FF6AB8 /* ppv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544721E9D3C1200FF6AB8 /* ppv.cpp */; }; + 48E544781E9D3CE400FF6AB8 /* npv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544761E9D3CE400FF6AB8 /* npv.cpp */; }; + 48E544791E9D3CE400FF6AB8 /* npv.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E544761E9D3CE400FF6AB8 /* npv.cpp */; }; + 48E5447C1E9D3F0400FF6AB8 /* fdr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5447A1E9D3F0400FF6AB8 /* fdr.cpp */; }; + 48E5447D1E9D3F0400FF6AB8 /* fdr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48E5447A1E9D3F0400FF6AB8 /* fdr.cpp */; }; 48E981CF189C38FB0042BE9D /* (null) in Sources */ = {isa = PBXBuildFile; }; 48EDB76C1D1320DD00F76E93 /* chimeravsearchcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48EDB76A1D1320DD00F76E93 /* chimeravsearchcommand.cpp */; }; 48F06CCD1D74BEC4004A45DD /* testphylotree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 48F06CCB1D74BEC4004A45DD /* testphylotree.cpp */; }; @@ -497,7 +543,6 @@ A7E9B88D12D37EC400DA6239 /* boneh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66612D37EC400DA6239 /* boneh.cpp */; }; A7E9B88E12D37EC400DA6239 /* bootstrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66812D37EC400DA6239 /* bootstrap.cpp */; }; A7E9B89012D37EC400DA6239 /* bstick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66C12D37EC400DA6239 /* bstick.cpp */; }; - A7E9B89112D37EC400DA6239 /* calculator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B66E12D37EC400DA6239 /* calculator.cpp */; }; A7E9B89212D37EC400DA6239 /* canberra.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B67012D37EC400DA6239 /* canberra.cpp */; }; A7E9B89312D37EC400DA6239 /* catchallcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B67212D37EC400DA6239 /* catchallcommand.cpp */; }; A7E9B89412D37EC400DA6239 /* ccode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B67412D37EC400DA6239 /* ccode.cpp */; }; @@ -680,9 +725,6 @@ A7E9B95412D37EC400DA6239 /* sharedmorisitahorn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80812D37EC400DA6239 /* sharedmorisitahorn.cpp */; }; A7E9B95512D37EC400DA6239 /* sharedochiai.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80B12D37EC400DA6239 /* sharedochiai.cpp */; }; A7E9B95612D37EC400DA6239 /* sharedordervector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */; }; - A7E9B95712D37EC400DA6239 /* sharedrabundfloatvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B80F12D37EC400DA6239 /* sharedrabundfloatvector.cpp */; }; - A7E9B95812D37EC400DA6239 /* sharedrabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81112D37EC400DA6239 /* sharedrabundvector.cpp */; }; - A7E9B95912D37EC400DA6239 /* sharedsabundvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81312D37EC400DA6239 /* sharedsabundvector.cpp */; }; A7E9B95A12D37EC400DA6239 /* sharedsobs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81512D37EC400DA6239 /* sharedsobs.cpp */; }; A7E9B95B12D37EC400DA6239 /* sharedsobscollectsummary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81712D37EC400DA6239 /* sharedsobscollectsummary.cpp */; }; A7E9B95C12D37EC400DA6239 /* sharedsorabund.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B81912D37EC400DA6239 /* sharedsorabund.cpp */; }; @@ -800,6 +842,11 @@ 219C1DE11552C508004209F9 /* newcommandtemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = newcommandtemplate.h; path = source/commands/newcommandtemplate.h; sourceTree = SOURCE_ROOT; }; 219C1DE31559BCCD004209F9 /* getcoremicrobiomecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = getcoremicrobiomecommand.cpp; path = source/commands/getcoremicrobiomecommand.cpp; sourceTree = SOURCE_ROOT; }; 219C1DE51559BCF2004209F9 /* getcoremicrobiomecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = getcoremicrobiomecommand.h; path = source/commands/getcoremicrobiomecommand.h; sourceTree = SOURCE_ROOT; }; + 480D1E281EA681D100BF9C77 /* testclustercalcs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = testclustercalcs.cpp; sourceTree = ""; }; + 480D1E291EA681D100BF9C77 /* testclustercalcs.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = testclustercalcs.hpp; sourceTree = ""; }; + 480D1E2D1EA685C500BF9C77 /* fakemcc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fakemcc.hpp; path = TestMothur/fakes/fakemcc.hpp; sourceTree = SOURCE_ROOT; }; + 480D1E2F1EA92D5500BF9C77 /* fakeoptimatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fakeoptimatrix.cpp; path = TestMothur/fakes/fakeoptimatrix.cpp; sourceTree = SOURCE_ROOT; }; + 480D1E301EA92D5500BF9C77 /* fakeoptimatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fakeoptimatrix.hpp; path = fakes/fakeoptimatrix.hpp; sourceTree = ""; }; 480E8DAF1CAB12ED00A0D137 /* testfastqread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testfastqread.cpp; path = TestMothur/testcontainers/testfastqread.cpp; sourceTree = SOURCE_ROOT; }; 480E8DB01CAB12ED00A0D137 /* testfastqread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testfastqread.h; path = TestMothur/testcontainers/testfastqread.h; sourceTree = SOURCE_ROOT; }; 481623E11B56A2DB004C60B7 /* pcrseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pcrseqscommand.cpp; path = source/commands/pcrseqscommand.cpp; sourceTree = SOURCE_ROOT; }; @@ -820,6 +867,10 @@ 48576EA41D05E8F600BBC9C0 /* testoptimatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testoptimatrix.h; path = testcontainers/testoptimatrix.h; sourceTree = ""; }; 48576EA61D05F59300BBC9C0 /* distpdataset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distpdataset.cpp; sourceTree = ""; }; 48576EA71D05F59300BBC9C0 /* distpdataset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = distpdataset.h; sourceTree = ""; }; + 485B0E061F264F2E00CA5F57 /* sharedrabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundvector.cpp; path = source/datastructures/sharedrabundvector.cpp; sourceTree = SOURCE_ROOT; }; + 485B0E071F264F2E00CA5F57 /* sharedrabundvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sharedrabundvector.hpp; path = source/datastructures/sharedrabundvector.hpp; sourceTree = SOURCE_ROOT; }; + 485B0E0C1F27C40500CA5F57 /* sharedrabundfloatvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundfloatvector.cpp; path = source/datastructures/sharedrabundfloatvector.cpp; sourceTree = SOURCE_ROOT; }; + 485B0E0D1F27C40500CA5F57 /* sharedrabundfloatvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sharedrabundfloatvector.hpp; path = source/datastructures/sharedrabundfloatvector.hpp; sourceTree = SOURCE_ROOT; }; 48705ABB19BE32C50075E977 /* getmimarkspackagecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = getmimarkspackagecommand.cpp; path = source/commands/getmimarkspackagecommand.cpp; sourceTree = SOURCE_ROOT; }; 48705ABC19BE32C50075E977 /* getmimarkspackagecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = getmimarkspackagecommand.h; path = source/commands/getmimarkspackagecommand.h; sourceTree = SOURCE_ROOT; }; 48705ABD19BE32C50075E977 /* oligos.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = oligos.cpp; path = source/datastructures/oligos.cpp; sourceTree = SOURCE_ROOT; }; @@ -833,6 +884,8 @@ 48844B261AA74AF9006EF2B8 /* compare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = compare.h; path = source/datastructures/compare.h; sourceTree = SOURCE_ROOT; }; 488841631CC6C34900C5E972 /* renamefilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = renamefilecommand.cpp; path = source/commands/renamefilecommand.cpp; sourceTree = SOURCE_ROOT; }; 488841641CC6C34900C5E972 /* renamefilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = renamefilecommand.h; path = source/commands/renamefilecommand.h; sourceTree = SOURCE_ROOT; }; + 4889EA201E8962D50054E0BB /* summary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = summary.cpp; path = source/summary.cpp; sourceTree = SOURCE_ROOT; }; + 4889EA211E8962D50054E0BB /* summary.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = summary.hpp; path = source/summary.hpp; sourceTree = SOURCE_ROOT; }; 48910D411D5243E500F60EDB /* mergecountcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mergecountcommand.cpp; path = source/commands/mergecountcommand.cpp; sourceTree = SOURCE_ROOT; }; 48910D421D5243E500F60EDB /* mergecountcommand.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = mergecountcommand.hpp; path = source/commands/mergecountcommand.hpp; sourceTree = SOURCE_ROOT; }; 48910D451D58CAD700F60EDB /* opticluster.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = opticluster.cpp; path = source/opticluster.cpp; sourceTree = ""; }; @@ -849,6 +902,12 @@ 48A11C6D1CDA40F0003481D8 /* testrenamefilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testrenamefilecommand.h; path = TestMothur/testcommands/testrenamefilecommand.h; sourceTree = SOURCE_ROOT; }; 48B662011BBB1B6600997EE4 /* testrenameseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testrenameseqscommand.cpp; path = TestMothur/testcommands/testrenameseqscommand.cpp; sourceTree = SOURCE_ROOT; }; 48B662021BBB1B6600997EE4 /* testrenameseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testrenameseqscommand.h; path = TestMothur/testcommands/testrenameseqscommand.h; sourceTree = SOURCE_ROOT; }; + 48BDDA6F1EC9D31400F0F6C0 /* sharedrabundvectors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundvectors.cpp; path = source/datastructures/sharedrabundvectors.cpp; sourceTree = SOURCE_ROOT; }; + 48BDDA701EC9D31400F0F6C0 /* sharedrabundvectors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sharedrabundvectors.hpp; path = source/datastructures/sharedrabundvectors.hpp; sourceTree = ""; }; + 48BDDA731ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundfloatvectors.cpp; path = source/datastructures/sharedrabundfloatvectors.cpp; sourceTree = ""; }; + 48BDDA741ECA067000F0F6C0 /* sharedrabundfloatvectors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sharedrabundfloatvectors.hpp; path = source/datastructures/sharedrabundfloatvectors.hpp; sourceTree = ""; }; + 48BDDA771ECA3B8E00F0F6C0 /* rabundfloatvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = rabundfloatvector.cpp; path = source/datastructures/rabundfloatvector.cpp; sourceTree = SOURCE_ROOT; }; + 48BDDA781ECA3B8E00F0F6C0 /* rabundfloatvector.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = rabundfloatvector.hpp; path = source/datastructures/rabundfloatvector.hpp; sourceTree = ""; }; 48C51DEE1A76B870004ECDF1 /* fastqread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fastqread.h; path = source/datastructures/fastqread.h; sourceTree = SOURCE_ROOT; }; 48C51DEF1A76B888004ECDF1 /* fastqread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fastqread.cpp; path = source/datastructures/fastqread.cpp; sourceTree = SOURCE_ROOT; }; 48C51DF11A793EFE004ECDF1 /* kmeralign.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = kmeralign.cpp; path = source/datastructures/kmeralign.cpp; sourceTree = SOURCE_ROOT; }; @@ -863,12 +922,74 @@ 48C728761B6AB4EE00D40830 /* testsequence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testsequence.h; path = TestMothur/testcontainers/testsequence.h; sourceTree = SOURCE_ROOT; }; 48C728771B728D6B00D40830 /* biominfocommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = biominfocommand.cpp; path = source/commands/biominfocommand.cpp; sourceTree = SOURCE_ROOT; }; 48C728781B728D6B00D40830 /* biominfocommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = biominfocommand.h; path = source/commands/biominfocommand.h; sourceTree = SOURCE_ROOT; }; + 48CC010E1EB79E49009D61E6 /* fakeoligos.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fakeoligos.h; path = fakes/fakeoligos.h; sourceTree = ""; }; 48D6E9661CA42389008DF76B /* testvsearchfileparser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testvsearchfileparser.cpp; path = TestMothur/testvsearchfileparser.cpp; sourceTree = SOURCE_ROOT; }; 48D6E9671CA42389008DF76B /* testvsearchfileparser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = testvsearchfileparser.h; path = TestMothur/testvsearchfileparser.h; sourceTree = SOURCE_ROOT; }; 48D6E9691CA4262A008DF76B /* dataset.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = dataset.cpp; path = TestMothur/dataset.cpp; sourceTree = SOURCE_ROOT; }; 48D6E96A1CA4262A008DF76B /* dataset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = dataset.h; path = TestMothur/dataset.h; sourceTree = SOURCE_ROOT; }; 48DB37B11B3B27E000C372A4 /* makefilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = makefilecommand.cpp; path = source/commands/makefilecommand.cpp; sourceTree = SOURCE_ROOT; }; 48DB37B21B3B27E000C372A4 /* makefilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = makefilecommand.h; path = source/commands/makefilecommand.h; sourceTree = SOURCE_ROOT; }; + 48E544101E92C49700FF6AB8 /* gtest-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-internal.h"; path = "TestMothur/gtest-internal.h"; sourceTree = SOURCE_ROOT; }; + 48E544111E92C49700FF6AB8 /* gtest-port.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-port.h"; path = "TestMothur/gtest-port.h"; sourceTree = SOURCE_ROOT; }; + 48E544121E92C49700FF6AB8 /* gtest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gtest.h; path = TestMothur/gtest.h; sourceTree = SOURCE_ROOT; }; + 48E544131E92C49700FF6AB8 /* gtest-port.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-port.cc"; path = "TestMothur/gtest-port.cc"; sourceTree = SOURCE_ROOT; }; + 48E544151E92C49700FF6AB8 /* gtest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = gtest.cc; path = TestMothur/gtest.cc; sourceTree = SOURCE_ROOT; }; + 48E544161E92C49700FF6AB8 /* gtest-death-test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-death-test.cc"; path = "TestMothur/gtest-death-test.cc"; sourceTree = SOURCE_ROOT; }; + 48E544171E92C49700FF6AB8 /* gtest-test-part.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-test-part.cc"; path = "TestMothur/gtest-test-part.cc"; sourceTree = SOURCE_ROOT; }; + 48E544181E92C49700FF6AB8 /* custom */ = {isa = PBXFileReference; lastKnownFileType = folder; path = custom; sourceTree = ""; }; + 48E5441A1E92C49700FF6AB8 /* gtest_pred_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gtest_pred_impl.h; path = TestMothur/gtest_pred_impl.h; sourceTree = SOURCE_ROOT; }; + 48E5441B1E92C49700FF6AB8 /* gtest_prod.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gtest_prod.h; path = TestMothur/gtest_prod.h; sourceTree = SOURCE_ROOT; }; + 48E5441C1E92C49700FF6AB8 /* gtest-death-test-internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-death-test-internal.h"; path = "TestMothur/gtest-death-test-internal.h"; sourceTree = SOURCE_ROOT; }; + 48E5441D1E92C49700FF6AB8 /* gtest-death-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-death-test.h"; path = "TestMothur/gtest-death-test.h"; sourceTree = SOURCE_ROOT; }; + 48E5441E1E92C49700FF6AB8 /* gtest-filepath.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-filepath.cc"; path = "TestMothur/gtest-filepath.cc"; sourceTree = SOURCE_ROOT; }; + 48E5441F1E92C49700FF6AB8 /* gtest-filepath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-filepath.h"; path = "TestMothur/gtest-filepath.h"; sourceTree = SOURCE_ROOT; }; + 48E544211E92C49700FF6AB8 /* gtest-linked_ptr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-linked_ptr.h"; path = "TestMothur/gtest-linked_ptr.h"; sourceTree = SOURCE_ROOT; }; + 48E544221E92C49700FF6AB8 /* gtest-message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-message.h"; path = "TestMothur/gtest-message.h"; sourceTree = SOURCE_ROOT; }; + 48E544231E92C49700FF6AB8 /* gtest-param-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-param-test.h"; path = "TestMothur/gtest-param-test.h"; sourceTree = SOURCE_ROOT; }; + 48E544241E92C49700FF6AB8 /* gtest-param-test.h.pump */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "gtest-param-test.h.pump"; path = "TestMothur/gtest-param-test.h.pump"; sourceTree = SOURCE_ROOT; }; + 48E544251E92C49700FF6AB8 /* gtest-param-util-generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-param-util-generated.h"; path = "TestMothur/gtest-param-util-generated.h"; sourceTree = SOURCE_ROOT; }; + 48E544261E92C49700FF6AB8 /* gtest-param-util-generated.h.pump */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "gtest-param-util-generated.h.pump"; path = "TestMothur/gtest-param-util-generated.h.pump"; sourceTree = SOURCE_ROOT; }; + 48E544271E92C49700FF6AB8 /* gtest-param-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-param-util.h"; path = "TestMothur/gtest-param-util.h"; sourceTree = SOURCE_ROOT; }; + 48E544281E92C49700FF6AB8 /* gtest-port-arch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-port-arch.h"; path = "TestMothur/gtest-port-arch.h"; sourceTree = SOURCE_ROOT; }; + 48E544291E92C49700FF6AB8 /* gtest-printers.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-printers.cc"; path = "TestMothur/gtest-printers.cc"; sourceTree = SOURCE_ROOT; }; + 48E5442A1E92C49700FF6AB8 /* gtest-printers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-printers.h"; path = "TestMothur/gtest-printers.h"; sourceTree = SOURCE_ROOT; }; + 48E5442B1E92C49700FF6AB8 /* gtest-spi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-spi.h"; path = "TestMothur/gtest-spi.h"; sourceTree = SOURCE_ROOT; }; + 48E5442C1E92C49700FF6AB8 /* gtest-string.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-string.h"; path = "TestMothur/gtest-string.h"; sourceTree = SOURCE_ROOT; }; + 48E5442D1E92C49700FF6AB8 /* gtest-test-part.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-test-part.h"; path = "TestMothur/gtest-test-part.h"; sourceTree = SOURCE_ROOT; }; + 48E5442E1E92C49700FF6AB8 /* gtest-tuple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-tuple.h"; path = "TestMothur/gtest-tuple.h"; sourceTree = SOURCE_ROOT; }; + 48E5442F1E92C49700FF6AB8 /* gtest-tuple.h.pump */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "gtest-tuple.h.pump"; path = "TestMothur/gtest-tuple.h.pump"; sourceTree = SOURCE_ROOT; }; + 48E544301E92C49700FF6AB8 /* gtest-type-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-type-util.h"; path = "TestMothur/gtest-type-util.h"; sourceTree = SOURCE_ROOT; }; + 48E544311E92C49700FF6AB8 /* gtest-type-util.h.pump */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "gtest-type-util.h.pump"; path = "TestMothur/gtest-type-util.h.pump"; sourceTree = SOURCE_ROOT; }; + 48E544321E92C49700FF6AB8 /* gtest-typed-test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "gtest-typed-test.cc"; path = "TestMothur/gtest-typed-test.cc"; sourceTree = SOURCE_ROOT; }; + 48E544331E92C49700FF6AB8 /* gtest-typed-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "gtest-typed-test.h"; path = "TestMothur/gtest-typed-test.h"; sourceTree = SOURCE_ROOT; }; + 48E5443F1E9C292900FF6AB8 /* mcc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mcc.cpp; path = source/calculators/mcc.cpp; sourceTree = SOURCE_ROOT; }; + 48E544401E9C292900FF6AB8 /* mcc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = mcc.hpp; path = source/calculators/mcc.hpp; sourceTree = SOURCE_ROOT; }; + 48E544431E9C2B1000FF6AB8 /* sensitivity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sensitivity.cpp; path = source/calculators/sensitivity.cpp; sourceTree = SOURCE_ROOT; }; + 48E544441E9C2B1000FF6AB8 /* sensitivity.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = sensitivity.hpp; path = source/calculators/sensitivity.hpp; sourceTree = SOURCE_ROOT; }; + 48E544471E9C2BE100FF6AB8 /* specificity.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = specificity.cpp; path = source/calculators/specificity.cpp; sourceTree = SOURCE_ROOT; }; + 48E544481E9C2BE100FF6AB8 /* specificity.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = specificity.hpp; path = source/calculators/specificity.hpp; sourceTree = SOURCE_ROOT; }; + 48E5444B1E9C2C8F00FF6AB8 /* tptn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tptn.cpp; path = source/calculators/tptn.cpp; sourceTree = SOURCE_ROOT; }; + 48E5444C1E9C2C8F00FF6AB8 /* tptn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tptn.hpp; path = source/calculators/tptn.hpp; sourceTree = SOURCE_ROOT; }; + 48E5444F1E9C2CFD00FF6AB8 /* tp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tp.cpp; path = source/calculators/tp.cpp; sourceTree = SOURCE_ROOT; }; + 48E544501E9C2CFD00FF6AB8 /* tp.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tp.hpp; path = source/calculators/tp.hpp; sourceTree = SOURCE_ROOT; }; + 48E544531E9C2DF500FF6AB8 /* tn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tn.cpp; path = source/calculators/tn.cpp; sourceTree = SOURCE_ROOT; }; + 48E544541E9C2DF500FF6AB8 /* tn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = tn.hpp; path = source/calculators/tn.hpp; sourceTree = SOURCE_ROOT; }; + 48E544571E9C2E6500FF6AB8 /* fp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fp.cpp; path = source/calculators/fp.cpp; sourceTree = SOURCE_ROOT; }; + 48E544581E9C2E6500FF6AB8 /* fp.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fp.hpp; path = source/calculators/fp.hpp; sourceTree = SOURCE_ROOT; }; + 48E5445B1E9C2F0F00FF6AB8 /* fn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fn.cpp; path = source/calculators/fn.cpp; sourceTree = SOURCE_ROOT; }; + 48E5445C1E9C2F0F00FF6AB8 /* fn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fn.hpp; path = source/calculators/fn.hpp; sourceTree = ""; }; + 48E5445F1E9C2FB800FF6AB8 /* fpfn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fpfn.cpp; path = source/calculators/fpfn.cpp; sourceTree = SOURCE_ROOT; }; + 48E544601E9C2FB800FF6AB8 /* fpfn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fpfn.hpp; path = source/calculators/fpfn.hpp; sourceTree = ""; }; + 48E5446A1E9D3A8C00FF6AB8 /* f1score.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = f1score.cpp; path = source/calculators/f1score.cpp; sourceTree = SOURCE_ROOT; }; + 48E5446B1E9D3A8C00FF6AB8 /* f1score.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = f1score.hpp; path = source/calculators/f1score.hpp; sourceTree = SOURCE_ROOT; }; + 48E5446E1E9D3B2D00FF6AB8 /* accuracy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = accuracy.cpp; path = source/calculators/accuracy.cpp; sourceTree = SOURCE_ROOT; }; + 48E5446F1E9D3B2D00FF6AB8 /* accuracy.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = accuracy.hpp; path = source/calculators/accuracy.hpp; sourceTree = ""; }; + 48E544721E9D3C1200FF6AB8 /* ppv.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ppv.cpp; path = source/calculators/ppv.cpp; sourceTree = SOURCE_ROOT; }; + 48E544731E9D3C1200FF6AB8 /* ppv.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ppv.hpp; path = source/calculators/ppv.hpp; sourceTree = ""; }; + 48E544761E9D3CE400FF6AB8 /* npv.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = npv.cpp; path = source/calculators/npv.cpp; sourceTree = SOURCE_ROOT; }; + 48E544771E9D3CE400FF6AB8 /* npv.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = npv.hpp; path = source/calculators/npv.hpp; sourceTree = ""; }; + 48E5447A1E9D3F0400FF6AB8 /* fdr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = fdr.cpp; path = source/calculators/fdr.cpp; sourceTree = SOURCE_ROOT; }; + 48E5447B1E9D3F0400FF6AB8 /* fdr.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = fdr.hpp; path = source/calculators/fdr.hpp; sourceTree = ""; }; 48EDB76A1D1320DD00F76E93 /* chimeravsearchcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = chimeravsearchcommand.cpp; path = source/commands/chimeravsearchcommand.cpp; sourceTree = SOURCE_ROOT; }; 48EDB76B1D1320DD00F76E93 /* chimeravsearchcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = chimeravsearchcommand.h; path = source/commands/chimeravsearchcommand.h; sourceTree = SOURCE_ROOT; }; 48F06CCB1D74BEC4004A45DD /* testphylotree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = testphylotree.cpp; path = testclassifier/testphylotree.cpp; sourceTree = ""; }; @@ -1056,7 +1177,6 @@ A7E9B66912D37EC400DA6239 /* bootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bootstrap.h; path = source/calculators/bootstrap.h; sourceTree = SOURCE_ROOT; }; A7E9B66C12D37EC400DA6239 /* bstick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bstick.cpp; path = source/calculators/bstick.cpp; sourceTree = SOURCE_ROOT; }; A7E9B66D12D37EC400DA6239 /* bstick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bstick.h; path = source/calculators/bstick.h; sourceTree = SOURCE_ROOT; }; - A7E9B66E12D37EC400DA6239 /* calculator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = calculator.cpp; path = source/calculators/calculator.cpp; sourceTree = SOURCE_ROOT; }; A7E9B66F12D37EC400DA6239 /* calculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = calculator.h; path = source/calculators/calculator.h; sourceTree = SOURCE_ROOT; }; A7E9B67012D37EC400DA6239 /* canberra.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = canberra.cpp; path = source/calculators/canberra.cpp; sourceTree = SOURCE_ROOT; }; A7E9B67112D37EC400DA6239 /* canberra.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = canberra.h; path = source/calculators/canberra.h; sourceTree = SOURCE_ROOT; }; @@ -1144,7 +1264,6 @@ A7E9B6C712D37EC400DA6239 /* deuniqueseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = deuniqueseqscommand.cpp; path = source/commands/deuniqueseqscommand.cpp; sourceTree = SOURCE_ROOT; }; A7E9B6C812D37EC400DA6239 /* deuniqueseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = deuniqueseqscommand.h; path = source/commands/deuniqueseqscommand.h; sourceTree = SOURCE_ROOT; }; A7E9B6C912D37EC400DA6239 /* display.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = display.h; path = source/display.h; sourceTree = ""; }; - A7E9B6CA12D37EC400DA6239 /* dist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = dist.h; path = source/calculators/dist.h; sourceTree = SOURCE_ROOT; }; A7E9B6CB12D37EC400DA6239 /* distancecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = distancecommand.cpp; path = source/commands/distancecommand.cpp; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; A7E9B6CC12D37EC400DA6239 /* distancecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = distancecommand.h; path = source/commands/distancecommand.h; sourceTree = SOURCE_ROOT; }; A7E9B6CD12D37EC400DA6239 /* distancedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = distancedb.cpp; path = source/datastructures/distancedb.cpp; sourceTree = SOURCE_ROOT; }; @@ -1442,12 +1561,6 @@ A7E9B80C12D37EC400DA6239 /* sharedochiai.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedochiai.h; path = source/calculators/sharedochiai.h; sourceTree = SOURCE_ROOT; }; A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedordervector.cpp; path = source/datastructures/sharedordervector.cpp; sourceTree = SOURCE_ROOT; }; A7E9B80E12D37EC400DA6239 /* sharedordervector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedordervector.h; path = source/datastructures/sharedordervector.h; sourceTree = SOURCE_ROOT; }; - A7E9B80F12D37EC400DA6239 /* sharedrabundfloatvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundfloatvector.cpp; path = source/datastructures/sharedrabundfloatvector.cpp; sourceTree = SOURCE_ROOT; }; - A7E9B81012D37EC400DA6239 /* sharedrabundfloatvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedrabundfloatvector.h; path = source/datastructures/sharedrabundfloatvector.h; sourceTree = SOURCE_ROOT; }; - A7E9B81112D37EC400DA6239 /* sharedrabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedrabundvector.cpp; path = source/datastructures/sharedrabundvector.cpp; sourceTree = SOURCE_ROOT; }; - A7E9B81212D37EC400DA6239 /* sharedrabundvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedrabundvector.h; path = source/datastructures/sharedrabundvector.h; sourceTree = SOURCE_ROOT; }; - A7E9B81312D37EC400DA6239 /* sharedsabundvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedsabundvector.cpp; path = source/datastructures/sharedsabundvector.cpp; sourceTree = SOURCE_ROOT; }; - A7E9B81412D37EC400DA6239 /* sharedsabundvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedsabundvector.h; path = source/datastructures/sharedsabundvector.h; sourceTree = SOURCE_ROOT; }; A7E9B81512D37EC400DA6239 /* sharedsobs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedsobs.cpp; path = source/calculators/sharedsobs.cpp; sourceTree = SOURCE_ROOT; }; A7E9B81612D37EC400DA6239 /* sharedsobs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sharedsobs.h; path = source/calculators/sharedsobs.h; sourceTree = SOURCE_ROOT; }; A7E9B81712D37EC400DA6239 /* sharedsobscollectsummary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = sharedsobscollectsummary.cpp; path = source/calculators/sharedsobscollectsummary.cpp; sourceTree = SOURCE_ROOT; }; @@ -1706,6 +1819,8 @@ A7E9B83112D37EC400DA6239 /* slibshuff.h */, A7876A28152A018B00A0AE86 /* subsample.h */, A7876A25152A017C00A0AE86 /* subsample.cpp */, + 4889EA201E8962D50054E0BB /* summary.cpp */, + 4889EA211E8962D50054E0BB /* summary.hpp */, 7B17437A17AF6F02004C161B /* svm */, A7C3DC0E14FE469500FE1924 /* trialswap2.h */, A7C3DC0D14FE469500FE1924 /* trialSwap2.cpp */, @@ -1735,10 +1850,55 @@ name = Products; sourceTree = ""; }; + 480D1E2B1EA6858700BF9C77 /* fakes */ = { + isa = PBXGroup; + children = ( + 480D1E2D1EA685C500BF9C77 /* fakemcc.hpp */, + 48CC010E1EB79E49009D61E6 /* fakeoligos.h */, + 480D1E2F1EA92D5500BF9C77 /* fakeoptimatrix.cpp */, + 480D1E301EA92D5500BF9C77 /* fakeoptimatrix.hpp */, + ); + name = fakes; + sourceTree = ""; + }; 481FB51A1AC0A63E0076CFF3 /* TestMothur */ = { isa = PBXGroup; children = ( 481FB51B1AC0A63E0076CFF3 /* main.cpp */, + 480D1E2B1EA6858700BF9C77 /* fakes */, + 48E544101E92C49700FF6AB8 /* gtest-internal.h */, + 48E544111E92C49700FF6AB8 /* gtest-port.h */, + 48E544121E92C49700FF6AB8 /* gtest.h */, + 48E544131E92C49700FF6AB8 /* gtest-port.cc */, + 48E544151E92C49700FF6AB8 /* gtest.cc */, + 48E544161E92C49700FF6AB8 /* gtest-death-test.cc */, + 48E544171E92C49700FF6AB8 /* gtest-test-part.cc */, + 48E544181E92C49700FF6AB8 /* custom */, + 48E5441A1E92C49700FF6AB8 /* gtest_pred_impl.h */, + 48E5441B1E92C49700FF6AB8 /* gtest_prod.h */, + 48E5441C1E92C49700FF6AB8 /* gtest-death-test-internal.h */, + 48E5441D1E92C49700FF6AB8 /* gtest-death-test.h */, + 48E5441E1E92C49700FF6AB8 /* gtest-filepath.cc */, + 48E5441F1E92C49700FF6AB8 /* gtest-filepath.h */, + 48E544211E92C49700FF6AB8 /* gtest-linked_ptr.h */, + 48E544221E92C49700FF6AB8 /* gtest-message.h */, + 48E544231E92C49700FF6AB8 /* gtest-param-test.h */, + 48E544241E92C49700FF6AB8 /* gtest-param-test.h.pump */, + 48E544251E92C49700FF6AB8 /* gtest-param-util-generated.h */, + 48E544261E92C49700FF6AB8 /* gtest-param-util-generated.h.pump */, + 48E544271E92C49700FF6AB8 /* gtest-param-util.h */, + 48E544281E92C49700FF6AB8 /* gtest-port-arch.h */, + 48E544291E92C49700FF6AB8 /* gtest-printers.cc */, + 48E5442A1E92C49700FF6AB8 /* gtest-printers.h */, + 48E5442B1E92C49700FF6AB8 /* gtest-spi.h */, + 48E5442C1E92C49700FF6AB8 /* gtest-string.h */, + 48E5442D1E92C49700FF6AB8 /* gtest-test-part.h */, + 48E5442E1E92C49700FF6AB8 /* gtest-tuple.h */, + 48E5442F1E92C49700FF6AB8 /* gtest-tuple.h.pump */, + 48E544301E92C49700FF6AB8 /* gtest-type-util.h */, + 48E544311E92C49700FF6AB8 /* gtest-type-util.h.pump */, + 48E544321E92C49700FF6AB8 /* gtest-typed-test.cc */, + 48E544331E92C49700FF6AB8 /* gtest-typed-test.h */, 48F06CCA1D74BC6F004A45DD /* testclassifier */, 48D6E9691CA4262A008DF76B /* dataset.cpp */, 48D6E96A1CA4262A008DF76B /* dataset.h */, @@ -1748,8 +1908,10 @@ 48576EA71D05F59300BBC9C0 /* distpdataset.h */, 4827A4DA1CB3ED2100345170 /* fastqdataset.cpp */, 4827A4DB1CB3ED2100345170 /* fastqdataset.h */, - 48910D4D1D58E26C00F60EDB /* testopticluster.cpp */, + 480D1E281EA681D100BF9C77 /* testclustercalcs.cpp */, + 480D1E291EA681D100BF9C77 /* testclustercalcs.hpp */, 48910D4E1D58E26C00F60EDB /* testopticluster.h */, + 48910D4D1D58E26C00F60EDB /* testopticluster.cpp */, 4846AD881D3810DD00DE9913 /* testtrimoligos.cpp */, 4846AD891D3810DD00DE9913 /* testtrimoligos.hpp */, 48D6E9661CA42389008DF76B /* testvsearchfileparser.cpp */, @@ -1793,6 +1955,223 @@ name = testcontainers; sourceTree = ""; }; + 48E5443E1E9C28CC00FF6AB8 /* clustercalcs */ = { + isa = PBXGroup; + children = ( + 48E5446E1E9D3B2D00FF6AB8 /* accuracy.cpp */, + 48E5446F1E9D3B2D00FF6AB8 /* accuracy.hpp */, + 48E5446B1E9D3A8C00FF6AB8 /* f1score.hpp */, + 48E5446A1E9D3A8C00FF6AB8 /* f1score.cpp */, + 48E5447A1E9D3F0400FF6AB8 /* fdr.cpp */, + 48E5447B1E9D3F0400FF6AB8 /* fdr.hpp */, + 48E5445B1E9C2F0F00FF6AB8 /* fn.cpp */, + 48E5445C1E9C2F0F00FF6AB8 /* fn.hpp */, + 48E544581E9C2E6500FF6AB8 /* fp.hpp */, + 48E544571E9C2E6500FF6AB8 /* fp.cpp */, + 48E5445F1E9C2FB800FF6AB8 /* fpfn.cpp */, + 48E544601E9C2FB800FF6AB8 /* fpfn.hpp */, + 48E544401E9C292900FF6AB8 /* mcc.hpp */, + 48E5443F1E9C292900FF6AB8 /* mcc.cpp */, + 48E544761E9D3CE400FF6AB8 /* npv.cpp */, + 48E544771E9D3CE400FF6AB8 /* npv.hpp */, + 48E544721E9D3C1200FF6AB8 /* ppv.cpp */, + 48E544731E9D3C1200FF6AB8 /* ppv.hpp */, + 48E544431E9C2B1000FF6AB8 /* sensitivity.cpp */, + 48E544441E9C2B1000FF6AB8 /* sensitivity.hpp */, + 48E544471E9C2BE100FF6AB8 /* specificity.cpp */, + 48E544481E9C2BE100FF6AB8 /* specificity.hpp */, + 48E544531E9C2DF500FF6AB8 /* tn.cpp */, + 48E544541E9C2DF500FF6AB8 /* tn.hpp */, + 48E5444F1E9C2CFD00FF6AB8 /* tp.cpp */, + 48E544501E9C2CFD00FF6AB8 /* tp.hpp */, + 48E5444B1E9C2C8F00FF6AB8 /* tptn.cpp */, + 48E5444C1E9C2C8F00FF6AB8 /* tptn.hpp */, + ); + name = clustercalcs; + sourceTree = ""; + }; + 48E544661E9D12CA00FF6AB8 /* otucalcs */ = { + isa = PBXGroup; + children = ( + A7E9B79D12D37EC400DA6239 /* qstat.cpp */, + A7E9B79E12D37EC400DA6239 /* qstat.h */, + A7E9B7E512D37EC400DA6239 /* shannon.cpp */, + A7E9B7E612D37EC400DA6239 /* shannon.h */, + A7E9B7E712D37EC400DA6239 /* shannoneven.cpp */, + A7E9B7E812D37EC400DA6239 /* shannoneven.h */, + A7A09B0E18773BF700FAA081 /* shannonrange.h */, + A7A09B0F18773C0E00FAA081 /* shannonrange.cpp */, + A7E9B7EA12D37EC400DA6239 /* sharedace.h */, + A7E9B7E912D37EC400DA6239 /* sharedace.cpp */, + A7E9B7EC12D37EC400DA6239 /* sharedanderbergs.cpp */, + A7E9B7ED12D37EC400DA6239 /* sharedanderbergs.h */, + A7E9B7EE12D37EC400DA6239 /* sharedbraycurtis.cpp */, + A7E9B7EF12D37EC400DA6239 /* sharedbraycurtis.h */, + A7E9B7F012D37EC400DA6239 /* sharedchao1.cpp */, + A7E9B7F112D37EC400DA6239 /* sharedchao1.h */, + A7E9B7F412D37EC400DA6239 /* sharedjabund.cpp */, + A7E9B7F512D37EC400DA6239 /* sharedjabund.h */, + A7E9B7F612D37EC400DA6239 /* sharedjackknife.cpp */, + A7E9B7F712D37EC400DA6239 /* sharedjackknife.h */, + A7E9B64F12D37EC300DA6239 /* ace.cpp */, + A7E9B65012D37EC300DA6239 /* ace.h */, + A7E9B65E12D37EC300DA6239 /* bergerparker.cpp */, + A7E9B65F12D37EC300DA6239 /* bergerparker.h */, + A7E9B66612D37EC400DA6239 /* boneh.cpp */, + A7E9B66712D37EC400DA6239 /* boneh.h */, + A7E9B66812D37EC400DA6239 /* bootstrap.cpp */, + A7E9B66912D37EC400DA6239 /* bootstrap.h */, + A7E9B66C12D37EC400DA6239 /* bstick.cpp */, + A7E9B66D12D37EC400DA6239 /* bstick.h */, + A7E9B67012D37EC400DA6239 /* canberra.cpp */, + A7E9B67112D37EC400DA6239 /* canberra.h */, + A7E9B67612D37EC400DA6239 /* chao1.cpp */, + A7E9B67712D37EC400DA6239 /* chao1.h */, + A7E9B6BB12D37EC400DA6239 /* coverage.cpp */, + A7E9B6BC12D37EC400DA6239 /* coverage.h */, + A7E9B6D712D37EC400DA6239 /* efron.cpp */, + A7E9B6D812D37EC400DA6239 /* efron.h */, + A7E9B6F012D37EC400DA6239 /* geom.cpp */, + A7E9B6F112D37EC400DA6239 /* geom.h */, + A7E9B70E12D37EC400DA6239 /* goodscoverage.cpp */, + A7E9B70F12D37EC400DA6239 /* goodscoverage.h */, + A7E9B71212D37EC400DA6239 /* gower.cpp */, + A7E9B71312D37EC400DA6239 /* gower.h */, + A7E9B71612D37EC400DA6239 /* hamming.cpp */, + A7E9B71712D37EC400DA6239 /* hamming.h */, + A7E9B72412D37EC400DA6239 /* heip.cpp */, + A7E9B72512D37EC400DA6239 /* heip.h */, + A7E9B72612D37EC400DA6239 /* hellinger.cpp */, + A7E9B72712D37EC400DA6239 /* hellinger.h */, + A7E9B72F12D37EC400DA6239 /* invsimpson.cpp */, + A7E9B73012D37EC400DA6239 /* invsimpson.h */, + A7E9B73112D37EC400DA6239 /* jackknife.cpp */, + A7E9B73212D37EC400DA6239 /* jackknife.h */, + A7E9B74112D37EC400DA6239 /* logsd.cpp */, + A7E9B74212D37EC400DA6239 /* logsd.h */, + A7E9B74712D37EC400DA6239 /* manhattan.cpp */, + A7E9B74812D37EC400DA6239 /* manhattan.h */, + A7E9B74B12D37EC400DA6239 /* memchi2.cpp */, + A7E9B74C12D37EC400DA6239 /* memchi2.h */, + A7E9B74D12D37EC400DA6239 /* memchord.cpp */, + A7E9B74E12D37EC400DA6239 /* memchord.h */, + A7E9B74F12D37EC400DA6239 /* memeuclidean.cpp */, + A7E9B75012D37EC400DA6239 /* memeuclidean.h */, + A7E9B75112D37EC400DA6239 /* mempearson.cpp */, + A7E9B75212D37EC400DA6239 /* mempearson.h */, + A7E9B76D12D37EC400DA6239 /* npshannon.cpp */, + A7E9B76E12D37EC400DA6239 /* npshannon.h */, + A7E9B76F12D37EC400DA6239 /* nseqs.h */, + A7E9B77112D37EC400DA6239 /* odum.cpp */, + A7E9B77212D37EC400DA6239 /* odum.h */, + A7E9B7F812D37EC400DA6239 /* sharedjclass.cpp */, + A7E9B7F912D37EC400DA6239 /* sharedjclass.h */, + A7E9B7FA12D37EC400DA6239 /* sharedjest.cpp */, + A7E9B7FB12D37EC400DA6239 /* sharedjest.h */, + A7222D711856276C0055A993 /* sharedjsd.h */, + A7222D721856277C0055A993 /* sharedjsd.cpp */, + A7E9B7FC12D37EC400DA6239 /* sharedkstest.cpp */, + A7E9B7FD12D37EC400DA6239 /* sharedkstest.h */, + A7E9B7FE12D37EC400DA6239 /* sharedkulczynski.cpp */, + A7E9B7FF12D37EC400DA6239 /* sharedkulczynski.h */, + A7E9B80012D37EC400DA6239 /* sharedkulczynskicody.cpp */, + A7E9B80112D37EC400DA6239 /* sharedkulczynskicody.h */, + A7E9B80212D37EC400DA6239 /* sharedlennon.cpp */, + A7E9B80312D37EC400DA6239 /* sharedlennon.h */, + A7E9B80612D37EC400DA6239 /* sharedmarczewski.cpp */, + A7E9B80712D37EC400DA6239 /* sharedmarczewski.h */, + A7E9B80812D37EC400DA6239 /* sharedmorisitahorn.cpp */, + A7E9B80912D37EC400DA6239 /* sharedmorisitahorn.h */, + A7E9B80A12D37EC400DA6239 /* sharednseqs.h */, + A7E9B80B12D37EC400DA6239 /* sharedochiai.cpp */, + A7E9B80C12D37EC400DA6239 /* sharedochiai.h */, + 48705AC119BE32C50075E977 /* sharedrjsd.cpp */, + 48705AC219BE32C50075E977 /* sharedrjsd.h */, + A7E9B81512D37EC400DA6239 /* sharedsobs.cpp */, + A7E9B81612D37EC400DA6239 /* sharedsobs.h */, + A7E9B81712D37EC400DA6239 /* sharedsobscollectsummary.cpp */, + A7E9B81812D37EC400DA6239 /* sharedsobscollectsummary.h */, + A7E9B81912D37EC400DA6239 /* sharedsorabund.cpp */, + A7E9B81A12D37EC400DA6239 /* sharedsorabund.h */, + A7E9B81B12D37EC400DA6239 /* sharedsorclass.cpp */, + A7E9B81C12D37EC400DA6239 /* sharedsorclass.h */, + A7E9B81D12D37EC400DA6239 /* sharedsorest.cpp */, + A7E9B81E12D37EC400DA6239 /* sharedsorest.h */, + A7E9B81F12D37EC400DA6239 /* sharedthetan.cpp */, + A7E9B82012D37EC400DA6239 /* sharedthetan.h */, + A7E9B82112D37EC400DA6239 /* sharedthetayc.cpp */, + A7E9B82212D37EC400DA6239 /* sharedthetayc.h */, + A7E9B82512D37EC400DA6239 /* shen.cpp */, + A7E9B82612D37EC400DA6239 /* shen.h */, + A7E9B82912D37EC400DA6239 /* simpson.cpp */, + A7E9B82A12D37EC400DA6239 /* simpson.h */, + A7E9B82B12D37EC400DA6239 /* simpsoneven.cpp */, + A7E9B82C12D37EC400DA6239 /* simpsoneven.h */, + A7E9B83212D37EC400DA6239 /* smithwilson.cpp */, + A7E9B83312D37EC400DA6239 /* smithwilson.h */, + A7E9B83412D37EC400DA6239 /* sobs.h */, + A7E9B83512D37EC400DA6239 /* soergel.cpp */, + A7E9B83612D37EC400DA6239 /* soergel.h */, + A7E9B83712D37EC400DA6239 /* solow.cpp */, + A7E9B83812D37EC400DA6239 /* solow.h */, + A7E9B83B12D37EC400DA6239 /* spearman.cpp */, + A7E9B83C12D37EC400DA6239 /* spearman.h */, + A7E9B83D12D37EC400DA6239 /* speciesprofile.cpp */, + A7E9B83E12D37EC400DA6239 /* speciesprofile.h */, + A7E9B84512D37EC400DA6239 /* structchi2.cpp */, + A7E9B84612D37EC400DA6239 /* structchi2.h */, + A7E9B84712D37EC400DA6239 /* structchord.cpp */, + A7E9B84812D37EC400DA6239 /* structchord.h */, + A7E9B84912D37EC400DA6239 /* structeuclidean.cpp */, + A7E9B84A12D37EC400DA6239 /* structeuclidean.h */, + A7E9B84B12D37EC400DA6239 /* structkulczynski.cpp */, + A7E9B84C12D37EC400DA6239 /* structkulczynski.h */, + A7E9B84D12D37EC400DA6239 /* structpearson.cpp */, + A7E9B84E12D37EC400DA6239 /* structpearson.h */, + A7E9B87212D37EC400DA6239 /* uvest.cpp */, + A7E9B87312D37EC400DA6239 /* uvest.h */, + A7E9B87F12D37EC400DA6239 /* whittaker.cpp */, + A7E9B88012D37EC400DA6239 /* whittaker.h */, + ); + name = otucalcs; + sourceTree = SOURCE_ROOT; + }; + 48E544671E9D14C500FF6AB8 /* distcalcs */ = { + isa = PBXGroup; + children = ( + 7E78911B135F3E8600E725D2 /* eachgapdistignorens.h */, + A7E9B6D512D37EC400DA6239 /* eachgapdist.h */, + A7E9B6D612D37EC400DA6239 /* eachgapignore.h */, + A7E9B72A12D37EC400DA6239 /* ignoregaps.h */, + A7E9B77312D37EC400DA6239 /* onegapdist.h */, + A7E9B77412D37EC400DA6239 /* onegapignore.h */, + ); + name = distcalcs; + sourceTree = ""; + }; + 48E544681E9D175100FF6AB8 /* unifraccalcs */ = { + isa = PBXGroup; + children = ( + A7E9B78412D37EC400DA6239 /* parsimony.h */, + A7E9B78312D37EC400DA6239 /* parsimony.cpp */, + A7E9B87112D37EC400DA6239 /* unweighted.h */, + A7E9B87012D37EC400DA6239 /* unweighted.cpp */, + A7E9B87D12D37EC400DA6239 /* weighted.h */, + A7E9B87C12D37EC400DA6239 /* weighted.cpp */, + ); + name = unifraccalcs; + sourceTree = ""; + }; + 48E544691E9D17E000FF6AB8 /* clearcutcalcs */ = { + isa = PBXGroup; + children = ( + A7E9B6C012D37EC400DA6239 /* dayhoff.h */, + A7E9B79912D37EC400DA6239 /* prng.cpp */, + A7E9B79A12D37EC400DA6239 /* prng.h */, + ); + name = clearcutcalcs; + sourceTree = ""; + }; 48F06CCA1D74BC6F004A45DD /* testclassifier */ = { isa = PBXGroup; children = ( @@ -2149,165 +2528,14 @@ A7E9BA3F12D395F700DA6239 /* calculators */ = { isa = PBXGroup; children = ( - 7E78911B135F3E8600E725D2 /* eachgapdistignorens.h */, - A7E9B64F12D37EC300DA6239 /* ace.cpp */, - A7E9B65012D37EC300DA6239 /* ace.h */, - A7E9B65E12D37EC300DA6239 /* bergerparker.cpp */, - A7E9B65F12D37EC300DA6239 /* bergerparker.h */, - A7E9B66612D37EC400DA6239 /* boneh.cpp */, - A7E9B66712D37EC400DA6239 /* boneh.h */, - A7E9B66812D37EC400DA6239 /* bootstrap.cpp */, - A7E9B66912D37EC400DA6239 /* bootstrap.h */, - A7E9B66C12D37EC400DA6239 /* bstick.cpp */, - A7E9B66D12D37EC400DA6239 /* bstick.h */, - A7E9B66E12D37EC400DA6239 /* calculator.cpp */, A7E9B66F12D37EC400DA6239 /* calculator.h */, - A7E9B67012D37EC400DA6239 /* canberra.cpp */, - A7E9B67112D37EC400DA6239 /* canberra.h */, - A7E9B67612D37EC400DA6239 /* chao1.cpp */, - A7E9B67712D37EC400DA6239 /* chao1.h */, - A7E9B6BB12D37EC400DA6239 /* coverage.cpp */, - A7E9B6BC12D37EC400DA6239 /* coverage.h */, - A7E9B6CA12D37EC400DA6239 /* dist.h */, - A7E9B6C012D37EC400DA6239 /* dayhoff.h */, - A7E9B6D512D37EC400DA6239 /* eachgapdist.h */, - A7E9B6D612D37EC400DA6239 /* eachgapignore.h */, - A7E9B6D712D37EC400DA6239 /* efron.cpp */, - A7E9B6D812D37EC400DA6239 /* efron.h */, A7E9B6E212D37EC400DA6239 /* filters.h */, - A7E9B6F012D37EC400DA6239 /* geom.cpp */, - A7E9B6F112D37EC400DA6239 /* geom.h */, - A7E9B70E12D37EC400DA6239 /* goodscoverage.cpp */, - A7E9B70F12D37EC400DA6239 /* goodscoverage.h */, - A7E9B71212D37EC400DA6239 /* gower.cpp */, - A7E9B71312D37EC400DA6239 /* gower.h */, - A7E9B71612D37EC400DA6239 /* hamming.cpp */, - A7E9B71712D37EC400DA6239 /* hamming.h */, - A7E9B72412D37EC400DA6239 /* heip.cpp */, - A7E9B72512D37EC400DA6239 /* heip.h */, - A7E9B72612D37EC400DA6239 /* hellinger.cpp */, - A7E9B72712D37EC400DA6239 /* hellinger.h */, - A7E9B72A12D37EC400DA6239 /* ignoregaps.h */, - A7E9B72F12D37EC400DA6239 /* invsimpson.cpp */, - A7E9B73012D37EC400DA6239 /* invsimpson.h */, - A7E9B73112D37EC400DA6239 /* jackknife.cpp */, - A7E9B73212D37EC400DA6239 /* jackknife.h */, - A7E9B74112D37EC400DA6239 /* logsd.cpp */, - A7E9B74212D37EC400DA6239 /* logsd.h */, - A7E9B74712D37EC400DA6239 /* manhattan.cpp */, - A7E9B74812D37EC400DA6239 /* manhattan.h */, - A7E9B74B12D37EC400DA6239 /* memchi2.cpp */, - A7E9B74C12D37EC400DA6239 /* memchi2.h */, - A7E9B74D12D37EC400DA6239 /* memchord.cpp */, - A7E9B74E12D37EC400DA6239 /* memchord.h */, - A7E9B74F12D37EC400DA6239 /* memeuclidean.cpp */, - A7E9B75012D37EC400DA6239 /* memeuclidean.h */, - A7E9B75112D37EC400DA6239 /* mempearson.cpp */, - A7E9B75212D37EC400DA6239 /* mempearson.h */, - A7E9B76D12D37EC400DA6239 /* npshannon.cpp */, - A7E9B76E12D37EC400DA6239 /* npshannon.h */, - A7E9B76F12D37EC400DA6239 /* nseqs.h */, - A7E9B77112D37EC400DA6239 /* odum.cpp */, - A7E9B77212D37EC400DA6239 /* odum.h */, - A7E9B77312D37EC400DA6239 /* onegapdist.h */, - A7E9B77412D37EC400DA6239 /* onegapignore.h */, - A7E9B78412D37EC400DA6239 /* parsimony.h */, - A7E9B78312D37EC400DA6239 /* parsimony.cpp */, - A7E9B79912D37EC400DA6239 /* prng.cpp */, - A7E9B79A12D37EC400DA6239 /* prng.h */, - A7E9B79D12D37EC400DA6239 /* qstat.cpp */, - A7E9B79E12D37EC400DA6239 /* qstat.h */, - A7E9B7E512D37EC400DA6239 /* shannon.cpp */, - A7E9B7E612D37EC400DA6239 /* shannon.h */, - A7E9B7E712D37EC400DA6239 /* shannoneven.cpp */, - A7E9B7E812D37EC400DA6239 /* shannoneven.h */, - A7A09B0E18773BF700FAA081 /* shannonrange.h */, - A7A09B0F18773C0E00FAA081 /* shannonrange.cpp */, - A7E9B7E912D37EC400DA6239 /* sharedace.cpp */, - A7E9B7F412D37EC400DA6239 /* sharedjabund.cpp */, - A7E9B7EA12D37EC400DA6239 /* sharedace.h */, - A7E9B7EC12D37EC400DA6239 /* sharedanderbergs.cpp */, - A7E9B7ED12D37EC400DA6239 /* sharedanderbergs.h */, - A7E9B7EE12D37EC400DA6239 /* sharedbraycurtis.cpp */, - A7E9B7EF12D37EC400DA6239 /* sharedbraycurtis.h */, - A7E9B7F012D37EC400DA6239 /* sharedchao1.cpp */, - A7E9B7F112D37EC400DA6239 /* sharedchao1.h */, - A7E9B7F512D37EC400DA6239 /* sharedjabund.h */, - A7E9B7F612D37EC400DA6239 /* sharedjackknife.cpp */, - A7E9B7F712D37EC400DA6239 /* sharedjackknife.h */, - A7E9B7F812D37EC400DA6239 /* sharedjclass.cpp */, - A7E9B7F912D37EC400DA6239 /* sharedjclass.h */, - A7E9B7FA12D37EC400DA6239 /* sharedjest.cpp */, - A7E9B7FB12D37EC400DA6239 /* sharedjest.h */, - A7222D711856276C0055A993 /* sharedjsd.h */, - A7222D721856277C0055A993 /* sharedjsd.cpp */, - A7E9B7FC12D37EC400DA6239 /* sharedkstest.cpp */, - A7E9B7FD12D37EC400DA6239 /* sharedkstest.h */, - A7E9B7FE12D37EC400DA6239 /* sharedkulczynski.cpp */, - A7E9B7FF12D37EC400DA6239 /* sharedkulczynski.h */, - A7E9B80012D37EC400DA6239 /* sharedkulczynskicody.cpp */, - A7E9B80112D37EC400DA6239 /* sharedkulczynskicody.h */, - A7E9B80212D37EC400DA6239 /* sharedlennon.cpp */, - A7E9B80312D37EC400DA6239 /* sharedlennon.h */, - A7E9B80612D37EC400DA6239 /* sharedmarczewski.cpp */, - A7E9B80712D37EC400DA6239 /* sharedmarczewski.h */, - A7E9B80812D37EC400DA6239 /* sharedmorisitahorn.cpp */, - A7E9B80912D37EC400DA6239 /* sharedmorisitahorn.h */, - A7E9B80A12D37EC400DA6239 /* sharednseqs.h */, - A7E9B80B12D37EC400DA6239 /* sharedochiai.cpp */, - A7E9B80C12D37EC400DA6239 /* sharedochiai.h */, - 48705AC119BE32C50075E977 /* sharedrjsd.cpp */, - 48705AC219BE32C50075E977 /* sharedrjsd.h */, - A7E9B81512D37EC400DA6239 /* sharedsobs.cpp */, - A7E9B81612D37EC400DA6239 /* sharedsobs.h */, - A7E9B81712D37EC400DA6239 /* sharedsobscollectsummary.cpp */, - A7E9B81812D37EC400DA6239 /* sharedsobscollectsummary.h */, - A7E9B81912D37EC400DA6239 /* sharedsorabund.cpp */, - A7E9B81A12D37EC400DA6239 /* sharedsorabund.h */, - A7E9B81B12D37EC400DA6239 /* sharedsorclass.cpp */, - A7E9B81C12D37EC400DA6239 /* sharedsorclass.h */, - A7E9B81D12D37EC400DA6239 /* sharedsorest.cpp */, - A7E9B81E12D37EC400DA6239 /* sharedsorest.h */, - A7E9B81F12D37EC400DA6239 /* sharedthetan.cpp */, - A7E9B82012D37EC400DA6239 /* sharedthetan.h */, - A7E9B82112D37EC400DA6239 /* sharedthetayc.cpp */, - A7E9B82212D37EC400DA6239 /* sharedthetayc.h */, - A7E9B82512D37EC400DA6239 /* shen.cpp */, - A7E9B82612D37EC400DA6239 /* shen.h */, - A7E9B82912D37EC400DA6239 /* simpson.cpp */, - A7E9B82A12D37EC400DA6239 /* simpson.h */, - A7E9B82B12D37EC400DA6239 /* simpsoneven.cpp */, - A7E9B82C12D37EC400DA6239 /* simpsoneven.h */, - A7E9B83212D37EC400DA6239 /* smithwilson.cpp */, - A7E9B83312D37EC400DA6239 /* smithwilson.h */, - A7E9B83412D37EC400DA6239 /* sobs.h */, - A7E9B83512D37EC400DA6239 /* soergel.cpp */, - A7E9B83612D37EC400DA6239 /* soergel.h */, - A7E9B83712D37EC400DA6239 /* solow.cpp */, - A7E9B83812D37EC400DA6239 /* solow.h */, - A7E9B83B12D37EC400DA6239 /* spearman.cpp */, - A7E9B83C12D37EC400DA6239 /* spearman.h */, - A7E9B83D12D37EC400DA6239 /* speciesprofile.cpp */, - A7E9B83E12D37EC400DA6239 /* speciesprofile.h */, - A7E9B84512D37EC400DA6239 /* structchi2.cpp */, - A7E9B84612D37EC400DA6239 /* structchi2.h */, - A7E9B84712D37EC400DA6239 /* structchord.cpp */, - A7E9B84812D37EC400DA6239 /* structchord.h */, - A7E9B84912D37EC400DA6239 /* structeuclidean.cpp */, - A7E9B84A12D37EC400DA6239 /* structeuclidean.h */, - A7E9B84B12D37EC400DA6239 /* structkulczynski.cpp */, - A7E9B84C12D37EC400DA6239 /* structkulczynski.h */, - A7E9B84D12D37EC400DA6239 /* structpearson.cpp */, - A7E9B84E12D37EC400DA6239 /* structpearson.h */, A7E9B86112D37EC400DA6239 /* treecalculator.h */, - A7E9B87112D37EC400DA6239 /* unweighted.h */, - A7E9B87012D37EC400DA6239 /* unweighted.cpp */, - A7E9B87212D37EC400DA6239 /* uvest.cpp */, - A7E9B87312D37EC400DA6239 /* uvest.h */, - A7E9B87D12D37EC400DA6239 /* weighted.h */, - A7E9B87C12D37EC400DA6239 /* weighted.cpp */, - A7E9B87F12D37EC400DA6239 /* whittaker.cpp */, - A7E9B88012D37EC400DA6239 /* whittaker.h */, + 48E544691E9D17E000FF6AB8 /* clearcutcalcs */, + 48E544671E9D14C500FF6AB8 /* distcalcs */, + 48E5443E1E9C28CC00FF6AB8 /* clustercalcs */, + 48E544661E9D12CA00FF6AB8 /* otucalcs */, + 48E544681E9D175100FF6AB8 /* unifraccalcs */, ); name = calculators; path = /Users/sarahwestcott/Desktop/mothur; @@ -2364,6 +2592,8 @@ A7E9B77812D37EC400DA6239 /* ordervector.hpp */, A7E9B79F12D37EC400DA6239 /* qualityscores.cpp */, A7E9B7A012D37EC400DA6239 /* qualityscores.h */, + 48BDDA771ECA3B8E00F0F6C0 /* rabundfloatvector.cpp */, + 48BDDA781ECA3B8E00F0F6C0 /* rabundfloatvector.hpp */, A7E9B7A312D37EC400DA6239 /* rabundvector.cpp */, A7E9B7A412D37EC400DA6239 /* rabundvector.hpp */, A7E9B7CB12D37EC400DA6239 /* reportfile.cpp */, @@ -2382,12 +2612,14 @@ A7E9B80512D37EC400DA6239 /* sharedlistvector.h */, A7E9B80E12D37EC400DA6239 /* sharedordervector.h */, A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */, - A7E9B81012D37EC400DA6239 /* sharedrabundfloatvector.h */, - A7E9B80F12D37EC400DA6239 /* sharedrabundfloatvector.cpp */, - A7E9B81112D37EC400DA6239 /* sharedrabundvector.cpp */, - A7E9B81212D37EC400DA6239 /* sharedrabundvector.h */, - A7E9B81312D37EC400DA6239 /* sharedsabundvector.cpp */, - A7E9B81412D37EC400DA6239 /* sharedsabundvector.h */, + 48BDDA731ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp */, + 48BDDA741ECA067000F0F6C0 /* sharedrabundfloatvectors.hpp */, + 485B0E061F264F2E00CA5F57 /* sharedrabundvector.cpp */, + 485B0E071F264F2E00CA5F57 /* sharedrabundvector.hpp */, + 485B0E0C1F27C40500CA5F57 /* sharedrabundfloatvector.cpp */, + 485B0E0D1F27C40500CA5F57 /* sharedrabundfloatvector.hpp */, + 48BDDA6F1EC9D31400F0F6C0 /* sharedrabundvectors.cpp */, + 48BDDA701EC9D31400F0F6C0 /* sharedrabundvectors.hpp */, A7E9B83912D37EC400DA6239 /* sparsematrix.cpp */, A7E9B83A12D37EC400DA6239 /* sparsematrix.hpp */, A7E0243F15B4522000A5F046 /* sparsedistancematrix.h */, @@ -2611,6 +2843,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 48E544421E9C292900FF6AB8 /* mcc.cpp in Sources */, 48C728651B66A77800D40830 /* testsequence.cpp in Sources */, 481FB5E51AC1B77E0076CFF3 /* nocommands.cpp in Sources */, 481FB5F61AC1B77E0076CFF3 /* quitcommand.cpp in Sources */, @@ -2621,6 +2854,7 @@ 481FB6351AC1B7EA0076CFF3 /* kmerdb.cpp in Sources */, 481FB5721AC1B6D40076CFF3 /* simpson.cpp in Sources */, 481FB55D1AC1B6690076CFF3 /* sharedchao1.cpp in Sources */, + 48BDDA7A1ECA3B8E00F0F6C0 /* rabundfloatvector.cpp in Sources */, 481FB5FE1AC1B7970076CFF3 /* removerarecommand.cpp in Sources */, 481FB53C1AC1B5F10076CFF3 /* bootstrap.cpp in Sources */, 481FB5E21AC1B77E0076CFF3 /* metastatscommand.cpp in Sources */, @@ -2649,6 +2883,8 @@ 481FB5C01AC1B74F0076CFF3 /* getlineagecommand.cpp in Sources */, 481FB5F71AC1B77E0076CFF3 /* rarefactcommand.cpp in Sources */, 481FB61F1AC1B7AC0076CFF3 /* venncommand.cpp in Sources */, + 480D1E311EA92D5500BF9C77 /* fakeoptimatrix.cpp in Sources */, + 48E5445A1E9C2E6500FF6AB8 /* fp.cpp in Sources */, 481FB61A1AC1B7AC0076CFF3 /* treegroupscommand.cpp in Sources */, 481FB66B1AC1B8520076CFF3 /* decisiontree.cpp in Sources */, 481FB60A1AC1B7970076CFF3 /* sffinfocommand.cpp in Sources */, @@ -2656,11 +2892,14 @@ 481FB6531AC1B8100076CFF3 /* gotohoverlap.cpp in Sources */, 481FB66D1AC1B8520076CFF3 /* rftreenode.cpp in Sources */, 481FB65B1AC1B82C0076CFF3 /* mothurfisher.cpp in Sources */, + 48E5445E1E9C2F0F00FF6AB8 /* fn.cpp in Sources */, 481FB6721AC1B8820076CFF3 /* refchimeratest.cpp in Sources */, 481FB6051AC1B7970076CFF3 /* seqerrorcommand.cpp in Sources */, 481FB6871AC1B8B80076CFF3 /* venn.cpp in Sources */, + 48E544791E9D3CE400FF6AB8 /* npv.cpp in Sources */, 481FB5D71AC1B75C0076CFF3 /* makebiomcommand.cpp in Sources */, 481FB6601AC1B8450076CFF3 /* nast.cpp in Sources */, + 48E544461E9C2B1000FF6AB8 /* sensitivity.cpp in Sources */, 481FB5861AC1B6FF0076CFF3 /* chimerarealigner.cpp in Sources */, 481FB5A81AC1B7300076CFF3 /* collectcommand.cpp in Sources */, 481FB5961AC1B71B0076CFF3 /* chimeraccodecommand.cpp in Sources */, @@ -2674,6 +2913,7 @@ 481FB63F1AC1B7EA0076CFF3 /* sequencecountparser.cpp in Sources */, 481FB67E1AC1B8960076CFF3 /* sharedutilities.cpp in Sources */, 481FB67C1AC1B88F0076CFF3 /* splitmatrix.cpp in Sources */, + 48E5447D1E9D3F0400FF6AB8 /* fdr.cpp in Sources */, 481FB59C1AC1B71B0076CFF3 /* chopseqscommand.cpp in Sources */, 481FB5DE1AC1B77E0076CFF3 /* mergesfffilecommand.cpp in Sources */, 481FB6421AC1B7EA0076CFF3 /* sharedlistvector.cpp in Sources */, @@ -2685,11 +2925,15 @@ 481FB5B81AC1B74F0076CFF3 /* getcoremicrobiomecommand.cpp in Sources */, 481FB54E1AC1B6340076CFF3 /* memchord.cpp in Sources */, 481FB6021AC1B7970076CFF3 /* screenseqscommand.cpp in Sources */, + 48E544621E9C2FB800FF6AB8 /* fpfn.cpp in Sources */, + 48E543EC1E8F15B800FF6AB8 /* opticluster.cpp in Sources */, 481FB52E1AC1B0CB0076CFF3 /* testsetseedcommand.cpp in Sources */, 481FB65A1AC1B8100076CFF3 /* wilcox.cpp in Sources */, + 48E5443C1E92C49700FF6AB8 /* gtest-typed-test.cc in Sources */, 481FB6251AC1B7EA0076CFF3 /* alignment.cpp in Sources */, 481FB5C51AC1B74F0076CFF3 /* getrabundcommand.cpp in Sources */, 481FB56E1AC1B6C30076CFF3 /* sharedsorest.cpp in Sources */, + 48E544751E9D3C1200FF6AB8 /* ppv.cpp in Sources */, 481FB6161AC1B7AC0076CFF3 /* summaryqualcommand.cpp in Sources */, 481FB56F1AC1B6C70076CFF3 /* sharedthetan.cpp in Sources */, 481FB5B21AC1B7300076CFF3 /* deuniqueseqscommand.cpp in Sources */, @@ -2715,12 +2959,14 @@ 480E8DB21CAB1F5E00A0D137 /* vsearchfileparser.cpp in Sources */, 481FB61E1AC1B7AC0076CFF3 /* unifracweightedcommand.cpp in Sources */, 48910D441D5243E500F60EDB /* mergecountcommand.cpp in Sources */, + 48E544341E92C49700FF6AB8 /* gtest-port.cc in Sources */, 481FB5951AC1B71B0076CFF3 /* chimerabellerophoncommand.cpp in Sources */, 481FB68D1AC1BA9E0076CFF3 /* classify.cpp in Sources */, 481FB65F1AC1B8450076CFF3 /* myseqdist.cpp in Sources */, 48C728751B6AB4CD00D40830 /* testgetgroupscommand.cpp in Sources */, 481FB6391AC1B7EA0076CFF3 /* ordervector.cpp in Sources */, 481FB59A1AC1B71B0076CFF3 /* chimeraslayercommand.cpp in Sources */, + 48E543EB1E8F15A500FF6AB8 /* summary.cpp in Sources */, 481FB5901AC1B71B0076CFF3 /* aligncommand.cpp in Sources */, 481FB6081AC1B7970076CFF3 /* setdircommand.cpp in Sources */, 481FB62C1AC1B7EA0076CFF3 /* designmap.cpp in Sources */, @@ -2733,6 +2979,7 @@ 481FB6641AC1B8450076CFF3 /* optionparser.cpp in Sources */, 481FB68B1AC1BA9E0076CFF3 /* aligntree.cpp in Sources */, 481FB5FB1AC1B77E0076CFF3 /* removelineagecommand.cpp in Sources */, + 48E5446D1E9D3A8C00FF6AB8 /* f1score.cpp in Sources */, 481FB57A1AC1B6EA0076CFF3 /* structchord.cpp in Sources */, 481FB6651AC1B8450076CFF3 /* overlap.cpp in Sources */, 481FB6841AC1B8B80076CFF3 /* trimoligos.cpp in Sources */, @@ -2763,8 +3010,10 @@ 481FB6171AC1B7AC0076CFF3 /* summarysharedcommand.cpp in Sources */, 481FB68C1AC1BA9E0076CFF3 /* bayesian.cpp in Sources */, 481FB5F41AC1B77E0076CFF3 /* preclustercommand.cpp in Sources */, + 48E543ED1E8F15C800FF6AB8 /* optimatrix.cpp in Sources */, 481FB5911AC1B71B0076CFF3 /* amovacommand.cpp in Sources */, 4829D9671B8387D0002EEED4 /* testbiominfocommand.cpp in Sources */, + 48BDDA721EC9D31400F0F6C0 /* sharedrabundvectors.cpp in Sources */, 481FB58A1AC1B6FF0076CFF3 /* myPerseus.cpp in Sources */, 487D09EC1CB2CEFE007039BF /* averagelinkage.cpp in Sources */, 481FB63E1AC1B7EA0076CFF3 /* sabundvector.cpp in Sources */, @@ -2777,6 +3026,7 @@ 481FB5CE1AC1B75C0076CFF3 /* homovacommand.cpp in Sources */, 481FB6551AC1B8100076CFF3 /* heatmap.cpp in Sources */, 481FB5E61AC1B77E0076CFF3 /* normalizesharedcommand.cpp in Sources */, + 48E5444E1E9C2C8F00FF6AB8 /* tptn.cpp in Sources */, 481FB5E71AC1B77E0076CFF3 /* nmdscommand.cpp in Sources */, 481FB52B1AC1B09F0076CFF3 /* setseedcommand.cpp in Sources */, 481FB5261AC0ADA00076CFF3 /* sequence.cpp in Sources */, @@ -2788,6 +3038,7 @@ 48C7286A1B69598400D40830 /* testmergegroupscommand.cpp in Sources */, 481FB62F1AC1B7EA0076CFF3 /* fastqread.cpp in Sources */, 481FB6901AC1BA9E0076CFF3 /* knn.cpp in Sources */, + 48E5444A1E9C2BE100FF6AB8 /* specificity.cpp in Sources */, 481FB5941AC1B71B0076CFF3 /* catchallcommand.cpp in Sources */, 481FB56C1AC1B6BE0076CFF3 /* sharedsorabund.cpp in Sources */, 481FB6411AC1B7EA0076CFF3 /* sequenceparser.cpp in Sources */, @@ -2820,6 +3071,7 @@ 481FB5AA1AC1B7300076CFF3 /* consensusseqscommand.cpp in Sources */, 481FB5AE1AC1B7300076CFF3 /* countseqscommand.cpp in Sources */, 48C7287A1B728D6B00D40830 /* biominfocommand.cpp in Sources */, + 48E544361E92C49700FF6AB8 /* gtest.cc in Sources */, 481FB5811AC1B6EA0076CFF3 /* whittaker.cpp in Sources */, 481FB58E1AC1B7060076CFF3 /* completelinkage.cpp in Sources */, 481FB6301AC1B7EA0076CFF3 /* flowdata.cpp in Sources */, @@ -2830,12 +3082,14 @@ 481FB5E01AC1B77E0076CFF3 /* mergegroupscommand.cpp in Sources */, 481FB56B1AC1B6BB0076CFF3 /* sharedsobscollectsummary.cpp in Sources */, 481FB57F1AC1B6EA0076CFF3 /* uvest.cpp in Sources */, + 48E543EE1E92B91100FF6AB8 /* chimeravsearchcommand.cpp in Sources */, 481FB5791AC1B6EA0076CFF3 /* structchi2.cpp in Sources */, 481FB63B1AC1B7EA0076CFF3 /* rabundvector.cpp in Sources */, 481FB5A91AC1B7300076CFF3 /* collectsharedcommand.cpp in Sources */, 481FB6211AC1B7BA0076CFF3 /* communitytype.cpp in Sources */, 48910D521D58E26C00F60EDB /* distcdataset.cpp in Sources */, 48C1DDC61D25C1BC00B5BA9D /* (null) in Sources */, + 48E544711E9D3B2D00FF6AB8 /* accuracy.cpp in Sources */, 481FB5621AC1B69E0076CFF3 /* sharedkstest.cpp in Sources */, 481FB5E91AC1B77E0076CFF3 /* otuhierarchycommand.cpp in Sources */, 481FB5351AC1B5D90076CFF3 /* fasta.cpp in Sources */, @@ -2849,6 +3103,7 @@ 481FB56A1AC1B6B80076CFF3 /* sharedsobs.cpp in Sources */, 481FB6671AC1B8450076CFF3 /* randomnumber.cpp in Sources */, 481FB5DB1AC1B75C0076CFF3 /* makelefsecommand.cpp in Sources */, + 48E544561E9C2DF500FF6AB8 /* tn.cpp in Sources */, 481FB6371AC1B7EA0076CFF3 /* nameassignment.cpp in Sources */, 481FB5D21AC1B75C0076CFF3 /* libshuffcommand.cpp in Sources */, 481FB5561AC1B6520076CFF3 /* shannon.cpp in Sources */, @@ -2859,10 +3114,10 @@ 481FB5BA1AC1B74F0076CFF3 /* getdistscommand.cpp in Sources */, 481FB6191AC1B7AC0076CFF3 /* systemcommand.cpp in Sources */, 481FB6611AC1B8450076CFF3 /* nastreport.cpp in Sources */, + 48E5443B1E92C49700FF6AB8 /* gtest-printers.cc in Sources */, 48DB37B41B3B27E000C372A4 /* makefilecommand.cpp in Sources */, 481FB6181AC1B7AC0076CFF3 /* summarytaxcommand.cpp in Sources */, 481FB5CD1AC1B74F0076CFF3 /* helpcommand.cpp in Sources */, - 481FB6451AC1B7EA0076CFF3 /* sharedrabundvector.cpp in Sources */, 481FB6701AC1B8820076CFF3 /* raredisplay.cpp in Sources */, 481FB5F91AC1B77E0076CFF3 /* removedistscommand.cpp in Sources */, 481FB6581AC1B8100076CFF3 /* libshuff.cpp in Sources */, @@ -2872,12 +3127,13 @@ 481FB5591AC1B65D0076CFF3 /* sharedjabund.cpp in Sources */, 481FB62A1AC1B7EA0076CFF3 /* counttable.cpp in Sources */, 481FB53A1AC1B5EC0076CFF3 /* bergerparker.cpp in Sources */, + 48E544521E9C2CFD00FF6AB8 /* tp.cpp in Sources */, 481FB6751AC1B88F0076CFF3 /* formatphylip.cpp in Sources */, 481FB5AD1AC1B7300076CFF3 /* countgroupscommand.cpp in Sources */, 481FB61C1AC1B7AC0076CFF3 /* trimseqscommand.cpp in Sources */, 481FB5311AC1B5CD0076CFF3 /* clearcut.cpp in Sources */, + 480D1E2A1EA681D100BF9C77 /* testclustercalcs.cpp in Sources */, 481FB5651AC1B6A70076CFF3 /* sharedlennon.cpp in Sources */, - 481FB53E1AC1B5FC0076CFF3 /* calculator.cpp in Sources */, 481FB6241AC1B7BA0076CFF3 /* qFinderDMM.cpp in Sources */, 481FB6311AC1B7EA0076CFF3 /* fullmatrix.cpp in Sources */, 481FB51C1AC0A63E0076CFF3 /* main.cpp in Sources */, @@ -2912,6 +3168,7 @@ 481FB6801AC1B8960076CFF3 /* slibshuff.cpp in Sources */, 481FB67B1AC1B88F0076CFF3 /* readphylipvector.cpp in Sources */, 481FB64C1AC1B7F40076CFF3 /* tree.cpp in Sources */, + 48E5443A1E92C49700FF6AB8 /* gtest-filepath.cc in Sources */, 481FB6631AC1B8450076CFF3 /* needlemanoverlap.cpp in Sources */, 481FB6931AC1BAA60076CFF3 /* taxonomynode.cpp in Sources */, 481FB60E1AC1B7AC0076CFF3 /* shhhseqscommand.cpp in Sources */, @@ -2936,8 +3193,10 @@ 481FB6101AC1B7AC0076CFF3 /* sparcccommand.cpp in Sources */, 481FB5E81AC1B77E0076CFF3 /* otuassociationcommand.cpp in Sources */, 481FB5B31AC1B7300076CFF3 /* deuniquetreecommand.cpp in Sources */, + 48E544381E92C49700FF6AB8 /* gtest-test-part.cc in Sources */, 481FB5D91AC1B75C0076CFF3 /* makefastqcommand.cpp in Sources */, 481FB5A21AC1B71B0076CFF3 /* clearcutcommand.cpp in Sources */, + 48E544371E92C49700FF6AB8 /* gtest-death-test.cc in Sources */, 48D6E9681CA42389008DF76B /* testvsearchfileparser.cpp in Sources */, 481FB5851AC1B6FF0076CFF3 /* chimeracheckrdp.cpp in Sources */, 481FB55C1AC1B6660076CFF3 /* sharedbraycurtis.cpp in Sources */, @@ -2956,17 +3215,16 @@ 481FB6151AC1B7AC0076CFF3 /* summarycommand.cpp in Sources */, 481FB5EE1AC1B77E0076CFF3 /* pcacommand.cpp in Sources */, 481FB5B71AC1B74F0076CFF3 /* getcommandinfocommand.cpp in Sources */, + 48BDDA761ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp in Sources */, 481FB5711AC1B6D40076CFF3 /* shen.cpp in Sources */, 481FB6501AC1B8100076CFF3 /* dlibshuff.cpp in Sources */, 481FB64D1AC1B7F40076CFF3 /* treemap.cpp in Sources */, 481FB67F1AC1B8960076CFF3 /* singlelinkage.cpp in Sources */, 481FB5641AC1B6A40076CFF3 /* sharedkulczynskicody.cpp in Sources */, - 481FB6461AC1B7EA0076CFF3 /* sharedsabundvector.cpp in Sources */, 481FB60D1AC1B7AC0076CFF3 /* shhhercommand.cpp in Sources */, 481FB5FA1AC1B77E0076CFF3 /* removegroupscommand.cpp in Sources */, 481FB5371AC1B5E00076CFF3 /* cluster.cpp in Sources */, 481FB53B1AC1B5EF0076CFF3 /* boneh.cpp in Sources */, - 481FB6441AC1B7EA0076CFF3 /* sharedrabundfloatvector.cpp in Sources */, 481FB6071AC1B7970076CFF3 /* setcurrentcommand.cpp in Sources */, 481FB5321AC1B5D00076CFF3 /* cmdargs.cpp in Sources */, 481FB6711AC1B8820076CFF3 /* rarefact.cpp in Sources */, @@ -3008,7 +3266,6 @@ A7E9B88D12D37EC400DA6239 /* boneh.cpp in Sources */, A7E9B88E12D37EC400DA6239 /* bootstrap.cpp in Sources */, A7E9B89012D37EC400DA6239 /* bstick.cpp in Sources */, - A7E9B89112D37EC400DA6239 /* calculator.cpp in Sources */, A7E9B89212D37EC400DA6239 /* canberra.cpp in Sources */, A7E9B89312D37EC400DA6239 /* catchallcommand.cpp in Sources */, A7E9B89412D37EC400DA6239 /* ccode.cpp in Sources */, @@ -3038,6 +3295,7 @@ A7E9B8AA12D37EC400DA6239 /* clusterfragmentscommand.cpp in Sources */, 48EDB76C1D1320DD00F76E93 /* chimeravsearchcommand.cpp in Sources */, A7E9B8AB12D37EC400DA6239 /* clustersplitcommand.cpp in Sources */, + 48E5446C1E9D3A8C00FF6AB8 /* f1score.cpp in Sources */, A7E9B8AC12D37EC400DA6239 /* cmdargs.cpp in Sources */, A7E9B8AD12D37EC400DA6239 /* collect.cpp in Sources */, A7E9B8AE12D37EC400DA6239 /* collectcommand.cpp in Sources */, @@ -3062,6 +3320,7 @@ A7E9B8C212D37EC400DA6239 /* engine.cpp in Sources */, A7E9B8C312D37EC400DA6239 /* fasta.cpp in Sources */, A7E9B8C412D37EC400DA6239 /* fastamap.cpp in Sources */, + 48BDDA751ECA067000F0F6C0 /* sharedrabundfloatvectors.cpp in Sources */, A7E9B8C512D37EC400DA6239 /* fileoutput.cpp in Sources */, A7E9B8C612D37EC400DA6239 /* filterseqscommand.cpp in Sources */, A7E9B8C812D37EC400DA6239 /* flowdata.cpp in Sources */, @@ -3082,6 +3341,7 @@ A7E9B8D712D37EC400DA6239 /* getsabundcommand.cpp in Sources */, A7E9B8D812D37EC400DA6239 /* getseqscommand.cpp in Sources */, A7E9B8D912D37EC400DA6239 /* getsharedotucommand.cpp in Sources */, + 48E544701E9D3B2D00FF6AB8 /* accuracy.cpp in Sources */, A7E9B8DB12D37EC400DA6239 /* goodscoverage.cpp in Sources */, A7E9B8DC12D37EC400DA6239 /* gotohoverlap.cpp in Sources */, A7E9B8DD12D37EC400DA6239 /* gower.cpp in Sources */, @@ -3110,9 +3370,11 @@ A7E9B8F112D37EC400DA6239 /* libshuffcommand.cpp in Sources */, A7E9B8F212D37EC400DA6239 /* listseqscommand.cpp in Sources */, A7E9B8F312D37EC400DA6239 /* listvector.cpp in Sources */, + 48E544451E9C2B1000FF6AB8 /* sensitivity.cpp in Sources */, A7E9B8F412D37EC400DA6239 /* logsd.cpp in Sources */, A7E9B8F512D37EC400DA6239 /* makegroupcommand.cpp in Sources */, 48705AC719BE32C50075E977 /* sharedrjsd.cpp in Sources */, + 48E5445D1E9C2F0F00FF6AB8 /* fn.cpp in Sources */, A7E9B8F612D37EC400DA6239 /* maligner.cpp in Sources */, A7E9B8F712D37EC400DA6239 /* manhattan.cpp in Sources */, A7E9B8F812D37EC400DA6239 /* matrixoutputcommand.cpp in Sources */, @@ -3146,6 +3408,7 @@ A7E9B91512D37EC400DA6239 /* pcoacommand.cpp in Sources */, A7E9B91712D37EC400DA6239 /* phylodiversitycommand.cpp in Sources */, 488841611CC515A000C5E972 /* (null) in Sources */, + 485B0E081F264F2E00CA5F57 /* sharedrabundvector.cpp in Sources */, A7E9B91812D37EC400DA6239 /* phylosummary.cpp in Sources */, A7E9B91912D37EC400DA6239 /* phylotree.cpp in Sources */, A7E9B91A12D37EC400DA6239 /* phylotypecommand.cpp in Sources */, @@ -3189,6 +3452,7 @@ 48910D4B1D58CBA300F60EDB /* optimatrix.cpp in Sources */, A7E9B94412D37EC400DA6239 /* shannoneven.cpp in Sources */, A7E9B94512D37EC400DA6239 /* sharedace.cpp in Sources */, + 48BDDA791ECA3B8E00F0F6C0 /* rabundfloatvector.cpp in Sources */, A7E9B94612D37EC400DA6239 /* sharedanderbergs.cpp in Sources */, A7E9B94712D37EC400DA6239 /* sharedbraycurtis.cpp in Sources */, A7E9B94812D37EC400DA6239 /* sharedchao1.cpp in Sources */, @@ -3197,6 +3461,7 @@ A7E9B94B12D37EC400DA6239 /* sharedjackknife.cpp in Sources */, A7E9B94C12D37EC400DA6239 /* sharedjclass.cpp in Sources */, A7E9B94D12D37EC400DA6239 /* sharedjest.cpp in Sources */, + 48E544741E9D3C1200FF6AB8 /* ppv.cpp in Sources */, A7E9B94E12D37EC400DA6239 /* sharedkstest.cpp in Sources */, A7E9B94F12D37EC400DA6239 /* sharedkulczynski.cpp in Sources */, A7E9B95012D37EC400DA6239 /* sharedkulczynskicody.cpp in Sources */, @@ -3208,9 +3473,6 @@ A7E9B95412D37EC400DA6239 /* sharedmorisitahorn.cpp in Sources */, A7E9B95512D37EC400DA6239 /* sharedochiai.cpp in Sources */, A7E9B95612D37EC400DA6239 /* sharedordervector.cpp in Sources */, - A7E9B95712D37EC400DA6239 /* sharedrabundfloatvector.cpp in Sources */, - A7E9B95812D37EC400DA6239 /* sharedrabundvector.cpp in Sources */, - A7E9B95912D37EC400DA6239 /* sharedsabundvector.cpp in Sources */, A7E9B95A12D37EC400DA6239 /* sharedsobs.cpp in Sources */, A7E9B95B12D37EC400DA6239 /* sharedsobscollectsummary.cpp in Sources */, A7E9B95C12D37EC400DA6239 /* sharedsorabund.cpp in Sources */, @@ -3241,12 +3503,15 @@ A7E9B97312D37EC400DA6239 /* structchord.cpp in Sources */, A7E9B97412D37EC400DA6239 /* structeuclidean.cpp in Sources */, A7E9B97512D37EC400DA6239 /* structkulczynski.cpp in Sources */, + 48BDDA711EC9D31400F0F6C0 /* sharedrabundvectors.cpp in Sources */, A7E9B97612D37EC400DA6239 /* structpearson.cpp in Sources */, + 48E544411E9C292900FF6AB8 /* mcc.cpp in Sources */, A7E9B97712D37EC400DA6239 /* subsamplecommand.cpp in Sources */, A7E9B97812D37EC400DA6239 /* suffixdb.cpp in Sources */, A7E9B97912D37EC400DA6239 /* suffixnodes.cpp in Sources */, A7E9B97A12D37EC400DA6239 /* suffixtree.cpp in Sources */, A7E9B97B12D37EC400DA6239 /* summarycommand.cpp in Sources */, + 48E544511E9C2CFD00FF6AB8 /* tp.cpp in Sources */, A7E9B97C12D37EC400DA6239 /* summarysharedcommand.cpp in Sources */, A7E9B97D12D37EC400DA6239 /* systemcommand.cpp in Sources */, 48C51DF31A793EFE004ECDF1 /* kmeralign.cpp in Sources */, @@ -3254,6 +3519,7 @@ A7E9B97F12D37EC400DA6239 /* tree.cpp in Sources */, A7E9B98012D37EC400DA6239 /* treegroupscommand.cpp in Sources */, A7E9B98112D37EC400DA6239 /* treemap.cpp in Sources */, + 4889EA221E8962D50054E0BB /* summary.cpp in Sources */, A7E9B98212D37EC400DA6239 /* treenode.cpp in Sources */, A7E9B98312D37EC400DA6239 /* trimflowscommand.cpp in Sources */, A7E9B98412D37EC400DA6239 /* trimseqscommand.cpp in Sources */, @@ -3262,6 +3528,7 @@ A7E9B98712D37EC400DA6239 /* unweighted.cpp in Sources */, A7E9B98812D37EC400DA6239 /* uvest.cpp in Sources */, A7E9B98912D37EC400DA6239 /* validcalculator.cpp in Sources */, + 48E544591E9C2E6500FF6AB8 /* fp.cpp in Sources */, A7E9B98A12D37EC400DA6239 /* validparameter.cpp in Sources */, A7E9B98B12D37EC400DA6239 /* venn.cpp in Sources */, A7E9B98C12D37EC400DA6239 /* venncommand.cpp in Sources */, @@ -3276,6 +3543,7 @@ A727864412E9E28C00F86ABA /* removerarecommand.cpp in Sources */, A71FE12C12EDF72400963CA7 /* mergegroupscommand.cpp in Sources */, 7E6BE10A12F710D8007ADDBE /* refchimeratest.cpp in Sources */, + 48E544551E9C2DF500FF6AB8 /* tn.cpp in Sources */, A7A61F2D130062E000E05B6B /* amovacommand.cpp in Sources */, A75790591301749D00A30DAB /* homovacommand.cpp in Sources */, 481623E21B56A2DB004C60B7 /* pcrseqscommand.cpp in Sources */, @@ -3293,6 +3561,7 @@ A795840D13F13CD900F201D5 /* countgroupscommand.cpp in Sources */, A7FF19F2140FFDA500AD216D /* trimoligos.cpp in Sources */, A7F9F5CF141A5E500032F693 /* sequenceparser.cpp in Sources */, + 48E544611E9C2FB800FF6AB8 /* fpfn.cpp in Sources */, A7FFB558142CA02C004884F2 /* summarytaxcommand.cpp in Sources */, A7BF221414587886000AD524 /* myPerseus.cpp in Sources */, A7BF2232145879B2000AD524 /* chimeraperseuscommand.cpp in Sources */, @@ -3302,6 +3571,7 @@ A77410F614697C300098E6AC /* seqnoise.cpp in Sources */, A754149714840CF7005850D1 /* summaryqualcommand.cpp in Sources */, 48705AC619BE32C50075E977 /* mergesfffilecommand.cpp in Sources */, + 48E544491E9C2BE100FF6AB8 /* specificity.cpp in Sources */, A7A3C8C914D041AD00B1BFBE /* otuassociationcommand.cpp in Sources */, A7A32DAA14DC43B00001D2E5 /* sortseqscommand.cpp in Sources */, A7EEB0F514F29BFE00344B83 /* classifytreecommand.cpp in Sources */, @@ -3319,6 +3589,7 @@ A70056E6156A93D000924A2D /* getotulabelscommand.cpp in Sources */, A70056EB156AB6E500924A2D /* removeotulabelscommand.cpp in Sources */, A74D59A4159A1E2000043046 /* counttable.cpp in Sources */, + 48E5447C1E9D3F0400FF6AB8 /* fdr.cpp in Sources */, A7E0243D15B4520A00A5F046 /* sparsedistancematrix.cpp in Sources */, A741FAD215D1688E0067BCC5 /* sequencecountparser.cpp in Sources */, A7C7DAB915DA758B0059B0CF /* sffmultiplecommand.cpp in Sources */, @@ -3326,6 +3597,7 @@ A7386C29161A110800651424 /* decisiontree.cpp in Sources */, A77E1938161B201E00DB1A2A /* randomforest.cpp in Sources */, 835FE03D19F00640005AA754 /* classifysvmsharedcommand.cpp in Sources */, + 48E5444D1E9C2C8F00FF6AB8 /* tptn.cpp in Sources */, A77E193B161B289600DB1A2A /* rftreenode.cpp in Sources */, A721AB6A161C570F009860A1 /* alignnode.cpp in Sources */, A721AB6B161C570F009860A1 /* aligntree.cpp in Sources */, @@ -3344,6 +3616,7 @@ A7548FB0171440ED00B1F05A /* qFinderDMM.cpp in Sources */, A77B7185173D2240002163C2 /* sparcccommand.cpp in Sources */, A77B7188173D4042002163C2 /* randomnumber.cpp in Sources */, + 485B0E0E1F27C40500CA5F57 /* sharedrabundfloatvector.cpp in Sources */, A77B718B173D40E5002163C2 /* calcsparcc.cpp in Sources */, A7E6F69E17427D06006775E2 /* makelookupcommand.cpp in Sources */, A7CFA4311755401800D9ED4D /* renameseqscommand.cpp in Sources */, @@ -3357,6 +3630,7 @@ A7D395C4184FA3A200A350D7 /* kmeans.cpp in Sources */, A7222D731856277C0055A993 /* sharedjsd.cpp in Sources */, A7B093C018579F0400843CD1 /* pam.cpp in Sources */, + 48E544781E9D3CE400FF6AB8 /* npv.cpp in Sources */, A7A09B1018773C0E00FAA081 /* shannonrange.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3368,7 +3642,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "compiler-default"; CLANG_WARN_CXX0X_EXTENSIONS = YES; "CLANG_WARN_CXX0X_EXTENSIONS[arch=*]" = NO; @@ -3381,10 +3655,10 @@ GCC_C_LANGUAGE_STANDARD = "compiler-default"; GCC_DYNAMIC_NO_PIC = NO; GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 3; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( - "VERSION=\"\\\"1.39.3\\\"\"", - "RELEASE_DATE=\"\\\"2/23/2017\\\"\"", + "VERSION=\"\\\"1.39.5\\\"\"", + "RELEASE_DATE=\"\\\"3/20/2017\\\"\"", "MOTHUR_FILES=\"\\\"/Users/sarahwestcott/desktop/release\\\"\"", ); GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO; @@ -3405,7 +3679,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; - CLANG_CXX_LANGUAGE_STANDARD = "c++14"; + CLANG_CXX_LANGUAGE_STANDARD = "c++0x"; CLANG_CXX_LIBRARY = "compiler-default"; CLANG_WARN_CXX0X_EXTENSIONS = YES; CLANG_WARN_UNREACHABLE_CODE = YES; @@ -3414,10 +3688,10 @@ DSTROOT = TARGET_BUILD_DIR; GCC_C_LANGUAGE_STANDARD = "compiler-default"; GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 3; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( - "VERSION=\"\\\"1.39.3\\\"\"", - "RELEASE_DATE=\"\\\"2/23/2017\\\"\"", + "VERSION=\"\\\"1.39.5\\\"\"", + "RELEASE_DATE=\"\\\"3/20/2017\\\"\"", "MOTHUR_FILES=\"\\\"/Users/sarahwestcott/desktop/release\\\"\"", ); GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO; @@ -3449,8 +3723,8 @@ GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( "MOTHUR_FILES=\"\\\"/Users/sarahwestcott/desktop/release\\\"\"", - "VERSION=\"\\\"1.39.1\\\"\"", - "RELEASE_DATE=\"\\\"2/2/2017\\\"\"", + "VERSION=\"\\\"1.39.5\\\"\"", + "RELEASE_DATE=\"\\\"3/20/2017\\\"\"", ); GCC_VERSION = ""; "GCC_VERSION[arch=*]" = ""; @@ -3473,18 +3747,19 @@ OTHER_CPLUSPLUSFLAGS = ( "-DBIT_VERSION", "-DUNIT_TEST", + "-DUSE_BOOST", "-DUSE_READLINE", "$(OTHER_CFLAGS)", - "-DUSE_BOOST", ); OTHER_LDFLAGS = ( "-lreadline", "-lboost_iostreams", "-lz", + "-pthreads", ); SDKROOT = macosx; SKIP_INSTALL = NO; - USER_HEADER_SEARCH_PATHS = /usr/local/include/; + USER_HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/gtest /usr/local/include"; }; name = Debug; }; @@ -3500,8 +3775,8 @@ GCC_MODEL_TUNING = ""; GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( - "VERSION=\"\\\"1.39.3\\\"\"", - "RELEASE_DATE=\"\\\"2/23/2017\\\"\"", + "VERSION=\"\\\"1.39.5\\\"\"", + "RELEASE_DATE=\"\\\"3/20/2017\\\"\"", "MOTHUR_FILES=\"\\\"/Users/sarahwestcott/desktop/release\\\"\"", ); GCC_VERSION = ""; @@ -3527,17 +3802,18 @@ "-DUSE_READLINE", "-DUNIT_TEST", "-DBIT_VERSION", - "$(OTHER_CFLAGS)", "-DUSE_BOOST", + "$(OTHER_CFLAGS)", ); OTHER_LDFLAGS = ( "-lreadline", "-lboost_iostreams", "-lz", + "-pthreads", ); SDKROOT = macosx; SKIP_INSTALL = NO; - USER_HEADER_SEARCH_PATHS = /usr/local/include/; + USER_HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/gtest /usr/local/include"; }; name = Release; }; @@ -3561,7 +3837,7 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = "compiler-default"; GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 3; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -3576,6 +3852,7 @@ ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/gtest /usr/local/include"; }; name = Debug; }; @@ -3600,7 +3877,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = "compiler-default"; - GCC_OPTIMIZATION_LEVEL = 3; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "VERSION=\"\\\"1.37.6\\\"\"", "RELEASE_DATE=\"\\\"06/20/2016\\\"\"", @@ -3614,6 +3891,7 @@ ONLY_ACTIVE_ARCH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + USER_HEADER_SEARCH_PATHS = "$(TARGET_BUILD_DIR)/gtest /usr/local/include"; }; name = Release; }; diff --git a/TestMothur/custom/gtest-port.h b/TestMothur/custom/gtest-port.h new file mode 100755 index 00000000..7e744bd3 --- /dev/null +++ b/TestMothur/custom/gtest-port.h @@ -0,0 +1,69 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Injection point for custom user configurations. +// The following macros can be defined: +// +// Flag related macros: +// GTEST_FLAG(flag_name) +// GTEST_USE_OWN_FLAGFILE_FLAG_ - Define to 0 when the system provides its +// own flagfile flag parsing. +// GTEST_DECLARE_bool_(name) +// GTEST_DECLARE_int32_(name) +// GTEST_DECLARE_string_(name) +// GTEST_DEFINE_bool_(name, default_val, doc) +// GTEST_DEFINE_int32_(name, default_val, doc) +// GTEST_DEFINE_string_(name, default_val, doc) +// +// Test filtering: +// GTEST_TEST_FILTER_ENV_VAR_ - The name of an environment variable that +// will be used if --GTEST_FLAG(test_filter) +// is not provided. +// +// Logging: +// GTEST_LOG_(severity) +// GTEST_CHECK_(condition) +// Functions LogToStderr() and FlushInfoLog() have to be provided too. +// +// Threading: +// GTEST_HAS_NOTIFICATION_ - Enabled if Notification is already provided. +// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Enabled if Mutex and ThreadLocal are +// already provided. +// Must also provide GTEST_DECLARE_STATIC_MUTEX_(mutex) and +// GTEST_DEFINE_STATIC_MUTEX_(mutex) +// +// GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) +// GTEST_LOCK_EXCLUDED_(locks) +// +// ** Custom implementation starts here ** + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ diff --git a/TestMothur/custom/gtest-printers.h b/TestMothur/custom/gtest-printers.h new file mode 100755 index 00000000..6c7e49ae --- /dev/null +++ b/TestMothur/custom/gtest-printers.h @@ -0,0 +1,42 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// This file provides an injection point for custom printers in a local +// installation of gTest. +// It will be included from gtest-printers.h and the overrides in this file +// will be visible to everyone. +// See documentation at gtest-printers.h for details on how to define a +// custom printer. +// +// ** Custom implementation starts here ** + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ diff --git a/TestMothur/custom/gtest.h b/TestMothur/custom/gtest.h new file mode 100755 index 00000000..c27412a8 --- /dev/null +++ b/TestMothur/custom/gtest.h @@ -0,0 +1,41 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Injection point for custom user configurations. +// The following macros can be defined: +// +// GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of +// OsStackTraceGetterInterface. +// +// ** Custom implementation starts here ** + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ diff --git a/TestMothur/dataset.cpp b/TestMothur/dataset.cpp index adcd6315..f81a84e2 100755 --- a/TestMothur/dataset.cpp +++ b/TestMothur/dataset.cpp @@ -56,34 +56,23 @@ void TestDataSet::createCountTable() { } /***********************************************************************/ -vector TestDataSet::getSubsetFNGFiles(int numSeqs) { - fillSeqs(); - vector subsetSeqs; - for (int i = 0; i < numSeqs; i++) { subsetSeqs.push_back(seqs[i]); } - seqs.clear(); - - fillNames(); - fillGroup(); - ofstream out, out2, out3; - m->openOutputFile("tempSeqs.txt", out); m->openOutputFile("tempNames.txt", out2); m->openOutputFile("tempGroup.txt", out3); - for (int i = 0; i < subsetSeqs.size(); i++) { - subsetSeqs[i].printSequence(out); - out2 << subsetSeqs[i].getName() << '\t' << nameMap[subsetSeqs[i].getName()] << '\n'; - out3 << subsetSeqs[i].getName() << '\t' << gMap->getGroup(subsetSeqs[i].getName()) << '\n'; - } - nameMap.clear(); - delete gMap; gMap = NULL; - - vector filenames; filenames.push_back("tempSeqs.txt"); filenames.push_back("tempNames.txt"); filenames.push_back("tempGroup.txt"); +vector TestDataSet::getSubsetFNGFiles() { + vector filenames; filenames.push_back("/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/tempSeqs.txt"); filenames.push_back("/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/tempNames.txt"); filenames.push_back("/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/tempGroup.txt"); return filenames; } /***********************************************************************/ +string TestDataSet::getSubsetFNGDistFile() { + + return "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/tempSeqs.dist"; +} +/***********************************************************************/ void TestDataSet::fillSeqs() { seqs.clear(); //read info from stable file - string testfile = m->getTestFilePath() + "testFile.fasta"; + //string testfile = m->getTestFilePath() + "testFile.fasta"; + string testfile ="/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/testFile.fasta"; ifstream in; m->openInputFile(testfile, in); @@ -101,7 +90,7 @@ void TestDataSet::fillNames() { nameMap.clear(); //read info from stable file - string testfile = m->getTestFilePath() + "testFile.names"; + string testfile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/testFile.names"; m->readNames(testfile, nameMap); } /***********************************************************************/ @@ -109,7 +98,7 @@ void TestDataSet::fillGroup() { if (gMap != NULL) { delete gMap; gMap = NULL; } //read info from stable file - string testfile = m->getTestFilePath() + "testFile.groups"; + string testfile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/testFile.groups"; gMap = new GroupMap(); gMap->readMap(testfile); @@ -120,7 +109,7 @@ void TestDataSet::fillLookup() { lookup.clear(); //read info from stable file - string testfile = m->getTestFilePath() + "testFile.opti_mcc.shared"; + string testfile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/testFile.opti_mcc.shared"; InputData input(testfile, "sharedfile"); lookup = input.getSharedRAbundVectors(); diff --git a/TestMothur/dataset.h b/TestMothur/dataset.h index 03b9674a..8b723013 100644 --- a/TestMothur/dataset.h +++ b/TestMothur/dataset.h @@ -25,7 +25,8 @@ class TestDataSet { GroupMap* getGroupMap() { fillGroup(); return gMap; } CountTable* getCountTable() { createCountTable(); return ct; } vector getLookup() { fillLookup(); return lookup; } - vector getSubsetFNGFiles(int); //number of uniques, Fasta, name, group returned + vector getSubsetFNGFiles(); //Fasta, name, group returned - containing 100 seqs + string getSubsetFNGDistFile(); private: MothurOut* m; diff --git a/TestMothur/distcdataset.cpp b/TestMothur/distcdataset.cpp index f8c275ec..e876c46a 100644 --- a/TestMothur/distcdataset.cpp +++ b/TestMothur/distcdataset.cpp @@ -6,8 +6,8 @@ /***********************************************************************/ DistCDataSet::DistCDataSet() { m = MothurOut::getInstance(); - columnFile = m->getTestFilePath() + "stability.MISeq_SOP.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.pick.dist"; - countFile = m->getTestFilePath() + "stability.count_table"; + columnFile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/stability.MISeq_SOP.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.pick.dist"; + countFile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/stability.count_table"; } /***********************************************************************/ vector DistCDataSet::getFiles(int numSeqs) { diff --git a/TestMothur/distpdataset.cpp b/TestMothur/distpdataset.cpp index d855da2a..3a85ee23 100644 --- a/TestMothur/distpdataset.cpp +++ b/TestMothur/distpdataset.cpp @@ -11,6 +11,6 @@ /***********************************************************************/ DistPDataSet::DistPDataSet() { m = MothurOut::getInstance(); - phylipFile = m->getTestFilePath() + "stability.MISeq_SOP.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.pick.phylip.dist"; + phylipFile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/stability.MISeq_SOP.trim.contigs.good.unique.good.filter.unique.precluster.pick.pick.pick.phylip.dist"; } /***********************************************************************/ diff --git a/TestMothur/fakes/fakemcc.hpp b/TestMothur/fakes/fakemcc.hpp new file mode 100644 index 00000000..d3886edd --- /dev/null +++ b/TestMothur/fakes/fakemcc.hpp @@ -0,0 +1,28 @@ +// +// fakemcc.hpp +// Mothur +// +// Created by Sarah Westcott on 4/18/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fakemcc_hpp +#define fakemcc_hpp + +#include "mothurout.h" + + +class FakeClusterCalcValues { + +public: + + FakeClusterCalcValues() { tp = 823; tn = 1944106; fp = 95; fn = 354; } + ~FakeClusterCalcValues() {} + + long long tp, tn, fp, fn; +}; + + + +#endif /* fakemcc_hpp */ + diff --git a/TestMothur/fakes/fakeoligos.h b/TestMothur/fakes/fakeoligos.h new file mode 100644 index 00000000..d4ebd41c --- /dev/null +++ b/TestMothur/fakes/fakeoligos.h @@ -0,0 +1,54 @@ +// +// fakeoligos.h +// Mothur +// +// Created by Sarah Westcott on 5/1/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fakeoligos_h +#define fakeoligos_h + +#include "mothurout.h" + + +class FakeOligos { + +public: + + FakeOligos() { + bdiffs=1; pdiffs=2; rdiffs=0; ldiffs=0; sdiffs=0; + + //single + primers["CCGTCAATTCMTTTRAGT"] = 0; + barcodes["AATGGTAC"] = 0; //F003D000 + barcodes["AACCTGGC"] = 1; //F003D002 + barcodes["TTCGTGGC"] = 2; //F003D004 + barcodes["TTCTTGAC"] = 3; //F003D006 + barcodes["TTCGCGAC"] = 4; //F003D008 + barcodes["TCCAGAAC"] = 5; //F003D142 + barcodes["AAGGCCTC"] = 6; //F003D144 + barcodes["TGACCGTC"] = 7; //F003D146 + barcodes["AGGTTGTC"] = 8; //F003D148 + barcodes["TGGTGAAC"] = 9; //F003D150 + barcodes["AACCGTGTC"] = 10; //MOCK.GQY1XT001 + + + } + ~FakeOligos() {} + + int bdiffs, pdiffs, rdiffs, ldiffs, sdiffs; + map barcodes; + map primers; + + vector revPrimer; + vector linker; + vector spacer; + map ipbarcodes; + map ipprimers; + +}; + + + +#endif /* fakeoligos_h */ diff --git a/TestMothur/fakes/fakeoptimatrix.cpp b/TestMothur/fakes/fakeoptimatrix.cpp new file mode 100644 index 00000000..49ef27ce --- /dev/null +++ b/TestMothur/fakes/fakeoptimatrix.cpp @@ -0,0 +1,42 @@ +// +// fakeoptimatrix.cpp +// Mothur +// +// Created by Sarah Westcott on 4/20/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "fakeoptimatrix.hpp" + +/***********************************************************************/ +FakeOptiMatrix::FakeOptiMatrix() : OptiMatrix() { + try { + m = MothurOut::getInstance(); + + //create 10 singletons + for (int i = 90; i < 100; i++) { singletons.push_back(toString(i)); } + + //create 90 non singletons + for (int i = 0; i < 90; i++) { nameMap.push_back(toString(i)); } + + closeness.resize(90); + int count = 0; + for (int i = 0; i < 9; i++) { + set close; + //create list of all sequences in this set + for (int j = 0; j < 10; j++) { close.insert((j+count)); } + + for (set::iterator it = close.begin(); it != close.end(); it++) { + //add close sequences to each sequence in this set, do not include self + for (int j = 0; j < 10; j++) { if ((j+count) != *it) { closeness[j+count].insert(*it); } } + } + count += 10; + } + } + catch(exception& e) { + m->errorOut(e, "FakeOptiMatrix", "FakeOptiMatrix"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/TestMothur/fakes/fakeoptimatrix.hpp b/TestMothur/fakes/fakeoptimatrix.hpp new file mode 100644 index 00000000..18583d21 --- /dev/null +++ b/TestMothur/fakes/fakeoptimatrix.hpp @@ -0,0 +1,22 @@ +// +// fakeoptimatrix.hpp +// Mothur +// +// Created by Sarah Westcott on 4/20/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fakeoptimatrix_hpp +#define fakeoptimatrix_hpp + +#include "optimatrix.h" + +class FakeOptiMatrix : public OptiMatrix { + +public: + FakeOptiMatrix(); + ~FakeOptiMatrix(){ } +}; + + +#endif /* fakeoptimatrix_hpp */ diff --git a/TestMothur/fastqdataset.cpp b/TestMothur/fastqdataset.cpp index a926456e..a4aa1dad 100644 --- a/TestMothur/fastqdataset.cpp +++ b/TestMothur/fastqdataset.cpp @@ -31,7 +31,7 @@ void TestFastqDataSet::fillForwardFastq() { ffastqReads.clear(); //read info from stable file - string testfile = m->getTestFilePath() + "F8D0_S345_L001_R1_001.fastq"; + string testfile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/F8D0_S345_L001_R1_001.fastq"; ifstream in; m->openInputFile(testfile, in); @@ -53,7 +53,7 @@ void TestFastqDataSet::fillReverseFastq() { rfastqReads.clear(); //read info from stable file - string testfile = m->getTestFilePath() + "F8D0_S345_L001_R2_001.fastq"; + string testfile = "/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/F8D0_S345_L001_R2_001.fastq"; ifstream in; m->openInputFile(testfile, in); diff --git a/TestMothur/gtest-all.cc b/TestMothur/gtest-all.cc new file mode 100755 index 00000000..aae6e315 --- /dev/null +++ b/TestMothur/gtest-all.cc @@ -0,0 +1,54 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: mheule@google.com (Markus Heule) +// +// Google C++ Testing Framework (Google Test) +// +// Sometimes it's desirable to build Google Test by compiling a single file. +// This file serves this purpose. + +// This line ensures that gtest.h can be compiled on its own, even +// when it's fused. + +#ifndef GTEST_ALL_H_ +#define GTEST_ALL_H_ + +#include "gtest.h" + +// The following lines pull in the real gtest *.cc files. +#include "gtest.cc" +#include "gtest-death-test.cc" +#include "gtest-filepath.cc" +#include "gtest-port.cc" +#include "gtest-printers.cc" +#include "gtest-test-part.cc" +#include "gtest-typed-test.cc" + +#endif diff --git a/TestMothur/gtest-death-test-internal.h b/TestMothur/gtest-death-test-internal.h new file mode 100755 index 00000000..06267d75 --- /dev/null +++ b/TestMothur/gtest-death-test-internal.h @@ -0,0 +1,319 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file defines internal utilities needed for implementing +// death tests. They are subject to change without notice. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ + +#include "gtest-internal.h" + +#include + +namespace testing { +namespace internal { + +GTEST_DECLARE_string_(internal_run_death_test); + +// Names of the flags (needed for parsing Google Test flags). +const char kDeathTestStyleFlag[] = "death_test_style"; +const char kDeathTestUseFork[] = "death_test_use_fork"; +const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; + +#if GTEST_HAS_DEATH_TEST + +// DeathTest is a class that hides much of the complexity of the +// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method +// returns a concrete class that depends on the prevailing death test +// style, as defined by the --gtest_death_test_style and/or +// --gtest_internal_run_death_test flags. + +// In describing the results of death tests, these terms are used with +// the corresponding definitions: +// +// exit status: The integer exit information in the format specified +// by wait(2) +// exit code: The integer code passed to exit(3), _exit(2), or +// returned from main() +class GTEST_API_ DeathTest { + public: + // Create returns false if there was an error determining the + // appropriate action to take for the current death test; for example, + // if the gtest_death_test_style flag is set to an invalid value. + // The LastMessage method will return a more detailed message in that + // case. Otherwise, the DeathTest pointer pointed to by the "test" + // argument is set. If the death test should be skipped, the pointer + // is set to NULL; otherwise, it is set to the address of a new concrete + // DeathTest object that controls the execution of the current test. + static bool Create(const char* statement, const RE* regex, + const char* file, int line, DeathTest** test); + DeathTest(); + virtual ~DeathTest() { } + + // A helper class that aborts a death test when it's deleted. + class ReturnSentinel { + public: + explicit ReturnSentinel(DeathTest* test) : test_(test) { } + ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); } + private: + DeathTest* const test_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); + } GTEST_ATTRIBUTE_UNUSED_; + + // An enumeration of possible roles that may be taken when a death + // test is encountered. EXECUTE means that the death test logic should + // be executed immediately. OVERSEE means that the program should prepare + // the appropriate environment for a child process to execute the death + // test, then wait for it to complete. + enum TestRole { OVERSEE_TEST, EXECUTE_TEST }; + + // An enumeration of the three reasons that a test might be aborted. + enum AbortReason { + TEST_ENCOUNTERED_RETURN_STATEMENT, + TEST_THREW_EXCEPTION, + TEST_DID_NOT_DIE + }; + + // Assumes one of the above roles. + virtual TestRole AssumeRole() = 0; + + // Waits for the death test to finish and returns its status. + virtual int Wait() = 0; + + // Returns true if the death test passed; that is, the test process + // exited during the test, its exit status matches a user-supplied + // predicate, and its stderr output matches a user-supplied regular + // expression. + // The user-supplied predicate may be a macro expression rather + // than a function pointer or functor, or else Wait and Passed could + // be combined. + virtual bool Passed(bool exit_status_ok) = 0; + + // Signals that the death test did not die as expected. + virtual void Abort(AbortReason reason) = 0; + + // Returns a human-readable outcome message regarding the outcome of + // the last death test. + static const char* LastMessage(); + + static void set_last_death_test_message(const std::string& message); + + private: + // A string containing a description of the outcome of the last death test. + static std::string last_death_test_message_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); +}; + +// Factory interface for death tests. May be mocked out for testing. +class DeathTestFactory { + public: + virtual ~DeathTestFactory() { } + virtual bool Create(const char* statement, const RE* regex, + const char* file, int line, DeathTest** test) = 0; +}; + +// A concrete DeathTestFactory implementation for normal use. +class DefaultDeathTestFactory : public DeathTestFactory { + public: + virtual bool Create(const char* statement, const RE* regex, + const char* file, int line, DeathTest** test); +}; + +// Returns true if exit_status describes a process that was terminated +// by a signal, or exited normally with a nonzero exit code. +GTEST_API_ bool ExitedUnsuccessfully(int exit_status); + +// Traps C++ exceptions escaping statement and reports them as test +// failures. Note that trapping SEH exceptions is not implemented here. +# if GTEST_HAS_EXCEPTIONS +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (const ::std::exception& gtest_exception) { \ + fprintf(\ + stderr, \ + "\n%s: Caught std::exception-derived exception escaping the " \ + "death test statement. Exception message: %s\n", \ + ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ + gtest_exception.what()); \ + fflush(stderr); \ + death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ + } catch (...) { \ + death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ + } + +# else +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) + +# endif + +// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, +// ASSERT_EXIT*, and EXPECT_EXIT*. +# define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + const ::testing::internal::RE& gtest_regex = (regex); \ + ::testing::internal::DeathTest* gtest_dt; \ + if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ + __FILE__, __LINE__, >est_dt)) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ + } \ + if (gtest_dt != NULL) { \ + ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ + gtest_dt_ptr(gtest_dt); \ + switch (gtest_dt->AssumeRole()) { \ + case ::testing::internal::DeathTest::OVERSEE_TEST: \ + if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ + } \ + break; \ + case ::testing::internal::DeathTest::EXECUTE_TEST: { \ + ::testing::internal::DeathTest::ReturnSentinel \ + gtest_sentinel(gtest_dt); \ + GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ + gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ + break; \ + } \ + default: \ + break; \ + } \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ + fail(::testing::internal::DeathTest::LastMessage()) +// The symbol "fail" here expands to something into which a message +// can be streamed. + +// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in +// NDEBUG mode. In this case we need the statements to be executed, the regex is +// ignored, and the macro must accept a streamed message even though the message +// is never printed. +# define GTEST_EXECUTE_STATEMENT_(statement, regex) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } else \ + ::testing::Message() + +// A class representing the parsed contents of the +// --gtest_internal_run_death_test flag, as it existed when +// RUN_ALL_TESTS was called. +class InternalRunDeathTestFlag { + public: + InternalRunDeathTestFlag(const std::string& a_file, + int a_line, + int an_index, + int a_write_fd) + : file_(a_file), line_(a_line), index_(an_index), + write_fd_(a_write_fd) {} + + ~InternalRunDeathTestFlag() { + if (write_fd_ >= 0) + posix::Close(write_fd_); + } + + const std::string& file() const { return file_; } + int line() const { return line_; } + int index() const { return index_; } + int write_fd() const { return write_fd_; } + + private: + std::string file_; + int line_; + int index_; + int write_fd_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); +}; + +// Returns a newly created InternalRunDeathTestFlag object with fields +// initialized from the GTEST_FLAG(internal_run_death_test) flag if +// the flag is specified; otherwise returns NULL. +InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); + +#else // GTEST_HAS_DEATH_TEST + +// This macro is used for implementing macros such as +// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where +// death tests are not supported. Those macros must compile on such systems +// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on +// systems that support death tests. This allows one to write such a macro +// on a system that does not support death tests and be sure that it will +// compile on a death-test supporting system. +// +// Parameters: +// statement - A statement that a macro such as EXPECT_DEATH would test +// for program termination. This macro has to make sure this +// statement is compiled but not executed, to ensure that +// EXPECT_DEATH_IF_SUPPORTED compiles with a certain +// parameter iff EXPECT_DEATH compiles with it. +// regex - A regex that a macro such as EXPECT_DEATH would use to test +// the output of statement. This parameter has to be +// compiled but not evaluated by this macro, to ensure that +// this macro only accepts expressions that a macro such as +// EXPECT_DEATH would accept. +// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED +// and a return statement for ASSERT_DEATH_IF_SUPPORTED. +// This ensures that ASSERT_DEATH_IF_SUPPORTED will not +// compile inside functions where ASSERT_DEATH doesn't +// compile. +// +// The branch that has an always false condition is used to ensure that +// statement and regex are compiled (and thus syntactically correct) but +// never executed. The unreachable code macro protects the terminator +// statement from generating an 'unreachable code' warning in case +// statement unconditionally returns or throws. The Message constructor at +// the end allows the syntax of streaming additional messages into the +// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. +# define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_LOG_(WARNING) \ + << "Death tests are not supported on this platform.\n" \ + << "Statement '" #statement "' cannot be verified."; \ + } else if (::testing::internal::AlwaysFalse()) { \ + ::testing::internal::RE::PartialMatch(".*", (regex)); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + terminator; \ + } else \ + ::testing::Message() + +#endif // GTEST_HAS_DEATH_TEST + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ diff --git a/TestMothur/gtest-death-test.cc b/TestMothur/gtest-death-test.cc new file mode 100755 index 00000000..00f48fce --- /dev/null +++ b/TestMothur/gtest-death-test.cc @@ -0,0 +1,1342 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev) +// +// This file implements death tests. + +#include "gtest-death-test.h" +#include "gtest-port.h" +#include "custom/gtest.h" + +#if GTEST_HAS_DEATH_TEST + +# if GTEST_OS_MAC +# include +# endif // GTEST_OS_MAC + +# include +# include +# include + +# if GTEST_OS_LINUX +# include +# endif // GTEST_OS_LINUX + +# include + +# if GTEST_OS_WINDOWS +# include +# else +# include +# include +# endif // GTEST_OS_WINDOWS + +# if GTEST_OS_QNX +# include +# endif // GTEST_OS_QNX + +#endif // GTEST_HAS_DEATH_TEST + +#include "gtest-message.h" +#include "gtest-string.h" + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick exists to +// prevent the accidental inclusion of gtest-internal-inl.h in the +// user's code. +#define GTEST_IMPLEMENTATION_ 1 +#include "gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ + +namespace testing { + +// Constants. + +// The default death test style. +static const char kDefaultDeathTestStyle[] = "fast"; + +GTEST_DEFINE_string_( + death_test_style, + internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle), + "Indicates how to run a death test in a forked child process: " + "\"threadsafe\" (child process re-executes the test binary " + "from the beginning, running only the specific death test) or " + "\"fast\" (child process runs the death test immediately " + "after forking)."); + +GTEST_DEFINE_bool_( + death_test_use_fork, + internal::BoolFromGTestEnv("death_test_use_fork", false), + "Instructs to use fork()/_exit() instead of clone() in death tests. " + "Ignored and always uses fork() on POSIX systems where clone() is not " + "implemented. Useful when running under valgrind or similar tools if " + "those do not support clone(). Valgrind 3.3.1 will just fail if " + "it sees an unsupported combination of clone() flags. " + "It is not recommended to use this flag w/o valgrind though it will " + "work in 99% of the cases. Once valgrind is fixed, this flag will " + "most likely be removed."); + +namespace internal { +GTEST_DEFINE_string_( + internal_run_death_test, "", + "Indicates the file, line number, temporal index of " + "the single death test to run, and a file descriptor to " + "which a success code may be sent, all separated by " + "the '|' characters. This flag is specified if and only if the current " + "process is a sub-process launched for running a thread-safe " + "death test. FOR INTERNAL USE ONLY."); +} // namespace internal + +#if GTEST_HAS_DEATH_TEST + +namespace internal { + +// Valid only for fast death tests. Indicates the code is running in the +// child process of a fast style death test. +# if !GTEST_OS_WINDOWS +static bool g_in_fast_death_test_child = false; +# endif + +// Returns a Boolean value indicating whether the caller is currently +// executing in the context of the death test child process. Tools such as +// Valgrind heap checkers may need this to modify their behavior in death +// tests. IMPORTANT: This is an internal utility. Using it may break the +// implementation of death tests. User code MUST NOT use it. +bool InDeathTestChild() { +# if GTEST_OS_WINDOWS + + // On Windows, death tests are thread-safe regardless of the value of the + // death_test_style flag. + return !GTEST_FLAG(internal_run_death_test).empty(); + +# else + + if (GTEST_FLAG(death_test_style) == "threadsafe") + return !GTEST_FLAG(internal_run_death_test).empty(); + else + return g_in_fast_death_test_child; +#endif +} + +} // namespace internal + +// ExitedWithCode constructor. +ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) { +} + +// ExitedWithCode function-call operator. +bool ExitedWithCode::operator()(int exit_status) const { +# if GTEST_OS_WINDOWS + + return exit_status == exit_code_; + +# else + + return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_; + +# endif // GTEST_OS_WINDOWS +} + +# if !GTEST_OS_WINDOWS +// KilledBySignal constructor. +KilledBySignal::KilledBySignal(int signum) : signum_(signum) { +} + +// KilledBySignal function-call operator. +bool KilledBySignal::operator()(int exit_status) const { +# if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) + { + bool result; + if (GTEST_KILLED_BY_SIGNAL_OVERRIDE_(signum_, exit_status, &result)) { + return result; + } + } +# endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_) + return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_; +} +# endif // !GTEST_OS_WINDOWS + +namespace internal { + +// Utilities needed for death tests. + +// Generates a textual description of a given exit code, in the format +// specified by wait(2). +static std::string ExitSummary(int exit_code) { + Message m; + +# if GTEST_OS_WINDOWS + + m << "Exited with exit status " << exit_code; + +# else + + if (WIFEXITED(exit_code)) { + m << "Exited with exit status " << WEXITSTATUS(exit_code); + } else if (WIFSIGNALED(exit_code)) { + m << "Terminated by signal " << WTERMSIG(exit_code); + } +# ifdef WCOREDUMP + if (WCOREDUMP(exit_code)) { + m << " (core dumped)"; + } +# endif +# endif // GTEST_OS_WINDOWS + + return m.GetString(); +} + +// Returns true if exit_status describes a process that was terminated +// by a signal, or exited normally with a nonzero exit code. +bool ExitedUnsuccessfully(int exit_status) { + return !ExitedWithCode(0)(exit_status); +} + +# if !GTEST_OS_WINDOWS +// Generates a textual failure message when a death test finds more than +// one thread running, or cannot determine the number of threads, prior +// to executing the given statement. It is the responsibility of the +// caller not to pass a thread_count of 1. +static std::string DeathTestThreadWarning(size_t thread_count) { + Message msg; + msg << "Death tests use fork(), which is unsafe particularly" + << " in a threaded context. For this test, " << GTEST_NAME_ << " "; + if (thread_count == 0) + msg << "couldn't detect the number of threads."; + else + msg << "detected " << thread_count << " threads."; + return msg.GetString(); +} +# endif // !GTEST_OS_WINDOWS + +// Flag characters for reporting a death test that did not die. +static const char kDeathTestLived = 'L'; +static const char kDeathTestReturned = 'R'; +static const char kDeathTestThrew = 'T'; +static const char kDeathTestInternalError = 'I'; + +// An enumeration describing all of the possible ways that a death test can +// conclude. DIED means that the process died while executing the test +// code; LIVED means that process lived beyond the end of the test code; +// RETURNED means that the test statement attempted to execute a return +// statement, which is not allowed; THREW means that the test statement +// returned control by throwing an exception. IN_PROGRESS means the test +// has not yet concluded. +// TODO(vladl@google.com): Unify names and possibly values for +// AbortReason, DeathTestOutcome, and flag characters above. +enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW }; + +// Routine for aborting the program which is safe to call from an +// exec-style death test child process, in which case the error +// message is propagated back to the parent process. Otherwise, the +// message is simply printed to stderr. In either case, the program +// then exits with status 1. +void DeathTestAbort(const std::string& message) { + // On a POSIX system, this function may be called from a threadsafe-style + // death test child process, which operates on a very small stack. Use + // the heap for any additional non-minuscule memory requirements. + const InternalRunDeathTestFlag* const flag = + GetUnitTestImpl()->internal_run_death_test_flag(); + if (flag != NULL) { + FILE* parent = posix::FDOpen(flag->write_fd(), "w"); + fputc(kDeathTestInternalError, parent); + fprintf(parent, "%s", message.c_str()); + fflush(parent); + _exit(1); + } else { + fprintf(stderr, "%s", message.c_str()); + fflush(stderr); + posix::Abort(); + } +} + +// A replacement for CHECK that calls DeathTestAbort if the assertion +// fails. +# define GTEST_DEATH_TEST_CHECK_(expression) \ + do { \ + if (!::testing::internal::IsTrue(expression)) { \ + DeathTestAbort( \ + ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ + + ::testing::internal::StreamableToString(__LINE__) + ": " \ + + #expression); \ + } \ + } while (::testing::internal::AlwaysFalse()) + +// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for +// evaluating any system call that fulfills two conditions: it must return +// -1 on failure, and set errno to EINTR when it is interrupted and +// should be tried again. The macro expands to a loop that repeatedly +// evaluates the expression as long as it evaluates to -1 and sets +// errno to EINTR. If the expression evaluates to -1 but errno is +// something other than EINTR, DeathTestAbort is called. +# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \ + do { \ + int gtest_retval; \ + do { \ + gtest_retval = (expression); \ + } while (gtest_retval == -1 && errno == EINTR); \ + if (gtest_retval == -1) { \ + DeathTestAbort( \ + ::std::string("CHECK failed: File ") + __FILE__ + ", line " \ + + ::testing::internal::StreamableToString(__LINE__) + ": " \ + + #expression + " != -1"); \ + } \ + } while (::testing::internal::AlwaysFalse()) + +// Returns the message describing the last system error in errno. +std::string GetLastErrnoDescription() { + return errno == 0 ? "" : posix::StrError(errno); +} + +// This is called from a death test parent process to read a failure +// message from the death test child process and log it with the FATAL +// severity. On Windows, the message is read from a pipe handle. On other +// platforms, it is read from a file descriptor. +static void FailFromInternalError(int fd) { + Message error; + char buffer[256]; + int num_read; + + do { + while ((num_read = posix::Read(fd, buffer, 255)) > 0) { + buffer[num_read] = '\0'; + error << buffer; + } + } while (num_read == -1 && errno == EINTR); + + if (num_read == 0) { + GTEST_LOG_(FATAL) << error.GetString(); + } else { + const int last_error = errno; + GTEST_LOG_(FATAL) << "Error while reading death test internal: " + << GetLastErrnoDescription() << " [" << last_error << "]"; + } +} + +// Death test constructor. Increments the running death test count +// for the current test. +DeathTest::DeathTest() { + TestInfo* const info = GetUnitTestImpl()->current_test_info(); + if (info == NULL) { + DeathTestAbort("Cannot run a death test outside of a TEST or " + "TEST_F construct"); + } +} + +// Creates and returns a death test by dispatching to the current +// death test factory. +bool DeathTest::Create(const char* statement, const RE* regex, + const char* file, int line, DeathTest** test) { + return GetUnitTestImpl()->death_test_factory()->Create( + statement, regex, file, line, test); +} + +const char* DeathTest::LastMessage() { + return last_death_test_message_.c_str(); +} + +void DeathTest::set_last_death_test_message(const std::string& message) { + last_death_test_message_ = message; +} + +std::string DeathTest::last_death_test_message_; + +// Provides cross platform implementation for some death functionality. +class DeathTestImpl : public DeathTest { + protected: + DeathTestImpl(const char* a_statement, const RE* a_regex) + : statement_(a_statement), + regex_(a_regex), + spawned_(false), + status_(-1), + outcome_(IN_PROGRESS), + read_fd_(-1), + write_fd_(-1) {} + + // read_fd_ is expected to be closed and cleared by a derived class. + ~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); } + + void Abort(AbortReason reason); + virtual bool Passed(bool status_ok); + + const char* statement() const { return statement_; } + const RE* regex() const { return regex_; } + bool spawned() const { return spawned_; } + void set_spawned(bool is_spawned) { spawned_ = is_spawned; } + int status() const { return status_; } + void set_status(int a_status) { status_ = a_status; } + DeathTestOutcome outcome() const { return outcome_; } + void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; } + int read_fd() const { return read_fd_; } + void set_read_fd(int fd) { read_fd_ = fd; } + int write_fd() const { return write_fd_; } + void set_write_fd(int fd) { write_fd_ = fd; } + + // Called in the parent process only. Reads the result code of the death + // test child process via a pipe, interprets it to set the outcome_ + // member, and closes read_fd_. Outputs diagnostics and terminates in + // case of unexpected codes. + void ReadAndInterpretStatusByte(); + + private: + // The textual content of the code this object is testing. This class + // doesn't own this string and should not attempt to delete it. + const char* const statement_; + // The regular expression which test output must match. DeathTestImpl + // doesn't own this object and should not attempt to delete it. + const RE* const regex_; + // True if the death test child process has been successfully spawned. + bool spawned_; + // The exit status of the child process. + int status_; + // How the death test concluded. + DeathTestOutcome outcome_; + // Descriptor to the read end of the pipe to the child process. It is + // always -1 in the child process. The child keeps its write end of the + // pipe in write_fd_. + int read_fd_; + // Descriptor to the child's write end of the pipe to the parent process. + // It is always -1 in the parent process. The parent keeps its end of the + // pipe in read_fd_. + int write_fd_; +}; + +// Called in the parent process only. Reads the result code of the death +// test child process via a pipe, interprets it to set the outcome_ +// member, and closes read_fd_. Outputs diagnostics and terminates in +// case of unexpected codes. +void DeathTestImpl::ReadAndInterpretStatusByte() { + char flag; + int bytes_read; + + // The read() here blocks until data is available (signifying the + // failure of the death test) or until the pipe is closed (signifying + // its success), so it's okay to call this in the parent before + // the child process has exited. + do { + bytes_read = posix::Read(read_fd(), &flag, 1); + } while (bytes_read == -1 && errno == EINTR); + + if (bytes_read == 0) { + set_outcome(DIED); + } else if (bytes_read == 1) { + switch (flag) { + case kDeathTestReturned: + set_outcome(RETURNED); + break; + case kDeathTestThrew: + set_outcome(THREW); + break; + case kDeathTestLived: + set_outcome(LIVED); + break; + case kDeathTestInternalError: + FailFromInternalError(read_fd()); // Does not return. + break; + default: + GTEST_LOG_(FATAL) << "Death test child process reported " + << "unexpected status byte (" + << static_cast(flag) << ")"; + } + } else { + GTEST_LOG_(FATAL) << "Read from death test child process failed: " + << GetLastErrnoDescription(); + } + GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd())); + set_read_fd(-1); +} + +// Signals that the death test code which should have exited, didn't. +// Should be called only in a death test child process. +// Writes a status byte to the child's status file descriptor, then +// calls _exit(1). +void DeathTestImpl::Abort(AbortReason reason) { + // The parent process considers the death test to be a failure if + // it finds any data in our pipe. So, here we write a single flag byte + // to the pipe, then exit. + const char status_ch = + reason == TEST_DID_NOT_DIE ? kDeathTestLived : + reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned; + + GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1)); + // We are leaking the descriptor here because on some platforms (i.e., + // when built as Windows DLL), destructors of global objects will still + // run after calling _exit(). On such systems, write_fd_ will be + // indirectly closed from the destructor of UnitTestImpl, causing double + // close if it is also closed here. On debug configurations, double close + // may assert. As there are no in-process buffers to flush here, we are + // relying on the OS to close the descriptor after the process terminates + // when the destructors are not run. + _exit(1); // Exits w/o any normal exit hooks (we were supposed to crash) +} + +// Returns an indented copy of stderr output for a death test. +// This makes distinguishing death test output lines from regular log lines +// much easier. +static ::std::string FormatDeathTestOutput(const ::std::string& output) { + ::std::string ret; + for (size_t at = 0; ; ) { + const size_t line_end = output.find('\n', at); + ret += "[ DEATH ] "; + if (line_end == ::std::string::npos) { + ret += output.substr(at); + break; + } + ret += output.substr(at, line_end + 1 - at); + at = line_end + 1; + } + return ret; +} + +// Assesses the success or failure of a death test, using both private +// members which have previously been set, and one argument: +// +// Private data members: +// outcome: An enumeration describing how the death test +// concluded: DIED, LIVED, THREW, or RETURNED. The death test +// fails in the latter three cases. +// status: The exit status of the child process. On *nix, it is in the +// in the format specified by wait(2). On Windows, this is the +// value supplied to the ExitProcess() API or a numeric code +// of the exception that terminated the program. +// regex: A regular expression object to be applied to +// the test's captured standard error output; the death test +// fails if it does not match. +// +// Argument: +// status_ok: true if exit_status is acceptable in the context of +// this particular death test, which fails if it is false +// +// Returns true iff all of the above conditions are met. Otherwise, the +// first failing condition, in the order given above, is the one that is +// reported. Also sets the last death test message string. +bool DeathTestImpl::Passed(bool status_ok) { + if (!spawned()) + return false; + + const std::string error_message = GetCapturedStderr(); + + bool success = false; + Message buffer; + + buffer << "Death test: " << statement() << "\n"; + switch (outcome()) { + case LIVED: + buffer << " Result: failed to die.\n" + << " Error msg:\n" << FormatDeathTestOutput(error_message); + break; + case THREW: + buffer << " Result: threw an exception.\n" + << " Error msg:\n" << FormatDeathTestOutput(error_message); + break; + case RETURNED: + buffer << " Result: illegal return in test statement.\n" + << " Error msg:\n" << FormatDeathTestOutput(error_message); + break; + case DIED: + if (status_ok) { + const bool matched = RE::PartialMatch(error_message.c_str(), *regex()); + if (matched) { + success = true; + } else { + buffer << " Result: died but not with expected error.\n" + << " Expected: " << regex()->pattern() << "\n" + << "Actual msg:\n" << FormatDeathTestOutput(error_message); + } + } else { + buffer << " Result: died but not with expected exit code:\n" + << " " << ExitSummary(status()) << "\n" + << "Actual msg:\n" << FormatDeathTestOutput(error_message); + } + break; + case IN_PROGRESS: + default: + GTEST_LOG_(FATAL) + << "DeathTest::Passed somehow called before conclusion of test"; + } + + DeathTest::set_last_death_test_message(buffer.GetString()); + return success; +} + +# if GTEST_OS_WINDOWS +// WindowsDeathTest implements death tests on Windows. Due to the +// specifics of starting new processes on Windows, death tests there are +// always threadsafe, and Google Test considers the +// --gtest_death_test_style=fast setting to be equivalent to +// --gtest_death_test_style=threadsafe there. +// +// A few implementation notes: Like the Linux version, the Windows +// implementation uses pipes for child-to-parent communication. But due to +// the specifics of pipes on Windows, some extra steps are required: +// +// 1. The parent creates a communication pipe and stores handles to both +// ends of it. +// 2. The parent starts the child and provides it with the information +// necessary to acquire the handle to the write end of the pipe. +// 3. The child acquires the write end of the pipe and signals the parent +// using a Windows event. +// 4. Now the parent can release the write end of the pipe on its side. If +// this is done before step 3, the object's reference count goes down to +// 0 and it is destroyed, preventing the child from acquiring it. The +// parent now has to release it, or read operations on the read end of +// the pipe will not return when the child terminates. +// 5. The parent reads child's output through the pipe (outcome code and +// any possible error messages) from the pipe, and its stderr and then +// determines whether to fail the test. +// +// Note: to distinguish Win32 API calls from the local method and function +// calls, the former are explicitly resolved in the global namespace. +// +class WindowsDeathTest : public DeathTestImpl { + public: + WindowsDeathTest(const char* a_statement, + const RE* a_regex, + const char* file, + int line) + : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {} + + // All of these virtual functions are inherited from DeathTest. + virtual int Wait(); + virtual TestRole AssumeRole(); + + private: + // The name of the file in which the death test is located. + const char* const file_; + // The line number on which the death test is located. + const int line_; + // Handle to the write end of the pipe to the child process. + AutoHandle write_handle_; + // Child process handle. + AutoHandle child_handle_; + // Event the child process uses to signal the parent that it has + // acquired the handle to the write end of the pipe. After seeing this + // event the parent can release its own handles to make sure its + // ReadFile() calls return when the child terminates. + AutoHandle event_handle_; +}; + +// Waits for the child in a death test to exit, returning its exit +// status, or 0 if no child process exists. As a side effect, sets the +// outcome data member. +int WindowsDeathTest::Wait() { + if (!spawned()) + return 0; + + // Wait until the child either signals that it has acquired the write end + // of the pipe or it dies. + const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() }; + switch (::WaitForMultipleObjects(2, + wait_handles, + FALSE, // Waits for any of the handles. + INFINITE)) { + case WAIT_OBJECT_0: + case WAIT_OBJECT_0 + 1: + break; + default: + GTEST_DEATH_TEST_CHECK_(false); // Should not get here. + } + + // The child has acquired the write end of the pipe or exited. + // We release the handle on our side and continue. + write_handle_.Reset(); + event_handle_.Reset(); + + ReadAndInterpretStatusByte(); + + // Waits for the child process to exit if it haven't already. This + // returns immediately if the child has already exited, regardless of + // whether previous calls to WaitForMultipleObjects synchronized on this + // handle or not. + GTEST_DEATH_TEST_CHECK_( + WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(), + INFINITE)); + DWORD status_code; + GTEST_DEATH_TEST_CHECK_( + ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE); + child_handle_.Reset(); + set_status(static_cast(status_code)); + return status(); +} + +// The AssumeRole process for a Windows death test. It creates a child +// process with the same executable as the current process to run the +// death test. The child process is given the --gtest_filter and +// --gtest_internal_run_death_test flags such that it knows to run the +// current death test only. +DeathTest::TestRole WindowsDeathTest::AssumeRole() { + const UnitTestImpl* const impl = GetUnitTestImpl(); + const InternalRunDeathTestFlag* const flag = + impl->internal_run_death_test_flag(); + const TestInfo* const info = impl->current_test_info(); + const int death_test_index = info->result()->death_test_count(); + + if (flag != NULL) { + // ParseInternalRunDeathTestFlag() has performed all the necessary + // processing. + set_write_fd(flag->write_fd()); + return EXECUTE_TEST; + } + + // WindowsDeathTest uses an anonymous pipe to communicate results of + // a death test. + SECURITY_ATTRIBUTES handles_are_inheritable = { + sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; + HANDLE read_handle, write_handle; + GTEST_DEATH_TEST_CHECK_( + ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable, + 0) // Default buffer size. + != FALSE); + set_read_fd(::_open_osfhandle(reinterpret_cast(read_handle), + O_RDONLY)); + write_handle_.Reset(write_handle); + event_handle_.Reset(::CreateEvent( + &handles_are_inheritable, + TRUE, // The event will automatically reset to non-signaled state. + FALSE, // The initial state is non-signalled. + NULL)); // The even is unnamed. + GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL); + const std::string filter_flag = + std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" + + info->test_case_name() + "." + info->name(); + const std::string internal_flag = + std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + + "=" + file_ + "|" + StreamableToString(line_) + "|" + + StreamableToString(death_test_index) + "|" + + StreamableToString(static_cast(::GetCurrentProcessId())) + + // size_t has the same width as pointers on both 32-bit and 64-bit + // Windows platforms. + // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx. + "|" + StreamableToString(reinterpret_cast(write_handle)) + + "|" + StreamableToString(reinterpret_cast(event_handle_.Get())); + + char executable_path[_MAX_PATH + 1]; // NOLINT + GTEST_DEATH_TEST_CHECK_( + _MAX_PATH + 1 != ::GetModuleFileNameA(NULL, + executable_path, + _MAX_PATH)); + + std::string command_line = + std::string(::GetCommandLineA()) + " " + filter_flag + " \"" + + internal_flag + "\""; + + DeathTest::set_last_death_test_message(""); + + CaptureStderr(); + // Flush the log buffers since the log streams are shared with the child. + FlushInfoLog(); + + // The child process will share the standard handles with the parent. + STARTUPINFOA startup_info; + memset(&startup_info, 0, sizeof(STARTUPINFO)); + startup_info.dwFlags = STARTF_USESTDHANDLES; + startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE); + startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE); + startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE); + + PROCESS_INFORMATION process_info; + GTEST_DEATH_TEST_CHECK_(::CreateProcessA( + executable_path, + const_cast(command_line.c_str()), + NULL, // Retuned process handle is not inheritable. + NULL, // Retuned thread handle is not inheritable. + TRUE, // Child inherits all inheritable handles (for write_handle_). + 0x0, // Default creation flags. + NULL, // Inherit the parent's environment. + UnitTest::GetInstance()->original_working_dir(), + &startup_info, + &process_info) != FALSE); + child_handle_.Reset(process_info.hProcess); + ::CloseHandle(process_info.hThread); + set_spawned(true); + return OVERSEE_TEST; +} +# else // We are not on Windows. + +// ForkingDeathTest provides implementations for most of the abstract +// methods of the DeathTest interface. Only the AssumeRole method is +// left undefined. +class ForkingDeathTest : public DeathTestImpl { + public: + ForkingDeathTest(const char* statement, const RE* regex); + + // All of these virtual functions are inherited from DeathTest. + virtual int Wait(); + + protected: + void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; } + + private: + // PID of child process during death test; 0 in the child process itself. + pid_t child_pid_; +}; + +// Constructs a ForkingDeathTest. +ForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex) + : DeathTestImpl(a_statement, a_regex), + child_pid_(-1) {} + +// Waits for the child in a death test to exit, returning its exit +// status, or 0 if no child process exists. As a side effect, sets the +// outcome data member. +int ForkingDeathTest::Wait() { + if (!spawned()) + return 0; + + ReadAndInterpretStatusByte(); + + int status_value; + GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0)); + set_status(status_value); + return status_value; +} + +// A concrete death test class that forks, then immediately runs the test +// in the child process. +class NoExecDeathTest : public ForkingDeathTest { + public: + NoExecDeathTest(const char* a_statement, const RE* a_regex) : + ForkingDeathTest(a_statement, a_regex) { } + virtual TestRole AssumeRole(); +}; + +// The AssumeRole process for a fork-and-run death test. It implements a +// straightforward fork, with a simple pipe to transmit the status byte. +DeathTest::TestRole NoExecDeathTest::AssumeRole() { + const size_t thread_count = GetThreadCount(); + if (thread_count != 1) { + GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count); + } + + int pipe_fd[2]; + GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1); + + DeathTest::set_last_death_test_message(""); + CaptureStderr(); + // When we fork the process below, the log file buffers are copied, but the + // file descriptors are shared. We flush all log files here so that closing + // the file descriptors in the child process doesn't throw off the + // synchronization between descriptors and buffers in the parent process. + // This is as close to the fork as possible to avoid a race condition in case + // there are multiple threads running before the death test, and another + // thread writes to the log file. + FlushInfoLog(); + + const pid_t child_pid = fork(); + GTEST_DEATH_TEST_CHECK_(child_pid != -1); + set_child_pid(child_pid); + if (child_pid == 0) { + GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0])); + set_write_fd(pipe_fd[1]); + // Redirects all logging to stderr in the child process to prevent + // concurrent writes to the log files. We capture stderr in the parent + // process and append the child process' output to a log. + LogToStderr(); + // Event forwarding to the listeners of event listener API mush be shut + // down in death test subprocesses. + GetUnitTestImpl()->listeners()->SuppressEventForwarding(); + g_in_fast_death_test_child = true; + return EXECUTE_TEST; + } else { + GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); + set_read_fd(pipe_fd[0]); + set_spawned(true); + return OVERSEE_TEST; + } +} + +// A concrete death test class that forks and re-executes the main +// program from the beginning, with command-line flags set that cause +// only this specific death test to be run. +class ExecDeathTest : public ForkingDeathTest { + public: + ExecDeathTest(const char* a_statement, const RE* a_regex, + const char* file, int line) : + ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { } + virtual TestRole AssumeRole(); + private: + static ::std::vector + GetArgvsForDeathTestChildProcess() { + ::std::vector args = GetInjectableArgvs(); +# if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) + ::std::vector extra_args = + GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_(); + args.insert(args.end(), extra_args.begin(), extra_args.end()); +# endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_) + return args; + } + // The name of the file in which the death test is located. + const char* const file_; + // The line number on which the death test is located. + const int line_; +}; + +// Utility class for accumulating command-line arguments. +class Arguments { + public: + Arguments() { + args_.push_back(NULL); + } + + ~Arguments() { + for (std::vector::iterator i = args_.begin(); i != args_.end(); + ++i) { + free(*i); + } + } + void AddArgument(const char* argument) { + args_.insert(args_.end() - 1, posix::StrDup(argument)); + } + + template + void AddArguments(const ::std::vector& arguments) { + for (typename ::std::vector::const_iterator i = arguments.begin(); + i != arguments.end(); + ++i) { + args_.insert(args_.end() - 1, posix::StrDup(i->c_str())); + } + } + char* const* Argv() { + return &args_[0]; + } + + private: + std::vector args_; +}; + +// A struct that encompasses the arguments to the child process of a +// threadsafe-style death test process. +struct ExecDeathTestArgs { + char* const* argv; // Command-line arguments for the child's call to exec + int close_fd; // File descriptor to close; the read end of a pipe +}; + +# if GTEST_OS_MAC +inline char** GetEnviron() { + // When Google Test is built as a framework on MacOS X, the environ variable + // is unavailable. Apple's documentation (man environ) recommends using + // _NSGetEnviron() instead. + return *_NSGetEnviron(); +} +# else +// Some POSIX platforms expect you to declare environ. extern "C" makes +// it reside in the global namespace. +extern "C" char** environ; +inline char** GetEnviron() { return environ; } +# endif // GTEST_OS_MAC + +# if !GTEST_OS_QNX +// The main function for a threadsafe-style death test child process. +// This function is called in a clone()-ed process and thus must avoid +// any potentially unsafe operations like malloc or libc functions. +static int ExecDeathTestChildMain(void* child_arg) { + ExecDeathTestArgs* const args = static_cast(child_arg); + GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd)); + + // We need to execute the test program in the same environment where + // it was originally invoked. Therefore we change to the original + // working directory first. + const char* const original_dir = + UnitTest::GetInstance()->original_working_dir(); + // We can safely call chdir() as it's a direct system call. + if (chdir(original_dir) != 0) { + DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + + GetLastErrnoDescription()); + return EXIT_FAILURE; + } + + // We can safely call execve() as it's a direct system call. We + // cannot use execvp() as it's a libc function and thus potentially + // unsafe. Since execve() doesn't search the PATH, the user must + // invoke the test program via a valid path that contains at least + // one path separator. + execve(args->argv[0], args->argv, GetEnviron()); + DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " + + original_dir + " failed: " + + GetLastErrnoDescription()); + return EXIT_FAILURE; +} +# endif // !GTEST_OS_QNX + +// Two utility routines that together determine the direction the stack +// grows. +// This could be accomplished more elegantly by a single recursive +// function, but we want to guard against the unlikely possibility of +// a smart compiler optimizing the recursion away. +// +// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining +// StackLowerThanAddress into StackGrowsDown, which then doesn't give +// correct answer. +void StackLowerThanAddress(const void* ptr, bool* result) GTEST_NO_INLINE_; +void StackLowerThanAddress(const void* ptr, bool* result) { + int dummy; + *result = (&dummy < ptr); +} + +// Make sure AddressSanitizer does not tamper with the stack here. +GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +bool StackGrowsDown() { + int dummy; + bool result; + StackLowerThanAddress(&dummy, &result); + return result; +} + +// Spawns a child process with the same executable as the current process in +// a thread-safe manner and instructs it to run the death test. The +// implementation uses fork(2) + exec. On systems where clone(2) is +// available, it is used instead, being slightly more thread-safe. On QNX, +// fork supports only single-threaded environments, so this function uses +// spawn(2) there instead. The function dies with an error message if +// anything goes wrong. +static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { + ExecDeathTestArgs args = { argv, close_fd }; + pid_t child_pid = -1; + +# if GTEST_OS_QNX + // Obtains the current directory and sets it to be closed in the child + // process. + const int cwd_fd = open(".", O_RDONLY); + GTEST_DEATH_TEST_CHECK_(cwd_fd != -1); + GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC)); + // We need to execute the test program in the same environment where + // it was originally invoked. Therefore we change to the original + // working directory first. + const char* const original_dir = + UnitTest::GetInstance()->original_working_dir(); + // We can safely call chdir() as it's a direct system call. + if (chdir(original_dir) != 0) { + DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " + + GetLastErrnoDescription()); + return EXIT_FAILURE; + } + + int fd_flags; + // Set close_fd to be closed after spawn. + GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD)); + GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD, + fd_flags | FD_CLOEXEC)); + struct inheritance inherit = {0}; + // spawn is a system call. + child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron()); + // Restores the current working directory. + GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1); + GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); + +# else // GTEST_OS_QNX +# if GTEST_OS_LINUX + // When a SIGPROF signal is received while fork() or clone() are executing, + // the process may hang. To avoid this, we ignore SIGPROF here and re-enable + // it after the call to fork()/clone() is complete. + struct sigaction saved_sigprof_action; + struct sigaction ignore_sigprof_action; + memset(&ignore_sigprof_action, 0, sizeof(ignore_sigprof_action)); + sigemptyset(&ignore_sigprof_action.sa_mask); + ignore_sigprof_action.sa_handler = SIG_IGN; + GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction( + SIGPROF, &ignore_sigprof_action, &saved_sigprof_action)); +# endif // GTEST_OS_LINUX + +# if GTEST_HAS_CLONE + const bool use_fork = GTEST_FLAG(death_test_use_fork); + + if (!use_fork) { + static const bool stack_grows_down = StackGrowsDown(); + const size_t stack_size = getpagesize(); + // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead. + void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED); + + // Maximum stack alignment in bytes: For a downward-growing stack, this + // amount is subtracted from size of the stack space to get an address + // that is within the stack space and is aligned on all systems we care + // about. As far as I know there is no ABI with stack alignment greater + // than 64. We assume stack and stack_size already have alignment of + // kMaxStackAlignment. + const size_t kMaxStackAlignment = 64; + void* const stack_top = + static_cast(stack) + + (stack_grows_down ? stack_size - kMaxStackAlignment : 0); + GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment && + reinterpret_cast(stack_top) % kMaxStackAlignment == 0); + + child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args); + + GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1); + } +# else + const bool use_fork = true; +# endif // GTEST_HAS_CLONE + + if (use_fork && (child_pid = fork()) == 0) { + ExecDeathTestChildMain(&args); + _exit(0); + } +# endif // GTEST_OS_QNX +# if GTEST_OS_LINUX + GTEST_DEATH_TEST_CHECK_SYSCALL_( + sigaction(SIGPROF, &saved_sigprof_action, NULL)); +# endif // GTEST_OS_LINUX + + GTEST_DEATH_TEST_CHECK_(child_pid != -1); + return child_pid; +} + +// The AssumeRole process for a fork-and-exec death test. It re-executes the +// main program from the beginning, setting the --gtest_filter +// and --gtest_internal_run_death_test flags to cause only the current +// death test to be re-run. +DeathTest::TestRole ExecDeathTest::AssumeRole() { + const UnitTestImpl* const impl = GetUnitTestImpl(); + const InternalRunDeathTestFlag* const flag = + impl->internal_run_death_test_flag(); + const TestInfo* const info = impl->current_test_info(); + const int death_test_index = info->result()->death_test_count(); + + if (flag != NULL) { + set_write_fd(flag->write_fd()); + return EXECUTE_TEST; + } + + int pipe_fd[2]; + GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1); + // Clear the close-on-exec flag on the write end of the pipe, lest + // it be closed when the child process does an exec: + GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1); + + const std::string filter_flag = + std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" + + info->test_case_name() + "." + info->name(); + const std::string internal_flag = + std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "=" + + file_ + "|" + StreamableToString(line_) + "|" + + StreamableToString(death_test_index) + "|" + + StreamableToString(pipe_fd[1]); + Arguments args; + args.AddArguments(GetArgvsForDeathTestChildProcess()); + args.AddArgument(filter_flag.c_str()); + args.AddArgument(internal_flag.c_str()); + + DeathTest::set_last_death_test_message(""); + + CaptureStderr(); + // See the comment in NoExecDeathTest::AssumeRole for why the next line + // is necessary. + FlushInfoLog(); + + const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]); + GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); + set_child_pid(child_pid); + set_read_fd(pipe_fd[0]); + set_spawned(true); + return OVERSEE_TEST; +} + +# endif // !GTEST_OS_WINDOWS + +// Creates a concrete DeathTest-derived class that depends on the +// --gtest_death_test_style flag, and sets the pointer pointed to +// by the "test" argument to its address. If the test should be +// skipped, sets that pointer to NULL. Returns true, unless the +// flag is set to an invalid value. +bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex, + const char* file, int line, + DeathTest** test) { + UnitTestImpl* const impl = GetUnitTestImpl(); + const InternalRunDeathTestFlag* const flag = + impl->internal_run_death_test_flag(); + const int death_test_index = impl->current_test_info() + ->increment_death_test_count(); + + if (flag != NULL) { + if (death_test_index > flag->index()) { + DeathTest::set_last_death_test_message( + "Death test count (" + StreamableToString(death_test_index) + + ") somehow exceeded expected maximum (" + + StreamableToString(flag->index()) + ")"); + return false; + } + + if (!(flag->file() == file && flag->line() == line && + flag->index() == death_test_index)) { + *test = NULL; + return true; + } + } + +# if GTEST_OS_WINDOWS + + if (GTEST_FLAG(death_test_style) == "threadsafe" || + GTEST_FLAG(death_test_style) == "fast") { + *test = new WindowsDeathTest(statement, regex, file, line); + } + +# else + + if (GTEST_FLAG(death_test_style) == "threadsafe") { + *test = new ExecDeathTest(statement, regex, file, line); + } else if (GTEST_FLAG(death_test_style) == "fast") { + *test = new NoExecDeathTest(statement, regex); + } + +# endif // GTEST_OS_WINDOWS + + else { // NOLINT - this is more readable than unbalanced brackets inside #if. + DeathTest::set_last_death_test_message( + "Unknown death test style \"" + GTEST_FLAG(death_test_style) + + "\" encountered"); + return false; + } + + return true; +} + +# if GTEST_OS_WINDOWS +// Recreates the pipe and event handles from the provided parameters, +// signals the event, and returns a file descriptor wrapped around the pipe +// handle. This function is called in the child process only. +int GetStatusFileDescriptor(unsigned int parent_process_id, + size_t write_handle_as_size_t, + size_t event_handle_as_size_t) { + AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE, + FALSE, // Non-inheritable. + parent_process_id)); + if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) { + DeathTestAbort("Unable to open parent process " + + StreamableToString(parent_process_id)); + } + + // TODO(vladl@google.com): Replace the following check with a + // compile-time assertion when available. + GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t)); + + const HANDLE write_handle = + reinterpret_cast(write_handle_as_size_t); + HANDLE dup_write_handle; + + // The newly initialized handle is accessible only in in the parent + // process. To obtain one accessible within the child, we need to use + // DuplicateHandle. + if (!::DuplicateHandle(parent_process_handle.Get(), write_handle, + ::GetCurrentProcess(), &dup_write_handle, + 0x0, // Requested privileges ignored since + // DUPLICATE_SAME_ACCESS is used. + FALSE, // Request non-inheritable handler. + DUPLICATE_SAME_ACCESS)) { + DeathTestAbort("Unable to duplicate the pipe handle " + + StreamableToString(write_handle_as_size_t) + + " from the parent process " + + StreamableToString(parent_process_id)); + } + + const HANDLE event_handle = reinterpret_cast(event_handle_as_size_t); + HANDLE dup_event_handle; + + if (!::DuplicateHandle(parent_process_handle.Get(), event_handle, + ::GetCurrentProcess(), &dup_event_handle, + 0x0, + FALSE, + DUPLICATE_SAME_ACCESS)) { + DeathTestAbort("Unable to duplicate the event handle " + + StreamableToString(event_handle_as_size_t) + + " from the parent process " + + StreamableToString(parent_process_id)); + } + + const int write_fd = + ::_open_osfhandle(reinterpret_cast(dup_write_handle), O_APPEND); + if (write_fd == -1) { + DeathTestAbort("Unable to convert pipe handle " + + StreamableToString(write_handle_as_size_t) + + " to a file descriptor"); + } + + // Signals the parent that the write end of the pipe has been acquired + // so the parent can release its own write end. + ::SetEvent(dup_event_handle); + + return write_fd; +} +# endif // GTEST_OS_WINDOWS + +// Returns a newly created InternalRunDeathTestFlag object with fields +// initialized from the GTEST_FLAG(internal_run_death_test) flag if +// the flag is specified; otherwise returns NULL. +InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { + if (GTEST_FLAG(internal_run_death_test) == "") return NULL; + + // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we + // can use it here. + int line = -1; + int index = -1; + ::std::vector< ::std::string> fields; + SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields); + int write_fd = -1; + +# if GTEST_OS_WINDOWS + + unsigned int parent_process_id = 0; + size_t write_handle_as_size_t = 0; + size_t event_handle_as_size_t = 0; + + if (fields.size() != 6 + || !ParseNaturalNumber(fields[1], &line) + || !ParseNaturalNumber(fields[2], &index) + || !ParseNaturalNumber(fields[3], &parent_process_id) + || !ParseNaturalNumber(fields[4], &write_handle_as_size_t) + || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) { + DeathTestAbort("Bad --gtest_internal_run_death_test flag: " + + GTEST_FLAG(internal_run_death_test)); + } + write_fd = GetStatusFileDescriptor(parent_process_id, + write_handle_as_size_t, + event_handle_as_size_t); +# else + + if (fields.size() != 4 + || !ParseNaturalNumber(fields[1], &line) + || !ParseNaturalNumber(fields[2], &index) + || !ParseNaturalNumber(fields[3], &write_fd)) { + DeathTestAbort("Bad --gtest_internal_run_death_test flag: " + + GTEST_FLAG(internal_run_death_test)); + } + +# endif // GTEST_OS_WINDOWS + + return new InternalRunDeathTestFlag(fields[0], line, index, write_fd); +} + +} // namespace internal + +#endif // GTEST_HAS_DEATH_TEST + +} // namespace testing diff --git a/TestMothur/gtest-death-test.h b/TestMothur/gtest-death-test.h new file mode 100755 index 00000000..1ac58aef --- /dev/null +++ b/TestMothur/gtest-death-test.h @@ -0,0 +1,294 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file defines the public API for death tests. It is +// #included by gtest.h so a user doesn't need to include this +// directly. + +#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ +#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ + +#include "gtest-death-test-internal.h" + +namespace testing { + +// This flag controls the style of death tests. Valid values are "threadsafe", +// meaning that the death test child process will re-execute the test binary +// from the start, running only a single death test, or "fast", +// meaning that the child process will execute the test logic immediately +// after forking. +GTEST_DECLARE_string_(death_test_style); + +#if GTEST_HAS_DEATH_TEST + +namespace internal { + +// Returns a Boolean value indicating whether the caller is currently +// executing in the context of the death test child process. Tools such as +// Valgrind heap checkers may need this to modify their behavior in death +// tests. IMPORTANT: This is an internal utility. Using it may break the +// implementation of death tests. User code MUST NOT use it. +GTEST_API_ bool InDeathTestChild(); + +} // namespace internal + +// The following macros are useful for writing death tests. + +// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is +// executed: +// +// 1. It generates a warning if there is more than one active +// thread. This is because it's safe to fork() or clone() only +// when there is a single thread. +// +// 2. The parent process clone()s a sub-process and runs the death +// test in it; the sub-process exits with code 0 at the end of the +// death test, if it hasn't exited already. +// +// 3. The parent process waits for the sub-process to terminate. +// +// 4. The parent process checks the exit code and error message of +// the sub-process. +// +// Examples: +// +// ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number"); +// for (int i = 0; i < 5; i++) { +// EXPECT_DEATH(server.ProcessRequest(i), +// "Invalid request .* in ProcessRequest()") +// << "Failed to die on request " << i; +// } +// +// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting"); +// +// bool KilledBySIGHUP(int exit_code) { +// return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP; +// } +// +// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); +// +// On the regular expressions used in death tests: +// +// On POSIX-compliant systems (*nix), we use the library, +// which uses the POSIX extended regex syntax. +// +// On other platforms (e.g. Windows), we only support a simple regex +// syntax implemented as part of Google Test. This limited +// implementation should be enough most of the time when writing +// death tests; though it lacks many features you can find in PCRE +// or POSIX extended regex syntax. For example, we don't support +// union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and +// repetition count ("x{5,7}"), among others. +// +// Below is the syntax that we do support. We chose it to be a +// subset of both PCRE and POSIX extended regex, so it's easy to +// learn wherever you come from. In the following: 'A' denotes a +// literal character, period (.), or a single \\ escape sequence; +// 'x' and 'y' denote regular expressions; 'm' and 'n' are for +// natural numbers. +// +// c matches any literal character c +// \\d matches any decimal digit +// \\D matches any character that's not a decimal digit +// \\f matches \f +// \\n matches \n +// \\r matches \r +// \\s matches any ASCII whitespace, including \n +// \\S matches any character that's not a whitespace +// \\t matches \t +// \\v matches \v +// \\w matches any letter, _, or decimal digit +// \\W matches any character that \\w doesn't match +// \\c matches any literal character c, which must be a punctuation +// . matches any single character except \n +// A? matches 0 or 1 occurrences of A +// A* matches 0 or many occurrences of A +// A+ matches 1 or many occurrences of A +// ^ matches the beginning of a string (not that of each line) +// $ matches the end of a string (not that of each line) +// xy matches x followed by y +// +// If you accidentally use PCRE or POSIX extended regex features +// not implemented by us, you will get a run-time failure. In that +// case, please try to rewrite your regular expression within the +// above syntax. +// +// This implementation is *not* meant to be as highly tuned or robust +// as a compiled regex library, but should perform well enough for a +// death test, which already incurs significant overhead by launching +// a child process. +// +// Known caveats: +// +// A "threadsafe" style death test obtains the path to the test +// program from argv[0] and re-executes it in the sub-process. For +// simplicity, the current implementation doesn't search the PATH +// when launching the sub-process. This means that the user must +// invoke the test program via a path that contains at least one +// path separator (e.g. path/to/foo_test and +// /absolute/path/to/bar_test are fine, but foo_test is not). This +// is rarely a problem as people usually don't put the test binary +// directory in PATH. +// +// TODO(wan@google.com): make thread-safe death tests search the PATH. + +// Asserts that a given statement causes the program to exit, with an +// integer exit status that satisfies predicate, and emitting error output +// that matches regex. +# define ASSERT_EXIT(statement, predicate, regex) \ + GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) + +// Like ASSERT_EXIT, but continues on to successive tests in the +// test case, if any: +# define EXPECT_EXIT(statement, predicate, regex) \ + GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) + +// Asserts that a given statement causes the program to exit, either by +// explicitly exiting with a nonzero exit code or being killed by a +// signal, and emitting error output that matches regex. +# define ASSERT_DEATH(statement, regex) \ + ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) + +// Like ASSERT_DEATH, but continues on to successive tests in the +// test case, if any: +# define EXPECT_DEATH(statement, regex) \ + EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) + +// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: + +// Tests that an exit code describes a normal exit with a given exit code. +class GTEST_API_ ExitedWithCode { + public: + explicit ExitedWithCode(int exit_code); + bool operator()(int exit_status) const; + private: + // No implementation - assignment is unsupported. + void operator=(const ExitedWithCode& other); + + const int exit_code_; +}; + +# if !GTEST_OS_WINDOWS +// Tests that an exit code describes an exit due to termination by a +// given signal. +class GTEST_API_ KilledBySignal { + public: + explicit KilledBySignal(int signum); + bool operator()(int exit_status) const; + private: + const int signum_; +}; +# endif // !GTEST_OS_WINDOWS + +// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. +// The death testing framework causes this to have interesting semantics, +// since the sideeffects of the call are only visible in opt mode, and not +// in debug mode. +// +// In practice, this can be used to test functions that utilize the +// LOG(DFATAL) macro using the following style: +// +// int DieInDebugOr12(int* sideeffect) { +// if (sideeffect) { +// *sideeffect = 12; +// } +// LOG(DFATAL) << "death"; +// return 12; +// } +// +// TEST(TestCase, TestDieOr12WorksInDgbAndOpt) { +// int sideeffect = 0; +// // Only asserts in dbg. +// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death"); +// +// #ifdef NDEBUG +// // opt-mode has sideeffect visible. +// EXPECT_EQ(12, sideeffect); +// #else +// // dbg-mode no visible sideeffect. +// EXPECT_EQ(0, sideeffect); +// #endif +// } +// +// This will assert that DieInDebugReturn12InOpt() crashes in debug +// mode, usually due to a DCHECK or LOG(DFATAL), but returns the +// appropriate fallback value (12 in this case) in opt mode. If you +// need to test that a function has appropriate side-effects in opt +// mode, include assertions against the side-effects. A general +// pattern for this is: +// +// EXPECT_DEBUG_DEATH({ +// // Side-effects here will have an effect after this statement in +// // opt mode, but none in debug mode. +// EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); +// }, "death"); +// +# ifdef NDEBUG + +# define EXPECT_DEBUG_DEATH(statement, regex) \ + GTEST_EXECUTE_STATEMENT_(statement, regex) + +# define ASSERT_DEBUG_DEATH(statement, regex) \ + GTEST_EXECUTE_STATEMENT_(statement, regex) + +# else + +# define EXPECT_DEBUG_DEATH(statement, regex) \ + EXPECT_DEATH(statement, regex) + +# define ASSERT_DEBUG_DEATH(statement, regex) \ + ASSERT_DEATH(statement, regex) + +# endif // NDEBUG for EXPECT_DEBUG_DEATH +#endif // GTEST_HAS_DEATH_TEST + +// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and +// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if +// death tests are supported; otherwise they just issue a warning. This is +// useful when you are combining death test assertions with normal test +// assertions in one test. +#if GTEST_HAS_DEATH_TEST +# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ + EXPECT_DEATH(statement, regex) +# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ + ASSERT_DEATH(statement, regex) +#else +# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ + GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, ) +# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ + GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return) +#endif + +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ diff --git a/TestMothur/gtest-filepath.cc b/TestMothur/gtest-filepath.cc new file mode 100755 index 00000000..4ce70135 --- /dev/null +++ b/TestMothur/gtest-filepath.cc @@ -0,0 +1,387 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: keith.ray@gmail.com (Keith Ray) + +#include "gtest-message.h" +#include "gtest-filepath.h" +#include "gtest-port.h" + +#include + +#if GTEST_OS_WINDOWS_MOBILE +# include +#elif GTEST_OS_WINDOWS +# include +# include +#elif GTEST_OS_SYMBIAN +// Symbian OpenC has PATH_MAX in sys/syslimits.h +# include +#else +# include +# include // Some Linux distributions define PATH_MAX here. +#endif // GTEST_OS_WINDOWS_MOBILE + +#if GTEST_OS_WINDOWS +# define GTEST_PATH_MAX_ _MAX_PATH +#elif defined(PATH_MAX) +# define GTEST_PATH_MAX_ PATH_MAX +#elif defined(_XOPEN_PATH_MAX) +# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX +#else +# define GTEST_PATH_MAX_ _POSIX_PATH_MAX +#endif // GTEST_OS_WINDOWS + +#include "gtest-string.h" + +namespace testing { +namespace internal { + +#if GTEST_OS_WINDOWS +// On Windows, '\\' is the standard path separator, but many tools and the +// Windows API also accept '/' as an alternate path separator. Unless otherwise +// noted, a file path can contain either kind of path separators, or a mixture +// of them. +const char kPathSeparator = '\\'; +const char kAlternatePathSeparator = '/'; +const char kAlternatePathSeparatorString[] = "/"; +# if GTEST_OS_WINDOWS_MOBILE +// Windows CE doesn't have a current directory. You should not use +// the current directory in tests on Windows CE, but this at least +// provides a reasonable fallback. +const char kCurrentDirectoryString[] = "\\"; +// Windows CE doesn't define INVALID_FILE_ATTRIBUTES +const DWORD kInvalidFileAttributes = 0xffffffff; +# else +const char kCurrentDirectoryString[] = ".\\"; +# endif // GTEST_OS_WINDOWS_MOBILE +#else +const char kPathSeparator = '/'; +const char kCurrentDirectoryString[] = "./"; +#endif // GTEST_OS_WINDOWS + +// Returns whether the given character is a valid path separator. +static bool IsPathSeparator(char c) { +#if GTEST_HAS_ALT_PATH_SEP_ + return (c == kPathSeparator) || (c == kAlternatePathSeparator); +#else + return c == kPathSeparator; +#endif +} + +// Returns the current working directory, or "" if unsuccessful. +FilePath FilePath::GetCurrentDir() { +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT + // Windows CE doesn't have a current directory, so we just return + // something reasonable. + return FilePath(kCurrentDirectoryString); +#elif GTEST_OS_WINDOWS + char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; + return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd); +#else + char cwd[GTEST_PATH_MAX_ + 1] = { '\0' }; + char* result = getcwd(cwd, sizeof(cwd)); +# if GTEST_OS_NACL + // getcwd will likely fail in NaCl due to the sandbox, so return something + // reasonable. The user may have provided a shim implementation for getcwd, + // however, so fallback only when failure is detected. + return FilePath(result == NULL ? kCurrentDirectoryString : cwd); +# endif // GTEST_OS_NACL + return FilePath(result == NULL ? "" : cwd); +#endif // GTEST_OS_WINDOWS_MOBILE +} + +// Returns a copy of the FilePath with the case-insensitive extension removed. +// Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns +// FilePath("dir/file"). If a case-insensitive extension is not +// found, returns a copy of the original FilePath. +FilePath FilePath::RemoveExtension(const char* extension) const { + const std::string dot_extension = std::string(".") + extension; + if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) { + return FilePath(pathname_.substr( + 0, pathname_.length() - dot_extension.length())); + } + return *this; +} + +// Returns a pointer to the last occurence of a valid path separator in +// the FilePath. On Windows, for example, both '/' and '\' are valid path +// separators. Returns NULL if no path separator was found. +const char* FilePath::FindLastPathSeparator() const { + const char* const last_sep = strrchr(c_str(), kPathSeparator); +#if GTEST_HAS_ALT_PATH_SEP_ + const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator); + // Comparing two pointers of which only one is NULL is undefined. + if (last_alt_sep != NULL && + (last_sep == NULL || last_alt_sep > last_sep)) { + return last_alt_sep; + } +#endif + return last_sep; +} + +// Returns a copy of the FilePath with the directory part removed. +// Example: FilePath("path/to/file").RemoveDirectoryName() returns +// FilePath("file"). If there is no directory part ("just_a_file"), it returns +// the FilePath unmodified. If there is no file part ("just_a_dir/") it +// returns an empty FilePath (""). +// On Windows platform, '\' is the path separator, otherwise it is '/'. +FilePath FilePath::RemoveDirectoryName() const { + const char* const last_sep = FindLastPathSeparator(); + return last_sep ? FilePath(last_sep + 1) : *this; +} + +// RemoveFileName returns the directory path with the filename removed. +// Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". +// If the FilePath is "a_file" or "/a_file", RemoveFileName returns +// FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does +// not have a file, like "just/a/dir/", it returns the FilePath unmodified. +// On Windows platform, '\' is the path separator, otherwise it is '/'. +FilePath FilePath::RemoveFileName() const { + const char* const last_sep = FindLastPathSeparator(); + std::string dir; + if (last_sep) { + dir = std::string(c_str(), last_sep + 1 - c_str()); + } else { + dir = kCurrentDirectoryString; + } + return FilePath(dir); +} + +// Helper functions for naming files in a directory for xml output. + +// Given directory = "dir", base_name = "test", number = 0, +// extension = "xml", returns "dir/test.xml". If number is greater +// than zero (e.g., 12), returns "dir/test_12.xml". +// On Windows platform, uses \ as the separator rather than /. +FilePath FilePath::MakeFileName(const FilePath& directory, + const FilePath& base_name, + int number, + const char* extension) { + std::string file; + if (number == 0) { + file = base_name.string() + "." + extension; + } else { + file = base_name.string() + "_" + StreamableToString(number) + + "." + extension; + } + return ConcatPaths(directory, FilePath(file)); +} + +// Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml". +// On Windows, uses \ as the separator rather than /. +FilePath FilePath::ConcatPaths(const FilePath& directory, + const FilePath& relative_path) { + if (directory.IsEmpty()) + return relative_path; + const FilePath dir(directory.RemoveTrailingPathSeparator()); + return FilePath(dir.string() + kPathSeparator + relative_path.string()); +} + +// Returns true if pathname describes something findable in the file-system, +// either a file, directory, or whatever. +bool FilePath::FileOrDirectoryExists() const { +#if GTEST_OS_WINDOWS_MOBILE + LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); + const DWORD attributes = GetFileAttributes(unicode); + delete [] unicode; + return attributes != kInvalidFileAttributes; +#else + posix::StatStruct file_stat; + return posix::Stat(pathname_.c_str(), &file_stat) == 0; +#endif // GTEST_OS_WINDOWS_MOBILE +} + +// Returns true if pathname describes a directory in the file-system +// that exists. +bool FilePath::DirectoryExists() const { + bool result = false; +#if GTEST_OS_WINDOWS + // Don't strip off trailing separator if path is a root directory on + // Windows (like "C:\\"). + const FilePath& path(IsRootDirectory() ? *this : + RemoveTrailingPathSeparator()); +#else + const FilePath& path(*this); +#endif + +#if GTEST_OS_WINDOWS_MOBILE + LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); + const DWORD attributes = GetFileAttributes(unicode); + delete [] unicode; + if ((attributes != kInvalidFileAttributes) && + (attributes & FILE_ATTRIBUTE_DIRECTORY)) { + result = true; + } +#else + posix::StatStruct file_stat; + result = posix::Stat(path.c_str(), &file_stat) == 0 && + posix::IsDir(file_stat); +#endif // GTEST_OS_WINDOWS_MOBILE + + return result; +} + +// Returns true if pathname describes a root directory. (Windows has one +// root directory per disk drive.) +bool FilePath::IsRootDirectory() const { +#if GTEST_OS_WINDOWS + // TODO(wan@google.com): on Windows a network share like + // \\server\share can be a root directory, although it cannot be the + // current directory. Handle this properly. + return pathname_.length() == 3 && IsAbsolutePath(); +#else + return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]); +#endif +} + +// Returns true if pathname describes an absolute path. +bool FilePath::IsAbsolutePath() const { + const char* const name = pathname_.c_str(); +#if GTEST_OS_WINDOWS + return pathname_.length() >= 3 && + ((name[0] >= 'a' && name[0] <= 'z') || + (name[0] >= 'A' && name[0] <= 'Z')) && + name[1] == ':' && + IsPathSeparator(name[2]); +#else + return IsPathSeparator(name[0]); +#endif +} + +// Returns a pathname for a file that does not currently exist. The pathname +// will be directory/base_name.extension or +// directory/base_name_.extension if directory/base_name.extension +// already exists. The number will be incremented until a pathname is found +// that does not already exist. +// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. +// There could be a race condition if two or more processes are calling this +// function at the same time -- they could both pick the same filename. +FilePath FilePath::GenerateUniqueFileName(const FilePath& directory, + const FilePath& base_name, + const char* extension) { + FilePath full_pathname; + int number = 0; + do { + full_pathname.Set(MakeFileName(directory, base_name, number++, extension)); + } while (full_pathname.FileOrDirectoryExists()); + return full_pathname; +} + +// Returns true if FilePath ends with a path separator, which indicates that +// it is intended to represent a directory. Returns false otherwise. +// This does NOT check that a directory (or file) actually exists. +bool FilePath::IsDirectory() const { + return !pathname_.empty() && + IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]); +} + +// Create directories so that path exists. Returns true if successful or if +// the directories already exist; returns false if unable to create directories +// for any reason. +bool FilePath::CreateDirectoriesRecursively() const { + if (!this->IsDirectory()) { + return false; + } + + if (pathname_.length() == 0 || this->DirectoryExists()) { + return true; + } + + const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName()); + return parent.CreateDirectoriesRecursively() && this->CreateFolder(); +} + +// Create the directory so that path exists. Returns true if successful or +// if the directory already exists; returns false if unable to create the +// directory for any reason, including if the parent directory does not +// exist. Not named "CreateDirectory" because that's a macro on Windows. +bool FilePath::CreateFolder() const { +#if GTEST_OS_WINDOWS_MOBILE + FilePath removed_sep(this->RemoveTrailingPathSeparator()); + LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); + int result = CreateDirectory(unicode, NULL) ? 0 : -1; + delete [] unicode; +#elif GTEST_OS_WINDOWS + int result = _mkdir(pathname_.c_str()); +#else + int result = mkdir(pathname_.c_str(), 0777); +#endif // GTEST_OS_WINDOWS_MOBILE + + if (result == -1) { + return this->DirectoryExists(); // An error is OK if the directory exists. + } + return true; // No error. +} + +// If input name has a trailing separator character, remove it and return the +// name, otherwise return the name string unmodified. +// On Windows platform, uses \ as the separator, other platforms use /. +FilePath FilePath::RemoveTrailingPathSeparator() const { + return IsDirectory() + ? FilePath(pathname_.substr(0, pathname_.length() - 1)) + : *this; +} + +// Removes any redundant separators that might be in the pathname. +// For example, "bar///foo" becomes "bar/foo". Does not eliminate other +// redundancies that might be in a pathname involving "." or "..". +// TODO(wan@google.com): handle Windows network shares (e.g. \\server\share). +void FilePath::Normalize() { + if (pathname_.c_str() == NULL) { + pathname_ = ""; + return; + } + const char* src = pathname_.c_str(); + char* const dest = new char[pathname_.length() + 1]; + char* dest_ptr = dest; + memset(dest_ptr, 0, pathname_.length() + 1); + + while (*src != '\0') { + *dest_ptr = *src; + if (!IsPathSeparator(*src)) { + src++; + } else { +#if GTEST_HAS_ALT_PATH_SEP_ + if (*dest_ptr == kAlternatePathSeparator) { + *dest_ptr = kPathSeparator; + } +#endif + while (IsPathSeparator(*src)) + src++; + } + dest_ptr++; + } + *dest_ptr = '\0'; + pathname_ = dest; + delete[] dest; +} + +} // namespace internal +} // namespace testing diff --git a/TestMothur/gtest-filepath.h b/TestMothur/gtest-filepath.h new file mode 100755 index 00000000..8af52f82 --- /dev/null +++ b/TestMothur/gtest-filepath.h @@ -0,0 +1,206 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: keith.ray@gmail.com (Keith Ray) +// +// Google Test filepath utilities +// +// This header file declares classes and functions used internally by +// Google Test. They are subject to change without notice. +// +// This file is #included in . +// Do not include this header file separately! + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ + +#include "gtest-string.h" + +namespace testing { +namespace internal { + +// FilePath - a class for file and directory pathname manipulation which +// handles platform-specific conventions (like the pathname separator). +// Used for helper functions for naming files in a directory for xml output. +// Except for Set methods, all methods are const or static, which provides an +// "immutable value object" -- useful for peace of mind. +// A FilePath with a value ending in a path separator ("like/this/") represents +// a directory, otherwise it is assumed to represent a file. In either case, +// it may or may not represent an actual file or directory in the file system. +// Names are NOT checked for syntax correctness -- no checking for illegal +// characters, malformed paths, etc. + +class GTEST_API_ FilePath { + public: + FilePath() : pathname_("") { } + FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } + + explicit FilePath(const std::string& pathname) : pathname_(pathname) { + Normalize(); + } + + FilePath& operator=(const FilePath& rhs) { + Set(rhs); + return *this; + } + + void Set(const FilePath& rhs) { + pathname_ = rhs.pathname_; + } + + const std::string& string() const { return pathname_; } + const char* c_str() const { return pathname_.c_str(); } + + // Returns the current working directory, or "" if unsuccessful. + static FilePath GetCurrentDir(); + + // Given directory = "dir", base_name = "test", number = 0, + // extension = "xml", returns "dir/test.xml". If number is greater + // than zero (e.g., 12), returns "dir/test_12.xml". + // On Windows platform, uses \ as the separator rather than /. + static FilePath MakeFileName(const FilePath& directory, + const FilePath& base_name, + int number, + const char* extension); + + // Given directory = "dir", relative_path = "test.xml", + // returns "dir/test.xml". + // On Windows, uses \ as the separator rather than /. + static FilePath ConcatPaths(const FilePath& directory, + const FilePath& relative_path); + + // Returns a pathname for a file that does not currently exist. The pathname + // will be directory/base_name.extension or + // directory/base_name_.extension if directory/base_name.extension + // already exists. The number will be incremented until a pathname is found + // that does not already exist. + // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. + // There could be a race condition if two or more processes are calling this + // function at the same time -- they could both pick the same filename. + static FilePath GenerateUniqueFileName(const FilePath& directory, + const FilePath& base_name, + const char* extension); + + // Returns true iff the path is "". + bool IsEmpty() const { return pathname_.empty(); } + + // If input name has a trailing separator character, removes it and returns + // the name, otherwise return the name string unmodified. + // On Windows platform, uses \ as the separator, other platforms use /. + FilePath RemoveTrailingPathSeparator() const; + + // Returns a copy of the FilePath with the directory part removed. + // Example: FilePath("path/to/file").RemoveDirectoryName() returns + // FilePath("file"). If there is no directory part ("just_a_file"), it returns + // the FilePath unmodified. If there is no file part ("just_a_dir/") it + // returns an empty FilePath (""). + // On Windows platform, '\' is the path separator, otherwise it is '/'. + FilePath RemoveDirectoryName() const; + + // RemoveFileName returns the directory path with the filename removed. + // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". + // If the FilePath is "a_file" or "/a_file", RemoveFileName returns + // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does + // not have a file, like "just/a/dir/", it returns the FilePath unmodified. + // On Windows platform, '\' is the path separator, otherwise it is '/'. + FilePath RemoveFileName() const; + + // Returns a copy of the FilePath with the case-insensitive extension removed. + // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns + // FilePath("dir/file"). If a case-insensitive extension is not + // found, returns a copy of the original FilePath. + FilePath RemoveExtension(const char* extension) const; + + // Creates directories so that path exists. Returns true if successful or if + // the directories already exist; returns false if unable to create + // directories for any reason. Will also return false if the FilePath does + // not represent a directory (that is, it doesn't end with a path separator). + bool CreateDirectoriesRecursively() const; + + // Create the directory so that path exists. Returns true if successful or + // if the directory already exists; returns false if unable to create the + // directory for any reason, including if the parent directory does not + // exist. Not named "CreateDirectory" because that's a macro on Windows. + bool CreateFolder() const; + + // Returns true if FilePath describes something in the file-system, + // either a file, directory, or whatever, and that something exists. + bool FileOrDirectoryExists() const; + + // Returns true if pathname describes a directory in the file-system + // that exists. + bool DirectoryExists() const; + + // Returns true if FilePath ends with a path separator, which indicates that + // it is intended to represent a directory. Returns false otherwise. + // This does NOT check that a directory (or file) actually exists. + bool IsDirectory() const; + + // Returns true if pathname describes a root directory. (Windows has one + // root directory per disk drive.) + bool IsRootDirectory() const; + + // Returns true if pathname describes an absolute path. + bool IsAbsolutePath() const; + + private: + // Replaces multiple consecutive separators with a single separator. + // For example, "bar///foo" becomes "bar/foo". Does not eliminate other + // redundancies that might be in a pathname involving "." or "..". + // + // A pathname with multiple consecutive separators may occur either through + // user error or as a result of some scripts or APIs that generate a pathname + // with a trailing separator. On other platforms the same API or script + // may NOT generate a pathname with a trailing "/". Then elsewhere that + // pathname may have another "/" and pathname components added to it, + // without checking for the separator already being there. + // The script language and operating system may allow paths like "foo//bar" + // but some of the functions in FilePath will not handle that correctly. In + // particular, RemoveTrailingPathSeparator() only removes one separator, and + // it is called in CreateDirectoriesRecursively() assuming that it will change + // a pathname from directory syntax (trailing separator) to filename syntax. + // + // On Windows this method also replaces the alternate path separator '/' with + // the primary path separator '\\', so that for example "bar\\/\\foo" becomes + // "bar\\foo". + + void Normalize(); + + // Returns a pointer to the last occurence of a valid path separator in + // the FilePath. On Windows, for example, both '/' and '\' are valid path + // separators. Returns NULL if no path separator was found. + const char* FindLastPathSeparator() const; + + std::string pathname_; +}; // class FilePath + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ diff --git a/TestMothur/gtest-internal.h b/TestMothur/gtest-internal.h new file mode 100755 index 00000000..7bdfabcc --- /dev/null +++ b/TestMothur/gtest-internal.h @@ -0,0 +1,1238 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file declares functions and macros used internally by +// Google Test. They are subject to change without notice. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ + +#include "gtest-port.h" + +#if GTEST_OS_LINUX +# include +# include +# include +# include +#endif // GTEST_OS_LINUX + +#if GTEST_HAS_EXCEPTIONS +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gtest-message.h" +#include "gtest-string.h" +#include "gtest-filepath.h" +#include "gtest-type-util.h" + +// Due to C++ preprocessor weirdness, we need double indirection to +// concatenate two tokens when one of them is __LINE__. Writing +// +// foo ## __LINE__ +// +// will result in the token foo__LINE__, instead of foo followed by +// the current line number. For more details, see +// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) +#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar + +class ProtocolMessage; +namespace proto2 { class Message; } + +namespace testing { + +// Forward declarations. + +class AssertionResult; // Result of an assertion. +class Message; // Represents a failure message. +class Test; // Represents a test. +class TestInfo; // Information about a test. +class TestPartResult; // Result of a test part. +class UnitTest; // A collection of test cases. + +template +::std::string PrintToString(const T& value); + +namespace internal { + +struct TraceInfo; // Information about a trace point. +class ScopedTrace; // Implements scoped trace. +class TestInfoImpl; // Opaque implementation of TestInfo +class UnitTestImpl; // Opaque implementation of UnitTest + +// The text used in failure messages to indicate the start of the +// stack trace. +GTEST_API_ extern const char kStackTraceMarker[]; + +// Two overloaded helpers for checking at compile time whether an +// expression is a null pointer literal (i.e. NULL or any 0-valued +// compile-time integral constant). Their return values have +// different sizes, so we can use sizeof() to test which version is +// picked by the compiler. These helpers have no implementations, as +// we only need their signatures. +// +// Given IsNullLiteralHelper(x), the compiler will pick the first +// version if x can be implicitly converted to Secret*, and pick the +// second version otherwise. Since Secret is a secret and incomplete +// type, the only expression a user can write that has type Secret* is +// a null pointer literal. Therefore, we know that x is a null +// pointer literal if and only if the first version is picked by the +// compiler. +char IsNullLiteralHelper(Secret* p); +char (&IsNullLiteralHelper(...))[2]; // NOLINT + +// A compile-time bool constant that is true if and only if x is a +// null pointer literal (i.e. NULL or any 0-valued compile-time +// integral constant). +#ifdef GTEST_ELLIPSIS_NEEDS_POD_ +// We lose support for NULL detection where the compiler doesn't like +// passing non-POD classes through ellipsis (...). +# define GTEST_IS_NULL_LITERAL_(x) false +#else +# define GTEST_IS_NULL_LITERAL_(x) \ + (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) +#endif // GTEST_ELLIPSIS_NEEDS_POD_ + +// Appends the user-supplied message to the Google-Test-generated message. +GTEST_API_ std::string AppendUserMessage( + const std::string& gtest_msg, const Message& user_msg); + +#if GTEST_HAS_EXCEPTIONS + +// This exception is thrown by (and only by) a failed Google Test +// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions +// are enabled). We derive it from std::runtime_error, which is for +// errors presumably detectable only at run time. Since +// std::runtime_error inherits from std::exception, many testing +// frameworks know how to extract and print the message inside it. +class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error { + public: + explicit GoogleTestFailureException(const TestPartResult& failure); +}; + +#endif // GTEST_HAS_EXCEPTIONS + +// A helper class for creating scoped traces in user programs. +class GTEST_API_ ScopedTrace { + public: + // The c'tor pushes the given source file location and message onto + // a trace stack maintained by Google Test. + ScopedTrace(const char* file, int line, const Message& message); + + // The d'tor pops the info pushed by the c'tor. + // + // Note that the d'tor is not virtual in order to be efficient. + // Don't inherit from ScopedTrace! + ~ScopedTrace(); + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace); +} GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its + // c'tor and d'tor. Therefore it doesn't + // need to be used otherwise. + +namespace edit_distance { +// Returns the optimal edits to go from 'left' to 'right'. +// All edits cost the same, with replace having lower priority than +// add/remove. +// Simple implementation of the Wagner–Fischer algorithm. +// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm +enum EditType { kMatch, kAdd, kRemove, kReplace }; +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, const std::vector& right); + +// Same as above, but the input is represented as strings. +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, + const std::vector& right); + +// Create a diff of the input strings in Unified diff format. +GTEST_API_ std::string CreateUnifiedDiff(const std::vector& left, + const std::vector& right, + size_t context = 2); + +} // namespace edit_distance + +// Calculate the diff between 'left' and 'right' and return it in unified diff +// format. +// If not null, stores in 'total_line_count' the total number of lines found +// in left + right. +GTEST_API_ std::string DiffStrings(const std::string& left, + const std::string& right, + size_t* total_line_count); + +// Constructs and returns the message for an equality assertion +// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. +// +// The first four parameters are the expressions used in the assertion +// and their values, as strings. For example, for ASSERT_EQ(foo, bar) +// where foo is 5 and bar is 6, we have: +// +// expected_expression: "foo" +// actual_expression: "bar" +// expected_value: "5" +// actual_value: "6" +// +// The ignoring_case parameter is true iff the assertion is a +// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will +// be inserted into the message. +GTEST_API_ AssertionResult EqFailure(const char* expected_expression, + const char* actual_expression, + const std::string& expected_value, + const std::string& actual_value, + bool ignoring_case); + +// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. +GTEST_API_ std::string GetBoolAssertionFailureMessage( + const AssertionResult& assertion_result, + const char* expression_text, + const char* actual_predicate_value, + const char* expected_predicate_value); + +// This template class represents an IEEE floating-point number +// (either single-precision or double-precision, depending on the +// template parameters). +// +// The purpose of this class is to do more sophisticated number +// comparison. (Due to round-off error, etc, it's very unlikely that +// two floating-points will be equal exactly. Hence a naive +// comparison by the == operation often doesn't work.) +// +// Format of IEEE floating-point: +// +// The most-significant bit being the leftmost, an IEEE +// floating-point looks like +// +// sign_bit exponent_bits fraction_bits +// +// Here, sign_bit is a single bit that designates the sign of the +// number. +// +// For float, there are 8 exponent bits and 23 fraction bits. +// +// For double, there are 11 exponent bits and 52 fraction bits. +// +// More details can be found at +// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. +// +// Template parameter: +// +// RawType: the raw floating-point type (either float or double) +template +class FloatingPoint { + public: + // Defines the unsigned integer type that has the same size as the + // floating point number. + typedef typename TypeWithSize::UInt Bits; + + // Constants. + + // # of bits in a number. + static const size_t kBitCount = 8*sizeof(RawType); + + // # of fraction bits in a number. + static const size_t kFractionBitCount = + std::numeric_limits::digits - 1; + + // # of exponent bits in a number. + static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; + + // The mask for the sign bit. + static const Bits kSignBitMask = static_cast(1) << (kBitCount - 1); + + // The mask for the fraction bits. + static const Bits kFractionBitMask = + ~static_cast(0) >> (kExponentBitCount + 1); + + // The mask for the exponent bits. + static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); + + // How many ULP's (Units in the Last Place) we want to tolerate when + // comparing two numbers. The larger the value, the more error we + // allow. A 0 value means that two numbers must be exactly the same + // to be considered equal. + // + // The maximum error of a single floating-point operation is 0.5 + // units in the last place. On Intel CPU's, all floating-point + // calculations are done with 80-bit precision, while double has 64 + // bits. Therefore, 4 should be enough for ordinary use. + // + // See the following article for more details on ULP: + // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + static const size_t kMaxUlps = 4; + + // Constructs a FloatingPoint from a raw floating-point number. + // + // On an Intel CPU, passing a non-normalized NAN (Not a Number) + // around may change its bits, although the new value is guaranteed + // to be also a NAN. Therefore, don't expect this constructor to + // preserve the bits in x when x is a NAN. + explicit FloatingPoint(const RawType& x) { u_.value_ = x; } + + // Static methods + + // Reinterprets a bit pattern as a floating-point number. + // + // This function is needed to test the AlmostEquals() method. + static RawType ReinterpretBits(const Bits bits) { + FloatingPoint fp(0); + fp.u_.bits_ = bits; + return fp.u_.value_; + } + + // Returns the floating-point number that represent positive infinity. + static RawType Infinity() { + return ReinterpretBits(kExponentBitMask); + } + + // Returns the maximum representable finite floating-point number. + static RawType Max(); + + // Non-static methods + + // Returns the bits that represents this number. + const Bits &bits() const { return u_.bits_; } + + // Returns the exponent bits of this number. + Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } + + // Returns the fraction bits of this number. + Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } + + // Returns the sign bit of this number. + Bits sign_bit() const { return kSignBitMask & u_.bits_; } + + // Returns true iff this is NAN (not a number). + bool is_nan() const { + // It's a NAN if the exponent bits are all ones and the fraction + // bits are not entirely zeros. + return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0); + } + + // Returns true iff this number is at most kMaxUlps ULP's away from + // rhs. In particular, this function: + // + // - returns false if either number is (or both are) NAN. + // - treats really large numbers as almost equal to infinity. + // - thinks +0.0 and -0.0 are 0 DLP's apart. + bool AlmostEquals(const FloatingPoint& rhs) const { + // The IEEE standard says that any comparison operation involving + // a NAN must return false. + if (is_nan() || rhs.is_nan()) return false; + + return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) + <= kMaxUlps; + } + + private: + // The data type used to store the actual floating-point number. + union FloatingPointUnion { + RawType value_; // The raw floating-point number. + Bits bits_; // The bits that represent the number. + }; + + // Converts an integer from the sign-and-magnitude representation to + // the biased representation. More precisely, let N be 2 to the + // power of (kBitCount - 1), an integer x is represented by the + // unsigned number x + N. + // + // For instance, + // + // -N + 1 (the most negative number representable using + // sign-and-magnitude) is represented by 1; + // 0 is represented by N; and + // N - 1 (the biggest number representable using + // sign-and-magnitude) is represented by 2N - 1. + // + // Read http://en.wikipedia.org/wiki/Signed_number_representations + // for more details on signed number representations. + static Bits SignAndMagnitudeToBiased(const Bits &sam) { + if (kSignBitMask & sam) { + // sam represents a negative number. + return ~sam + 1; + } else { + // sam represents a positive number. + return kSignBitMask | sam; + } + } + + // Given two numbers in the sign-and-magnitude representation, + // returns the distance between them as an unsigned number. + static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, + const Bits &sam2) { + const Bits biased1 = SignAndMagnitudeToBiased(sam1); + const Bits biased2 = SignAndMagnitudeToBiased(sam2); + return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); + } + + FloatingPointUnion u_; +}; + +// We cannot use std::numeric_limits::max() as it clashes with the max() +// macro defined by . +template <> +inline float FloatingPoint::Max() { return FLT_MAX; } +template <> +inline double FloatingPoint::Max() { return DBL_MAX; } + +// Typedefs the instances of the FloatingPoint template class that we +// care to use. +typedef FloatingPoint Float; +typedef FloatingPoint Double; + +// In order to catch the mistake of putting tests that use different +// test fixture classes in the same test case, we need to assign +// unique IDs to fixture classes and compare them. The TypeId type is +// used to hold such IDs. The user should treat TypeId as an opaque +// type: the only operation allowed on TypeId values is to compare +// them for equality using the == operator. +typedef const void* TypeId; + +template +class TypeIdHelper { + public: + // dummy_ must not have a const type. Otherwise an overly eager + // compiler (e.g. MSVC 7.1 & 8.0) may try to merge + // TypeIdHelper::dummy_ for different Ts as an "optimization". + static bool dummy_; +}; + +template +bool TypeIdHelper::dummy_ = false; + +// GetTypeId() returns the ID of type T. Different values will be +// returned for different types. Calling the function twice with the +// same type argument is guaranteed to return the same ID. +template +TypeId GetTypeId() { + // The compiler is required to allocate a different + // TypeIdHelper::dummy_ variable for each T used to instantiate + // the template. Therefore, the address of dummy_ is guaranteed to + // be unique. + return &(TypeIdHelper::dummy_); +} + +// Returns the type ID of ::testing::Test. Always call this instead +// of GetTypeId< ::testing::Test>() to get the type ID of +// ::testing::Test, as the latter may give the wrong result due to a +// suspected linker bug when compiling Google Test as a Mac OS X +// framework. +GTEST_API_ TypeId GetTestTypeId(); + +// Defines the abstract factory interface that creates instances +// of a Test object. +class TestFactoryBase { + public: + virtual ~TestFactoryBase() {} + + // Creates a test instance to run. The instance is both created and destroyed + // within TestInfoImpl::Run() + virtual Test* CreateTest() = 0; + + protected: + TestFactoryBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase); +}; + +// This class provides implementation of TeastFactoryBase interface. +// It is used in TEST and TEST_F macros. +template +class TestFactoryImpl : public TestFactoryBase { + public: + virtual Test* CreateTest() { return new TestClass; } +}; + +#if GTEST_OS_WINDOWS + +// Predicate-formatters for implementing the HRESULT checking macros +// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} +// We pass a long instead of HRESULT to avoid causing an +// include dependency for the HRESULT type. +GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr, + long hr); // NOLINT +GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, + long hr); // NOLINT + +#endif // GTEST_OS_WINDOWS + +// Types of SetUpTestCase() and TearDownTestCase() functions. +typedef void (*SetUpTestCaseFunc)(); +typedef void (*TearDownTestCaseFunc)(); + +struct CodeLocation { + CodeLocation(const string& a_file, int a_line) : file(a_file), line(a_line) {} + + string file; + int line; +}; + +// Creates a new TestInfo object and registers it with Google Test; +// returns the created object. +// +// Arguments: +// +// test_case_name: name of the test case +// name: name of the test +// type_param the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param text representation of the test's value parameter, +// or NULL if this is not a type-parameterized test. +// code_location: code location where the test is defined +// fixture_class_id: ID of the test fixture class +// set_up_tc: pointer to the function that sets up the test case +// tear_down_tc: pointer to the function that tears down the test case +// factory: pointer to the factory that creates a test object. +// The newly created TestInfo instance will assume +// ownership of the factory object. +GTEST_API_ TestInfo* MakeAndRegisterTestInfo( + const char* test_case_name, + const char* name, + const char* type_param, + const char* value_param, + CodeLocation code_location, + TypeId fixture_class_id, + SetUpTestCaseFunc set_up_tc, + TearDownTestCaseFunc tear_down_tc, + TestFactoryBase* factory); + +// If *pstr starts with the given prefix, modifies *pstr to be right +// past the prefix and returns true; otherwise leaves *pstr unchanged +// and returns false. None of pstr, *pstr, and prefix can be NULL. +GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr); + +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// State of the definition of a type-parameterized test case. +class GTEST_API_ TypedTestCasePState { + public: + TypedTestCasePState() : registered_(false) {} + + // Adds the given test name to defined_test_names_ and return true + // if the test case hasn't been registered; otherwise aborts the + // program. + bool AddTestName(const char* file, int line, const char* case_name, + const char* test_name) { + if (registered_) { + fprintf(stderr, "%s Test %s must be defined before " + "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", + FormatFileLocation(file, line).c_str(), test_name, case_name); + fflush(stderr); + posix::Abort(); + } + registered_tests_.insert( + ::std::make_pair(test_name, CodeLocation(file, line))); + return true; + } + + bool TestExists(const std::string& test_name) const { + return registered_tests_.count(test_name) > 0; + } + + const CodeLocation& GetCodeLocation(const std::string& test_name) const { + RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name); + GTEST_CHECK_(it != registered_tests_.end()); + return it->second; + } + + // Verifies that registered_tests match the test names in + // defined_test_names_; returns registered_tests if successful, or + // aborts the program otherwise. + const char* VerifyRegisteredTestNames( + const char* file, int line, const char* registered_tests); + + private: + typedef ::std::map RegisteredTestsMap; + + bool registered_; + RegisteredTestsMap registered_tests_; +}; + +// Skips to the first non-space char after the first comma in 'str'; +// returns NULL if no comma is found in 'str'. +inline const char* SkipComma(const char* str) { + const char* comma = strchr(str, ','); + if (comma == NULL) { + return NULL; + } + while (IsSpace(*(++comma))) {} + return comma; +} + +// Returns the prefix of 'str' before the first comma in it; returns +// the entire string if it contains no comma. +inline std::string GetPrefixUntilComma(const char* str) { + const char* comma = strchr(str, ','); + return comma == NULL ? str : std::string(str, comma); +} + +// Splits a given string on a given delimiter, populating a given +// vector with the fields. +void SplitString(const ::std::string& str, char delimiter, + ::std::vector< ::std::string>* dest); + +// TypeParameterizedTest::Register() +// registers a list of type-parameterized tests with Google Test. The +// return value is insignificant - we just need to return something +// such that we can call this function in a namespace scope. +// +// Implementation note: The GTEST_TEMPLATE_ macro declares a template +// template parameter. It's defined in gtest-type-util.h. +template +class TypeParameterizedTest { + public: + // 'index' is the index of the test in the type list 'Types' + // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase, + // Types). Valid values for 'index' are [0, N - 1] where N is the + // length of Types. + static bool Register(const char* prefix, + CodeLocation code_location, + const char* case_name, const char* test_names, + int index) { + typedef typename Types::Head Type; + typedef Fixture FixtureClass; + typedef typename GTEST_BIND_(TestSel, Type) TestClass; + + // First, registers the first type-parameterized test in the type + // list. + MakeAndRegisterTestInfo( + (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/" + + StreamableToString(index)).c_str(), + StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), + GetTypeName().c_str(), + NULL, // No value parameter. + code_location, + GetTypeId(), + TestClass::SetUpTestCase, + TestClass::TearDownTestCase, + new TestFactoryImpl); + + // Next, recurses (at compile time) with the tail of the type list. + return TypeParameterizedTest + ::Register(prefix, code_location, case_name, test_names, index + 1); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTest { + public: + static bool Register(const char* /*prefix*/, CodeLocation, + const char* /*case_name*/, const char* /*test_names*/, + int /*index*/) { + return true; + } +}; + +// TypeParameterizedTestCase::Register() +// registers *all combinations* of 'Tests' and 'Types' with Google +// Test. The return value is insignificant - we just need to return +// something such that we can call this function in a namespace scope. +template +class TypeParameterizedTestCase { + public: + static bool Register(const char* prefix, CodeLocation code_location, + const TypedTestCasePState* state, + const char* case_name, const char* test_names) { + std::string test_name = StripTrailingSpaces( + GetPrefixUntilComma(test_names)); + if (!state->TestExists(test_name)) { + fprintf(stderr, "Failed to get code location for test %s.%s at %s.", + case_name, test_name.c_str(), + FormatFileLocation(code_location.file.c_str(), + code_location.line).c_str()); + fflush(stderr); + posix::Abort(); + } + const CodeLocation& test_location = state->GetCodeLocation(test_name); + + typedef typename Tests::Head Head; + + // First, register the first test in 'Test' for each type in 'Types'. + TypeParameterizedTest::Register( + prefix, test_location, case_name, test_names, 0); + + // Next, recurses (at compile time) with the tail of the test list. + return TypeParameterizedTestCase + ::Register(prefix, code_location, state, + case_name, SkipComma(test_names)); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTestCase { + public: + static bool Register(const char* /*prefix*/, CodeLocation, + const TypedTestCasePState* /*state*/, + const char* /*case_name*/, const char* /*test_names*/) { + return true; + } +}; + +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// Returns the current OS stack trace as an std::string. +// +// The maximum number of stack frames to be included is specified by +// the gtest_stack_trace_depth flag. The skip_count parameter +// specifies the number of top frames to be skipped, which doesn't +// count against the number of frames to be included. +// +// For example, if Foo() calls Bar(), which in turn calls +// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in +// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. +GTEST_API_ std::string GetCurrentOsStackTraceExceptTop( + UnitTest* unit_test, int skip_count); + +// Helpers for suppressing warnings on unreachable code or constant +// condition. + +// Always returns true. +GTEST_API_ bool AlwaysTrue(); + +// Always returns false. +inline bool AlwaysFalse() { return !AlwaysTrue(); } + +// Helper for suppressing false warning from Clang on a const char* +// variable declared in a conditional expression always being NULL in +// the else branch. +struct GTEST_API_ ConstCharPtr { + ConstCharPtr(const char* str) : value(str) {} + operator bool() const { return true; } + const char* value; +}; + +// A simple Linear Congruential Generator for generating random +// numbers with a uniform distribution. Unlike rand() and srand(), it +// doesn't use global state (and therefore can't interfere with user +// code). Unlike rand_r(), it's portable. An LCG isn't very random, +// but it's good enough for our purposes. +class GTEST_API_ Random { + public: + static const UInt32 kMaxRange = 1u << 31; + + explicit Random(UInt32 seed) : state_(seed) {} + + void Reseed(UInt32 seed) { state_ = seed; } + + // Generates a random number from [0, range). Crashes if 'range' is + // 0 or greater than kMaxRange. + UInt32 Generate(UInt32 range); + + private: + UInt32 state_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); +}; + +// Defining a variable of type CompileAssertTypesEqual will cause a +// compiler error iff T1 and T2 are different types. +template +struct CompileAssertTypesEqual; + +template +struct CompileAssertTypesEqual { +}; + +// Removes the reference from a type if it is a reference type, +// otherwise leaves it unchanged. This is the same as +// tr1::remove_reference, which is not widely available yet. +template +struct RemoveReference { typedef T type; }; // NOLINT +template +struct RemoveReference { typedef T type; }; // NOLINT + +// A handy wrapper around RemoveReference that works when the argument +// T depends on template parameters. +#define GTEST_REMOVE_REFERENCE_(T) \ + typename ::testing::internal::RemoveReference::type + +// Removes const from a type if it is a const type, otherwise leaves +// it unchanged. This is the same as tr1::remove_const, which is not +// widely available yet. +template +struct RemoveConst { typedef T type; }; // NOLINT +template +struct RemoveConst { typedef T type; }; // NOLINT + +// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above +// definition to fail to remove the const in 'const int[3]' and 'const +// char[3][4]'. The following specialization works around the bug. +template +struct RemoveConst { + typedef typename RemoveConst::type type[N]; +}; + +#if defined(_MSC_VER) && _MSC_VER < 1400 +// This is the only specialization that allows VC++ 7.1 to remove const in +// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC +// and thus needs to be conditionally compiled. +template +struct RemoveConst { + typedef typename RemoveConst::type type[N]; +}; +#endif + +// A handy wrapper around RemoveConst that works when the argument +// T depends on template parameters. +#define GTEST_REMOVE_CONST_(T) \ + typename ::testing::internal::RemoveConst::type + +// Turns const U&, U&, const U, and U all into U. +#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ + GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) + +// Adds reference to a type if it is not a reference type, +// otherwise leaves it unchanged. This is the same as +// tr1::add_reference, which is not widely available yet. +template +struct AddReference { typedef T& type; }; // NOLINT +template +struct AddReference { typedef T& type; }; // NOLINT + +// A handy wrapper around AddReference that works when the argument T +// depends on template parameters. +#define GTEST_ADD_REFERENCE_(T) \ + typename ::testing::internal::AddReference::type + +// Adds a reference to const on top of T as necessary. For example, +// it transforms +// +// char ==> const char& +// const char ==> const char& +// char& ==> const char& +// const char& ==> const char& +// +// The argument T must depend on some template parameters. +#define GTEST_REFERENCE_TO_CONST_(T) \ + GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T)) + +// ImplicitlyConvertible::value is a compile-time bool +// constant that's true iff type From can be implicitly converted to +// type To. +template +class ImplicitlyConvertible { + private: + // We need the following helper functions only for their types. + // They have no implementations. + + // MakeFrom() is an expression whose type is From. We cannot simply + // use From(), as the type From may not have a public default + // constructor. + static typename AddReference::type MakeFrom(); + + // These two functions are overloaded. Given an expression + // Helper(x), the compiler will pick the first version if x can be + // implicitly converted to type To; otherwise it will pick the + // second version. + // + // The first version returns a value of size 1, and the second + // version returns a value of size 2. Therefore, by checking the + // size of Helper(x), which can be done at compile time, we can tell + // which version of Helper() is used, and hence whether x can be + // implicitly converted to type To. + static char Helper(To); + static char (&Helper(...))[2]; // NOLINT + + // We have to put the 'public' section after the 'private' section, + // or MSVC refuses to compile the code. + public: +#if defined(__BORLANDC__) + // C++Builder cannot use member overload resolution during template + // instantiation. The simplest workaround is to use its C++0x type traits + // functions (C++Builder 2009 and above only). + static const bool value = __is_convertible(From, To); +#else + // MSVC warns about implicitly converting from double to int for + // possible loss of data, so we need to temporarily disable the + // warning. + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244) + static const bool value = + sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1; + GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif // __BORLANDC__ +}; +template +const bool ImplicitlyConvertible::value; + +// IsAProtocolMessage::value is a compile-time bool constant that's +// true iff T is type ProtocolMessage, proto2::Message, or a subclass +// of those. +template +struct IsAProtocolMessage + : public bool_constant< + ImplicitlyConvertible::value || + ImplicitlyConvertible::value> { +}; + +// When the compiler sees expression IsContainerTest(0), if C is an +// STL-style container class, the first overload of IsContainerTest +// will be viable (since both C::iterator* and C::const_iterator* are +// valid types and NULL can be implicitly converted to them). It will +// be picked over the second overload as 'int' is a perfect match for +// the type of argument 0. If C::iterator or C::const_iterator is not +// a valid type, the first overload is not viable, and the second +// overload will be picked. Therefore, we can determine whether C is +// a container class by checking the type of IsContainerTest(0). +// The value of the expression is insignificant. +// +// Note that we look for both C::iterator and C::const_iterator. The +// reason is that C++ injects the name of a class as a member of the +// class itself (e.g. you can refer to class iterator as either +// 'iterator' or 'iterator::iterator'). If we look for C::iterator +// only, for example, we would mistakenly think that a class named +// iterator is an STL container. +// +// Also note that the simpler approach of overloading +// IsContainerTest(typename C::const_iterator*) and +// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++. +typedef int IsContainer; +template +IsContainer IsContainerTest(int /* dummy */, + typename C::iterator* /* it */ = NULL, + typename C::const_iterator* /* const_it */ = NULL) { + return 0; +} + +typedef char IsNotContainer; +template +IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } + +// EnableIf::type is void when 'Cond' is true, and +// undefined when 'Cond' is false. To use SFINAE to make a function +// overload only apply when a particular expression is true, add +// "typename EnableIf::type* = 0" as the last parameter. +template struct EnableIf; +template<> struct EnableIf { typedef void type; }; // NOLINT + +// Utilities for native arrays. + +// ArrayEq() compares two k-dimensional native arrays using the +// elements' operator==, where k can be any integer >= 0. When k is +// 0, ArrayEq() degenerates into comparing a single pair of values. + +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs); + +// This generic version is used when k is 0. +template +inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } + +// This overload is used when k >= 1. +template +inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { + return internal::ArrayEq(lhs, N, rhs); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous ArrayEq() function, arrays with different sizes would +// lead to different copies of the template code. +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs) { + for (size_t i = 0; i != size; i++) { + if (!internal::ArrayEq(lhs[i], rhs[i])) + return false; + } + return true; +} + +// Finds the first element in the iterator range [begin, end) that +// equals elem. Element may be a native array type itself. +template +Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { + for (Iter it = begin; it != end; ++it) { + if (internal::ArrayEq(*it, elem)) + return it; + } + return end; +} + +// CopyArray() copies a k-dimensional native array using the elements' +// operator=, where k can be any integer >= 0. When k is 0, +// CopyArray() degenerates into copying a single value. + +template +void CopyArray(const T* from, size_t size, U* to); + +// This generic version is used when k is 0. +template +inline void CopyArray(const T& from, U* to) { *to = from; } + +// This overload is used when k >= 1. +template +inline void CopyArray(const T(&from)[N], U(*to)[N]) { + internal::CopyArray(from, N, *to); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous CopyArray() function, arrays with different sizes +// would lead to different copies of the template code. +template +void CopyArray(const T* from, size_t size, U* to) { + for (size_t i = 0; i != size; i++) { + internal::CopyArray(from[i], to + i); + } +} + +// The relation between an NativeArray object (see below) and the +// native array it represents. +// We use 2 different structs to allow non-copyable types to be used, as long +// as RelationToSourceReference() is passed. +struct RelationToSourceReference {}; +struct RelationToSourceCopy {}; + +// Adapts a native array to a read-only STL-style container. Instead +// of the complete STL container concept, this adaptor only implements +// members useful for Google Mock's container matchers. New members +// should be added as needed. To simplify the implementation, we only +// support Element being a raw type (i.e. having no top-level const or +// reference modifier). It's the client's responsibility to satisfy +// this requirement. Element can be an array type itself (hence +// multi-dimensional arrays are supported). +template +class NativeArray { + public: + // STL-style container typedefs. + typedef Element value_type; + typedef Element* iterator; + typedef const Element* const_iterator; + + // Constructs from a native array. References the source. + NativeArray(const Element* array, size_t count, RelationToSourceReference) { + InitRef(array, count); + } + + // Constructs from a native array. Copies the source. + NativeArray(const Element* array, size_t count, RelationToSourceCopy) { + InitCopy(array, count); + } + + // Copy constructor. + NativeArray(const NativeArray& rhs) { + (this->*rhs.clone_)(rhs.array_, rhs.size_); + } + + ~NativeArray() { + if (clone_ != &NativeArray::InitRef) + delete[] array_; + } + + // STL-style container methods. + size_t size() const { return size_; } + const_iterator begin() const { return array_; } + const_iterator end() const { return array_ + size_; } + bool operator==(const NativeArray& rhs) const { + return size() == rhs.size() && + ArrayEq(begin(), size(), rhs.begin()); + } + + private: + enum { + kCheckTypeIsNotConstOrAReference = StaticAssertTypeEqHelper< + Element, GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>::value, + }; + + // Initializes this object with a copy of the input. + void InitCopy(const Element* array, size_t a_size) { + Element* const copy = new Element[a_size]; + CopyArray(array, a_size, copy); + array_ = copy; + size_ = a_size; + clone_ = &NativeArray::InitCopy; + } + + // Initializes this object with a reference of the input. + void InitRef(const Element* array, size_t a_size) { + array_ = array; + size_ = a_size; + clone_ = &NativeArray::InitRef; + } + + const Element* array_; + size_t size_; + void (NativeArray::*clone_)(const Element*, size_t); + + GTEST_DISALLOW_ASSIGN_(NativeArray); +}; + +} // namespace internal +} // namespace testing + +#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ + ::testing::internal::AssertHelper(result_type, file, line, message) \ + = ::testing::Message() + +#define GTEST_MESSAGE_(message, result_type) \ + GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) + +#define GTEST_FATAL_FAILURE_(message) \ + return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) + +#define GTEST_NONFATAL_FAILURE_(message) \ + GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) + +#define GTEST_SUCCESS_(message) \ + GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) + +// Suppresses MSVC warnings 4072 (unreachable code) for the code following +// statement if it returns or throws (or doesn't return or throw in some +// situations). +#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ + if (::testing::internal::AlwaysTrue()) { statement; } + +#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::ConstCharPtr gtest_msg = "") { \ + bool gtest_caught_expected = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + } \ + catch (...) { \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws a different type."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + if (!gtest_caught_expected) { \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ + fail(gtest_msg.value) + +#define GTEST_TEST_NO_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (...) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ + fail("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws.") + +#define GTEST_TEST_ANY_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + bool gtest_caught_any = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (...) { \ + gtest_caught_any = true; \ + } \ + if (!gtest_caught_any) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ + fail("Expected: " #statement " throws an exception.\n" \ + " Actual: it doesn't.") + + +// Implements Boolean test assertions such as EXPECT_TRUE. expression can be +// either a boolean expression or an AssertionResult. text is a textual +// represenation of expression as it was passed into the EXPECT_TRUE. +#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (const ::testing::AssertionResult gtest_ar_ = \ + ::testing::AssertionResult(expression)) \ + ; \ + else \ + fail(::testing::internal::GetBoolAssertionFailureMessage(\ + gtest_ar_, text, #actual, #expected).c_str()) + +#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ + fail("Expected: " #statement " doesn't generate new fatal " \ + "failures in the current thread.\n" \ + " Actual: it does.") + +// Expands to the name of the class that implements the given test. +#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ + test_case_name##_##test_name##_Test + +// Helper macro for defining tests. +#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ +class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ + public:\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ + private:\ + virtual void TestBody();\ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ +};\ +\ +::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ + ::test_info_ =\ + ::testing::internal::MakeAndRegisterTestInfo(\ + #test_case_name, #test_name, NULL, NULL, \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), \ + (parent_id), \ + parent_class::SetUpTestCase, \ + parent_class::TearDownTestCase, \ + new ::testing::internal::TestFactoryImpl<\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ +void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ + diff --git a/TestMothur/gtest-linked_ptr.h b/TestMothur/gtest-linked_ptr.h new file mode 100755 index 00000000..8409d96c --- /dev/null +++ b/TestMothur/gtest-linked_ptr.h @@ -0,0 +1,243 @@ +// Copyright 2003 Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: Dan Egnor (egnor@google.com) +// +// A "smart" pointer type with reference tracking. Every pointer to a +// particular object is kept on a circular linked list. When the last pointer +// to an object is destroyed or reassigned, the object is deleted. +// +// Used properly, this deletes the object when the last reference goes away. +// There are several caveats: +// - Like all reference counting schemes, cycles lead to leaks. +// - Each smart pointer is actually two pointers (8 bytes instead of 4). +// - Every time a pointer is assigned, the entire list of pointers to that +// object is traversed. This class is therefore NOT SUITABLE when there +// will often be more than two or three pointers to a particular object. +// - References are only tracked as long as linked_ptr<> objects are copied. +// If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS +// will happen (double deletion). +// +// A good use of this class is storing object references in STL containers. +// You can safely put linked_ptr<> in a vector<>. +// Other uses may not be as good. +// +// Note: If you use an incomplete type with linked_ptr<>, the class +// *containing* linked_ptr<> must have a constructor and destructor (even +// if they do nothing!). +// +// Bill Gibbons suggested we use something like this. +// +// Thread Safety: +// Unlike other linked_ptr implementations, in this implementation +// a linked_ptr object is thread-safe in the sense that: +// - it's safe to copy linked_ptr objects concurrently, +// - it's safe to copy *from* a linked_ptr and read its underlying +// raw pointer (e.g. via get()) concurrently, and +// - it's safe to write to two linked_ptrs that point to the same +// shared object concurrently. +// TODO(wan@google.com): rename this to safe_linked_ptr to avoid +// confusion with normal linked_ptr. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ + +#include +#include + +#include "gtest-port.h" + +namespace testing { +namespace internal { + +// Protects copying of all linked_ptr objects. +GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex); + +// This is used internally by all instances of linked_ptr<>. It needs to be +// a non-template class because different types of linked_ptr<> can refer to +// the same object (linked_ptr(obj) vs linked_ptr(obj)). +// So, it needs to be possible for different types of linked_ptr to participate +// in the same circular linked list, so we need a single class type here. +// +// DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr. +class linked_ptr_internal { + public: + // Create a new circle that includes only this instance. + void join_new() { + next_ = this; + } + + // Many linked_ptr operations may change p.link_ for some linked_ptr + // variable p in the same circle as this object. Therefore we need + // to prevent two such operations from occurring concurrently. + // + // Note that different types of linked_ptr objects can coexist in a + // circle (e.g. linked_ptr, linked_ptr, and + // linked_ptr). Therefore we must use a single mutex to + // protect all linked_ptr objects. This can create serious + // contention in production code, but is acceptable in a testing + // framework. + + // Join an existing circle. + void join(linked_ptr_internal const* ptr) + GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { + MutexLock lock(&g_linked_ptr_mutex); + + linked_ptr_internal const* p = ptr; + while (p->next_ != ptr) { + assert(p->next_ != this && + "Trying to join() a linked ring we are already in. " + "Is GMock thread safety enabled?"); + p = p->next_; + } + p->next_ = this; + next_ = ptr; + } + + // Leave whatever circle we're part of. Returns true if we were the + // last member of the circle. Once this is done, you can join() another. + bool depart() + GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) { + MutexLock lock(&g_linked_ptr_mutex); + + if (next_ == this) return true; + linked_ptr_internal const* p = next_; + while (p->next_ != this) { + assert(p->next_ != next_ && + "Trying to depart() a linked ring we are not in. " + "Is GMock thread safety enabled?"); + p = p->next_; + } + p->next_ = next_; + return false; + } + + private: + mutable linked_ptr_internal const* next_; +}; + +template +class linked_ptr { + public: + typedef T element_type; + + // Take over ownership of a raw pointer. This should happen as soon as + // possible after the object is created. + explicit linked_ptr(T* ptr = NULL) { capture(ptr); } + ~linked_ptr() { depart(); } + + // Copy an existing linked_ptr<>, adding ourselves to the list of references. + template linked_ptr(linked_ptr const& ptr) { copy(&ptr); } + linked_ptr(linked_ptr const& ptr) { // NOLINT + assert(&ptr != this); + copy(&ptr); + } + + // Assignment releases the old value and acquires the new. + template linked_ptr& operator=(linked_ptr const& ptr) { + depart(); + copy(&ptr); + return *this; + } + + linked_ptr& operator=(linked_ptr const& ptr) { + if (&ptr != this) { + depart(); + copy(&ptr); + } + return *this; + } + + // Smart pointer members. + void reset(T* ptr = NULL) { + depart(); + capture(ptr); + } + T* get() const { return value_; } + T* operator->() const { return value_; } + T& operator*() const { return *value_; } + + bool operator==(T* p) const { return value_ == p; } + bool operator!=(T* p) const { return value_ != p; } + template + bool operator==(linked_ptr const& ptr) const { + return value_ == ptr.get(); + } + template + bool operator!=(linked_ptr const& ptr) const { + return value_ != ptr.get(); + } + + private: + template + friend class linked_ptr; + + T* value_; + linked_ptr_internal link_; + + void depart() { + if (link_.depart()) delete value_; + } + + void capture(T* ptr) { + value_ = ptr; + link_.join_new(); + } + + template void copy(linked_ptr const* ptr) { + value_ = ptr->get(); + if (value_) + link_.join(&ptr->link_); + else + link_.join_new(); + } +}; + +template inline +bool operator==(T* ptr, const linked_ptr& x) { + return ptr == x.get(); +} + +template inline +bool operator!=(T* ptr, const linked_ptr& x) { + return ptr != x.get(); +} + +// A function to convert T* into linked_ptr +// Doing e.g. make_linked_ptr(new FooBarBaz(arg)) is a shorter notation +// for linked_ptr >(new FooBarBaz(arg)) +template +linked_ptr make_linked_ptr(T* ptr) { + return linked_ptr(ptr); +} + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ diff --git a/TestMothur/gtest-message.h b/TestMothur/gtest-message.h new file mode 100755 index 00000000..114e9a5d --- /dev/null +++ b/TestMothur/gtest-message.h @@ -0,0 +1,250 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file defines the Message class. +// +// IMPORTANT NOTE: Due to limitation of the C++ language, we have to +// leave some internal implementation details in this header file. +// They are clearly marked by comments like this: +// +// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +// +// Such code is NOT meant to be used by a user directly, and is subject +// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user +// program! + +#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ +#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ + +#include + +#include "gtest-port.h" + +// Ensures that there is at least one operator<< in the global namespace. +// See Message& operator<<(...) below for why. +void operator<<(const testing::internal::Secret&, int); + +namespace testing { + +// The Message class works like an ostream repeater. +// +// Typical usage: +// +// 1. You stream a bunch of values to a Message object. +// It will remember the text in a stringstream. +// 2. Then you stream the Message object to an ostream. +// This causes the text in the Message to be streamed +// to the ostream. +// +// For example; +// +// testing::Message foo; +// foo << 1 << " != " << 2; +// std::cout << foo; +// +// will print "1 != 2". +// +// Message is not intended to be inherited from. In particular, its +// destructor is not virtual. +// +// Note that stringstream behaves differently in gcc and in MSVC. You +// can stream a NULL char pointer to it in the former, but not in the +// latter (it causes an access violation if you do). The Message +// class hides this difference by treating a NULL char pointer as +// "(null)". +class GTEST_API_ Message { + private: + // The type of basic IO manipulators (endl, ends, and flush) for + // narrow streams. + typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); + + public: + // Constructs an empty Message. + Message(); + + // Copy constructor. + Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT + *ss_ << msg.GetString(); + } + + // Constructs a Message from a C-string. + explicit Message(const char* str) : ss_(new ::std::stringstream) { + *ss_ << str; + } + +#if GTEST_OS_SYMBIAN + // Streams a value (either a pointer or not) to this object. + template + inline Message& operator <<(const T& value) { + StreamHelper(typename internal::is_pointer::type(), value); + return *this; + } +#else + // Streams a non-pointer value to this object. + template + inline Message& operator <<(const T& val) { + // Some libraries overload << for STL containers. These + // overloads are defined in the global namespace instead of ::std. + // + // C++'s symbol lookup rule (i.e. Koenig lookup) says that these + // overloads are visible in either the std namespace or the global + // namespace, but not other namespaces, including the testing + // namespace which Google Test's Message class is in. + // + // To allow STL containers (and other types that has a << operator + // defined in the global namespace) to be used in Google Test + // assertions, testing::Message must access the custom << operator + // from the global namespace. With this using declaration, + // overloads of << defined in the global namespace and those + // visible via Koenig lookup are both exposed in this function. + using ::operator <<; + *ss_ << val; + return *this; + } + + // Streams a pointer value to this object. + // + // This function is an overload of the previous one. When you + // stream a pointer to a Message, this definition will be used as it + // is more specialized. (The C++ Standard, section + // [temp.func.order].) If you stream a non-pointer, then the + // previous definition will be used. + // + // The reason for this overload is that streaming a NULL pointer to + // ostream is undefined behavior. Depending on the compiler, you + // may get "0", "(nil)", "(null)", or an access violation. To + // ensure consistent result across compilers, we always treat NULL + // as "(null)". + template + inline Message& operator <<(T* const& pointer) { // NOLINT + if (pointer == NULL) { + *ss_ << "(null)"; + } else { + *ss_ << pointer; + } + return *this; + } +#endif // GTEST_OS_SYMBIAN + + // Since the basic IO manipulators are overloaded for both narrow + // and wide streams, we have to provide this specialized definition + // of operator <<, even though its body is the same as the + // templatized version above. Without this definition, streaming + // endl or other basic IO manipulators to Message will confuse the + // compiler. + Message& operator <<(BasicNarrowIoManip val) { + *ss_ << val; + return *this; + } + + // Instead of 1/0, we want to see true/false for bool values. + Message& operator <<(bool b) { + return *this << (b ? "true" : "false"); + } + + // These two overloads allow streaming a wide C string to a Message + // using the UTF-8 encoding. + Message& operator <<(const wchar_t* wide_c_str); + Message& operator <<(wchar_t* wide_c_str); + +#if GTEST_HAS_STD_WSTRING + // Converts the given wide string to a narrow string using the UTF-8 + // encoding, and streams the result to this Message object. + Message& operator <<(const ::std::wstring& wstr); +#endif // GTEST_HAS_STD_WSTRING + +#if GTEST_HAS_GLOBAL_WSTRING + // Converts the given wide string to a narrow string using the UTF-8 + // encoding, and streams the result to this Message object. + Message& operator <<(const ::wstring& wstr); +#endif // GTEST_HAS_GLOBAL_WSTRING + + // Gets the text streamed to this object so far as an std::string. + // Each '\0' character in the buffer is replaced with "\\0". + // + // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + std::string GetString() const; + + private: + +#if GTEST_OS_SYMBIAN + // These are needed as the Nokia Symbian Compiler cannot decide between + // const T& and const T* in a function template. The Nokia compiler _can_ + // decide between class template specializations for T and T*, so a + // tr1::type_traits-like is_pointer works, and we can overload on that. + template + inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) { + if (pointer == NULL) { + *ss_ << "(null)"; + } else { + *ss_ << pointer; + } + } + template + inline void StreamHelper(internal::false_type /*is_pointer*/, + const T& value) { + // See the comments in Message& operator <<(const T&) above for why + // we need this using statement. + using ::operator <<; + *ss_ << value; + } +#endif // GTEST_OS_SYMBIAN + + // We'll hold the text streamed to this object here. + const internal::scoped_ptr< ::std::stringstream> ss_; + + // We declare (but don't implement) this to prevent the compiler + // from implementing the assignment operator. + void operator=(const Message&); +}; + +// Streams a Message to an ostream. +inline std::ostream& operator <<(std::ostream& os, const Message& sb) { + return os << sb.GetString(); +} + +namespace internal { + +// Converts a streamable value to an std::string. A NULL pointer is +// converted to "(null)". When the input value is a ::string, +// ::std::string, ::wstring, or ::std::wstring object, each NUL +// character in it is replaced with "\\0". +template +std::string StreamableToString(const T& streamable) { + return (Message() << streamable).GetString(); +} + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ diff --git a/TestMothur/gtest-param-test.h b/TestMothur/gtest-param-test.h new file mode 100755 index 00000000..9fa3e3a9 --- /dev/null +++ b/TestMothur/gtest-param-test.h @@ -0,0 +1,1444 @@ +// This file was GENERATED by command: +// pump.py gtest-param-test.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: vladl@google.com (Vlad Losev) +// +// Macros and functions for implementing parameterized tests +// in Google C++ Testing Framework (Google Test) +// +// This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ +#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ + + +// Value-parameterized tests allow you to test your code with different +// parameters without writing multiple copies of the same test. +// +// Here is how you use value-parameterized tests: + +#if 0 + +// To write value-parameterized tests, first you should define a fixture +// class. It is usually derived from testing::TestWithParam (see below for +// another inheritance scheme that's sometimes useful in more complicated +// class hierarchies), where the type of your parameter values. +// TestWithParam is itself derived from testing::Test. T can be any +// copyable type. If it's a raw pointer, you are responsible for managing the +// lifespan of the pointed values. + +class FooTest : public ::testing::TestWithParam { + // You can implement all the usual class fixture members here. +}; + +// Then, use the TEST_P macro to define as many parameterized tests +// for this fixture as you want. The _P suffix is for "parameterized" +// or "pattern", whichever you prefer to think. + +TEST_P(FooTest, DoesBlah) { + // Inside a test, access the test parameter with the GetParam() method + // of the TestWithParam class: + EXPECT_TRUE(foo.Blah(GetParam())); + ... +} + +TEST_P(FooTest, HasBlahBlah) { + ... +} + +// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test +// case with any set of parameters you want. Google Test defines a number +// of functions for generating test parameters. They return what we call +// (surprise!) parameter generators. Here is a summary of them, which +// are all in the testing namespace: +// +// +// Range(begin, end [, step]) - Yields values {begin, begin+step, +// begin+step+step, ...}. The values do not +// include end. step defaults to 1. +// Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}. +// ValuesIn(container) - Yields values from a C-style array, an STL +// ValuesIn(begin,end) container, or an iterator range [begin, end). +// Bool() - Yields sequence {false, true}. +// Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product +// for the math savvy) of the values generated +// by the N generators. +// +// For more details, see comments at the definitions of these functions below +// in this file. +// +// The following statement will instantiate tests from the FooTest test case +// each with parameter values "meeny", "miny", and "moe". + +INSTANTIATE_TEST_CASE_P(InstantiationName, + FooTest, + Values("meeny", "miny", "moe")); + +// To distinguish different instances of the pattern, (yes, you +// can instantiate it more then once) the first argument to the +// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the +// actual test case name. Remember to pick unique prefixes for different +// instantiations. The tests from the instantiation above will have +// these names: +// +// * InstantiationName/FooTest.DoesBlah/0 for "meeny" +// * InstantiationName/FooTest.DoesBlah/1 for "miny" +// * InstantiationName/FooTest.DoesBlah/2 for "moe" +// * InstantiationName/FooTest.HasBlahBlah/0 for "meeny" +// * InstantiationName/FooTest.HasBlahBlah/1 for "miny" +// * InstantiationName/FooTest.HasBlahBlah/2 for "moe" +// +// You can use these names in --gtest_filter. +// +// This statement will instantiate all tests from FooTest again, each +// with parameter values "cat" and "dog": + +const char* pets[] = {"cat", "dog"}; +INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); + +// The tests from the instantiation above will have these names: +// +// * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat" +// * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog" +// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat" +// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog" +// +// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests +// in the given test case, whether their definitions come before or +// AFTER the INSTANTIATE_TEST_CASE_P statement. +// +// Please also note that generator expressions (including parameters to the +// generators) are evaluated in InitGoogleTest(), after main() has started. +// This allows the user on one hand, to adjust generator parameters in order +// to dynamically determine a set of tests to run and on the other hand, +// give the user a chance to inspect the generated tests with Google Test +// reflection API before RUN_ALL_TESTS() is executed. +// +// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc +// for more examples. +// +// In the future, we plan to publish the API for defining new parameter +// generators. But for now this interface remains part of the internal +// implementation and is subject to change. +// +// +// A parameterized test fixture must be derived from testing::Test and from +// testing::WithParamInterface, where T is the type of the parameter +// values. Inheriting from TestWithParam satisfies that requirement because +// TestWithParam inherits from both Test and WithParamInterface. In more +// complicated hierarchies, however, it is occasionally useful to inherit +// separately from Test and WithParamInterface. For example: + +class BaseTest : public ::testing::Test { + // You can inherit all the usual members for a non-parameterized test + // fixture here. +}; + +class DerivedTest : public BaseTest, public ::testing::WithParamInterface { + // The usual test fixture members go here too. +}; + +TEST_F(BaseTest, HasFoo) { + // This is an ordinary non-parameterized test. +} + +TEST_P(DerivedTest, DoesBlah) { + // GetParam works just the same here as if you inherit from TestWithParam. + EXPECT_TRUE(foo.Blah(GetParam())); +} + +#endif // 0 + +#include "gtest-port.h" + +#if !GTEST_OS_SYMBIAN +# include +#endif + +// scripts/fuse_gtest.py depends on gtest's own header being #included +// *unconditionally*. Therefore these #includes cannot be moved +// inside #if GTEST_HAS_PARAM_TEST. +#include "gtest-internal.h" +#include "gtest-param-util.h" +#include "gtest-param-util-generated.h" + +#if GTEST_HAS_PARAM_TEST + +namespace testing { + +// Functions producing parameter generators. +// +// Google Test uses these generators to produce parameters for value- +// parameterized tests. When a parameterized test case is instantiated +// with a particular generator, Google Test creates and runs tests +// for each element in the sequence produced by the generator. +// +// In the following sample, tests from test case FooTest are instantiated +// each three times with parameter values 3, 5, and 8: +// +// class FooTest : public TestWithParam { ... }; +// +// TEST_P(FooTest, TestThis) { +// } +// TEST_P(FooTest, TestThat) { +// } +// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8)); +// + +// Range() returns generators providing sequences of values in a range. +// +// Synopsis: +// Range(start, end) +// - returns a generator producing a sequence of values {start, start+1, +// start+2, ..., }. +// Range(start, end, step) +// - returns a generator producing a sequence of values {start, start+step, +// start+step+step, ..., }. +// Notes: +// * The generated sequences never include end. For example, Range(1, 5) +// returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2) +// returns a generator producing {1, 3, 5, 7}. +// * start and end must have the same type. That type may be any integral or +// floating-point type or a user defined type satisfying these conditions: +// * It must be assignable (have operator=() defined). +// * It must have operator+() (operator+(int-compatible type) for +// two-operand version). +// * It must have operator<() defined. +// Elements in the resulting sequences will also have that type. +// * Condition start < end must be satisfied in order for resulting sequences +// to contain any elements. +// +template +internal::ParamGenerator Range(T start, T end, IncrementT step) { + return internal::ParamGenerator( + new internal::RangeGenerator(start, end, step)); +} + +template +internal::ParamGenerator Range(T start, T end) { + return Range(start, end, 1); +} + +// ValuesIn() function allows generation of tests with parameters coming from +// a container. +// +// Synopsis: +// ValuesIn(const T (&array)[N]) +// - returns a generator producing sequences with elements from +// a C-style array. +// ValuesIn(const Container& container) +// - returns a generator producing sequences with elements from +// an STL-style container. +// ValuesIn(Iterator begin, Iterator end) +// - returns a generator producing sequences with elements from +// a range [begin, end) defined by a pair of STL-style iterators. These +// iterators can also be plain C pointers. +// +// Please note that ValuesIn copies the values from the containers +// passed in and keeps them to generate tests in RUN_ALL_TESTS(). +// +// Examples: +// +// This instantiates tests from test case StringTest +// each with C-string values of "foo", "bar", and "baz": +// +// const char* strings[] = {"foo", "bar", "baz"}; +// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings)); +// +// This instantiates tests from test case StlStringTest +// each with STL strings with values "a" and "b": +// +// ::std::vector< ::std::string> GetParameterStrings() { +// ::std::vector< ::std::string> v; +// v.push_back("a"); +// v.push_back("b"); +// return v; +// } +// +// INSTANTIATE_TEST_CASE_P(CharSequence, +// StlStringTest, +// ValuesIn(GetParameterStrings())); +// +// +// This will also instantiate tests from CharTest +// each with parameter values 'a' and 'b': +// +// ::std::list GetParameterChars() { +// ::std::list list; +// list.push_back('a'); +// list.push_back('b'); +// return list; +// } +// ::std::list l = GetParameterChars(); +// INSTANTIATE_TEST_CASE_P(CharSequence2, +// CharTest, +// ValuesIn(l.begin(), l.end())); +// +template +internal::ParamGenerator< + typename ::testing::internal::IteratorTraits::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end) { + typedef typename ::testing::internal::IteratorTraits + ::value_type ParamType; + return internal::ParamGenerator( + new internal::ValuesInIteratorRangeGenerator(begin, end)); +} + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]) { + return ValuesIn(array, array + N); +} + +template +internal::ParamGenerator ValuesIn( + const Container& container) { + return ValuesIn(container.begin(), container.end()); +} + +// Values() allows generating tests from explicitly specified list of +// parameters. +// +// Synopsis: +// Values(T v1, T v2, ..., T vN) +// - returns a generator producing sequences with elements v1, v2, ..., vN. +// +// For example, this instantiates tests from test case BarTest each +// with values "one", "two", and "three": +// +// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three")); +// +// This instantiates tests from test case BazTest each with values 1, 2, 3.5. +// The exact type of values will depend on the type of parameter in BazTest. +// +// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5)); +// +// Currently, Values() supports from 1 to 50 parameters. +// +template +internal::ValueArray1 Values(T1 v1) { + return internal::ValueArray1(v1); +} + +template +internal::ValueArray2 Values(T1 v1, T2 v2) { + return internal::ValueArray2(v1, v2); +} + +template +internal::ValueArray3 Values(T1 v1, T2 v2, T3 v3) { + return internal::ValueArray3(v1, v2, v3); +} + +template +internal::ValueArray4 Values(T1 v1, T2 v2, T3 v3, T4 v4) { + return internal::ValueArray4(v1, v2, v3, v4); +} + +template +internal::ValueArray5 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5) { + return internal::ValueArray5(v1, v2, v3, v4, v5); +} + +template +internal::ValueArray6 Values(T1 v1, T2 v2, T3 v3, + T4 v4, T5 v5, T6 v6) { + return internal::ValueArray6(v1, v2, v3, v4, v5, v6); +} + +template +internal::ValueArray7 Values(T1 v1, T2 v2, T3 v3, + T4 v4, T5 v5, T6 v6, T7 v7) { + return internal::ValueArray7(v1, v2, v3, v4, v5, + v6, v7); +} + +template +internal::ValueArray8 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8) { + return internal::ValueArray8(v1, v2, v3, v4, + v5, v6, v7, v8); +} + +template +internal::ValueArray9 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9) { + return internal::ValueArray9(v1, v2, v3, + v4, v5, v6, v7, v8, v9); +} + +template +internal::ValueArray10 Values(T1 v1, + T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10) { + return internal::ValueArray10(v1, + v2, v3, v4, v5, v6, v7, v8, v9, v10); +} + +template +internal::ValueArray11 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11) { + return internal::ValueArray11(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11); +} + +template +internal::ValueArray12 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12) { + return internal::ValueArray12(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12); +} + +template +internal::ValueArray13 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13) { + return internal::ValueArray13(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13); +} + +template +internal::ValueArray14 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) { + return internal::ValueArray14(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, + v14); +} + +template +internal::ValueArray15 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, + T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) { + return internal::ValueArray15(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, + v13, v14, v15); +} + +template +internal::ValueArray16 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16) { + return internal::ValueArray16(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, + v12, v13, v14, v15, v16); +} + +template +internal::ValueArray17 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17) { + return internal::ValueArray17(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, + v11, v12, v13, v14, v15, v16, v17); +} + +template +internal::ValueArray18 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, + T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18) { + return internal::ValueArray18(v1, v2, v3, v4, v5, v6, v7, v8, v9, + v10, v11, v12, v13, v14, v15, v16, v17, v18); +} + +template +internal::ValueArray19 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, + T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, + T15 v15, T16 v16, T17 v17, T18 v18, T19 v19) { + return internal::ValueArray19(v1, v2, v3, v4, v5, v6, v7, v8, + v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19); +} + +template +internal::ValueArray20 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, + T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20) { + return internal::ValueArray20(v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20); +} + +template +internal::ValueArray21 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, + T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21) { + return internal::ValueArray21(v1, v2, v3, v4, v5, v6, + v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21); +} + +template +internal::ValueArray22 Values(T1 v1, T2 v2, T3 v3, + T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22) { + return internal::ValueArray22(v1, v2, v3, v4, + v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, + v20, v21, v22); +} + +template +internal::ValueArray23 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22, T23 v23) { + return internal::ValueArray23(v1, v2, v3, + v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, + v20, v21, v22, v23); +} + +template +internal::ValueArray24 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22, T23 v23, T24 v24) { + return internal::ValueArray24(v1, v2, + v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, + v19, v20, v21, v22, v23, v24); +} + +template +internal::ValueArray25 Values(T1 v1, + T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, + T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, + T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25) { + return internal::ValueArray25(v1, + v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, + v18, v19, v20, v21, v22, v23, v24, v25); +} + +template +internal::ValueArray26 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26) { + return internal::ValueArray26(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, + v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26); +} + +template +internal::ValueArray27 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27) { + return internal::ValueArray27(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, + v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27); +} + +template +internal::ValueArray28 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28) { + return internal::ValueArray28(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, + v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, + v28); +} + +template +internal::ValueArray29 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29) { + return internal::ValueArray29(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, + v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, + v27, v28, v29); +} + +template +internal::ValueArray30 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, + T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, + T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, + T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) { + return internal::ValueArray30(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, + v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, + v26, v27, v28, v29, v30); +} + +template +internal::ValueArray31 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) { + return internal::ValueArray31(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, + v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, + v25, v26, v27, v28, v29, v30, v31); +} + +template +internal::ValueArray32 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, + T32 v32) { + return internal::ValueArray32(v1, v2, v3, v4, v5, v6, v7, v8, v9, + v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, + v24, v25, v26, v27, v28, v29, v30, v31, v32); +} + +template +internal::ValueArray33 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, + T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, + T32 v32, T33 v33) { + return internal::ValueArray33(v1, v2, v3, v4, v5, v6, v7, v8, + v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, + v24, v25, v26, v27, v28, v29, v30, v31, v32, v33); +} + +template +internal::ValueArray34 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, + T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, + T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, + T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, + T31 v31, T32 v32, T33 v33, T34 v34) { + return internal::ValueArray34(v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, + v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34); +} + +template +internal::ValueArray35 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, + T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, + T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, + T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35) { + return internal::ValueArray35(v1, v2, v3, v4, v5, v6, + v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, + v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35); +} + +template +internal::ValueArray36 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, + T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, + T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, + T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36) { + return internal::ValueArray36(v1, v2, v3, v4, + v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, + v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, + v34, v35, v36); +} + +template +internal::ValueArray37 Values(T1 v1, T2 v2, T3 v3, + T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, + T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, + T37 v37) { + return internal::ValueArray37(v1, v2, v3, + v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, + v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, + v34, v35, v36, v37); +} + +template +internal::ValueArray38 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, + T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, + T37 v37, T38 v38) { + return internal::ValueArray38(v1, v2, + v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, + v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, + v33, v34, v35, v36, v37, v38); +} + +template +internal::ValueArray39 Values(T1 v1, T2 v2, + T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, + T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, + T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, + T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, + T37 v37, T38 v38, T39 v39) { + return internal::ValueArray39(v1, + v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, + v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, + v32, v33, v34, v35, v36, v37, v38, v39); +} + +template +internal::ValueArray40 Values(T1 v1, + T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, + T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, + T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, + T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, + T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) { + return internal::ValueArray40(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, + v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, + v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40); +} + +template +internal::ValueArray41 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41) { + return internal::ValueArray41(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, + v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, + v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41); +} + +template +internal::ValueArray42 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42) { + return internal::ValueArray42(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, + v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, + v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, + v42); +} + +template +internal::ValueArray43 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43) { + return internal::ValueArray43(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, + v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, + v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, + v41, v42, v43); +} + +template +internal::ValueArray44 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44) { + return internal::ValueArray44(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, + v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, + v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, + v40, v41, v42, v43, v44); +} + +template +internal::ValueArray45 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, + T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, + T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, + T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, + T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, + T41 v41, T42 v42, T43 v43, T44 v44, T45 v45) { + return internal::ValueArray45(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, + v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, + v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, + v39, v40, v41, v42, v43, v44, v45); +} + +template +internal::ValueArray46 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, + T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, + T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) { + return internal::ValueArray46(v1, v2, v3, v4, v5, v6, v7, v8, v9, + v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, + v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, + v38, v39, v40, v41, v42, v43, v44, v45, v46); +} + +template +internal::ValueArray47 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, + T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, + T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) { + return internal::ValueArray47(v1, v2, v3, v4, v5, v6, v7, v8, + v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, + v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, + v38, v39, v40, v41, v42, v43, v44, v45, v46, v47); +} + +template +internal::ValueArray48 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, + T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, + T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, + T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, + T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, + T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, + T48 v48) { + return internal::ValueArray48(v1, v2, v3, v4, v5, v6, v7, + v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, + v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, + v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48); +} + +template +internal::ValueArray49 Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, + T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, + T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, + T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, + T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, + T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, + T47 v47, T48 v48, T49 v49) { + return internal::ValueArray49(v1, v2, v3, v4, v5, v6, + v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, + v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, + v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49); +} + +template +internal::ValueArray50 Values(T1 v1, T2 v2, T3 v3, T4 v4, + T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, + T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, + T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, + T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, + T38 v38, T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, + T46 v46, T47 v47, T48 v48, T49 v49, T50 v50) { + return internal::ValueArray50(v1, v2, v3, v4, + v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, + v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, + v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, + v48, v49, v50); +} + +// Bool() allows generating tests with parameters in a set of (false, true). +// +// Synopsis: +// Bool() +// - returns a generator producing sequences with elements {false, true}. +// +// It is useful when testing code that depends on Boolean flags. Combinations +// of multiple flags can be tested when several Bool()'s are combined using +// Combine() function. +// +// In the following example all tests in the test case FlagDependentTest +// will be instantiated twice with parameters false and true. +// +// class FlagDependentTest : public testing::TestWithParam { +// virtual void SetUp() { +// external_flag = GetParam(); +// } +// } +// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool()); +// +inline internal::ParamGenerator Bool() { + return Values(false, true); +} + +# if GTEST_HAS_COMBINE +// Combine() allows the user to combine two or more sequences to produce +// values of a Cartesian product of those sequences' elements. +// +// Synopsis: +// Combine(gen1, gen2, ..., genN) +// - returns a generator producing sequences with elements coming from +// the Cartesian product of elements from the sequences generated by +// gen1, gen2, ..., genN. The sequence elements will have a type of +// tuple where T1, T2, ..., TN are the types +// of elements from sequences produces by gen1, gen2, ..., genN. +// +// Combine can have up to 10 arguments. This number is currently limited +// by the maximum number of elements in the tuple implementation used by Google +// Test. +// +// Example: +// +// This will instantiate tests in test case AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// class AnimalTest +// : public testing::TestWithParam > {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest, +// Combine(Values("cat", "dog"), +// Values(BLACK, WHITE))); +// +// This will instantiate tests in FlagDependentTest with all variations of two +// Boolean flags: +// +// class FlagDependentTest +// : public testing::TestWithParam > { +// virtual void SetUp() { +// // Assigns external_flag_1 and external_flag_2 values from the tuple. +// tie(external_flag_1, external_flag_2) = GetParam(); +// } +// }; +// +// TEST_P(FlagDependentTest, TestFeature1) { +// // Test your code using external_flag_1 and external_flag_2 here. +// } +// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest, +// Combine(Bool(), Bool())); +// +template +internal::CartesianProductHolder2 Combine( + const Generator1& g1, const Generator2& g2) { + return internal::CartesianProductHolder2( + g1, g2); +} + +template +internal::CartesianProductHolder3 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3) { + return internal::CartesianProductHolder3( + g1, g2, g3); +} + +template +internal::CartesianProductHolder4 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4) { + return internal::CartesianProductHolder4( + g1, g2, g3, g4); +} + +template +internal::CartesianProductHolder5 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5) { + return internal::CartesianProductHolder5( + g1, g2, g3, g4, g5); +} + +template +internal::CartesianProductHolder6 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5, const Generator6& g6) { + return internal::CartesianProductHolder6( + g1, g2, g3, g4, g5, g6); +} + +template +internal::CartesianProductHolder7 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5, const Generator6& g6, + const Generator7& g7) { + return internal::CartesianProductHolder7( + g1, g2, g3, g4, g5, g6, g7); +} + +template +internal::CartesianProductHolder8 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5, const Generator6& g6, + const Generator7& g7, const Generator8& g8) { + return internal::CartesianProductHolder8( + g1, g2, g3, g4, g5, g6, g7, g8); +} + +template +internal::CartesianProductHolder9 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5, const Generator6& g6, + const Generator7& g7, const Generator8& g8, const Generator9& g9) { + return internal::CartesianProductHolder9( + g1, g2, g3, g4, g5, g6, g7, g8, g9); +} + +template +internal::CartesianProductHolder10 Combine( + const Generator1& g1, const Generator2& g2, const Generator3& g3, + const Generator4& g4, const Generator5& g5, const Generator6& g6, + const Generator7& g7, const Generator8& g8, const Generator9& g9, + const Generator10& g10) { + return internal::CartesianProductHolder10( + g1, g2, g3, g4, g5, g6, g7, g8, g9, g10); +} +# endif // GTEST_HAS_COMBINE + + + +# define TEST_P(test_case_name, test_name) \ + class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ + : public test_case_name { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ + virtual void TestBody(); \ + private: \ + static int AddToRegistry() { \ + ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ + GetTestCasePatternHolder(\ + #test_case_name, \ + ::testing::internal::CodeLocation(\ + __FILE__, __LINE__))->AddTestPattern(\ + #test_case_name, \ + #test_name, \ + new ::testing::internal::TestMetaFactory< \ + GTEST_TEST_CLASS_NAME_(\ + test_case_name, test_name)>()); \ + return 0; \ + } \ + static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ + }; \ + int GTEST_TEST_CLASS_NAME_(test_case_name, \ + test_name)::gtest_registering_dummy_ = \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() + +// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user +// to specify a function or functor that generates custom test name suffixes +// based on the test parameters. The function should accept one argument of +// type testing::TestParamInfo, and return std::string. +// +// testing::PrintToStringParamName is a builtin test suffix generator that +// returns the value of testing::PrintToString(GetParam()). It does not work +// for std::string or C strings. +// +// Note: test names must be non-empty, unique, and may only contain ASCII +// alphanumeric characters or underscore. + +# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \ + ::testing::internal::ParamGenerator \ + gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \ + ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \ + const ::testing::TestParamInfo& info) { \ + return ::testing::internal::GetParamNameGen \ + (__VA_ARGS__)(info); \ + } \ + int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \ + ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ + GetTestCasePatternHolder(\ + #test_case_name, \ + ::testing::internal::CodeLocation(\ + __FILE__, __LINE__))->AddTestCaseInstantiation(\ + #prefix, \ + >est_##prefix##test_case_name##_EvalGenerator_, \ + >est_##prefix##test_case_name##_EvalGenerateName_, \ + __FILE__, __LINE__) + +} // namespace testing + +#endif // GTEST_HAS_PARAM_TEST + +#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ diff --git a/TestMothur/gtest-param-test.h.pump b/TestMothur/gtest-param-test.h.pump new file mode 100755 index 00000000..aa59e9d4 --- /dev/null +++ b/TestMothur/gtest-param-test.h.pump @@ -0,0 +1,510 @@ +$$ -*- mode: c++; -*- +$var n = 50 $$ Maximum length of Values arguments we want to support. +$var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: vladl@google.com (Vlad Losev) +// +// Macros and functions for implementing parameterized tests +// in Google C++ Testing Framework (Google Test) +// +// This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +#ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ +#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ + + +// Value-parameterized tests allow you to test your code with different +// parameters without writing multiple copies of the same test. +// +// Here is how you use value-parameterized tests: + +#if 0 + +// To write value-parameterized tests, first you should define a fixture +// class. It is usually derived from testing::TestWithParam (see below for +// another inheritance scheme that's sometimes useful in more complicated +// class hierarchies), where the type of your parameter values. +// TestWithParam is itself derived from testing::Test. T can be any +// copyable type. If it's a raw pointer, you are responsible for managing the +// lifespan of the pointed values. + +class FooTest : public ::testing::TestWithParam { + // You can implement all the usual class fixture members here. +}; + +// Then, use the TEST_P macro to define as many parameterized tests +// for this fixture as you want. The _P suffix is for "parameterized" +// or "pattern", whichever you prefer to think. + +TEST_P(FooTest, DoesBlah) { + // Inside a test, access the test parameter with the GetParam() method + // of the TestWithParam class: + EXPECT_TRUE(foo.Blah(GetParam())); + ... +} + +TEST_P(FooTest, HasBlahBlah) { + ... +} + +// Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test +// case with any set of parameters you want. Google Test defines a number +// of functions for generating test parameters. They return what we call +// (surprise!) parameter generators. Here is a summary of them, which +// are all in the testing namespace: +// +// +// Range(begin, end [, step]) - Yields values {begin, begin+step, +// begin+step+step, ...}. The values do not +// include end. step defaults to 1. +// Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}. +// ValuesIn(container) - Yields values from a C-style array, an STL +// ValuesIn(begin,end) container, or an iterator range [begin, end). +// Bool() - Yields sequence {false, true}. +// Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product +// for the math savvy) of the values generated +// by the N generators. +// +// For more details, see comments at the definitions of these functions below +// in this file. +// +// The following statement will instantiate tests from the FooTest test case +// each with parameter values "meeny", "miny", and "moe". + +INSTANTIATE_TEST_CASE_P(InstantiationName, + FooTest, + Values("meeny", "miny", "moe")); + +// To distinguish different instances of the pattern, (yes, you +// can instantiate it more then once) the first argument to the +// INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the +// actual test case name. Remember to pick unique prefixes for different +// instantiations. The tests from the instantiation above will have +// these names: +// +// * InstantiationName/FooTest.DoesBlah/0 for "meeny" +// * InstantiationName/FooTest.DoesBlah/1 for "miny" +// * InstantiationName/FooTest.DoesBlah/2 for "moe" +// * InstantiationName/FooTest.HasBlahBlah/0 for "meeny" +// * InstantiationName/FooTest.HasBlahBlah/1 for "miny" +// * InstantiationName/FooTest.HasBlahBlah/2 for "moe" +// +// You can use these names in --gtest_filter. +// +// This statement will instantiate all tests from FooTest again, each +// with parameter values "cat" and "dog": + +const char* pets[] = {"cat", "dog"}; +INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets)); + +// The tests from the instantiation above will have these names: +// +// * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat" +// * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog" +// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat" +// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog" +// +// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests +// in the given test case, whether their definitions come before or +// AFTER the INSTANTIATE_TEST_CASE_P statement. +// +// Please also note that generator expressions (including parameters to the +// generators) are evaluated in InitGoogleTest(), after main() has started. +// This allows the user on one hand, to adjust generator parameters in order +// to dynamically determine a set of tests to run and on the other hand, +// give the user a chance to inspect the generated tests with Google Test +// reflection API before RUN_ALL_TESTS() is executed. +// +// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc +// for more examples. +// +// In the future, we plan to publish the API for defining new parameter +// generators. But for now this interface remains part of the internal +// implementation and is subject to change. +// +// +// A parameterized test fixture must be derived from testing::Test and from +// testing::WithParamInterface, where T is the type of the parameter +// values. Inheriting from TestWithParam satisfies that requirement because +// TestWithParam inherits from both Test and WithParamInterface. In more +// complicated hierarchies, however, it is occasionally useful to inherit +// separately from Test and WithParamInterface. For example: + +class BaseTest : public ::testing::Test { + // You can inherit all the usual members for a non-parameterized test + // fixture here. +}; + +class DerivedTest : public BaseTest, public ::testing::WithParamInterface { + // The usual test fixture members go here too. +}; + +TEST_F(BaseTest, HasFoo) { + // This is an ordinary non-parameterized test. +} + +TEST_P(DerivedTest, DoesBlah) { + // GetParam works just the same here as if you inherit from TestWithParam. + EXPECT_TRUE(foo.Blah(GetParam())); +} + +#endif // 0 + +#include "gtest-port.h" + +#if !GTEST_OS_SYMBIAN +# include +#endif + +// scripts/fuse_gtest.py depends on gtest's own header being #included +// *unconditionally*. Therefore these #includes cannot be moved +// inside #if GTEST_HAS_PARAM_TEST. +#include "gtest-internal.h" +#include "gtest-param-util.h" +#include "gtest-param-util-generated.h" + +#if GTEST_HAS_PARAM_TEST + +namespace testing { + +// Functions producing parameter generators. +// +// Google Test uses these generators to produce parameters for value- +// parameterized tests. When a parameterized test case is instantiated +// with a particular generator, Google Test creates and runs tests +// for each element in the sequence produced by the generator. +// +// In the following sample, tests from test case FooTest are instantiated +// each three times with parameter values 3, 5, and 8: +// +// class FooTest : public TestWithParam { ... }; +// +// TEST_P(FooTest, TestThis) { +// } +// TEST_P(FooTest, TestThat) { +// } +// INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8)); +// + +// Range() returns generators providing sequences of values in a range. +// +// Synopsis: +// Range(start, end) +// - returns a generator producing a sequence of values {start, start+1, +// start+2, ..., }. +// Range(start, end, step) +// - returns a generator producing a sequence of values {start, start+step, +// start+step+step, ..., }. +// Notes: +// * The generated sequences never include end. For example, Range(1, 5) +// returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2) +// returns a generator producing {1, 3, 5, 7}. +// * start and end must have the same type. That type may be any integral or +// floating-point type or a user defined type satisfying these conditions: +// * It must be assignable (have operator=() defined). +// * It must have operator+() (operator+(int-compatible type) for +// two-operand version). +// * It must have operator<() defined. +// Elements in the resulting sequences will also have that type. +// * Condition start < end must be satisfied in order for resulting sequences +// to contain any elements. +// +template +internal::ParamGenerator Range(T start, T end, IncrementT step) { + return internal::ParamGenerator( + new internal::RangeGenerator(start, end, step)); +} + +template +internal::ParamGenerator Range(T start, T end) { + return Range(start, end, 1); +} + +// ValuesIn() function allows generation of tests with parameters coming from +// a container. +// +// Synopsis: +// ValuesIn(const T (&array)[N]) +// - returns a generator producing sequences with elements from +// a C-style array. +// ValuesIn(const Container& container) +// - returns a generator producing sequences with elements from +// an STL-style container. +// ValuesIn(Iterator begin, Iterator end) +// - returns a generator producing sequences with elements from +// a range [begin, end) defined by a pair of STL-style iterators. These +// iterators can also be plain C pointers. +// +// Please note that ValuesIn copies the values from the containers +// passed in and keeps them to generate tests in RUN_ALL_TESTS(). +// +// Examples: +// +// This instantiates tests from test case StringTest +// each with C-string values of "foo", "bar", and "baz": +// +// const char* strings[] = {"foo", "bar", "baz"}; +// INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings)); +// +// This instantiates tests from test case StlStringTest +// each with STL strings with values "a" and "b": +// +// ::std::vector< ::std::string> GetParameterStrings() { +// ::std::vector< ::std::string> v; +// v.push_back("a"); +// v.push_back("b"); +// return v; +// } +// +// INSTANTIATE_TEST_CASE_P(CharSequence, +// StlStringTest, +// ValuesIn(GetParameterStrings())); +// +// +// This will also instantiate tests from CharTest +// each with parameter values 'a' and 'b': +// +// ::std::list GetParameterChars() { +// ::std::list list; +// list.push_back('a'); +// list.push_back('b'); +// return list; +// } +// ::std::list l = GetParameterChars(); +// INSTANTIATE_TEST_CASE_P(CharSequence2, +// CharTest, +// ValuesIn(l.begin(), l.end())); +// +template +internal::ParamGenerator< + typename ::testing::internal::IteratorTraits::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end) { + typedef typename ::testing::internal::IteratorTraits + ::value_type ParamType; + return internal::ParamGenerator( + new internal::ValuesInIteratorRangeGenerator(begin, end)); +} + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]) { + return ValuesIn(array, array + N); +} + +template +internal::ParamGenerator ValuesIn( + const Container& container) { + return ValuesIn(container.begin(), container.end()); +} + +// Values() allows generating tests from explicitly specified list of +// parameters. +// +// Synopsis: +// Values(T v1, T v2, ..., T vN) +// - returns a generator producing sequences with elements v1, v2, ..., vN. +// +// For example, this instantiates tests from test case BarTest each +// with values "one", "two", and "three": +// +// INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three")); +// +// This instantiates tests from test case BazTest each with values 1, 2, 3.5. +// The exact type of values will depend on the type of parameter in BazTest. +// +// INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5)); +// +// Currently, Values() supports from 1 to $n parameters. +// +$range i 1..n +$for i [[ +$range j 1..i + +template <$for j, [[typename T$j]]> +internal::ValueArray$i<$for j, [[T$j]]> Values($for j, [[T$j v$j]]) { + return internal::ValueArray$i<$for j, [[T$j]]>($for j, [[v$j]]); +} + +]] + +// Bool() allows generating tests with parameters in a set of (false, true). +// +// Synopsis: +// Bool() +// - returns a generator producing sequences with elements {false, true}. +// +// It is useful when testing code that depends on Boolean flags. Combinations +// of multiple flags can be tested when several Bool()'s are combined using +// Combine() function. +// +// In the following example all tests in the test case FlagDependentTest +// will be instantiated twice with parameters false and true. +// +// class FlagDependentTest : public testing::TestWithParam { +// virtual void SetUp() { +// external_flag = GetParam(); +// } +// } +// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool()); +// +inline internal::ParamGenerator Bool() { + return Values(false, true); +} + +# if GTEST_HAS_COMBINE +// Combine() allows the user to combine two or more sequences to produce +// values of a Cartesian product of those sequences' elements. +// +// Synopsis: +// Combine(gen1, gen2, ..., genN) +// - returns a generator producing sequences with elements coming from +// the Cartesian product of elements from the sequences generated by +// gen1, gen2, ..., genN. The sequence elements will have a type of +// tuple where T1, T2, ..., TN are the types +// of elements from sequences produces by gen1, gen2, ..., genN. +// +// Combine can have up to $maxtuple arguments. This number is currently limited +// by the maximum number of elements in the tuple implementation used by Google +// Test. +// +// Example: +// +// This will instantiate tests in test case AnimalTest each one with +// the parameter values tuple("cat", BLACK), tuple("cat", WHITE), +// tuple("dog", BLACK), and tuple("dog", WHITE): +// +// enum Color { BLACK, GRAY, WHITE }; +// class AnimalTest +// : public testing::TestWithParam > {...}; +// +// TEST_P(AnimalTest, AnimalLooksNice) {...} +// +// INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest, +// Combine(Values("cat", "dog"), +// Values(BLACK, WHITE))); +// +// This will instantiate tests in FlagDependentTest with all variations of two +// Boolean flags: +// +// class FlagDependentTest +// : public testing::TestWithParam > { +// virtual void SetUp() { +// // Assigns external_flag_1 and external_flag_2 values from the tuple. +// tie(external_flag_1, external_flag_2) = GetParam(); +// } +// }; +// +// TEST_P(FlagDependentTest, TestFeature1) { +// // Test your code using external_flag_1 and external_flag_2 here. +// } +// INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest, +// Combine(Bool(), Bool())); +// +$range i 2..maxtuple +$for i [[ +$range j 1..i + +template <$for j, [[typename Generator$j]]> +internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine( + $for j, [[const Generator$j& g$j]]) { + return internal::CartesianProductHolder$i<$for j, [[Generator$j]]>( + $for j, [[g$j]]); +} + +]] +# endif // GTEST_HAS_COMBINE + + + +# define TEST_P(test_case_name, test_name) \ + class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ + : public test_case_name { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ + virtual void TestBody(); \ + private: \ + static int AddToRegistry() { \ + ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ + GetTestCasePatternHolder(\ + #test_case_name, \ + ::testing::internal::CodeLocation(\ + __FILE__, __LINE__))->AddTestPattern(\ + #test_case_name, \ + #test_name, \ + new ::testing::internal::TestMetaFactory< \ + GTEST_TEST_CLASS_NAME_(\ + test_case_name, test_name)>()); \ + return 0; \ + } \ + static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ + GTEST_DISALLOW_COPY_AND_ASSIGN_(\ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ + }; \ + int GTEST_TEST_CLASS_NAME_(test_case_name, \ + test_name)::gtest_registering_dummy_ = \ + GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ + void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() + +// The optional last argument to INSTANTIATE_TEST_CASE_P allows the user +// to specify a function or functor that generates custom test name suffixes +// based on the test parameters. The function should accept one argument of +// type testing::TestParamInfo, and return std::string. +// +// testing::PrintToStringParamName is a builtin test suffix generator that +// returns the value of testing::PrintToString(GetParam()). +// +// Note: test names must be non-empty, unique, and may only contain ASCII +// alphanumeric characters or underscore. Because PrintToString adds quotes +// to std::string and C strings, it won't work for these types. + +# define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator, ...) \ + ::testing::internal::ParamGenerator \ + gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \ + ::std::string gtest_##prefix##test_case_name##_EvalGenerateName_( \ + const ::testing::TestParamInfo& info) { \ + return ::testing::internal::GetParamNameGen \ + (__VA_ARGS__)(info); \ + } \ + int gtest_##prefix##test_case_name##_dummy_ GTEST_ATTRIBUTE_UNUSED_ = \ + ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ + GetTestCasePatternHolder(\ + #test_case_name, \ + ::testing::internal::CodeLocation(\ + __FILE__, __LINE__))->AddTestCaseInstantiation(\ + #prefix, \ + >est_##prefix##test_case_name##_EvalGenerator_, \ + >est_##prefix##test_case_name##_EvalGenerateName_, \ + __FILE__, __LINE__) + +} // namespace testing + +#endif // GTEST_HAS_PARAM_TEST + +#endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ diff --git a/TestMothur/gtest-param-util-generated.h b/TestMothur/gtest-param-util-generated.h new file mode 100755 index 00000000..dfeeb409 --- /dev/null +++ b/TestMothur/gtest-param-util-generated.h @@ -0,0 +1,5146 @@ +// This file was GENERATED by command: +// pump.py gtest-param-util-generated.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: vladl@google.com (Vlad Losev) + +// Type and function utilities for implementing parameterized tests. +// This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +// Currently Google Test supports at most 50 arguments in Values, +// and at most 10 arguments in Combine. Please contact +// googletestframework@googlegroups.com if you need more. +// Please note that the number of arguments to Combine is limited +// by the maximum arity of the implementation of tuple which is +// currently set at 10. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ + +// scripts/fuse_gtest.py depends on gtest's own header being #included +// *unconditionally*. Therefore these #includes cannot be moved +// inside #if GTEST_HAS_PARAM_TEST. +#include "gtest-param-util.h" +#include "gtest-port.h" + +#if GTEST_HAS_PARAM_TEST + +namespace testing { + +// Forward declarations of ValuesIn(), which is implemented in +// include/gtest-param-test.h. +template +internal::ParamGenerator< + typename ::testing::internal::IteratorTraits::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end); + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]); + +template +internal::ParamGenerator ValuesIn( + const Container& container); + +namespace internal { + +// Used in the Values() function to provide polymorphic capabilities. +template +class ValueArray1 { + public: + explicit ValueArray1(T1 v1) : v1_(v1) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray1& other); + + const T1 v1_; +}; + +template +class ValueArray2 { + public: + ValueArray2(T1 v1, T2 v2) : v1_(v1), v2_(v2) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray2& other); + + const T1 v1_; + const T2 v2_; +}; + +template +class ValueArray3 { + public: + ValueArray3(T1 v1, T2 v2, T3 v3) : v1_(v1), v2_(v2), v3_(v3) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray3& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; +}; + +template +class ValueArray4 { + public: + ValueArray4(T1 v1, T2 v2, T3 v3, T4 v4) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray4& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; +}; + +template +class ValueArray5 { + public: + ValueArray5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray5& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; +}; + +template +class ValueArray6 { + public: + ValueArray6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray6& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; +}; + +template +class ValueArray7 { + public: + ValueArray7(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray7& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; +}; + +template +class ValueArray8 { + public: + ValueArray8(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, + T8 v8) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray8& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; +}; + +template +class ValueArray9 { + public: + ValueArray9(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, + T9 v9) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray9& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; +}; + +template +class ValueArray10 { + public: + ValueArray10(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray10& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; +}; + +template +class ValueArray11 { + public: + ValueArray11(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), + v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray11& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; +}; + +template +class ValueArray12 { + public: + ValueArray12(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), + v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray12& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; +}; + +template +class ValueArray13 { + public: + ValueArray13(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), + v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), + v12_(v12), v13_(v13) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray13& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; +}; + +template +class ValueArray14 { + public: + ValueArray14(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray14& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; +}; + +template +class ValueArray15 { + public: + ValueArray15(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray15& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; +}; + +template +class ValueArray16 { + public: + ValueArray16(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), + v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), + v16_(v16) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray16& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; +}; + +template +class ValueArray17 { + public: + ValueArray17(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, + T17 v17) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray17& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; +}; + +template +class ValueArray18 { + public: + ValueArray18(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray18& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; +}; + +template +class ValueArray19 { + public: + ValueArray19(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), + v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), + v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray19& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; +}; + +template +class ValueArray20 { + public: + ValueArray20(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), + v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), + v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), + v19_(v19), v20_(v20) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray20& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; +}; + +template +class ValueArray21 { + public: + ValueArray21(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), + v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), + v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), + v18_(v18), v19_(v19), v20_(v20), v21_(v21) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray21& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; +}; + +template +class ValueArray22 { + public: + ValueArray22(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray22& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; +}; + +template +class ValueArray23 { + public: + ValueArray23(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray23& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; +}; + +template +class ValueArray24 { + public: + ValueArray24(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), + v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), + v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), + v22_(v22), v23_(v23), v24_(v24) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray24& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; +}; + +template +class ValueArray25 { + public: + ValueArray25(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, + T25 v25) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray25& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; +}; + +template +class ValueArray26 { + public: + ValueArray26(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray26& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; +}; + +template +class ValueArray27 { + public: + ValueArray27(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), + v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), + v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), + v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), + v26_(v26), v27_(v27) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray27& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; +}; + +template +class ValueArray28 { + public: + ValueArray28(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), + v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), + v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), + v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), + v25_(v25), v26_(v26), v27_(v27), v28_(v28) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray28& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; +}; + +template +class ValueArray29 { + public: + ValueArray29(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), + v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), + v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), + v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), + v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray29& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; +}; + +template +class ValueArray30 { + public: + ValueArray30(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray30& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; +}; + +template +class ValueArray31 { + public: + ValueArray31(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30), v31_(v31) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray31& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; +}; + +template +class ValueArray32 { + public: + ValueArray32(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), + v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), + v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), + v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), + v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray32& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; +}; + +template +class ValueArray33 { + public: + ValueArray33(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, + T33 v33) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray33& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; +}; + +template +class ValueArray34 { + public: + ValueArray34(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33), v34_(v34) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray34& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; +}; + +template +class ValueArray35 { + public: + ValueArray35(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), + v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), + v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), + v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), + v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), + v32_(v32), v33_(v33), v34_(v34), v35_(v35) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray35& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; +}; + +template +class ValueArray36 { + public: + ValueArray36(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), + v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), + v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), + v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), + v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), + v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray36& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; +}; + +template +class ValueArray37 { + public: + ValueArray37(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), + v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), + v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), + v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), + v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), + v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), + v36_(v36), v37_(v37) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray37& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; +}; + +template +class ValueArray38 { + public: + ValueArray38(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), + v35_(v35), v36_(v36), v37_(v37), v38_(v38) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray38& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; +}; + +template +class ValueArray39 { + public: + ValueArray39(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), + v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray39& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; +}; + +template +class ValueArray40 { + public: + ValueArray40(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), + v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), + v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), + v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), + v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), + v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), + v40_(v40) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray40& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; +}; + +template +class ValueArray41 { + public: + ValueArray41(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, + T41 v41) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), + v39_(v39), v40_(v40), v41_(v41) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray41& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; +}; + +template +class ValueArray42 { + public: + ValueArray42(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), + v39_(v39), v40_(v40), v41_(v41), v42_(v42) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray42& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; +}; + +template +class ValueArray43 { + public: + ValueArray43(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), + v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), + v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), + v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), + v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), + v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), + v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray43& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; +}; + +template +class ValueArray44 { + public: + ValueArray44(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), + v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), + v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), + v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), + v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), + v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36), + v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42), + v43_(v43), v44_(v44) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray44& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; +}; + +template +class ValueArray45 { + public: + ValueArray45(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), + v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), + v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), + v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), + v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), + v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), + v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41), + v42_(v42), v43_(v43), v44_(v44), v45_(v45) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray45& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; +}; + +template +class ValueArray46 { + public: + ValueArray46(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) : v1_(v1), v2_(v2), v3_(v3), + v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), + v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40), + v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_), static_cast(v46_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray46& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; + const T46 v46_; +}; + +template +class ValueArray47 { + public: + ValueArray47(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) : v1_(v1), v2_(v2), + v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), + v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), + v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), + v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), + v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), + v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40), + v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46), + v47_(v47) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_), static_cast(v46_), static_cast(v47_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray47& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; + const T46 v46_; + const T47 v47_; +}; + +template +class ValueArray48 { + public: + ValueArray48(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48) : v1_(v1), + v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), + v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), + v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), + v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), + v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), + v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), + v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), + v46_(v46), v47_(v47), v48_(v48) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_), static_cast(v46_), static_cast(v47_), + static_cast(v48_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray48& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; + const T46 v46_; + const T47 v47_; + const T48 v48_; +}; + +template +class ValueArray49 { + public: + ValueArray49(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48, + T49 v49) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), + v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44), + v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_), static_cast(v46_), static_cast(v47_), + static_cast(v48_), static_cast(v49_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray49& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; + const T46 v46_; + const T47 v47_; + const T48 v48_; + const T49 v49_; +}; + +template +class ValueArray50 { + public: + ValueArray50(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, + T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, + T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, + T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, + T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41, + T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48, T49 v49, + T50 v50) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), + v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), + v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), + v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), + v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), + v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), + v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44), + v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49), v50_(v50) {} + + template + operator ParamGenerator() const { + const T array[] = {static_cast(v1_), static_cast(v2_), + static_cast(v3_), static_cast(v4_), static_cast(v5_), + static_cast(v6_), static_cast(v7_), static_cast(v8_), + static_cast(v9_), static_cast(v10_), static_cast(v11_), + static_cast(v12_), static_cast(v13_), static_cast(v14_), + static_cast(v15_), static_cast(v16_), static_cast(v17_), + static_cast(v18_), static_cast(v19_), static_cast(v20_), + static_cast(v21_), static_cast(v22_), static_cast(v23_), + static_cast(v24_), static_cast(v25_), static_cast(v26_), + static_cast(v27_), static_cast(v28_), static_cast(v29_), + static_cast(v30_), static_cast(v31_), static_cast(v32_), + static_cast(v33_), static_cast(v34_), static_cast(v35_), + static_cast(v36_), static_cast(v37_), static_cast(v38_), + static_cast(v39_), static_cast(v40_), static_cast(v41_), + static_cast(v42_), static_cast(v43_), static_cast(v44_), + static_cast(v45_), static_cast(v46_), static_cast(v47_), + static_cast(v48_), static_cast(v49_), static_cast(v50_)}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray50& other); + + const T1 v1_; + const T2 v2_; + const T3 v3_; + const T4 v4_; + const T5 v5_; + const T6 v6_; + const T7 v7_; + const T8 v8_; + const T9 v9_; + const T10 v10_; + const T11 v11_; + const T12 v12_; + const T13 v13_; + const T14 v14_; + const T15 v15_; + const T16 v16_; + const T17 v17_; + const T18 v18_; + const T19 v19_; + const T20 v20_; + const T21 v21_; + const T22 v22_; + const T23 v23_; + const T24 v24_; + const T25 v25_; + const T26 v26_; + const T27 v27_; + const T28 v28_; + const T29 v29_; + const T30 v30_; + const T31 v31_; + const T32 v32_; + const T33 v33_; + const T34 v34_; + const T35 v35_; + const T36 v36_; + const T37 v37_; + const T38 v38_; + const T39 v39_; + const T40 v40_; + const T41 v41_; + const T42 v42_; + const T43 v43_; + const T44 v44_; + const T45 v45_; + const T46 v46_; + const T47 v47_; + const T48 v48_; + const T49 v49_; + const T50 v50_; +}; + +# if GTEST_HAS_COMBINE +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Generates values from the Cartesian product of values produced +// by the argument generators. +// +template +class CartesianProductGenerator2 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator2(const ParamGenerator& g1, + const ParamGenerator& g2) + : g1_(g1), g2_(g2) {} + virtual ~CartesianProductGenerator2() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current2_; + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + ParamType current_value_; + }; // class CartesianProductGenerator2::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator2& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; +}; // class CartesianProductGenerator2 + + +template +class CartesianProductGenerator3 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator3(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3) + : g1_(g1), g2_(g2), g3_(g3) {} + virtual ~CartesianProductGenerator3() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current3_; + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + ParamType current_value_; + }; // class CartesianProductGenerator3::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator3& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; +}; // class CartesianProductGenerator3 + + +template +class CartesianProductGenerator4 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator4(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {} + virtual ~CartesianProductGenerator4() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current4_; + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + ParamType current_value_; + }; // class CartesianProductGenerator4::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator4& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; +}; // class CartesianProductGenerator4 + + +template +class CartesianProductGenerator5 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator5(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {} + virtual ~CartesianProductGenerator5() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current5_; + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + ParamType current_value_; + }; // class CartesianProductGenerator5::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator5& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; +}; // class CartesianProductGenerator5 + + +template +class CartesianProductGenerator6 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator6(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5, + const ParamGenerator& g6) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {} + virtual ~CartesianProductGenerator6() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5, + const ParamGenerator& g6, + const typename ParamGenerator::iterator& current6) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5), + begin6_(g6.begin()), end6_(g6.end()), current6_(current6) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current6_; + if (current6_ == end6_) { + current6_ = begin6_; + ++current5_; + } + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_ && + current6_ == typed_other->current6_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_), + begin6_(other.begin6_), + end6_(other.end6_), + current6_(other.current6_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_, *current6_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_ || + current6_ == end6_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + const typename ParamGenerator::iterator begin6_; + const typename ParamGenerator::iterator end6_; + typename ParamGenerator::iterator current6_; + ParamType current_value_; + }; // class CartesianProductGenerator6::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator6& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; + const ParamGenerator g6_; +}; // class CartesianProductGenerator6 + + +template +class CartesianProductGenerator7 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator7(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5, + const ParamGenerator& g6, const ParamGenerator& g7) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {} + virtual ~CartesianProductGenerator7() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_, + g7_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5, + const ParamGenerator& g6, + const typename ParamGenerator::iterator& current6, + const ParamGenerator& g7, + const typename ParamGenerator::iterator& current7) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5), + begin6_(g6.begin()), end6_(g6.end()), current6_(current6), + begin7_(g7.begin()), end7_(g7.end()), current7_(current7) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current7_; + if (current7_ == end7_) { + current7_ = begin7_; + ++current6_; + } + if (current6_ == end6_) { + current6_ = begin6_; + ++current5_; + } + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_ && + current6_ == typed_other->current6_ && + current7_ == typed_other->current7_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_), + begin6_(other.begin6_), + end6_(other.end6_), + current6_(other.current6_), + begin7_(other.begin7_), + end7_(other.end7_), + current7_(other.current7_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_, *current6_, *current7_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_ || + current6_ == end6_ || + current7_ == end7_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + const typename ParamGenerator::iterator begin6_; + const typename ParamGenerator::iterator end6_; + typename ParamGenerator::iterator current6_; + const typename ParamGenerator::iterator begin7_; + const typename ParamGenerator::iterator end7_; + typename ParamGenerator::iterator current7_; + ParamType current_value_; + }; // class CartesianProductGenerator7::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator7& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; + const ParamGenerator g6_; + const ParamGenerator g7_; +}; // class CartesianProductGenerator7 + + +template +class CartesianProductGenerator8 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator8(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5, + const ParamGenerator& g6, const ParamGenerator& g7, + const ParamGenerator& g8) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), + g8_(g8) {} + virtual ~CartesianProductGenerator8() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_, + g7_.begin(), g8_, g8_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_, + g8_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5, + const ParamGenerator& g6, + const typename ParamGenerator::iterator& current6, + const ParamGenerator& g7, + const typename ParamGenerator::iterator& current7, + const ParamGenerator& g8, + const typename ParamGenerator::iterator& current8) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5), + begin6_(g6.begin()), end6_(g6.end()), current6_(current6), + begin7_(g7.begin()), end7_(g7.end()), current7_(current7), + begin8_(g8.begin()), end8_(g8.end()), current8_(current8) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current8_; + if (current8_ == end8_) { + current8_ = begin8_; + ++current7_; + } + if (current7_ == end7_) { + current7_ = begin7_; + ++current6_; + } + if (current6_ == end6_) { + current6_ = begin6_; + ++current5_; + } + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_ && + current6_ == typed_other->current6_ && + current7_ == typed_other->current7_ && + current8_ == typed_other->current8_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_), + begin6_(other.begin6_), + end6_(other.end6_), + current6_(other.current6_), + begin7_(other.begin7_), + end7_(other.end7_), + current7_(other.current7_), + begin8_(other.begin8_), + end8_(other.end8_), + current8_(other.current8_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_, *current6_, *current7_, *current8_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_ || + current6_ == end6_ || + current7_ == end7_ || + current8_ == end8_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + const typename ParamGenerator::iterator begin6_; + const typename ParamGenerator::iterator end6_; + typename ParamGenerator::iterator current6_; + const typename ParamGenerator::iterator begin7_; + const typename ParamGenerator::iterator end7_; + typename ParamGenerator::iterator current7_; + const typename ParamGenerator::iterator begin8_; + const typename ParamGenerator::iterator end8_; + typename ParamGenerator::iterator current8_; + ParamType current_value_; + }; // class CartesianProductGenerator8::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator8& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; + const ParamGenerator g6_; + const ParamGenerator g7_; + const ParamGenerator g8_; +}; // class CartesianProductGenerator8 + + +template +class CartesianProductGenerator9 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator9(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5, + const ParamGenerator& g6, const ParamGenerator& g7, + const ParamGenerator& g8, const ParamGenerator& g9) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8), + g9_(g9) {} + virtual ~CartesianProductGenerator9() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_, + g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_, + g8_.end(), g9_, g9_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5, + const ParamGenerator& g6, + const typename ParamGenerator::iterator& current6, + const ParamGenerator& g7, + const typename ParamGenerator::iterator& current7, + const ParamGenerator& g8, + const typename ParamGenerator::iterator& current8, + const ParamGenerator& g9, + const typename ParamGenerator::iterator& current9) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5), + begin6_(g6.begin()), end6_(g6.end()), current6_(current6), + begin7_(g7.begin()), end7_(g7.end()), current7_(current7), + begin8_(g8.begin()), end8_(g8.end()), current8_(current8), + begin9_(g9.begin()), end9_(g9.end()), current9_(current9) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current9_; + if (current9_ == end9_) { + current9_ = begin9_; + ++current8_; + } + if (current8_ == end8_) { + current8_ = begin8_; + ++current7_; + } + if (current7_ == end7_) { + current7_ = begin7_; + ++current6_; + } + if (current6_ == end6_) { + current6_ = begin6_; + ++current5_; + } + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_ && + current6_ == typed_other->current6_ && + current7_ == typed_other->current7_ && + current8_ == typed_other->current8_ && + current9_ == typed_other->current9_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_), + begin6_(other.begin6_), + end6_(other.end6_), + current6_(other.current6_), + begin7_(other.begin7_), + end7_(other.end7_), + current7_(other.current7_), + begin8_(other.begin8_), + end8_(other.end8_), + current8_(other.current8_), + begin9_(other.begin9_), + end9_(other.end9_), + current9_(other.current9_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_, *current6_, *current7_, *current8_, + *current9_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_ || + current6_ == end6_ || + current7_ == end7_ || + current8_ == end8_ || + current9_ == end9_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + const typename ParamGenerator::iterator begin6_; + const typename ParamGenerator::iterator end6_; + typename ParamGenerator::iterator current6_; + const typename ParamGenerator::iterator begin7_; + const typename ParamGenerator::iterator end7_; + typename ParamGenerator::iterator current7_; + const typename ParamGenerator::iterator begin8_; + const typename ParamGenerator::iterator end8_; + typename ParamGenerator::iterator current8_; + const typename ParamGenerator::iterator begin9_; + const typename ParamGenerator::iterator end9_; + typename ParamGenerator::iterator current9_; + ParamType current_value_; + }; // class CartesianProductGenerator9::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator9& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; + const ParamGenerator g6_; + const ParamGenerator g7_; + const ParamGenerator g8_; + const ParamGenerator g9_; +}; // class CartesianProductGenerator9 + + +template +class CartesianProductGenerator10 + : public ParamGeneratorInterface< ::testing::tuple > { + public: + typedef ::testing::tuple ParamType; + + CartesianProductGenerator10(const ParamGenerator& g1, + const ParamGenerator& g2, const ParamGenerator& g3, + const ParamGenerator& g4, const ParamGenerator& g5, + const ParamGenerator& g6, const ParamGenerator& g7, + const ParamGenerator& g8, const ParamGenerator& g9, + const ParamGenerator& g10) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8), + g9_(g9), g10_(g10) {} + virtual ~CartesianProductGenerator10() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_, + g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_, + g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin(), g10_, g10_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(), + g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_, + g8_.end(), g9_, g9_.end(), g10_, g10_.end()); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + const ParamGenerator& g1, + const typename ParamGenerator::iterator& current1, + const ParamGenerator& g2, + const typename ParamGenerator::iterator& current2, + const ParamGenerator& g3, + const typename ParamGenerator::iterator& current3, + const ParamGenerator& g4, + const typename ParamGenerator::iterator& current4, + const ParamGenerator& g5, + const typename ParamGenerator::iterator& current5, + const ParamGenerator& g6, + const typename ParamGenerator::iterator& current6, + const ParamGenerator& g7, + const typename ParamGenerator::iterator& current7, + const ParamGenerator& g8, + const typename ParamGenerator::iterator& current8, + const ParamGenerator& g9, + const typename ParamGenerator::iterator& current9, + const ParamGenerator& g10, + const typename ParamGenerator::iterator& current10) + : base_(base), + begin1_(g1.begin()), end1_(g1.end()), current1_(current1), + begin2_(g2.begin()), end2_(g2.end()), current2_(current2), + begin3_(g3.begin()), end3_(g3.end()), current3_(current3), + begin4_(g4.begin()), end4_(g4.end()), current4_(current4), + begin5_(g5.begin()), end5_(g5.end()), current5_(current5), + begin6_(g6.begin()), end6_(g6.end()), current6_(current6), + begin7_(g7.begin()), end7_(g7.end()), current7_(current7), + begin8_(g8.begin()), end8_(g8.end()), current8_(current8), + begin9_(g9.begin()), end9_(g9.end()), current9_(current9), + begin10_(g10.begin()), end10_(g10.end()), current10_(current10) { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current10_; + if (current10_ == end10_) { + current10_ = begin10_; + ++current9_; + } + if (current9_ == end9_) { + current9_ = begin9_; + ++current8_; + } + if (current8_ == end8_) { + current8_ = begin8_; + ++current7_; + } + if (current7_ == end7_) { + current7_ = begin7_; + ++current6_; + } + if (current6_ == end6_) { + current6_ = begin6_; + ++current5_; + } + if (current5_ == end5_) { + current5_ = begin5_; + ++current4_; + } + if (current4_ == end4_) { + current4_ = begin4_; + ++current3_; + } + if (current3_ == end3_) { + current3_ = begin3_; + ++current2_; + } + if (current2_ == end2_) { + current2_ = begin2_; + ++current1_; + } + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ( + current1_ == typed_other->current1_ && + current2_ == typed_other->current2_ && + current3_ == typed_other->current3_ && + current4_ == typed_other->current4_ && + current5_ == typed_other->current5_ && + current6_ == typed_other->current6_ && + current7_ == typed_other->current7_ && + current8_ == typed_other->current8_ && + current9_ == typed_other->current9_ && + current10_ == typed_other->current10_); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), + begin1_(other.begin1_), + end1_(other.end1_), + current1_(other.current1_), + begin2_(other.begin2_), + end2_(other.end2_), + current2_(other.current2_), + begin3_(other.begin3_), + end3_(other.end3_), + current3_(other.current3_), + begin4_(other.begin4_), + end4_(other.end4_), + current4_(other.current4_), + begin5_(other.begin5_), + end5_(other.end5_), + current5_(other.current5_), + begin6_(other.begin6_), + end6_(other.end6_), + current6_(other.current6_), + begin7_(other.begin7_), + end7_(other.end7_), + current7_(other.current7_), + begin8_(other.begin8_), + end8_(other.end8_), + current8_(other.current8_), + begin9_(other.begin9_), + end9_(other.end9_), + current9_(other.current9_), + begin10_(other.begin10_), + end10_(other.end10_), + current10_(other.current10_) { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType(*current1_, *current2_, *current3_, + *current4_, *current5_, *current6_, *current7_, *current8_, + *current9_, *current10_); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return + current1_ == end1_ || + current2_ == end2_ || + current3_ == end3_ || + current4_ == end4_ || + current5_ == end5_ || + current6_ == end6_ || + current7_ == end7_ || + current8_ == end8_ || + current9_ == end9_ || + current10_ == end10_; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. + const typename ParamGenerator::iterator begin1_; + const typename ParamGenerator::iterator end1_; + typename ParamGenerator::iterator current1_; + const typename ParamGenerator::iterator begin2_; + const typename ParamGenerator::iterator end2_; + typename ParamGenerator::iterator current2_; + const typename ParamGenerator::iterator begin3_; + const typename ParamGenerator::iterator end3_; + typename ParamGenerator::iterator current3_; + const typename ParamGenerator::iterator begin4_; + const typename ParamGenerator::iterator end4_; + typename ParamGenerator::iterator current4_; + const typename ParamGenerator::iterator begin5_; + const typename ParamGenerator::iterator end5_; + typename ParamGenerator::iterator current5_; + const typename ParamGenerator::iterator begin6_; + const typename ParamGenerator::iterator end6_; + typename ParamGenerator::iterator current6_; + const typename ParamGenerator::iterator begin7_; + const typename ParamGenerator::iterator end7_; + typename ParamGenerator::iterator current7_; + const typename ParamGenerator::iterator begin8_; + const typename ParamGenerator::iterator end8_; + typename ParamGenerator::iterator current8_; + const typename ParamGenerator::iterator begin9_; + const typename ParamGenerator::iterator end9_; + typename ParamGenerator::iterator current9_; + const typename ParamGenerator::iterator begin10_; + const typename ParamGenerator::iterator end10_; + typename ParamGenerator::iterator current10_; + ParamType current_value_; + }; // class CartesianProductGenerator10::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator10& other); + + const ParamGenerator g1_; + const ParamGenerator g2_; + const ParamGenerator g3_; + const ParamGenerator g4_; + const ParamGenerator g5_; + const ParamGenerator g6_; + const ParamGenerator g7_; + const ParamGenerator g8_; + const ParamGenerator g9_; + const ParamGenerator g10_; +}; // class CartesianProductGenerator10 + + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Helper classes providing Combine() with polymorphic features. They allow +// casting CartesianProductGeneratorN to ParamGenerator if T is +// convertible to U. +// +template +class CartesianProductHolder2 { + public: +CartesianProductHolder2(const Generator1& g1, const Generator2& g2) + : g1_(g1), g2_(g2) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator2( + static_cast >(g1_), + static_cast >(g2_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder2& other); + + const Generator1 g1_; + const Generator2 g2_; +}; // class CartesianProductHolder2 + +template +class CartesianProductHolder3 { + public: +CartesianProductHolder3(const Generator1& g1, const Generator2& g2, + const Generator3& g3) + : g1_(g1), g2_(g2), g3_(g3) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator3( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder3& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; +}; // class CartesianProductHolder3 + +template +class CartesianProductHolder4 { + public: +CartesianProductHolder4(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator4( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder4& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; +}; // class CartesianProductHolder4 + +template +class CartesianProductHolder5 { + public: +CartesianProductHolder5(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator5( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder5& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; +}; // class CartesianProductHolder5 + +template +class CartesianProductHolder6 { + public: +CartesianProductHolder6(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5, + const Generator6& g6) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator6( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_), + static_cast >(g6_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder6& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; + const Generator6 g6_; +}; // class CartesianProductHolder6 + +template +class CartesianProductHolder7 { + public: +CartesianProductHolder7(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5, + const Generator6& g6, const Generator7& g7) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator7( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_), + static_cast >(g6_), + static_cast >(g7_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder7& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; + const Generator6 g6_; + const Generator7 g7_; +}; // class CartesianProductHolder7 + +template +class CartesianProductHolder8 { + public: +CartesianProductHolder8(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5, + const Generator6& g6, const Generator7& g7, const Generator8& g8) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), + g8_(g8) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator8( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_), + static_cast >(g6_), + static_cast >(g7_), + static_cast >(g8_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder8& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; + const Generator6 g6_; + const Generator7 g7_; + const Generator8 g8_; +}; // class CartesianProductHolder8 + +template +class CartesianProductHolder9 { + public: +CartesianProductHolder9(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5, + const Generator6& g6, const Generator7& g7, const Generator8& g8, + const Generator9& g9) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8), + g9_(g9) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator9( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_), + static_cast >(g6_), + static_cast >(g7_), + static_cast >(g8_), + static_cast >(g9_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder9& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; + const Generator6 g6_; + const Generator7 g7_; + const Generator8 g8_; + const Generator9 g9_; +}; // class CartesianProductHolder9 + +template +class CartesianProductHolder10 { + public: +CartesianProductHolder10(const Generator1& g1, const Generator2& g2, + const Generator3& g3, const Generator4& g4, const Generator5& g5, + const Generator6& g6, const Generator7& g7, const Generator8& g8, + const Generator9& g9, const Generator10& g10) + : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8), + g9_(g9), g10_(g10) {} + template + operator ParamGenerator< ::testing::tuple >() const { + return ParamGenerator< ::testing::tuple >( + new CartesianProductGenerator10( + static_cast >(g1_), + static_cast >(g2_), + static_cast >(g3_), + static_cast >(g4_), + static_cast >(g5_), + static_cast >(g6_), + static_cast >(g7_), + static_cast >(g8_), + static_cast >(g9_), + static_cast >(g10_))); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder10& other); + + const Generator1 g1_; + const Generator2 g2_; + const Generator3 g3_; + const Generator4 g4_; + const Generator5 g5_; + const Generator6 g6_; + const Generator7 g7_; + const Generator8 g8_; + const Generator9 g9_; + const Generator10 g10_; +}; // class CartesianProductHolder10 + +# endif // GTEST_HAS_COMBINE + +} // namespace internal +} // namespace testing + +#endif // GTEST_HAS_PARAM_TEST + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ diff --git a/TestMothur/gtest-param-util-generated.h.pump b/TestMothur/gtest-param-util-generated.h.pump new file mode 100755 index 00000000..e9207988 --- /dev/null +++ b/TestMothur/gtest-param-util-generated.h.pump @@ -0,0 +1,286 @@ +$$ -*- mode: c++; -*- +$var n = 50 $$ Maximum length of Values arguments we want to support. +$var maxtuple = 10 $$ Maximum number of Combine arguments we want to support. +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: vladl@google.com (Vlad Losev) + +// Type and function utilities for implementing parameterized tests. +// This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +// Currently Google Test supports at most $n arguments in Values, +// and at most $maxtuple arguments in Combine. Please contact +// googletestframework@googlegroups.com if you need more. +// Please note that the number of arguments to Combine is limited +// by the maximum arity of the implementation of tuple which is +// currently set at $maxtuple. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ + +// scripts/fuse_gtest.py depends on gtest's own header being #included +// *unconditionally*. Therefore these #includes cannot be moved +// inside #if GTEST_HAS_PARAM_TEST. +#include "gtest-param-util.h" +#include "gtest-port.h" + +#if GTEST_HAS_PARAM_TEST + +namespace testing { + +// Forward declarations of ValuesIn(), which is implemented in +// include/gtest-param-test.h. +template +internal::ParamGenerator< + typename ::testing::internal::IteratorTraits::value_type> +ValuesIn(ForwardIterator begin, ForwardIterator end); + +template +internal::ParamGenerator ValuesIn(const T (&array)[N]); + +template +internal::ParamGenerator ValuesIn( + const Container& container); + +namespace internal { + +// Used in the Values() function to provide polymorphic capabilities. +$range i 1..n +$for i [[ +$range j 1..i + +template <$for j, [[typename T$j]]> +class ValueArray$i { + public: + $if i==1 [[explicit ]]ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {} + + template + operator ParamGenerator() const { + const T array[] = {$for j, [[static_cast(v$(j)_)]]}; + return ValuesIn(array); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const ValueArray$i& other); + +$for j [[ + + const T$j v$(j)_; +]] + +}; + +]] + +# if GTEST_HAS_COMBINE +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Generates values from the Cartesian product of values produced +// by the argument generators. +// +$range i 2..maxtuple +$for i [[ +$range j 1..i +$range k 2..i + +template <$for j, [[typename T$j]]> +class CartesianProductGenerator$i + : public ParamGeneratorInterface< ::testing::tuple<$for j, [[T$j]]> > { + public: + typedef ::testing::tuple<$for j, [[T$j]]> ParamType; + + CartesianProductGenerator$i($for j, [[const ParamGenerator& g$j]]) + : $for j, [[g$(j)_(g$j)]] {} + virtual ~CartesianProductGenerator$i() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, $for j, [[ + + const ParamGenerator& g$j, + const typename ParamGenerator::iterator& current$(j)]]) + : base_(base), +$for j, [[ + + begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j) +]] { + ComputeCurrentValue(); + } + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + virtual void Advance() { + assert(!AtEnd()); + ++current$(i)_; + +$for k [[ + if (current$(i+2-k)_ == end$(i+2-k)_) { + current$(i+2-k)_ = begin$(i+2-k)_; + ++current$(i+2-k-1)_; + } + +]] + ComputeCurrentValue(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const ParamType* Current() const { return ¤t_value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const Iterator* typed_other = + CheckedDowncastToActualType(&other); + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + return (AtEnd() && typed_other->AtEnd()) || + ($for j && [[ + + current$(j)_ == typed_other->current$(j)_ +]]); + } + + private: + Iterator(const Iterator& other) + : base_(other.base_), $for j, [[ + + begin$(j)_(other.begin$(j)_), + end$(j)_(other.end$(j)_), + current$(j)_(other.current$(j)_) +]] { + ComputeCurrentValue(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = ParamType($for j, [[*current$(j)_]]); + } + bool AtEnd() const { + // We must report iterator past the end of the range when either of the + // component iterators has reached the end of its range. + return +$for j || [[ + + current$(j)_ == end$(j)_ +]]; + } + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + // begin[i]_ and end[i]_ define the i-th range that Iterator traverses. + // current[i]_ is the actual traversing iterator. +$for j [[ + + const typename ParamGenerator::iterator begin$(j)_; + const typename ParamGenerator::iterator end$(j)_; + typename ParamGenerator::iterator current$(j)_; +]] + + ParamType current_value_; + }; // class CartesianProductGenerator$i::Iterator + + // No implementation - assignment is unsupported. + void operator=(const CartesianProductGenerator$i& other); + + +$for j [[ + const ParamGenerator g$(j)_; + +]] +}; // class CartesianProductGenerator$i + + +]] + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Helper classes providing Combine() with polymorphic features. They allow +// casting CartesianProductGeneratorN to ParamGenerator if T is +// convertible to U. +// +$range i 2..maxtuple +$for i [[ +$range j 1..i + +template <$for j, [[class Generator$j]]> +class CartesianProductHolder$i { + public: +CartesianProductHolder$i($for j, [[const Generator$j& g$j]]) + : $for j, [[g$(j)_(g$j)]] {} + template <$for j, [[typename T$j]]> + operator ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >() const { + return ParamGenerator< ::testing::tuple<$for j, [[T$j]]> >( + new CartesianProductGenerator$i<$for j, [[T$j]]>( +$for j,[[ + + static_cast >(g$(j)_) +]])); + } + + private: + // No implementation - assignment is unsupported. + void operator=(const CartesianProductHolder$i& other); + + +$for j [[ + const Generator$j g$(j)_; + +]] +}; // class CartesianProductHolder$i + +]] + +# endif // GTEST_HAS_COMBINE + +} // namespace internal +} // namespace testing + +#endif // GTEST_HAS_PARAM_TEST + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ diff --git a/TestMothur/gtest-param-util.h b/TestMothur/gtest-param-util.h new file mode 100755 index 00000000..16601755 --- /dev/null +++ b/TestMothur/gtest-param-util.h @@ -0,0 +1,731 @@ +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: vladl@google.com (Vlad Losev) + +// Type and function utilities for implementing parameterized tests. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ + +#include + +#include +#include +#include +#include + +// scripts/fuse_gtest.py depends on gtest's own header being #included +// *unconditionally*. Therefore these #includes cannot be moved +// inside #if GTEST_HAS_PARAM_TEST. +#include "gtest-internal.h" +#include "gtest-linked_ptr.h" +#include "gtest-port.h" +#include "gtest-printers.h" + +#if GTEST_HAS_PARAM_TEST + +namespace testing { + +// Input to a parameterized test name generator, describing a test parameter. +// Consists of the parameter value and the integer parameter index. +template +struct TestParamInfo { + TestParamInfo(const ParamType& a_param, size_t an_index) : + param(a_param), + index(an_index) {} + ParamType param; + size_t index; +}; + +// A builtin parameterized test name generator which returns the result of +// testing::PrintToString. +struct PrintToStringParamName { + template + std::string operator()(const TestParamInfo& info) const { + return PrintToString(info.param); + } +}; + +namespace internal { + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Outputs a message explaining invalid registration of different +// fixture class for the same test case. This may happen when +// TEST_P macro is used to define two tests with the same name +// but in different namespaces. +GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name, + CodeLocation code_location); + +template class ParamGeneratorInterface; +template class ParamGenerator; + +// Interface for iterating over elements provided by an implementation +// of ParamGeneratorInterface. +template +class ParamIteratorInterface { + public: + virtual ~ParamIteratorInterface() {} + // A pointer to the base generator instance. + // Used only for the purposes of iterator comparison + // to make sure that two iterators belong to the same generator. + virtual const ParamGeneratorInterface* BaseGenerator() const = 0; + // Advances iterator to point to the next element + // provided by the generator. The caller is responsible + // for not calling Advance() on an iterator equal to + // BaseGenerator()->End(). + virtual void Advance() = 0; + // Clones the iterator object. Used for implementing copy semantics + // of ParamIterator. + virtual ParamIteratorInterface* Clone() const = 0; + // Dereferences the current iterator and provides (read-only) access + // to the pointed value. It is the caller's responsibility not to call + // Current() on an iterator equal to BaseGenerator()->End(). + // Used for implementing ParamGenerator::operator*(). + virtual const T* Current() const = 0; + // Determines whether the given iterator and other point to the same + // element in the sequence generated by the generator. + // Used for implementing ParamGenerator::operator==(). + virtual bool Equals(const ParamIteratorInterface& other) const = 0; +}; + +// Class iterating over elements provided by an implementation of +// ParamGeneratorInterface. It wraps ParamIteratorInterface +// and implements the const forward iterator concept. +template +class ParamIterator { + public: + typedef T value_type; + typedef const T& reference; + typedef ptrdiff_t difference_type; + + // ParamIterator assumes ownership of the impl_ pointer. + ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} + ParamIterator& operator=(const ParamIterator& other) { + if (this != &other) + impl_.reset(other.impl_->Clone()); + return *this; + } + + const T& operator*() const { return *impl_->Current(); } + const T* operator->() const { return impl_->Current(); } + // Prefix version of operator++. + ParamIterator& operator++() { + impl_->Advance(); + return *this; + } + // Postfix version of operator++. + ParamIterator operator++(int /*unused*/) { + ParamIteratorInterface* clone = impl_->Clone(); + impl_->Advance(); + return ParamIterator(clone); + } + bool operator==(const ParamIterator& other) const { + return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_); + } + bool operator!=(const ParamIterator& other) const { + return !(*this == other); + } + + private: + friend class ParamGenerator; + explicit ParamIterator(ParamIteratorInterface* impl) : impl_(impl) {} + scoped_ptr > impl_; +}; + +// ParamGeneratorInterface is the binary interface to access generators +// defined in other translation units. +template +class ParamGeneratorInterface { + public: + typedef T ParamType; + + virtual ~ParamGeneratorInterface() {} + + // Generator interface definition + virtual ParamIteratorInterface* Begin() const = 0; + virtual ParamIteratorInterface* End() const = 0; +}; + +// Wraps ParamGeneratorInterface and provides general generator syntax +// compatible with the STL Container concept. +// This class implements copy initialization semantics and the contained +// ParamGeneratorInterface instance is shared among all copies +// of the original object. This is possible because that instance is immutable. +template +class ParamGenerator { + public: + typedef ParamIterator iterator; + + explicit ParamGenerator(ParamGeneratorInterface* impl) : impl_(impl) {} + ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {} + + ParamGenerator& operator=(const ParamGenerator& other) { + impl_ = other.impl_; + return *this; + } + + iterator begin() const { return iterator(impl_->Begin()); } + iterator end() const { return iterator(impl_->End()); } + + private: + linked_ptr > impl_; +}; + +// Generates values from a range of two comparable values. Can be used to +// generate sequences of user-defined types that implement operator+() and +// operator<(). +// This class is used in the Range() function. +template +class RangeGenerator : public ParamGeneratorInterface { + public: + RangeGenerator(T begin, T end, IncrementT step) + : begin_(begin), end_(end), + step_(step), end_index_(CalculateEndIndex(begin, end, step)) {} + virtual ~RangeGenerator() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, begin_, 0, step_); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, end_, end_index_, step_); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, T value, int index, + IncrementT step) + : base_(base), value_(value), index_(index), step_(step) {} + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + virtual void Advance() { + value_ = static_cast(value_ + step_); + index_++; + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + virtual const T* Current() const { return &value_; } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const int other_index = + CheckedDowncastToActualType(&other)->index_; + return index_ == other_index; + } + + private: + Iterator(const Iterator& other) + : ParamIteratorInterface(), + base_(other.base_), value_(other.value_), index_(other.index_), + step_(other.step_) {} + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + T value_; + int index_; + const IncrementT step_; + }; // class RangeGenerator::Iterator + + static int CalculateEndIndex(const T& begin, + const T& end, + const IncrementT& step) { + int end_index = 0; + for (T i = begin; i < end; i = static_cast(i + step)) + end_index++; + return end_index; + } + + // No implementation - assignment is unsupported. + void operator=(const RangeGenerator& other); + + const T begin_; + const T end_; + const IncrementT step_; + // The index for the end() iterator. All the elements in the generated + // sequence are indexed (0-based) to aid iterator comparison. + const int end_index_; +}; // class RangeGenerator + + +// Generates values from a pair of STL-style iterators. Used in the +// ValuesIn() function. The elements are copied from the source range +// since the source can be located on the stack, and the generator +// is likely to persist beyond that stack frame. +template +class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { + public: + template + ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end) + : container_(begin, end) {} + virtual ~ValuesInIteratorRangeGenerator() {} + + virtual ParamIteratorInterface* Begin() const { + return new Iterator(this, container_.begin()); + } + virtual ParamIteratorInterface* End() const { + return new Iterator(this, container_.end()); + } + + private: + typedef typename ::std::vector ContainerType; + + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + typename ContainerType::const_iterator iterator) + : base_(base), iterator_(iterator) {} + virtual ~Iterator() {} + + virtual const ParamGeneratorInterface* BaseGenerator() const { + return base_; + } + virtual void Advance() { + ++iterator_; + value_.reset(); + } + virtual ParamIteratorInterface* Clone() const { + return new Iterator(*this); + } + // We need to use cached value referenced by iterator_ because *iterator_ + // can return a temporary object (and of type other then T), so just + // having "return &*iterator_;" doesn't work. + // value_ is updated here and not in Advance() because Advance() + // can advance iterator_ beyond the end of the range, and we cannot + // detect that fact. The client code, on the other hand, is + // responsible for not calling Current() on an out-of-range iterator. + virtual const T* Current() const { + if (value_.get() == NULL) + value_.reset(new T(*iterator_)); + return value_.get(); + } + virtual bool Equals(const ParamIteratorInterface& other) const { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + return iterator_ == + CheckedDowncastToActualType(&other)->iterator_; + } + + private: + Iterator(const Iterator& other) + // The explicit constructor call suppresses a false warning + // emitted by gcc when supplied with the -Wextra option. + : ParamIteratorInterface(), + base_(other.base_), + iterator_(other.iterator_) {} + + const ParamGeneratorInterface* const base_; + typename ContainerType::const_iterator iterator_; + // A cached value of *iterator_. We keep it here to allow access by + // pointer in the wrapping iterator's operator->(). + // value_ needs to be mutable to be accessed in Current(). + // Use of scoped_ptr helps manage cached value's lifetime, + // which is bound by the lifespan of the iterator itself. + mutable scoped_ptr value_; + }; // class ValuesInIteratorRangeGenerator::Iterator + + // No implementation - assignment is unsupported. + void operator=(const ValuesInIteratorRangeGenerator& other); + + const ContainerType container_; +}; // class ValuesInIteratorRangeGenerator + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Default parameterized test name generator, returns a string containing the +// integer test parameter index. +template +std::string DefaultParamName(const TestParamInfo& info) { + Message name_stream; + name_stream << info.index; + return name_stream.GetString(); +} + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Parameterized test name overload helpers, which help the +// INSTANTIATE_TEST_CASE_P macro choose between the default parameterized +// test name generator and user param name generator. +template +ParamNameGenFunctor GetParamNameGen(ParamNameGenFunctor func) { + return func; +} + +template +struct ParamNameGenFunc { + typedef std::string Type(const TestParamInfo&); +}; + +template +typename ParamNameGenFunc::Type *GetParamNameGen() { + return DefaultParamName; +} + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Stores a parameter value and later creates tests parameterized with that +// value. +template +class ParameterizedTestFactory : public TestFactoryBase { + public: + typedef typename TestClass::ParamType ParamType; + explicit ParameterizedTestFactory(ParamType parameter) : + parameter_(parameter) {} + virtual Test* CreateTest() { + TestClass::SetParam(¶meter_); + return new TestClass(); + } + + private: + const ParamType parameter_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// TestMetaFactoryBase is a base class for meta-factories that create +// test factories for passing into MakeAndRegisterTestInfo function. +template +class TestMetaFactoryBase { + public: + virtual ~TestMetaFactoryBase() {} + + virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0; +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// TestMetaFactory creates test factories for passing into +// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives +// ownership of test factory pointer, same factory object cannot be passed +// into that method twice. But ParameterizedTestCaseInfo is going to call +// it for each Test/Parameter value combination. Thus it needs meta factory +// creator class. +template +class TestMetaFactory + : public TestMetaFactoryBase { + public: + typedef typename TestCase::ParamType ParamType; + + TestMetaFactory() {} + + virtual TestFactoryBase* CreateTestFactory(ParamType parameter) { + return new ParameterizedTestFactory(parameter); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestCaseInfoBase is a generic interface +// to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase +// accumulates test information provided by TEST_P macro invocations +// and generators provided by INSTANTIATE_TEST_CASE_P macro invocations +// and uses that information to register all resulting test instances +// in RegisterTests method. The ParameterizeTestCaseRegistry class holds +// a collection of pointers to the ParameterizedTestCaseInfo objects +// and calls RegisterTests() on each of them when asked. +class ParameterizedTestCaseInfoBase { + public: + virtual ~ParameterizedTestCaseInfoBase() {} + + // Base part of test case name for display purposes. + virtual const string& GetTestCaseName() const = 0; + // Test case id to verify identity. + virtual TypeId GetTestCaseTypeId() const = 0; + // UnitTest class invokes this method to register tests in this + // test case right before running them in RUN_ALL_TESTS macro. + // This method should not be called more then once on any single + // instance of a ParameterizedTestCaseInfoBase derived class. + virtual void RegisterTests() = 0; + + protected: + ParameterizedTestCaseInfoBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestCaseInfo accumulates tests obtained from TEST_P +// macro invocations for a particular test case and generators +// obtained from INSTANTIATE_TEST_CASE_P macro invocations for that +// test case. It registers tests with all values generated by all +// generators when asked. +template +class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { + public: + // ParamType and GeneratorCreationFunc are private types but are required + // for declarations of public methods AddTestPattern() and + // AddTestCaseInstantiation(). + typedef typename TestCase::ParamType ParamType; + // A function that returns an instance of appropriate generator type. + typedef ParamGenerator(GeneratorCreationFunc)(); + typedef typename ParamNameGenFunc::Type ParamNameGeneratorFunc; + + explicit ParameterizedTestCaseInfo( + const char* name, CodeLocation code_location) + : test_case_name_(name), code_location_(code_location) {} + + // Test case base name for display purposes. + virtual const string& GetTestCaseName() const { return test_case_name_; } + // Test case id to verify identity. + virtual TypeId GetTestCaseTypeId() const { return GetTypeId(); } + // TEST_P macro uses AddTestPattern() to record information + // about a single test in a LocalTestInfo structure. + // test_case_name is the base name of the test case (without invocation + // prefix). test_base_name is the name of an individual test without + // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is + // test case base name and DoBar is test base name. + void AddTestPattern(const char* test_case_name, + const char* test_base_name, + TestMetaFactoryBase* meta_factory) { + tests_.push_back(linked_ptr(new TestInfo(test_case_name, + test_base_name, + meta_factory))); + } + // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information + // about a generator. + int AddTestCaseInstantiation(const string& instantiation_name, + GeneratorCreationFunc* func, + ParamNameGeneratorFunc* name_func, + const char* file, + int line) { + instantiations_.push_back( + InstantiationInfo(instantiation_name, func, name_func, file, line)); + return 0; // Return value used only to run this method in namespace scope. + } + // UnitTest class invokes this method to register tests in this test case + // test cases right before running tests in RUN_ALL_TESTS macro. + // This method should not be called more then once on any single + // instance of a ParameterizedTestCaseInfoBase derived class. + // UnitTest has a guard to prevent from calling this method more then once. + virtual void RegisterTests() { + for (typename TestInfoContainer::iterator test_it = tests_.begin(); + test_it != tests_.end(); ++test_it) { + linked_ptr test_info = *test_it; + for (typename InstantiationContainer::iterator gen_it = + instantiations_.begin(); gen_it != instantiations_.end(); + ++gen_it) { + const string& instantiation_name = gen_it->name; + ParamGenerator generator((*gen_it->generator)()); + ParamNameGeneratorFunc* name_func = gen_it->name_func; + const char* file = gen_it->file; + int line = gen_it->line; + + string test_case_name; + if ( !instantiation_name.empty() ) + test_case_name = instantiation_name + "/"; + test_case_name += test_info->test_case_base_name; + + size_t i = 0; + std::set test_param_names; + for (typename ParamGenerator::iterator param_it = + generator.begin(); + param_it != generator.end(); ++param_it, ++i) { + Message test_name_stream; + + std::string param_name = name_func( + TestParamInfo(*param_it, i)); + + GTEST_CHECK_(IsValidParamName(param_name)) + << "Parameterized test name '" << param_name + << "' is invalid, in " << file + << " line " << line << std::endl; + + GTEST_CHECK_(test_param_names.count(param_name) == 0) + << "Duplicate parameterized test name '" << param_name + << "', in " << file << " line " << line << std::endl; + + test_param_names.insert(param_name); + + test_name_stream << test_info->test_base_name << "/" << param_name; + MakeAndRegisterTestInfo( + test_case_name.c_str(), + test_name_stream.GetString().c_str(), + NULL, // No type parameter. + PrintToString(*param_it).c_str(), + code_location_, + GetTestCaseTypeId(), + TestCase::SetUpTestCase, + TestCase::TearDownTestCase, + test_info->test_meta_factory->CreateTestFactory(*param_it)); + } // for param_it + } // for gen_it + } // for test_it + } // RegisterTests + + private: + // LocalTestInfo structure keeps information about a single test registered + // with TEST_P macro. + struct TestInfo { + TestInfo(const char* a_test_case_base_name, + const char* a_test_base_name, + TestMetaFactoryBase* a_test_meta_factory) : + test_case_base_name(a_test_case_base_name), + test_base_name(a_test_base_name), + test_meta_factory(a_test_meta_factory) {} + + const string test_case_base_name; + const string test_base_name; + const scoped_ptr > test_meta_factory; + }; + typedef ::std::vector > TestInfoContainer; + // Records data received from INSTANTIATE_TEST_CASE_P macros: + // + struct InstantiationInfo { + InstantiationInfo(const std::string &name_in, + GeneratorCreationFunc* generator_in, + ParamNameGeneratorFunc* name_func_in, + const char* file_in, + int line_in) + : name(name_in), + generator(generator_in), + name_func(name_func_in), + file(file_in), + line(line_in) {} + + std::string name; + GeneratorCreationFunc* generator; + ParamNameGeneratorFunc* name_func; + const char* file; + int line; + }; + typedef ::std::vector InstantiationContainer; + + static bool IsValidParamName(const std::string& name) { + // Check for empty string + if (name.empty()) + return false; + + // Check for invalid characters + for (std::string::size_type index = 0; index < name.size(); ++index) { + if (!isalnum(name[index]) && name[index] != '_') + return false; + } + + return true; + } + + const string test_case_name_; + CodeLocation code_location_; + TestInfoContainer tests_; + InstantiationContainer instantiations_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo); +}; // class ParameterizedTestCaseInfo + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase +// classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P +// macros use it to locate their corresponding ParameterizedTestCaseInfo +// descriptors. +class ParameterizedTestCaseRegistry { + public: + ParameterizedTestCaseRegistry() {} + ~ParameterizedTestCaseRegistry() { + for (TestCaseInfoContainer::iterator it = test_case_infos_.begin(); + it != test_case_infos_.end(); ++it) { + delete *it; + } + } + + // Looks up or creates and returns a structure containing information about + // tests and instantiations of a particular test case. + template + ParameterizedTestCaseInfo* GetTestCasePatternHolder( + const char* test_case_name, + CodeLocation code_location) { + ParameterizedTestCaseInfo* typed_test_info = NULL; + for (TestCaseInfoContainer::iterator it = test_case_infos_.begin(); + it != test_case_infos_.end(); ++it) { + if ((*it)->GetTestCaseName() == test_case_name) { + if ((*it)->GetTestCaseTypeId() != GetTypeId()) { + // Complain about incorrect usage of Google Test facilities + // and terminate the program since we cannot guaranty correct + // test case setup and tear-down in this case. + ReportInvalidTestCaseType(test_case_name, code_location); + posix::Abort(); + } else { + // At this point we are sure that the object we found is of the same + // type we are looking for, so we downcast it to that type + // without further checks. + typed_test_info = CheckedDowncastToActualType< + ParameterizedTestCaseInfo >(*it); + } + break; + } + } + if (typed_test_info == NULL) { + typed_test_info = new ParameterizedTestCaseInfo( + test_case_name, code_location); + test_case_infos_.push_back(typed_test_info); + } + return typed_test_info; + } + void RegisterTests() { + for (TestCaseInfoContainer::iterator it = test_case_infos_.begin(); + it != test_case_infos_.end(); ++it) { + (*it)->RegisterTests(); + } + } + + private: + typedef ::std::vector TestCaseInfoContainer; + + TestCaseInfoContainer test_case_infos_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry); +}; + +} // namespace internal +} // namespace testing + +#endif // GTEST_HAS_PARAM_TEST + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ diff --git a/TestMothur/gtest-port-arch.h b/TestMothur/gtest-port-arch.h new file mode 100755 index 00000000..74ab9490 --- /dev/null +++ b/TestMothur/gtest-port-arch.h @@ -0,0 +1,93 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The Google C++ Testing Framework (Google Test) +// +// This header file defines the GTEST_OS_* macro. +// It is separate from gtest-port.h so that custom/gtest-port.h can include it. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ + +// Determines the platform on which Google Test is compiled. +#ifdef __CYGWIN__ +# define GTEST_OS_CYGWIN 1 +#elif defined __SYMBIAN32__ +# define GTEST_OS_SYMBIAN 1 +#elif defined _WIN32 +# define GTEST_OS_WINDOWS 1 +# ifdef _WIN32_WCE +# define GTEST_OS_WINDOWS_MOBILE 1 +# elif defined(__MINGW__) || defined(__MINGW32__) +# define GTEST_OS_WINDOWS_MINGW 1 +# elif defined(WINAPI_FAMILY) +# include +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define GTEST_OS_WINDOWS_DESKTOP 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) +# define GTEST_OS_WINDOWS_PHONE 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +# define GTEST_OS_WINDOWS_RT 1 +# else + // WINAPI_FAMILY defined but no known partition matched. + // Default to desktop. +# define GTEST_OS_WINDOWS_DESKTOP 1 +# endif +# else +# define GTEST_OS_WINDOWS_DESKTOP 1 +# endif // _WIN32_WCE +#elif defined __APPLE__ +# define GTEST_OS_MAC 1 +# if TARGET_OS_IPHONE +# define GTEST_OS_IOS 1 +# endif +#elif defined __FreeBSD__ +# define GTEST_OS_FREEBSD 1 +#elif defined __linux__ +# define GTEST_OS_LINUX 1 +# if defined __ANDROID__ +# define GTEST_OS_LINUX_ANDROID 1 +# endif +#elif defined __MVS__ +# define GTEST_OS_ZOS 1 +#elif defined(__sun) && defined(__SVR4) +# define GTEST_OS_SOLARIS 1 +#elif defined(_AIX) +# define GTEST_OS_AIX 1 +#elif defined(__hpux) +# define GTEST_OS_HPUX 1 +#elif defined __native_client__ +# define GTEST_OS_NACL 1 +#elif defined __OpenBSD__ +# define GTEST_OS_OPENBSD 1 +#elif defined __QNX__ +# define GTEST_OS_QNX 1 +#endif // __CYGWIN__ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/TestMothur/gtest-port.cc b/TestMothur/gtest-port.cc new file mode 100755 index 00000000..82b93dbd --- /dev/null +++ b/TestMothur/gtest-port.cc @@ -0,0 +1,1259 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +#include "gtest-port.h" + +#include +#include +#include +#include +#include + +#if GTEST_OS_WINDOWS +# include +# include +# include +# include // Used in ThreadLocal. +#else +# include +#endif // GTEST_OS_WINDOWS + +#if GTEST_OS_MAC +# include +# include +# include +#endif // GTEST_OS_MAC + +#if GTEST_OS_QNX +# include +# include +# include +#endif // GTEST_OS_QNX + +#if GTEST_OS_AIX +# include +# include +#endif // GTEST_OS_AIX + +#include "gtest-spi.h" +#include "gtest-message.h" +#include "gtest-internal.h" +#include "gtest-string.h" + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick exists to +// prevent the accidental inclusion of gtest-internal-inl.h in the +// user's code. +#define GTEST_IMPLEMENTATION_ 1 +#include "gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ + +namespace testing { +namespace internal { + +#if defined(_MSC_VER) || defined(__BORLANDC__) +// MSVC and C++Builder do not provide a definition of STDERR_FILENO. +const int kStdOutFileno = 1; +const int kStdErrFileno = 2; +#else +const int kStdOutFileno = STDOUT_FILENO; +const int kStdErrFileno = STDERR_FILENO; +#endif // _MSC_VER + +#if GTEST_OS_LINUX + +namespace { +template +T ReadProcFileField(const string& filename, int field) { + std::string dummy; + std::ifstream file(filename.c_str()); + while (field-- > 0) { + file >> dummy; + } + T output = 0; + file >> output; + return output; +} +} // namespace + +// Returns the number of active threads, or 0 when there is an error. +size_t GetThreadCount() { + const string filename = + (Message() << "/proc/" << getpid() << "/stat").GetString(); + return ReadProcFileField(filename, 19); +} + +#elif GTEST_OS_MAC + +size_t GetThreadCount() { + const task_t task = mach_task_self(); + mach_msg_type_number_t thread_count; + thread_act_array_t thread_list; + const kern_return_t status = task_threads(task, &thread_list, &thread_count); + if (status == KERN_SUCCESS) { + // task_threads allocates resources in thread_list and we need to free them + // to avoid leaks. + vm_deallocate(task, + reinterpret_cast(thread_list), + sizeof(thread_t) * thread_count); + return static_cast(thread_count); + } else { + return 0; + } +} + +#elif GTEST_OS_QNX + +// Returns the number of threads running in the process, or 0 to indicate that +// we cannot detect it. +size_t GetThreadCount() { + const int fd = open("/proc/self/as", O_RDONLY); + if (fd < 0) { + return 0; + } + procfs_info process_info; + const int status = + devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), NULL); + close(fd); + if (status == EOK) { + return static_cast(process_info.num_threads); + } else { + return 0; + } +} + +#elif GTEST_OS_AIX + +size_t GetThreadCount() { + struct procentry64 entry; + pid_t pid = getpid(); + int status = getprocs64(&entry, sizeof(entry), NULL, 0, &pid, 1); + if (status == 1) { + return entry.pi_thcount; + } else { + return 0; + } +} + +#else + +size_t GetThreadCount() { + // There's no portable way to detect the number of threads, so we just + // return 0 to indicate that we cannot detect it. + return 0; +} + +#endif // GTEST_OS_LINUX + +#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS + +void SleepMilliseconds(int n) { + ::Sleep(n); +} + +AutoHandle::AutoHandle() + : handle_(INVALID_HANDLE_VALUE) {} + +AutoHandle::AutoHandle(Handle handle) + : handle_(handle) {} + +AutoHandle::~AutoHandle() { + Reset(); +} + +AutoHandle::Handle AutoHandle::Get() const { + return handle_; +} + +void AutoHandle::Reset() { + Reset(INVALID_HANDLE_VALUE); +} + +void AutoHandle::Reset(HANDLE handle) { + // Resetting with the same handle we already own is invalid. + if (handle_ != handle) { + if (IsCloseable()) { + ::CloseHandle(handle_); + } + handle_ = handle; + } else { + GTEST_CHECK_(!IsCloseable()) + << "Resetting a valid handle to itself is likely a programmer error " + "and thus not allowed."; + } +} + +bool AutoHandle::IsCloseable() const { + // Different Windows APIs may use either of these values to represent an + // invalid handle. + return handle_ != NULL && handle_ != INVALID_HANDLE_VALUE; +} + +Notification::Notification() + : event_(::CreateEvent(NULL, // Default security attributes. + TRUE, // Do not reset automatically. + FALSE, // Initially unset. + NULL)) { // Anonymous event. + GTEST_CHECK_(event_.Get() != NULL); +} + +void Notification::Notify() { + GTEST_CHECK_(::SetEvent(event_.Get()) != FALSE); +} + +void Notification::WaitForNotification() { + GTEST_CHECK_( + ::WaitForSingleObject(event_.Get(), INFINITE) == WAIT_OBJECT_0); +} + +Mutex::Mutex() + : owner_thread_id_(0), + type_(kDynamic), + critical_section_init_phase_(0), + critical_section_(new CRITICAL_SECTION) { + ::InitializeCriticalSection(critical_section_); +} + +Mutex::~Mutex() { + // Static mutexes are leaked intentionally. It is not thread-safe to try + // to clean them up. + // TODO(yukawa): Switch to Slim Reader/Writer (SRW) Locks, which requires + // nothing to clean it up but is available only on Vista and later. + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa904937.aspx + if (type_ == kDynamic) { + ::DeleteCriticalSection(critical_section_); + delete critical_section_; + critical_section_ = NULL; + } +} + +void Mutex::Lock() { + ThreadSafeLazyInit(); + ::EnterCriticalSection(critical_section_); + owner_thread_id_ = ::GetCurrentThreadId(); +} + +void Mutex::Unlock() { + ThreadSafeLazyInit(); + // We don't protect writing to owner_thread_id_ here, as it's the + // caller's responsibility to ensure that the current thread holds the + // mutex when this is called. + owner_thread_id_ = 0; + ::LeaveCriticalSection(critical_section_); +} + +// Does nothing if the current thread holds the mutex. Otherwise, crashes +// with high probability. +void Mutex::AssertHeld() { + ThreadSafeLazyInit(); + GTEST_CHECK_(owner_thread_id_ == ::GetCurrentThreadId()) + << "The current thread is not holding the mutex @" << this; +} + +// Initializes owner_thread_id_ and critical_section_ in static mutexes. +void Mutex::ThreadSafeLazyInit() { + // Dynamic mutexes are initialized in the constructor. + if (type_ == kStatic) { + switch ( + ::InterlockedCompareExchange(&critical_section_init_phase_, 1L, 0L)) { + case 0: + // If critical_section_init_phase_ was 0 before the exchange, we + // are the first to test it and need to perform the initialization. + owner_thread_id_ = 0; + critical_section_ = new CRITICAL_SECTION; + ::InitializeCriticalSection(critical_section_); + // Updates the critical_section_init_phase_ to 2 to signal + // initialization complete. + GTEST_CHECK_(::InterlockedCompareExchange( + &critical_section_init_phase_, 2L, 1L) == + 1L); + break; + case 1: + // Somebody else is already initializing the mutex; spin until they + // are done. + while (::InterlockedCompareExchange(&critical_section_init_phase_, + 2L, + 2L) != 2L) { + // Possibly yields the rest of the thread's time slice to other + // threads. + ::Sleep(0); + } + break; + + case 2: + break; // The mutex is already initialized and ready for use. + + default: + GTEST_CHECK_(false) + << "Unexpected value of critical_section_init_phase_ " + << "while initializing a static mutex."; + } + } +} + +namespace { + +class ThreadWithParamSupport : public ThreadWithParamBase { + public: + static HANDLE CreateThread(Runnable* runnable, + Notification* thread_can_start) { + ThreadMainParam* param = new ThreadMainParam(runnable, thread_can_start); + DWORD thread_id; + // TODO(yukawa): Consider to use _beginthreadex instead. + HANDLE thread_handle = ::CreateThread( + NULL, // Default security. + 0, // Default stack size. + &ThreadWithParamSupport::ThreadMain, + param, // Parameter to ThreadMainStatic + 0x0, // Default creation flags. + &thread_id); // Need a valid pointer for the call to work under Win98. + GTEST_CHECK_(thread_handle != NULL) << "CreateThread failed with error " + << ::GetLastError() << "."; + if (thread_handle == NULL) { + delete param; + } + return thread_handle; + } + + private: + struct ThreadMainParam { + ThreadMainParam(Runnable* runnable, Notification* thread_can_start) + : runnable_(runnable), + thread_can_start_(thread_can_start) { + } + scoped_ptr runnable_; + // Does not own. + Notification* thread_can_start_; + }; + + static DWORD WINAPI ThreadMain(void* ptr) { + // Transfers ownership. + scoped_ptr param(static_cast(ptr)); + if (param->thread_can_start_ != NULL) + param->thread_can_start_->WaitForNotification(); + param->runnable_->Run(); + return 0; + } + + // Prohibit instantiation. + ThreadWithParamSupport(); + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParamSupport); +}; + +} // namespace + +ThreadWithParamBase::ThreadWithParamBase(Runnable *runnable, + Notification* thread_can_start) + : thread_(ThreadWithParamSupport::CreateThread(runnable, + thread_can_start)) { +} + +ThreadWithParamBase::~ThreadWithParamBase() { + Join(); +} + +void ThreadWithParamBase::Join() { + GTEST_CHECK_(::WaitForSingleObject(thread_.Get(), INFINITE) == WAIT_OBJECT_0) + << "Failed to join the thread with error " << ::GetLastError() << "."; +} + +// Maps a thread to a set of ThreadIdToThreadLocals that have values +// instantiated on that thread and notifies them when the thread exits. A +// ThreadLocal instance is expected to persist until all threads it has +// values on have terminated. +class ThreadLocalRegistryImpl { + public: + // Registers thread_local_instance as having value on the current thread. + // Returns a value that can be used to identify the thread from other threads. + static ThreadLocalValueHolderBase* GetValueOnCurrentThread( + const ThreadLocalBase* thread_local_instance) { + DWORD current_thread = ::GetCurrentThreadId(); + MutexLock lock(&mutex_); + ThreadIdToThreadLocals* const thread_to_thread_locals = + GetThreadLocalsMapLocked(); + ThreadIdToThreadLocals::iterator thread_local_pos = + thread_to_thread_locals->find(current_thread); + if (thread_local_pos == thread_to_thread_locals->end()) { + thread_local_pos = thread_to_thread_locals->insert( + std::make_pair(current_thread, ThreadLocalValues())).first; + StartWatcherThreadFor(current_thread); + } + ThreadLocalValues& thread_local_values = thread_local_pos->second; + ThreadLocalValues::iterator value_pos = + thread_local_values.find(thread_local_instance); + if (value_pos == thread_local_values.end()) { + value_pos = + thread_local_values + .insert(std::make_pair( + thread_local_instance, + linked_ptr( + thread_local_instance->NewValueForCurrentThread()))) + .first; + } + return value_pos->second.get(); + } + + static void OnThreadLocalDestroyed( + const ThreadLocalBase* thread_local_instance) { + std::vector > value_holders; + // Clean up the ThreadLocalValues data structure while holding the lock, but + // defer the destruction of the ThreadLocalValueHolderBases. + { + MutexLock lock(&mutex_); + ThreadIdToThreadLocals* const thread_to_thread_locals = + GetThreadLocalsMapLocked(); + for (ThreadIdToThreadLocals::iterator it = + thread_to_thread_locals->begin(); + it != thread_to_thread_locals->end(); + ++it) { + ThreadLocalValues& thread_local_values = it->second; + ThreadLocalValues::iterator value_pos = + thread_local_values.find(thread_local_instance); + if (value_pos != thread_local_values.end()) { + value_holders.push_back(value_pos->second); + thread_local_values.erase(value_pos); + // This 'if' can only be successful at most once, so theoretically we + // could break out of the loop here, but we don't bother doing so. + } + } + } + // Outside the lock, let the destructor for 'value_holders' deallocate the + // ThreadLocalValueHolderBases. + } + + static void OnThreadExit(DWORD thread_id) { + GTEST_CHECK_(thread_id != 0) << ::GetLastError(); + std::vector > value_holders; + // Clean up the ThreadIdToThreadLocals data structure while holding the + // lock, but defer the destruction of the ThreadLocalValueHolderBases. + { + MutexLock lock(&mutex_); + ThreadIdToThreadLocals* const thread_to_thread_locals = + GetThreadLocalsMapLocked(); + ThreadIdToThreadLocals::iterator thread_local_pos = + thread_to_thread_locals->find(thread_id); + if (thread_local_pos != thread_to_thread_locals->end()) { + ThreadLocalValues& thread_local_values = thread_local_pos->second; + for (ThreadLocalValues::iterator value_pos = + thread_local_values.begin(); + value_pos != thread_local_values.end(); + ++value_pos) { + value_holders.push_back(value_pos->second); + } + thread_to_thread_locals->erase(thread_local_pos); + } + } + // Outside the lock, let the destructor for 'value_holders' deallocate the + // ThreadLocalValueHolderBases. + } + + private: + // In a particular thread, maps a ThreadLocal object to its value. + typedef std::map > ThreadLocalValues; + // Stores all ThreadIdToThreadLocals having values in a thread, indexed by + // thread's ID. + typedef std::map ThreadIdToThreadLocals; + + // Holds the thread id and thread handle that we pass from + // StartWatcherThreadFor to WatcherThreadFunc. + typedef std::pair ThreadIdAndHandle; + + static void StartWatcherThreadFor(DWORD thread_id) { + // The returned handle will be kept in thread_map and closed by + // watcher_thread in WatcherThreadFunc. + HANDLE thread = ::OpenThread(SYNCHRONIZE | THREAD_QUERY_INFORMATION, + FALSE, + thread_id); + GTEST_CHECK_(thread != NULL); + // We need to to pass a valid thread ID pointer into CreateThread for it + // to work correctly under Win98. + DWORD watcher_thread_id; + HANDLE watcher_thread = ::CreateThread( + NULL, // Default security. + 0, // Default stack size + &ThreadLocalRegistryImpl::WatcherThreadFunc, + reinterpret_cast(new ThreadIdAndHandle(thread_id, thread)), + CREATE_SUSPENDED, + &watcher_thread_id); + GTEST_CHECK_(watcher_thread != NULL); + // Give the watcher thread the same priority as ours to avoid being + // blocked by it. + ::SetThreadPriority(watcher_thread, + ::GetThreadPriority(::GetCurrentThread())); + ::ResumeThread(watcher_thread); + ::CloseHandle(watcher_thread); + } + + // Monitors exit from a given thread and notifies those + // ThreadIdToThreadLocals about thread termination. + static DWORD WINAPI WatcherThreadFunc(LPVOID param) { + const ThreadIdAndHandle* tah = + reinterpret_cast(param); + GTEST_CHECK_( + ::WaitForSingleObject(tah->second, INFINITE) == WAIT_OBJECT_0); + OnThreadExit(tah->first); + ::CloseHandle(tah->second); + delete tah; + return 0; + } + + // Returns map of thread local instances. + static ThreadIdToThreadLocals* GetThreadLocalsMapLocked() { + mutex_.AssertHeld(); + static ThreadIdToThreadLocals* map = new ThreadIdToThreadLocals; + return map; + } + + // Protects access to GetThreadLocalsMapLocked() and its return value. + static Mutex mutex_; + // Protects access to GetThreadMapLocked() and its return value. + static Mutex thread_map_mutex_; +}; + +Mutex ThreadLocalRegistryImpl::mutex_(Mutex::kStaticMutex); +Mutex ThreadLocalRegistryImpl::thread_map_mutex_(Mutex::kStaticMutex); + +ThreadLocalValueHolderBase* ThreadLocalRegistry::GetValueOnCurrentThread( + const ThreadLocalBase* thread_local_instance) { + return ThreadLocalRegistryImpl::GetValueOnCurrentThread( + thread_local_instance); +} + +void ThreadLocalRegistry::OnThreadLocalDestroyed( + const ThreadLocalBase* thread_local_instance) { + ThreadLocalRegistryImpl::OnThreadLocalDestroyed(thread_local_instance); +} + +#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS + +#if GTEST_USES_POSIX_RE + +// Implements RE. Currently only needed for death tests. + +RE::~RE() { + if (is_valid_) { + // regfree'ing an invalid regex might crash because the content + // of the regex is undefined. Since the regex's are essentially + // the same, one cannot be valid (or invalid) without the other + // being so too. + regfree(&partial_regex_); + regfree(&full_regex_); + } + free(const_cast(pattern_)); +} + +// Returns true iff regular expression re matches the entire str. +bool RE::FullMatch(const char* str, const RE& re) { + if (!re.is_valid_) return false; + + regmatch_t match; + return regexec(&re.full_regex_, str, 1, &match, 0) == 0; +} + +// Returns true iff regular expression re matches a substring of str +// (including str itself). +bool RE::PartialMatch(const char* str, const RE& re) { + if (!re.is_valid_) return false; + + regmatch_t match; + return regexec(&re.partial_regex_, str, 1, &match, 0) == 0; +} + +// Initializes an RE from its string representation. +void RE::Init(const char* regex) { + pattern_ = posix::StrDup(regex); + + // Reserves enough bytes to hold the regular expression used for a + // full match. + const size_t full_regex_len = strlen(regex) + 10; + char* const full_pattern = new char[full_regex_len]; + + snprintf(full_pattern, full_regex_len, "^(%s)$", regex); + is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0; + // We want to call regcomp(&partial_regex_, ...) even if the + // previous expression returns false. Otherwise partial_regex_ may + // not be properly initialized can may cause trouble when it's + // freed. + // + // Some implementation of POSIX regex (e.g. on at least some + // versions of Cygwin) doesn't accept the empty string as a valid + // regex. We change it to an equivalent form "()" to be safe. + if (is_valid_) { + const char* const partial_regex = (*regex == '\0') ? "()" : regex; + is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0; + } + EXPECT_TRUE(is_valid_) + << "Regular expression \"" << regex + << "\" is not a valid POSIX Extended regular expression."; + + delete[] full_pattern; +} + +#elif GTEST_USES_SIMPLE_RE + +// Returns true iff ch appears anywhere in str (excluding the +// terminating '\0' character). +bool IsInSet(char ch, const char* str) { + return ch != '\0' && strchr(str, ch) != NULL; +} + +// Returns true iff ch belongs to the given classification. Unlike +// similar functions in , these aren't affected by the +// current locale. +bool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; } +bool IsAsciiPunct(char ch) { + return IsInSet(ch, "^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~"); +} +bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); } +bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); } +bool IsAsciiWordChar(char ch) { + return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || + ('0' <= ch && ch <= '9') || ch == '_'; +} + +// Returns true iff "\\c" is a supported escape sequence. +bool IsValidEscape(char c) { + return (IsAsciiPunct(c) || IsInSet(c, "dDfnrsStvwW")); +} + +// Returns true iff the given atom (specified by escaped and pattern) +// matches ch. The result is undefined if the atom is invalid. +bool AtomMatchesChar(bool escaped, char pattern_char, char ch) { + if (escaped) { // "\\p" where p is pattern_char. + switch (pattern_char) { + case 'd': return IsAsciiDigit(ch); + case 'D': return !IsAsciiDigit(ch); + case 'f': return ch == '\f'; + case 'n': return ch == '\n'; + case 'r': return ch == '\r'; + case 's': return IsAsciiWhiteSpace(ch); + case 'S': return !IsAsciiWhiteSpace(ch); + case 't': return ch == '\t'; + case 'v': return ch == '\v'; + case 'w': return IsAsciiWordChar(ch); + case 'W': return !IsAsciiWordChar(ch); + } + return IsAsciiPunct(pattern_char) && pattern_char == ch; + } + + return (pattern_char == '.' && ch != '\n') || pattern_char == ch; +} + +// Helper function used by ValidateRegex() to format error messages. +std::string FormatRegexSyntaxError(const char* regex, int index) { + return (Message() << "Syntax error at index " << index + << " in simple regular expression \"" << regex << "\": ").GetString(); +} + +// Generates non-fatal failures and returns false if regex is invalid; +// otherwise returns true. +bool ValidateRegex(const char* regex) { + if (regex == NULL) { + // TODO(wan@google.com): fix the source file location in the + // assertion failures to match where the regex is used in user + // code. + ADD_FAILURE() << "NULL is not a valid simple regular expression."; + return false; + } + + bool is_valid = true; + + // True iff ?, *, or + can follow the previous atom. + bool prev_repeatable = false; + for (int i = 0; regex[i]; i++) { + if (regex[i] == '\\') { // An escape sequence + i++; + if (regex[i] == '\0') { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) + << "'\\' cannot appear at the end."; + return false; + } + + if (!IsValidEscape(regex[i])) { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1) + << "invalid escape sequence \"\\" << regex[i] << "\"."; + is_valid = false; + } + prev_repeatable = true; + } else { // Not an escape sequence. + const char ch = regex[i]; + + if (ch == '^' && i > 0) { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) + << "'^' can only appear at the beginning."; + is_valid = false; + } else if (ch == '$' && regex[i + 1] != '\0') { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) + << "'$' can only appear at the end."; + is_valid = false; + } else if (IsInSet(ch, "()[]{}|")) { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) + << "'" << ch << "' is unsupported."; + is_valid = false; + } else if (IsRepeat(ch) && !prev_repeatable) { + ADD_FAILURE() << FormatRegexSyntaxError(regex, i) + << "'" << ch << "' can only follow a repeatable token."; + is_valid = false; + } + + prev_repeatable = !IsInSet(ch, "^$?*+"); + } + } + + return is_valid; +} + +// Matches a repeated regex atom followed by a valid simple regular +// expression. The regex atom is defined as c if escaped is false, +// or \c otherwise. repeat is the repetition meta character (?, *, +// or +). The behavior is undefined if str contains too many +// characters to be indexable by size_t, in which case the test will +// probably time out anyway. We are fine with this limitation as +// std::string has it too. +bool MatchRepetitionAndRegexAtHead( + bool escaped, char c, char repeat, const char* regex, + const char* str) { + const size_t min_count = (repeat == '+') ? 1 : 0; + const size_t max_count = (repeat == '?') ? 1 : + static_cast(-1) - 1; + // We cannot call numeric_limits::max() as it conflicts with the + // max() macro on Windows. + + for (size_t i = 0; i <= max_count; ++i) { + // We know that the atom matches each of the first i characters in str. + if (i >= min_count && MatchRegexAtHead(regex, str + i)) { + // We have enough matches at the head, and the tail matches too. + // Since we only care about *whether* the pattern matches str + // (as opposed to *how* it matches), there is no need to find a + // greedy match. + return true; + } + if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i])) + return false; + } + return false; +} + +// Returns true iff regex matches a prefix of str. regex must be a +// valid simple regular expression and not start with "^", or the +// result is undefined. +bool MatchRegexAtHead(const char* regex, const char* str) { + if (*regex == '\0') // An empty regex matches a prefix of anything. + return true; + + // "$" only matches the end of a string. Note that regex being + // valid guarantees that there's nothing after "$" in it. + if (*regex == '$') + return *str == '\0'; + + // Is the first thing in regex an escape sequence? + const bool escaped = *regex == '\\'; + if (escaped) + ++regex; + if (IsRepeat(regex[1])) { + // MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so + // here's an indirect recursion. It terminates as the regex gets + // shorter in each recursion. + return MatchRepetitionAndRegexAtHead( + escaped, regex[0], regex[1], regex + 2, str); + } else { + // regex isn't empty, isn't "$", and doesn't start with a + // repetition. We match the first atom of regex with the first + // character of str and recurse. + return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) && + MatchRegexAtHead(regex + 1, str + 1); + } +} + +// Returns true iff regex matches any substring of str. regex must be +// a valid simple regular expression, or the result is undefined. +// +// The algorithm is recursive, but the recursion depth doesn't exceed +// the regex length, so we won't need to worry about running out of +// stack space normally. In rare cases the time complexity can be +// exponential with respect to the regex length + the string length, +// but usually it's must faster (often close to linear). +bool MatchRegexAnywhere(const char* regex, const char* str) { + if (regex == NULL || str == NULL) + return false; + + if (*regex == '^') + return MatchRegexAtHead(regex + 1, str); + + // A successful match can be anywhere in str. + do { + if (MatchRegexAtHead(regex, str)) + return true; + } while (*str++ != '\0'); + return false; +} + +// Implements the RE class. + +RE::~RE() { + free(const_cast(pattern_)); + free(const_cast(full_pattern_)); +} + +// Returns true iff regular expression re matches the entire str. +bool RE::FullMatch(const char* str, const RE& re) { + return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str); +} + +// Returns true iff regular expression re matches a substring of str +// (including str itself). +bool RE::PartialMatch(const char* str, const RE& re) { + return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str); +} + +// Initializes an RE from its string representation. +void RE::Init(const char* regex) { + pattern_ = full_pattern_ = NULL; + if (regex != NULL) { + pattern_ = posix::StrDup(regex); + } + + is_valid_ = ValidateRegex(regex); + if (!is_valid_) { + // No need to calculate the full pattern when the regex is invalid. + return; + } + + const size_t len = strlen(regex); + // Reserves enough bytes to hold the regular expression used for a + // full match: we need space to prepend a '^', append a '$', and + // terminate the string with '\0'. + char* buffer = static_cast(malloc(len + 3)); + full_pattern_ = buffer; + + if (*regex != '^') + *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'. + + // We don't use snprintf or strncpy, as they trigger a warning when + // compiled with VC++ 8.0. + memcpy(buffer, regex, len); + buffer += len; + + if (len == 0 || regex[len - 1] != '$') + *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'. + + *buffer = '\0'; +} + +#endif // GTEST_USES_POSIX_RE + +const char kUnknownFile[] = "unknown file"; + +// Formats a source file path and a line number as they would appear +// in an error message from the compiler used to compile this code. +GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) { + const std::string file_name(file == NULL ? kUnknownFile : file); + + if (line < 0) { + return file_name + ":"; + } +#ifdef _MSC_VER + return file_name + "(" + StreamableToString(line) + "):"; +#else + return file_name + ":" + StreamableToString(line) + ":"; +#endif // _MSC_VER +} + +// Formats a file location for compiler-independent XML output. +// Although this function is not platform dependent, we put it next to +// FormatFileLocation in order to contrast the two functions. +// Note that FormatCompilerIndependentFileLocation() does NOT append colon +// to the file location it produces, unlike FormatFileLocation(). +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation( + const char* file, int line) { + const std::string file_name(file == NULL ? kUnknownFile : file); + + if (line < 0) + return file_name; + else + return file_name + ":" + StreamableToString(line); +} + +GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line) + : severity_(severity) { + const char* const marker = + severity == GTEST_INFO ? "[ INFO ]" : + severity == GTEST_WARNING ? "[WARNING]" : + severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]"; + GetStream() << ::std::endl << marker << " " + << FormatFileLocation(file, line).c_str() << ": "; +} + +// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. +GTestLog::~GTestLog() { + GetStream() << ::std::endl; + if (severity_ == GTEST_FATAL) { + fflush(stderr); + posix::Abort(); + } +} +// Disable Microsoft deprecation warnings for POSIX functions called from +// this class (creat, dup, dup2, and close) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) + +#if GTEST_HAS_STREAM_REDIRECTION + +// Object that captures an output stream (stdout/stderr). +class CapturedStream { + public: + // The ctor redirects the stream to a temporary file. + explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { +# if GTEST_OS_WINDOWS + char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT + char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT + + ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path); + const UINT success = ::GetTempFileNameA(temp_dir_path, + "gtest_redir", + 0, // Generate unique file name. + temp_file_path); + GTEST_CHECK_(success != 0) + << "Unable to create a temporary file in " << temp_dir_path; + const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); + GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file " + << temp_file_path; + filename_ = temp_file_path; +# else + // There's no guarantee that a test has write access to the current + // directory, so we create the temporary file in the /tmp directory + // instead. We use /tmp on most systems, and /sdcard on Android. + // That's because Android doesn't have /tmp. +# if GTEST_OS_LINUX_ANDROID + // Note: Android applications are expected to call the framework's + // Context.getExternalStorageDirectory() method through JNI to get + // the location of the world-writable SD Card directory. However, + // this requires a Context handle, which cannot be retrieved + // globally from native code. Doing so also precludes running the + // code as part of a regular standalone executable, which doesn't + // run in a Dalvik process (e.g. when running it through 'adb shell'). + // + // The location /sdcard is directly accessible from native code + // and is the only location (unofficially) supported by the Android + // team. It's generally a symlink to the real SD Card mount point + // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or + // other OEM-customized locations. Never rely on these, and always + // use /sdcard. + char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX"; +# else + char name_template[] = "/tmp/captured_stream.XXXXXX"; +# endif // GTEST_OS_LINUX_ANDROID + const int captured_fd = mkstemp(name_template); + filename_ = name_template; +# endif // GTEST_OS_WINDOWS + fflush(NULL); + dup2(captured_fd, fd_); + close(captured_fd); + } + + ~CapturedStream() { + remove(filename_.c_str()); + } + + std::string GetCapturedString() { + if (uncaptured_fd_ != -1) { + // Restores the original stream. + fflush(NULL); + dup2(uncaptured_fd_, fd_); + close(uncaptured_fd_); + uncaptured_fd_ = -1; + } + + FILE* const file = posix::FOpen(filename_.c_str(), "r"); + const std::string content = ReadEntireFile(file); + posix::FClose(file); + return content; + } + + private: + const int fd_; // A stream to capture. + int uncaptured_fd_; + // Name of the temporary file holding the stderr output. + ::std::string filename_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream); +}; + +GTEST_DISABLE_MSC_WARNINGS_POP_() + +static CapturedStream* g_captured_stderr = NULL; +static CapturedStream* g_captured_stdout = NULL; + +// Starts capturing an output stream (stdout/stderr). +void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) { + if (*stream != NULL) { + GTEST_LOG_(FATAL) << "Only one " << stream_name + << " capturer can exist at a time."; + } + *stream = new CapturedStream(fd); +} + +// Stops capturing the output stream and returns the captured string. +std::string GetCapturedStream(CapturedStream** captured_stream) { + const std::string content = (*captured_stream)->GetCapturedString(); + + delete *captured_stream; + *captured_stream = NULL; + + return content; +} + +// Starts capturing stdout. +void CaptureStdout() { + CaptureStream(kStdOutFileno, "stdout", &g_captured_stdout); +} + +// Starts capturing stderr. +void CaptureStderr() { + CaptureStream(kStdErrFileno, "stderr", &g_captured_stderr); +} + +// Stops capturing stdout and returns the captured string. +std::string GetCapturedStdout() { + return GetCapturedStream(&g_captured_stdout); +} + +// Stops capturing stderr and returns the captured string. +std::string GetCapturedStderr() { + return GetCapturedStream(&g_captured_stderr); +} + +#endif // GTEST_HAS_STREAM_REDIRECTION + +std::string TempDir() { +#if GTEST_OS_WINDOWS_MOBILE + return "\\temp\\"; +#elif GTEST_OS_WINDOWS + const char* temp_dir = posix::GetEnv("TEMP"); + if (temp_dir == NULL || temp_dir[0] == '\0') + return "\\temp\\"; + else if (temp_dir[strlen(temp_dir) - 1] == '\\') + return temp_dir; + else + return std::string(temp_dir) + "\\"; +#elif GTEST_OS_LINUX_ANDROID + return "/sdcard/"; +#else + return "/tmp/"; +#endif // GTEST_OS_WINDOWS_MOBILE +} + +size_t GetFileSize(FILE* file) { + fseek(file, 0, SEEK_END); + return static_cast(ftell(file)); +} + +std::string ReadEntireFile(FILE* file) { + const size_t file_size = GetFileSize(file); + char* const buffer = new char[file_size]; + + size_t bytes_last_read = 0; // # of bytes read in the last fread() + size_t bytes_read = 0; // # of bytes read so far + + fseek(file, 0, SEEK_SET); + + // Keeps reading the file until we cannot read further or the + // pre-determined file size is reached. + do { + bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file); + bytes_read += bytes_last_read; + } while (bytes_last_read > 0 && bytes_read < file_size); + + const std::string content(buffer, bytes_read); + delete[] buffer; + + return content; +} + +#if GTEST_HAS_DEATH_TEST + +static const ::std::vector* g_injected_test_argvs = + NULL; // Owned. + +void SetInjectableArgvs(const ::std::vector* argvs) { + if (g_injected_test_argvs != argvs) + delete g_injected_test_argvs; + g_injected_test_argvs = argvs; +} + +const ::std::vector& GetInjectableArgvs() { + if (g_injected_test_argvs != NULL) { + return *g_injected_test_argvs; + } + return GetArgvs(); +} +#endif // GTEST_HAS_DEATH_TEST + +#if GTEST_OS_WINDOWS_MOBILE +namespace posix { +void Abort() { + DebugBreak(); + TerminateProcess(GetCurrentProcess(), 1); +} +} // namespace posix +#endif // GTEST_OS_WINDOWS_MOBILE + +// Returns the name of the environment variable corresponding to the +// given flag. For example, FlagToEnvVar("foo") will return +// "GTEST_FOO" in the open-source version. +static std::string FlagToEnvVar(const char* flag) { + const std::string full_flag = + (Message() << GTEST_FLAG_PREFIX_ << flag).GetString(); + + Message env_var; + for (size_t i = 0; i != full_flag.length(); i++) { + env_var << ToUpper(full_flag.c_str()[i]); + } + + return env_var.GetString(); +} + +// Parses 'str' for a 32-bit signed integer. If successful, writes +// the result to *value and returns true; otherwise leaves *value +// unchanged and returns false. +bool ParseInt32(const Message& src_text, const char* str, Int32* value) { + // Parses the environment variable as a decimal integer. + char* end = NULL; + const long long_value = strtol(str, &end, 10); // NOLINT + + // Has strtol() consumed all characters in the string? + if (*end != '\0') { + // No - an invalid character was encountered. + Message msg; + msg << "WARNING: " << src_text + << " is expected to be a 32-bit integer, but actually" + << " has value \"" << str << "\".\n"; + printf("%s", msg.GetString().c_str()); + fflush(stdout); + return false; + } + + // Is the parsed value in the range of an Int32? + const Int32 result = static_cast(long_value); + if (long_value == LONG_MAX || long_value == LONG_MIN || + // The parsed value overflows as a long. (strtol() returns + // LONG_MAX or LONG_MIN when the input overflows.) + result != long_value + // The parsed value overflows as an Int32. + ) { + Message msg; + msg << "WARNING: " << src_text + << " is expected to be a 32-bit integer, but actually" + << " has value " << str << ", which overflows.\n"; + printf("%s", msg.GetString().c_str()); + fflush(stdout); + return false; + } + + *value = result; + return true; +} + +// Reads and returns the Boolean environment variable corresponding to +// the given flag; if it's not set, returns default_value. +// +// The value is considered true iff it's not "0". +bool BoolFromGTestEnv(const char* flag, bool default_value) { +#if defined(GTEST_GET_BOOL_FROM_ENV_) + return GTEST_GET_BOOL_FROM_ENV_(flag, default_value); +#endif // defined(GTEST_GET_BOOL_FROM_ENV_) + const std::string env_var = FlagToEnvVar(flag); + const char* const string_value = posix::GetEnv(env_var.c_str()); + return string_value == NULL ? + default_value : strcmp(string_value, "0") != 0; +} + +// Reads and returns a 32-bit integer stored in the environment +// variable corresponding to the given flag; if it isn't set or +// doesn't represent a valid 32-bit integer, returns default_value. +Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) { +#if defined(GTEST_GET_INT32_FROM_ENV_) + return GTEST_GET_INT32_FROM_ENV_(flag, default_value); +#endif // defined(GTEST_GET_INT32_FROM_ENV_) + const std::string env_var = FlagToEnvVar(flag); + const char* const string_value = posix::GetEnv(env_var.c_str()); + if (string_value == NULL) { + // The environment variable is not set. + return default_value; + } + + Int32 result = default_value; + if (!ParseInt32(Message() << "Environment variable " << env_var, + string_value, &result)) { + printf("The default value %s is used.\n", + (Message() << default_value).GetString().c_str()); + fflush(stdout); + return default_value; + } + + return result; +} + +// Reads and returns the string environment variable corresponding to +// the given flag; if it's not set, returns default_value. +std::string StringFromGTestEnv(const char* flag, const char* default_value) { +#if defined(GTEST_GET_STRING_FROM_ENV_) + return GTEST_GET_STRING_FROM_ENV_(flag, default_value); +#endif // defined(GTEST_GET_STRING_FROM_ENV_) + const std::string env_var = FlagToEnvVar(flag); + const char* value = posix::GetEnv(env_var.c_str()); + if (value != NULL) { + return value; + } + + // As a special case for the 'output' flag, if GTEST_OUTPUT is not + // set, we look for XML_OUTPUT_FILE, which is set by the Bazel build + // system. The value of XML_OUTPUT_FILE is a filename without the + // "xml:" prefix of GTEST_OUTPUT. + // + // The net priority order after flag processing is thus: + // --gtest_output command line flag + // GTEST_OUTPUT environment variable + // XML_OUTPUT_FILE environment variable + // 'default_value' + if (strcmp(flag, "output") == 0) { + value = posix::GetEnv("XML_OUTPUT_FILE"); + if (value != NULL) { + return std::string("xml:") + value; + } + } + return default_value; +} + +} // namespace internal +} // namespace testing diff --git a/TestMothur/gtest-port.h b/TestMothur/gtest-port.h new file mode 100755 index 00000000..07b2a1a3 --- /dev/null +++ b/TestMothur/gtest-port.h @@ -0,0 +1,2554 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: wan@google.com (Zhanyong Wan) +// +// Low-level types and utilities for porting Google Test to various +// platforms. All macros ending with _ and symbols defined in an +// internal namespace are subject to change without notice. Code +// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't +// end with _ are part of Google Test's public API and can be used by +// code outside Google Test. +// +// This file is fundamental to Google Test. All other Google Test source +// files are expected to #include this. Therefore, it cannot #include +// any other Google Test header. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ + +// Environment-describing macros +// ----------------------------- +// +// Google Test can be used in many different environments. Macros in +// this section tell Google Test what kind of environment it is being +// used in, such that Google Test can provide environment-specific +// features and implementations. +// +// Google Test tries to automatically detect the properties of its +// environment, so users usually don't need to worry about these +// macros. However, the automatic detection is not perfect. +// Sometimes it's necessary for a user to define some of the following +// macros in the build script to override Google Test's decisions. +// +// If the user doesn't define a macro in the list, Google Test will +// provide a default definition. After this header is #included, all +// macros in this list will be defined to either 1 or 0. +// +// Notes to maintainers: +// - Each macro here is a user-tweakable knob; do not grow the list +// lightly. +// - Use #if to key off these macros. Don't use #ifdef or "#if +// defined(...)", which will not work as these macros are ALWAYS +// defined. +// +// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2) +// is/isn't available. +// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions +// are enabled. +// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string +// is/isn't available (some systems define +// ::string, which is different to std::string). +// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string +// is/isn't available (some systems define +// ::wstring, which is different to std::wstring). +// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular +// expressions are/aren't available. +// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that +// is/isn't available. +// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't +// enabled. +// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that +// std::wstring does/doesn't work (Google Test can +// be used where std::wstring is unavailable). +// GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple +// is/isn't available. +// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the +// compiler supports Microsoft's "Structured +// Exception Handling". +// GTEST_HAS_STREAM_REDIRECTION +// - Define it to 1/0 to indicate whether the +// platform supports I/O stream redirection using +// dup() and dup2(). +// GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google +// Test's own tr1 tuple implementation should be +// used. Unused when the user sets +// GTEST_HAS_TR1_TUPLE to 0. +// GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test +// is building in C++11/C++98 mode. +// GTEST_LINKED_AS_SHARED_LIBRARY +// - Define to 1 when compiling tests that use +// Google Test as a shared library (known as +// DLL on Windows). +// GTEST_CREATE_SHARED_LIBRARY +// - Define to 1 when compiling Google Test itself +// as a shared library. + +// Platform-indicating macros +// -------------------------- +// +// Macros indicating the platform on which Google Test is being used +// (a macro is defined to 1 if compiled on the given platform; +// otherwise UNDEFINED -- it's never defined to 0.). Google Test +// defines these macros automatically. Code outside Google Test MUST +// NOT define them. +// +// GTEST_OS_AIX - IBM AIX +// GTEST_OS_CYGWIN - Cygwin +// GTEST_OS_FREEBSD - FreeBSD +// GTEST_OS_HPUX - HP-UX +// GTEST_OS_LINUX - Linux +// GTEST_OS_LINUX_ANDROID - Google Android +// GTEST_OS_MAC - Mac OS X +// GTEST_OS_IOS - iOS +// GTEST_OS_NACL - Google Native Client (NaCl) +// GTEST_OS_OPENBSD - OpenBSD +// GTEST_OS_QNX - QNX +// GTEST_OS_SOLARIS - Sun Solaris +// GTEST_OS_SYMBIAN - Symbian +// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) +// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop +// GTEST_OS_WINDOWS_MINGW - MinGW +// GTEST_OS_WINDOWS_MOBILE - Windows Mobile +// GTEST_OS_WINDOWS_PHONE - Windows Phone +// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT +// GTEST_OS_ZOS - z/OS +// +// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the +// most stable support. Since core members of the Google Test project +// don't have access to other platforms, support for them may be less +// stable. If you notice any problems on your platform, please notify +// googletestframework@googlegroups.com (patches for fixing them are +// even more welcome!). +// +// It is possible that none of the GTEST_OS_* macros are defined. + +// Feature-indicating macros +// ------------------------- +// +// Macros indicating which Google Test features are available (a macro +// is defined to 1 if the corresponding feature is supported; +// otherwise UNDEFINED -- it's never defined to 0.). Google Test +// defines these macros automatically. Code outside Google Test MUST +// NOT define them. +// +// These macros are public so that portable tests can be written. +// Such tests typically surround code using a feature with an #if +// which controls that code. For example: +// +// #if GTEST_HAS_DEATH_TEST +// EXPECT_DEATH(DoSomethingDeadly()); +// #endif +// +// GTEST_HAS_COMBINE - the Combine() function (for value-parameterized +// tests) +// GTEST_HAS_DEATH_TEST - death tests +// GTEST_HAS_PARAM_TEST - value-parameterized tests +// GTEST_HAS_TYPED_TEST - typed tests +// GTEST_HAS_TYPED_TEST_P - type-parameterized tests +// GTEST_IS_THREADSAFE - Google Test is thread-safe. +// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with +// GTEST_HAS_POSIX_RE (see above) which users can +// define themselves. +// GTEST_USES_SIMPLE_RE - our own simple regex is used; +// the above two are mutually exclusive. +// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ(). + +// Misc public macros +// ------------------ +// +// GTEST_FLAG(flag_name) - references the variable corresponding to +// the given Google Test flag. + +// Internal utilities +// ------------------ +// +// The following macros and utilities are for Google Test's INTERNAL +// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY. +// +// Macros for basic C++ coding: +// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. +// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a +// variable don't have to be used. +// GTEST_DISALLOW_ASSIGN_ - disables operator=. +// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. +// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. +// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is +// suppressed (constant conditional). +// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 +// is suppressed. +// +// C++11 feature wrappers: +// +// testing::internal::move - portability wrapper for std::move. +// +// Synchronization: +// Mutex, MutexLock, ThreadLocal, GetThreadCount() +// - synchronization primitives. +// +// Template meta programming: +// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only. +// IteratorTraits - partial implementation of std::iterator_traits, which +// is not available in libCstd when compiled with Sun C++. +// +// Smart pointers: +// scoped_ptr - as in TR2. +// +// Regular expressions: +// RE - a simple regular expression class using the POSIX +// Extended Regular Expression syntax on UNIX-like +// platforms, or a reduced regular exception syntax on +// other platforms, including Windows. +// +// Logging: +// GTEST_LOG_() - logs messages at the specified severity level. +// LogToStderr() - directs all log messages to stderr. +// FlushInfoLog() - flushes informational log messages. +// +// Stdout and stderr capturing: +// CaptureStdout() - starts capturing stdout. +// GetCapturedStdout() - stops capturing stdout and returns the captured +// string. +// CaptureStderr() - starts capturing stderr. +// GetCapturedStderr() - stops capturing stderr and returns the captured +// string. +// +// Integer types: +// TypeWithSize - maps an integer to a int type. +// Int32, UInt32, Int64, UInt64, TimeInMillis +// - integers of known sizes. +// BiggestInt - the biggest signed integer type. +// +// Command-line utilities: +// GTEST_DECLARE_*() - declares a flag. +// GTEST_DEFINE_*() - defines a flag. +// GetInjectableArgvs() - returns the command line as a vector of strings. +// +// Environment variable utilities: +// GetEnv() - gets the value of an environment variable. +// BoolFromGTestEnv() - parses a bool environment variable. +// Int32FromGTestEnv() - parses an Int32 environment variable. +// StringFromGTestEnv() - parses a string environment variable. + +#include // for isspace, etc +#include // for ptrdiff_t +#include +#include +#include +#ifndef _WIN32_WCE +# include +# include +#endif // !_WIN32_WCE + +#if defined __APPLE__ +# include +# include +#endif + +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include +#include // NOLINT + +#include "gtest-port-arch.h" +#include "custom/gtest-port.h" + +#if !defined(GTEST_DEV_EMAIL_) +# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" +# define GTEST_FLAG_PREFIX_ "gtest_" +# define GTEST_FLAG_PREFIX_DASH_ "gtest-" +# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" +# define GTEST_NAME_ "Google Test" +# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" +#endif // !defined(GTEST_DEV_EMAIL_) + +#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_) +# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" +#endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_) + +// Determines the version of gcc that is used to compile this. +#ifdef __GNUC__ +// 40302 means version 4.3.2. +# define GTEST_GCC_VER_ \ + (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) +#endif // __GNUC__ + +// Macros for disabling Microsoft Visual C++ warnings. +// +// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385) +// /* code that triggers warnings C4800 and C4385 */ +// GTEST_DISABLE_MSC_WARNINGS_POP_() +#if _MSC_VER >= 1500 +# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ + __pragma(warning(push)) \ + __pragma(warning(disable: warnings)) +# define GTEST_DISABLE_MSC_WARNINGS_POP_() \ + __pragma(warning(pop)) +#else +// Older versions of MSVC don't have __pragma. +# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) +# define GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif + +#ifndef GTEST_LANG_CXX11 +// gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when +// -std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a +// value for __cplusplus, and recent versions of clang, gcc, and +// probably other compilers set that too in C++11 mode. +# if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L +// Compiling in at least C++11 mode. +# define GTEST_LANG_CXX11 1 +# else +# define GTEST_LANG_CXX11 0 +# endif +#endif + +// Distinct from C++11 language support, some environments don't provide +// proper C++11 library support. Notably, it's possible to build in +// C++11 mode when targeting Mac OS X 10.6, which has an old libstdc++ +// with no C++11 support. +// +// libstdc++ has sufficient C++11 support as of GCC 4.6.0, __GLIBCXX__ +// 20110325, but maintenance releases in the 4.4 and 4.5 series followed +// this date, so check for those versions by their date stamps. +// https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html#abi.versioning +#if GTEST_LANG_CXX11 && \ + (!defined(__GLIBCXX__) || ( \ + __GLIBCXX__ >= 20110325ul && /* GCC >= 4.6.0 */ \ + /* Blacklist of patch releases of older branches: */ \ + __GLIBCXX__ != 20110416ul && /* GCC 4.4.6 */ \ + __GLIBCXX__ != 20120313ul && /* GCC 4.4.7 */ \ + __GLIBCXX__ != 20110428ul && /* GCC 4.5.3 */ \ + __GLIBCXX__ != 20120702ul)) /* GCC 4.5.4 */ +# define GTEST_STDLIB_CXX11 1 +#endif + +// Only use C++11 library features if the library provides them. +#if GTEST_STDLIB_CXX11 +# define GTEST_HAS_STD_BEGIN_AND_END_ 1 +# define GTEST_HAS_STD_FORWARD_LIST_ 1 +# define GTEST_HAS_STD_FUNCTION_ 1 +# define GTEST_HAS_STD_INITIALIZER_LIST_ 1 +# define GTEST_HAS_STD_MOVE_ 1 +# define GTEST_HAS_STD_SHARED_PTR_ 1 +# define GTEST_HAS_STD_TYPE_TRAITS_ 1 +# define GTEST_HAS_STD_UNIQUE_PTR_ 1 +#endif + +// C++11 specifies that provides std::tuple. +// Some platforms still might not have it, however. +#if GTEST_LANG_CXX11 +# define GTEST_HAS_STD_TUPLE_ 1 +# if defined(__clang__) +// Inspired by http://clang.llvm.org/docs/LanguageExtensions.html#__has_include +# if defined(__has_include) && !__has_include() +# undef GTEST_HAS_STD_TUPLE_ +# endif +# elif defined(_MSC_VER) +// Inspired by boost/config/stdlib/dinkumware.hpp +# if defined(_CPPLIB_VER) && _CPPLIB_VER < 520 +# undef GTEST_HAS_STD_TUPLE_ +# endif +# elif defined(__GLIBCXX__) +// Inspired by boost/config/stdlib/libstdcpp3.hpp, +// http://gcc.gnu.org/gcc-4.2/changes.html and +// http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01.html#manual.intro.status.standard.200x +# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2) +# undef GTEST_HAS_STD_TUPLE_ +# endif +# endif +#endif + +// Brings in definitions for functions used in the testing::internal::posix +// namespace (read, write, close, chdir, isatty, stat). We do not currently +// use them on Windows Mobile. +#if GTEST_OS_WINDOWS +# if !GTEST_OS_WINDOWS_MOBILE +# include +# include +# endif +// In order to avoid having to include , use forward declaration +// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. +// This assumption is verified by +// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. +struct _RTL_CRITICAL_SECTION; +#else +// This assumes that non-Windows OSes provide unistd.h. For OSes where this +// is not the case, we need to include headers that provide the functions +// mentioned above. +# include +# include +#endif // GTEST_OS_WINDOWS + +#if GTEST_OS_LINUX_ANDROID +// Used to define __ANDROID_API__ matching the target NDK API level. +# include // NOLINT +#endif + +// Defines this to true iff Google Test can use POSIX regular expressions. +#ifndef GTEST_HAS_POSIX_RE +# if GTEST_OS_LINUX_ANDROID +// On Android, is only available starting with Gingerbread. +# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) +# else +# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) +# endif +#endif + +#if GTEST_USES_PCRE +// The appropriate headers have already been included. + +#elif GTEST_HAS_POSIX_RE + +// On some platforms, needs someone to define size_t, and +// won't compile otherwise. We can #include it here as we already +// included , which is guaranteed to define size_t through +// . +# include // NOLINT + +# define GTEST_USES_POSIX_RE 1 + +#elif GTEST_OS_WINDOWS + +// is not available on Windows. Use our own simple regex +// implementation instead. +# define GTEST_USES_SIMPLE_RE 1 + +#else + +// may not be available on this platform. Use our own +// simple regex implementation instead. +# define GTEST_USES_SIMPLE_RE 1 + +#endif // GTEST_USES_PCRE + +#ifndef GTEST_HAS_EXCEPTIONS +// The user didn't tell us whether exceptions are enabled, so we need +// to figure it out. +# if defined(_MSC_VER) || defined(__BORLANDC__) +// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS +// macro to enable exceptions, so we'll do the same. +// Assumes that exceptions are enabled by default. +# ifndef _HAS_EXCEPTIONS +# define _HAS_EXCEPTIONS 1 +# endif // _HAS_EXCEPTIONS +# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS +# elif defined(__clang__) +// clang defines __EXCEPTIONS iff exceptions are enabled before clang 220714, +// but iff cleanups are enabled after that. In Obj-C++ files, there can be +// cleanups for ObjC exceptions which also need cleanups, even if C++ exceptions +// are disabled. clang has __has_feature(cxx_exceptions) which checks for C++ +// exceptions starting at clang r206352, but which checked for cleanups prior to +// that. To reliably check for C++ exception availability with clang, check for +// __EXCEPTIONS && __has_feature(cxx_exceptions). +# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) +# elif defined(__GNUC__) && __EXCEPTIONS +// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__SUNPRO_CC) +// Sun Pro CC supports exceptions. However, there is no compile-time way of +// detecting whether they are enabled or not. Therefore, we assume that +// they are enabled unless the user tells us otherwise. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__IBMCPP__) && __EXCEPTIONS +// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__HP_aCC) +// Exception handling is in effect by default in HP aCC compiler. It has to +// be turned of by +noeh compiler option if desired. +# define GTEST_HAS_EXCEPTIONS 1 +# else +// For other compilers, we assume exceptions are disabled to be +// conservative. +# define GTEST_HAS_EXCEPTIONS 0 +# endif // defined(_MSC_VER) || defined(__BORLANDC__) +#endif // GTEST_HAS_EXCEPTIONS + +#if !defined(GTEST_HAS_STD_STRING) +// Even though we don't use this macro any longer, we keep it in case +// some clients still depend on it. +# define GTEST_HAS_STD_STRING 1 +#elif !GTEST_HAS_STD_STRING +// The user told us that ::std::string isn't available. +# error "Google Test cannot be used where ::std::string isn't available." +#endif // !defined(GTEST_HAS_STD_STRING) + +#ifndef GTEST_HAS_GLOBAL_STRING +// The user didn't tell us whether ::string is available, so we need +// to figure it out. + +# define GTEST_HAS_GLOBAL_STRING 0 + +#endif // GTEST_HAS_GLOBAL_STRING + +#ifndef GTEST_HAS_STD_WSTRING +// The user didn't tell us whether ::std::wstring is available, so we need +// to figure it out. +// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring +// is available. + +// Cygwin 1.7 and below doesn't support ::std::wstring. +// Solaris' libc++ doesn't support it either. Android has +// no support for it at least as recent as Froyo (2.2). +# define GTEST_HAS_STD_WSTRING \ + (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) + +#endif // GTEST_HAS_STD_WSTRING + +#ifndef GTEST_HAS_GLOBAL_WSTRING +// The user didn't tell us whether ::wstring is available, so we need +// to figure it out. +# define GTEST_HAS_GLOBAL_WSTRING \ + (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING) +#endif // GTEST_HAS_GLOBAL_WSTRING + +// Determines whether RTTI is available. +#ifndef GTEST_HAS_RTTI +// The user didn't tell us whether RTTI is enabled, so we need to +// figure it out. + +# ifdef _MSC_VER + +# ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif + +// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled. +# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) + +# ifdef __GXX_RTTI +// When building against STLport with the Android NDK and with +// -frtti -fno-exceptions, the build fails at link time with undefined +// references to __cxa_bad_typeid. Note sure if STL or toolchain bug, +// so disable RTTI when detected. +# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ + !defined(__EXCEPTIONS) +# define GTEST_HAS_RTTI 0 +# else +# define GTEST_HAS_RTTI 1 +# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS +# else +# define GTEST_HAS_RTTI 0 +# endif // __GXX_RTTI + +// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends +// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the +// first version with C++ support. +# elif defined(__clang__) + +# define GTEST_HAS_RTTI __has_feature(cxx_rtti) + +// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if +// both the typeid and dynamic_cast features are present. +# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) + +# ifdef __RTTI_ALL__ +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif + +# else + +// For all other compilers, we assume RTTI is enabled. +# define GTEST_HAS_RTTI 1 + +# endif // _MSC_VER + +#endif // GTEST_HAS_RTTI + +// It's this header's responsibility to #include when RTTI +// is enabled. +#if GTEST_HAS_RTTI +# include +#endif + +// Determines whether Google Test can use the pthreads library. +#ifndef GTEST_HAS_PTHREAD +// The user didn't tell us explicitly, so we make reasonable assumptions about +// which platforms have pthreads support. +// +// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 +// to your compiler flags. +# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \ + || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL) +#endif // GTEST_HAS_PTHREAD + +#if GTEST_HAS_PTHREAD +// gtest-port.h guarantees to #include when GTEST_HAS_PTHREAD is +// true. +# include // NOLINT + +// For timespec and nanosleep, used below. +# include // NOLINT +#endif + +// Determines if hash_map/hash_set are available. +// Only used for testing against those containers. +#if !defined(GTEST_HAS_HASH_MAP_) +# if _MSC_VER +# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available. +# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available. +# endif // _MSC_VER +#endif // !defined(GTEST_HAS_HASH_MAP_) + +// Determines whether Google Test can use tr1/tuple. You can define +// this macro to 0 to prevent Google Test from using tuple (any +// feature depending on tuple with be disabled in this mode). +#ifndef GTEST_HAS_TR1_TUPLE +# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) +// STLport, provided with the Android NDK, has neither or . +# define GTEST_HAS_TR1_TUPLE 0 +# else +// The user didn't tell us not to do it, so we assume it's OK. +# define GTEST_HAS_TR1_TUPLE 1 +# endif +#endif // GTEST_HAS_TR1_TUPLE + +// Determines whether Google Test's own tr1 tuple implementation +// should be used. +#ifndef GTEST_USE_OWN_TR1_TUPLE +// The user didn't tell us, so we need to figure it out. + +// We use our own TR1 tuple if we aren't sure the user has an +// implementation of it already. At this time, libstdc++ 4.0.0+ and +// MSVC 2010 are the only mainstream standard libraries that come +// with a TR1 tuple implementation. NVIDIA's CUDA NVCC compiler +// pretends to be GCC by defining __GNUC__ and friends, but cannot +// compile GCC's tuple implementation. MSVC 2008 (9.0) provides TR1 +// tuple in a 323 MB Feature Pack download, which we cannot assume the +// user has. QNX's QCC compiler is a modified GCC but it doesn't +// support TR1 tuple. libc++ only provides std::tuple, in C++11 mode, +// and it can be used with some compilers that define __GNUC__. +# if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \ + && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600 +# define GTEST_ENV_HAS_TR1_TUPLE_ 1 +# endif + +// C++11 specifies that provides std::tuple. Use that if gtest is used +// in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6 +// can build with clang but need to use gcc4.2's libstdc++). +# if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325) +# define GTEST_ENV_HAS_STD_TUPLE_ 1 +# endif + +# if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_ +# define GTEST_USE_OWN_TR1_TUPLE 0 +# else +# define GTEST_USE_OWN_TR1_TUPLE 1 +# endif + +#endif // GTEST_USE_OWN_TR1_TUPLE + +// To avoid conditional compilation everywhere, we make it +// gtest-port.h's responsibility to #include the header implementing +// tuple. +#if GTEST_HAS_STD_TUPLE_ +# include // IWYU pragma: export +# define GTEST_TUPLE_NAMESPACE_ ::std +#endif // GTEST_HAS_STD_TUPLE_ + +// We include tr1::tuple even if std::tuple is available to define printers for +// them. +#if GTEST_HAS_TR1_TUPLE +# ifndef GTEST_TUPLE_NAMESPACE_ +# define GTEST_TUPLE_NAMESPACE_ ::std::tr1 +# endif // GTEST_TUPLE_NAMESPACE_ + +# if GTEST_USE_OWN_TR1_TUPLE +# include "gtest-tuple.h" // IWYU pragma: export // NOLINT +# elif GTEST_ENV_HAS_STD_TUPLE_ +# include +// C++11 puts its tuple into the ::std namespace rather than +// ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there. +// This causes undefined behavior, but supported compilers react in +// the way we intend. +namespace std { +namespace tr1 { +using ::std::get; +using ::std::make_tuple; +using ::std::tuple; +using ::std::tuple_element; +using ::std::tuple_size; +} +} + +# elif GTEST_OS_SYMBIAN + +// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to +// use STLport's tuple implementation, which unfortunately doesn't +// work as the copy of STLport distributed with Symbian is incomplete. +// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to +// use its own tuple implementation. +# ifdef BOOST_HAS_TR1_TUPLE +# undef BOOST_HAS_TR1_TUPLE +# endif // BOOST_HAS_TR1_TUPLE + +// This prevents , which defines +// BOOST_HAS_TR1_TUPLE, from being #included by Boost's . +# define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED +# include // IWYU pragma: export // NOLINT + +# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) +// GCC 4.0+ implements tr1/tuple in the header. This does +// not conform to the TR1 spec, which requires the header to be . + +# if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 +// Until version 4.3.2, gcc has a bug that causes , +// which is #included by , to not compile when RTTI is +// disabled. _TR1_FUNCTIONAL is the header guard for +// . Hence the following #define is a hack to prevent +// from being included. +# define _TR1_FUNCTIONAL 1 +# include +# undef _TR1_FUNCTIONAL // Allows the user to #include + // if he chooses to. +# else +# include // NOLINT +# endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 + +# else +// If the compiler is not GCC 4.0+, we assume the user is using a +// spec-conforming TR1 implementation. +# include // IWYU pragma: export // NOLINT +# endif // GTEST_USE_OWN_TR1_TUPLE + +#endif // GTEST_HAS_TR1_TUPLE + +// Determines whether clone(2) is supported. +// Usually it will only be available on Linux, excluding +// Linux on the Itanium architecture. +// Also see http://linux.die.net/man/2/clone. +#ifndef GTEST_HAS_CLONE +// The user didn't tell us, so we need to figure it out. + +# if GTEST_OS_LINUX && !defined(__ia64__) +# if GTEST_OS_LINUX_ANDROID +// On Android, clone() is only available on ARM starting with Gingerbread. +# if defined(__arm__) && __ANDROID_API__ >= 9 +# define GTEST_HAS_CLONE 1 +# else +# define GTEST_HAS_CLONE 0 +# endif +# else +# define GTEST_HAS_CLONE 1 +# endif +# else +# define GTEST_HAS_CLONE 0 +# endif // GTEST_OS_LINUX && !defined(__ia64__) + +#endif // GTEST_HAS_CLONE + +// Determines whether to support stream redirection. This is used to test +// output correctness and to implement death tests. +#ifndef GTEST_HAS_STREAM_REDIRECTION +// By default, we assume that stream redirection is supported on all +// platforms except known mobile ones. +# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || \ + GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT +# define GTEST_HAS_STREAM_REDIRECTION 0 +# else +# define GTEST_HAS_STREAM_REDIRECTION 1 +# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN +#endif // GTEST_HAS_STREAM_REDIRECTION + +// Determines whether to support death tests. +// Google Test does not support death tests for VC 7.1 and earlier as +// abort() in a VC 7.1 application compiled as GUI in debug config +// pops up a dialog window that cannot be suppressed programmatically. +#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ + (GTEST_OS_MAC && !GTEST_OS_IOS) || \ + (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ + GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \ + GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD) +# define GTEST_HAS_DEATH_TEST 1 +#endif + +// We don't support MSVC 7.1 with exceptions disabled now. Therefore +// all the compilers we care about are adequate for supporting +// value-parameterized tests. +#define GTEST_HAS_PARAM_TEST 1 + +// Determines whether to support type-driven tests. + +// Typed tests need and variadic macros, which GCC, VC++ 8.0, +// Sun Pro CC, IBM Visual Age, and HP aCC support. +#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \ + defined(__IBMCPP__) || defined(__HP_aCC) +# define GTEST_HAS_TYPED_TEST 1 +# define GTEST_HAS_TYPED_TEST_P 1 +#endif + +// Determines whether to support Combine(). This only makes sense when +// value-parameterized tests are enabled. The implementation doesn't +// work on Sun Studio since it doesn't understand templated conversion +// operators. +#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC) +# define GTEST_HAS_COMBINE 1 +#endif + +// Determines whether the system compiler uses UTF-16 for encoding wide strings. +#define GTEST_WIDE_STRING_USES_UTF16_ \ + (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX) + +// Determines whether test results can be streamed to a socket. +#if GTEST_OS_LINUX +# define GTEST_CAN_STREAM_RESULTS_ 1 +#endif + +// Defines some utility macros. + +// The GNU compiler emits a warning if nested "if" statements are followed by +// an "else" statement and braces are not used to explicitly disambiguate the +// "else" binding. This leads to problems with code like: +// +// if (gate) +// ASSERT_*(condition) << "Some message"; +// +// The "switch (0) case 0:" idiom is used to suppress this. +#ifdef __INTEL_COMPILER +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ +#else +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT +#endif + +// Use this annotation at the end of a struct/class definition to +// prevent the compiler from optimizing away instances that are never +// used. This is useful when all interesting logic happens inside the +// c'tor and / or d'tor. Example: +// +// struct Foo { +// Foo() { ... } +// } GTEST_ATTRIBUTE_UNUSED_; +// +// Also use it after a variable or parameter declaration to tell the +// compiler the variable/parameter does not have to be used. +#if defined(__GNUC__) && !defined(COMPILER_ICC) +# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) +#elif defined(__clang__) +# if __has_attribute(unused) +# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) +# endif +#endif +#ifndef GTEST_ATTRIBUTE_UNUSED_ +# define GTEST_ATTRIBUTE_UNUSED_ +#endif + +// A macro to disallow operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_ASSIGN_(type)\ + void operator=(type const &) + +// A macro to disallow copy constructor and operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\ + type(type const &);\ + GTEST_DISALLOW_ASSIGN_(type) + +// Tell the compiler to warn about unused return values for functions declared +// with this macro. The macro should be used on function declarations +// following the argument list: +// +// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; +#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC) +# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) +#else +# define GTEST_MUST_USE_RESULT_ +#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC + +// MS C++ compiler emits warning when a conditional expression is compile time +// constant. In some contexts this warning is false positive and needs to be +// suppressed. Use the following two macros in such cases: +// +// GTEST_INTENTIONAL_CONST_COND_PUSH_() +// while (true) { +// GTEST_INTENTIONAL_CONST_COND_POP_() +// } +# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) +# define GTEST_INTENTIONAL_CONST_COND_POP_() \ + GTEST_DISABLE_MSC_WARNINGS_POP_() + +// Determine whether the compiler supports Microsoft's Structured Exception +// Handling. This is supported by several Windows compilers but generally +// does not exist on any other system. +#ifndef GTEST_HAS_SEH +// The user didn't tell us, so we need to figure it out. + +# if defined(_MSC_VER) || defined(__BORLANDC__) +// These two compilers are known to support SEH. +# define GTEST_HAS_SEH 1 +# else +// Assume no SEH. +# define GTEST_HAS_SEH 0 +# endif + +#define GTEST_IS_THREADSAFE \ + (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ \ + || (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) \ + || GTEST_HAS_PTHREAD) + +#endif // GTEST_HAS_SEH + +#ifdef _MSC_VER +# if GTEST_LINKED_AS_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllimport) +# elif GTEST_CREATE_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllexport) +# endif +#elif __GNUC__ >= 4 || defined(__clang__) +# define GTEST_API_ __attribute__((visibility ("default"))) +#endif // _MSC_VER + +#ifndef GTEST_API_ +# define GTEST_API_ +#endif + +#ifdef __GNUC__ +// Ask the compiler to never inline a given function. +# define GTEST_NO_INLINE_ __attribute__((noinline)) +#else +# define GTEST_NO_INLINE_ +#endif + +// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. +#if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) +# define GTEST_HAS_CXXABI_H_ 1 +#else +# define GTEST_HAS_CXXABI_H_ 0 +#endif + +// A function level attribute to disable checking for use of uninitialized +// memory when built with MemorySanitizer. +#if defined(__clang__) +# if __has_feature(memory_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \ + __attribute__((no_sanitize_memory)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +# endif // __has_feature(memory_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +#endif // __clang__ + +// A function level attribute to disable AddressSanitizer instrumentation. +#if defined(__clang__) +# if __has_feature(address_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ + __attribute__((no_sanitize_address)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +# endif // __has_feature(address_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +#endif // __clang__ + +// A function level attribute to disable ThreadSanitizer instrumentation. +#if defined(__clang__) +# if __has_feature(thread_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \ + __attribute__((no_sanitize_thread)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +# endif // __has_feature(thread_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +#endif // __clang__ + +namespace testing { + +class Message; + +#if defined(GTEST_TUPLE_NAMESPACE_) +// Import tuple and friends into the ::testing namespace. +// It is part of our interface, having them in ::testing allows us to change +// their types as needed. +using GTEST_TUPLE_NAMESPACE_::get; +using GTEST_TUPLE_NAMESPACE_::make_tuple; +using GTEST_TUPLE_NAMESPACE_::tuple; +using GTEST_TUPLE_NAMESPACE_::tuple_size; +using GTEST_TUPLE_NAMESPACE_::tuple_element; +#endif // defined(GTEST_TUPLE_NAMESPACE_) + +namespace internal { + +// A secret type that Google Test users don't know about. It has no +// definition on purpose. Therefore it's impossible to create a +// Secret object, which is what we want. +class Secret; + +// The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time +// expression is true. For example, you could use it to verify the +// size of a static array: +// +// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, +// names_incorrect_size); +// +// or to make sure a struct is smaller than a certain size: +// +// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large); +// +// The second argument to the macro is the name of the variable. If +// the expression is false, most compilers will issue a warning/error +// containing the name of the variable. + +#if GTEST_LANG_CXX11 +# define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) +#else // !GTEST_LANG_CXX11 +template + struct CompileAssert { +}; + +# define GTEST_COMPILE_ASSERT_(expr, msg) \ + typedef ::testing::internal::CompileAssert<(static_cast(expr))> \ + msg[static_cast(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_ +#endif // !GTEST_LANG_CXX11 + +// Implementation details of GTEST_COMPILE_ASSERT_: +// +// (In C++11, we simply use static_assert instead of the following) +// +// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1 +// elements (and thus is invalid) when the expression is false. +// +// - The simpler definition +// +// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1] +// +// does not work, as gcc supports variable-length arrays whose sizes +// are determined at run-time (this is gcc's extension and not part +// of the C++ standard). As a result, gcc fails to reject the +// following code with the simple definition: +// +// int foo; +// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is +// // not a compile-time constant. +// +// - By using the type CompileAssert<(bool(expr))>, we ensures that +// expr is a compile-time constant. (Template arguments must be +// determined at compile-time.) +// +// - The outter parentheses in CompileAssert<(bool(expr))> are necessary +// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written +// +// CompileAssert +// +// instead, these compilers will refuse to compile +// +// GTEST_COMPILE_ASSERT_(5 > 0, some_message); +// +// (They seem to think the ">" in "5 > 0" marks the end of the +// template argument list.) +// +// - The array size is (bool(expr) ? 1 : -1), instead of simply +// +// ((expr) ? 1 : -1). +// +// This is to avoid running into a bug in MS VC 7.1, which +// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. + +// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h. +// +// This template is declared, but intentionally undefined. +template +struct StaticAssertTypeEqHelper; + +template +struct StaticAssertTypeEqHelper { + enum { value = true }; +}; + +// Evaluates to the number of elements in 'array'. +#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) + +#if GTEST_HAS_GLOBAL_STRING +typedef ::string string; +#else +typedef ::std::string string; +#endif // GTEST_HAS_GLOBAL_STRING + +#if GTEST_HAS_GLOBAL_WSTRING +typedef ::wstring wstring; +#elif GTEST_HAS_STD_WSTRING +typedef ::std::wstring wstring; +#endif // GTEST_HAS_GLOBAL_WSTRING + +// A helper for suppressing warnings on constant condition. It just +// returns 'condition'. +GTEST_API_ bool IsTrue(bool condition); + +// Defines scoped_ptr. + +// This implementation of scoped_ptr is PARTIAL - it only contains +// enough stuff to satisfy Google Test's need. +template +class scoped_ptr { + public: + typedef T element_type; + + explicit scoped_ptr(T* p = NULL) : ptr_(p) {} + ~scoped_ptr() { reset(); } + + T& operator*() const { return *ptr_; } + T* operator->() const { return ptr_; } + T* get() const { return ptr_; } + + T* release() { + T* const ptr = ptr_; + ptr_ = NULL; + return ptr; + } + + void reset(T* p = NULL) { + if (p != ptr_) { + if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type. + delete ptr_; + } + ptr_ = p; + } + } + + friend void swap(scoped_ptr& a, scoped_ptr& b) { + using std::swap; + swap(a.ptr_, b.ptr_); + } + + private: + T* ptr_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr); +}; + +// Defines RE. + +// A simple C++ wrapper for . It uses the POSIX Extended +// Regular Expression syntax. +class GTEST_API_ RE { + public: + // A copy constructor is required by the Standard to initialize object + // references from r-values. + RE(const RE& other) { Init(other.pattern()); } + + // Constructs an RE from a string. + RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT + +#if GTEST_HAS_GLOBAL_STRING + + RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT + +#endif // GTEST_HAS_GLOBAL_STRING + + RE(const char* regex) { Init(regex); } // NOLINT + ~RE(); + + // Returns the string representation of the regex. + const char* pattern() const { return pattern_; } + + // FullMatch(str, re) returns true iff regular expression re matches + // the entire str. + // PartialMatch(str, re) returns true iff regular expression re + // matches a substring of str (including str itself). + // + // TODO(wan@google.com): make FullMatch() and PartialMatch() work + // when str contains NUL characters. + static bool FullMatch(const ::std::string& str, const RE& re) { + return FullMatch(str.c_str(), re); + } + static bool PartialMatch(const ::std::string& str, const RE& re) { + return PartialMatch(str.c_str(), re); + } + +#if GTEST_HAS_GLOBAL_STRING + + static bool FullMatch(const ::string& str, const RE& re) { + return FullMatch(str.c_str(), re); + } + static bool PartialMatch(const ::string& str, const RE& re) { + return PartialMatch(str.c_str(), re); + } + +#endif // GTEST_HAS_GLOBAL_STRING + + static bool FullMatch(const char* str, const RE& re); + static bool PartialMatch(const char* str, const RE& re); + + private: + void Init(const char* regex); + + // We use a const char* instead of an std::string, as Google Test used to be + // used where std::string is not available. TODO(wan@google.com): change to + // std::string. + const char* pattern_; + bool is_valid_; + +#if GTEST_USES_POSIX_RE + + regex_t full_regex_; // For FullMatch(). + regex_t partial_regex_; // For PartialMatch(). + +#else // GTEST_USES_SIMPLE_RE + + const char* full_pattern_; // For FullMatch(); + +#endif + + GTEST_DISALLOW_ASSIGN_(RE); +}; + +// Formats a source file path and a line number as they would appear +// in an error message from the compiler used to compile this code. +GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); + +// Formats a file location for compiler-independent XML output. +// Although this function is not platform dependent, we put it next to +// FormatFileLocation in order to contrast the two functions. +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, + int line); + +// Defines logging utilities: +// GTEST_LOG_(severity) - logs messages at the specified severity level. The +// message itself is streamed into the macro. +// LogToStderr() - directs all log messages to stderr. +// FlushInfoLog() - flushes informational log messages. + +enum GTestLogSeverity { + GTEST_INFO, + GTEST_WARNING, + GTEST_ERROR, + GTEST_FATAL +}; + +// Formats log entry severity, provides a stream object for streaming the +// log message, and terminates the message with a newline when going out of +// scope. +class GTEST_API_ GTestLog { + public: + GTestLog(GTestLogSeverity severity, const char* file, int line); + + // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. + ~GTestLog(); + + ::std::ostream& GetStream() { return ::std::cerr; } + + private: + const GTestLogSeverity severity_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog); +}; + +#if !defined(GTEST_LOG_) + +# define GTEST_LOG_(severity) \ + ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ + __FILE__, __LINE__).GetStream() + +inline void LogToStderr() {} +inline void FlushInfoLog() { fflush(NULL); } + +#endif // !defined(GTEST_LOG_) + +#if !defined(GTEST_CHECK_) +// INTERNAL IMPLEMENTATION - DO NOT USE. +// +// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition +// is not satisfied. +// Synopsys: +// GTEST_CHECK_(boolean_condition); +// or +// GTEST_CHECK_(boolean_condition) << "Additional message"; +// +// This checks the condition and if the condition is not satisfied +// it prints message about the condition violation, including the +// condition itself, plus additional message streamed into it, if any, +// and then it aborts the program. It aborts the program irrespective of +// whether it is built in the debug mode or not. +# define GTEST_CHECK_(condition) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::IsTrue(condition)) \ + ; \ + else \ + GTEST_LOG_(FATAL) << "Condition " #condition " failed. " +#endif // !defined(GTEST_CHECK_) + +// An all-mode assert to verify that the given POSIX-style function +// call returns 0 (indicating success). Known limitation: this +// doesn't expand to a balanced 'if' statement, so enclose the macro +// in {} if you need to use it as the only statement in an 'if' +// branch. +#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ + if (const int gtest_error = (posix_call)) \ + GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ + << gtest_error + +#if GTEST_HAS_STD_MOVE_ +using std::move; +#else // GTEST_HAS_STD_MOVE_ +template +const T& move(const T& t) { + return t; +} +#endif // GTEST_HAS_STD_MOVE_ + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Use ImplicitCast_ as a safe version of static_cast for upcasting in +// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a +// const Foo*). When you use ImplicitCast_, the compiler checks that +// the cast is safe. Such explicit ImplicitCast_s are necessary in +// surprisingly many situations where C++ demands an exact type match +// instead of an argument type convertable to a target type. +// +// The syntax for using ImplicitCast_ is the same as for static_cast: +// +// ImplicitCast_(expr) +// +// ImplicitCast_ would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +// +// This relatively ugly name is intentional. It prevents clashes with +// similar functions users may have (e.g., implicit_cast). The internal +// namespace alone is not enough because the function can be found by ADL. +template +inline To ImplicitCast_(To x) { return x; } + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, +// when you downcast, you should use this macro. In debug mode, we +// use dynamic_cast<> to double-check the downcast is legal (we die +// if it's not). In normal mode, we do the efficient static_cast<> +// instead. Thus, it's important to test in debug mode to make sure +// the cast is legal! +// This is the only place in the code we should use dynamic_cast<>. +// In particular, you SHOULDN'T be using dynamic_cast<> in order to +// do RTTI (eg code like this: +// if (dynamic_cast(foo)) HandleASubclass1Object(foo); +// if (dynamic_cast(foo)) HandleASubclass2Object(foo); +// You should design the code some other way not to need this. +// +// This relatively ugly name is intentional. It prevents clashes with +// similar functions users may have (e.g., down_cast). The internal +// namespace alone is not enough because the function can be found by ADL. +template // use like this: DownCast_(foo); +inline To DownCast_(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + GTEST_INTENTIONAL_CONST_COND_PUSH_() + if (false) { + GTEST_INTENTIONAL_CONST_COND_POP_() + const To to = NULL; + ::testing::internal::ImplicitCast_(to); + } + +#if GTEST_HAS_RTTI + // RTTI: debug mode only! + GTEST_CHECK_(f == NULL || dynamic_cast(f) != NULL); +#endif + return static_cast(f); +} + +// Downcasts the pointer of type Base to Derived. +// Derived must be a subclass of Base. The parameter MUST +// point to a class of type Derived, not any subclass of it. +// When RTTI is available, the function performs a runtime +// check to enforce this. +template +Derived* CheckedDowncastToActualType(Base* base) { +#if GTEST_HAS_RTTI + GTEST_CHECK_(typeid(*base) == typeid(Derived)); +#endif + +#if GTEST_HAS_DOWNCAST_ + return ::down_cast(base); +#elif GTEST_HAS_RTTI + return dynamic_cast(base); // NOLINT +#else + return static_cast(base); // Poor man's downcast. +#endif +} + +#if GTEST_HAS_STREAM_REDIRECTION + +// Defines the stderr capturer: +// CaptureStdout - starts capturing stdout. +// GetCapturedStdout - stops capturing stdout and returns the captured string. +// CaptureStderr - starts capturing stderr. +// GetCapturedStderr - stops capturing stderr and returns the captured string. +// +GTEST_API_ void CaptureStdout(); +GTEST_API_ std::string GetCapturedStdout(); +GTEST_API_ void CaptureStderr(); +GTEST_API_ std::string GetCapturedStderr(); + +#endif // GTEST_HAS_STREAM_REDIRECTION + +// Returns a path to temporary directory. +GTEST_API_ std::string TempDir(); + +// Returns the size (in bytes) of a file. +GTEST_API_ size_t GetFileSize(FILE* file); + +// Reads the entire content of a file as a string. +GTEST_API_ std::string ReadEntireFile(FILE* file); + +// All command line arguments. +GTEST_API_ const ::std::vector& GetArgvs(); + +#if GTEST_HAS_DEATH_TEST + +const ::std::vector& GetInjectableArgvs(); +void SetInjectableArgvs(const ::std::vector* + new_argvs); + + +#endif // GTEST_HAS_DEATH_TEST + +// Defines synchronization primitives. +#if GTEST_IS_THREADSAFE +# if GTEST_HAS_PTHREAD +// Sleeps for (roughly) n milliseconds. This function is only for testing +// Google Test's own constructs. Don't use it in user tests, either +// directly or indirectly. +inline void SleepMilliseconds(int n) { + const timespec time = { + 0, // 0 seconds. + n * 1000L * 1000L, // And n ms. + }; + nanosleep(&time, NULL); +} +# endif // GTEST_HAS_PTHREAD + +# if GTEST_HAS_NOTIFICATION_ +// Notification has already been imported into the namespace. +// Nothing to do here. + +# elif GTEST_HAS_PTHREAD +// Allows a controller thread to pause execution of newly created +// threads until notified. Instances of this class must be created +// and destroyed in the controller thread. +// +// This class is only for testing Google Test's own constructs. Do not +// use it in user tests, either directly or indirectly. +class Notification { + public: + Notification() : notified_(false) { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); + } + ~Notification() { + pthread_mutex_destroy(&mutex_); + } + + // Notifies all threads created with this notification to start. Must + // be called from the controller thread. + void Notify() { + pthread_mutex_lock(&mutex_); + notified_ = true; + pthread_mutex_unlock(&mutex_); + } + + // Blocks until the controller thread notifies. Must be called from a test + // thread. + void WaitForNotification() { + for (;;) { + pthread_mutex_lock(&mutex_); + const bool notified = notified_; + pthread_mutex_unlock(&mutex_); + if (notified) + break; + SleepMilliseconds(10); + } + } + + private: + pthread_mutex_t mutex_; + bool notified_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); +}; + +# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + +GTEST_API_ void SleepMilliseconds(int n); + +// Provides leak-safe Windows kernel handle ownership. +// Used in death tests and in threading support. +class GTEST_API_ AutoHandle { + public: + // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to + // avoid including in this header file. Including is + // undesirable because it defines a lot of symbols and macros that tend to + // conflict with client code. This assumption is verified by + // WindowsTypesTest.HANDLEIsVoidStar. + typedef void* Handle; + AutoHandle(); + explicit AutoHandle(Handle handle); + + ~AutoHandle(); + + Handle Get() const; + void Reset(); + void Reset(Handle handle); + + private: + // Returns true iff the handle is a valid handle object that can be closed. + bool IsCloseable() const; + + Handle handle_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle); +}; + +// Allows a controller thread to pause execution of newly created +// threads until notified. Instances of this class must be created +// and destroyed in the controller thread. +// +// This class is only for testing Google Test's own constructs. Do not +// use it in user tests, either directly or indirectly. +class GTEST_API_ Notification { + public: + Notification(); + void Notify(); + void WaitForNotification(); + + private: + AutoHandle event_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); +}; +# endif // GTEST_HAS_NOTIFICATION_ + +// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD +// defined, but we don't want to use MinGW's pthreads implementation, which +// has conformance problems with some versions of the POSIX standard. +# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW + +// As a C-function, ThreadFuncWithCLinkage cannot be templated itself. +// Consequently, it cannot select a correct instantiation of ThreadWithParam +// in order to call its Run(). Introducing ThreadWithParamBase as a +// non-templated base class for ThreadWithParam allows us to bypass this +// problem. +class ThreadWithParamBase { + public: + virtual ~ThreadWithParamBase() {} + virtual void Run() = 0; +}; + +// pthread_create() accepts a pointer to a function type with the C linkage. +// According to the Standard (7.5/1), function types with different linkages +// are different even if they are otherwise identical. Some compilers (for +// example, SunStudio) treat them as different types. Since class methods +// cannot be defined with C-linkage we need to define a free C-function to +// pass into pthread_create(). +extern "C" inline void* ThreadFuncWithCLinkage(void* thread) { + static_cast(thread)->Run(); + return NULL; +} + +// Helper class for testing Google Test's multi-threading constructs. +// To use it, write: +// +// void ThreadFunc(int param) { /* Do things with param */ } +// Notification thread_can_start; +// ... +// // The thread_can_start parameter is optional; you can supply NULL. +// ThreadWithParam thread(&ThreadFunc, 5, &thread_can_start); +// thread_can_start.Notify(); +// +// These classes are only for testing Google Test's own constructs. Do +// not use them in user tests, either directly or indirectly. +template +class ThreadWithParam : public ThreadWithParamBase { + public: + typedef void UserThreadFunc(T); + + ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) + : func_(func), + param_(param), + thread_can_start_(thread_can_start), + finished_(false) { + ThreadWithParamBase* const base = this; + // The thread can be created only after all fields except thread_ + // have been initialized. + GTEST_CHECK_POSIX_SUCCESS_( + pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base)); + } + ~ThreadWithParam() { Join(); } + + void Join() { + if (!finished_) { + GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0)); + finished_ = true; + } + } + + virtual void Run() { + if (thread_can_start_ != NULL) + thread_can_start_->WaitForNotification(); + func_(param_); + } + + private: + UserThreadFunc* const func_; // User-supplied thread function. + const T param_; // User-supplied parameter to the thread function. + // When non-NULL, used to block execution until the controller thread + // notifies. + Notification* const thread_can_start_; + bool finished_; // true iff we know that the thread function has finished. + pthread_t thread_; // The native thread object. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); +}; +# endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || + // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ + +# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +// Mutex and ThreadLocal have already been imported into the namespace. +// Nothing to do here. + +# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + +// Mutex implements mutex on Windows platforms. It is used in conjunction +// with class MutexLock: +// +// Mutex mutex; +// ... +// MutexLock lock(&mutex); // Acquires the mutex and releases it at the +// // end of the current scope. +// +// A static Mutex *must* be defined or declared using one of the following +// macros: +// GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex); +// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex); +// +// (A non-static Mutex is defined/declared in the usual way). +class GTEST_API_ Mutex { + public: + enum MutexType { kStatic = 0, kDynamic = 1 }; + // We rely on kStaticMutex being 0 as it is to what the linker initializes + // type_ in static mutexes. critical_section_ will be initialized lazily + // in ThreadSafeLazyInit(). + enum StaticConstructorSelector { kStaticMutex = 0 }; + + // This constructor intentionally does nothing. It relies on type_ being + // statically initialized to 0 (effectively setting it to kStatic) and on + // ThreadSafeLazyInit() to lazily initialize the rest of the members. + explicit Mutex(StaticConstructorSelector /*dummy*/) {} + + Mutex(); + ~Mutex(); + + void Lock(); + + void Unlock(); + + // Does nothing if the current thread holds the mutex. Otherwise, crashes + // with high probability. + void AssertHeld(); + + private: + // Initializes owner_thread_id_ and critical_section_ in static mutexes. + void ThreadSafeLazyInit(); + + // Per http://blogs.msdn.com/b/oldnewthing/archive/2004/02/23/78395.aspx, + // we assume that 0 is an invalid value for thread IDs. + unsigned int owner_thread_id_; + + // For static mutexes, we rely on these members being initialized to zeros + // by the linker. + MutexType type_; + long critical_section_init_phase_; // NOLINT + _RTL_CRITICAL_SECTION* critical_section_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); +}; + +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::Mutex mutex + +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ + ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(Mutex* mutex) + : mutex_(mutex) { mutex_->Lock(); } + + ~GTestMutexLock() { mutex_->Unlock(); } + + private: + Mutex* const mutex_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); +}; + +typedef GTestMutexLock MutexLock; + +// Base class for ValueHolder. Allows a caller to hold and delete a value +// without knowing its type. +class ThreadLocalValueHolderBase { + public: + virtual ~ThreadLocalValueHolderBase() {} +}; + +// Provides a way for a thread to send notifications to a ThreadLocal +// regardless of its parameter type. +class ThreadLocalBase { + public: + // Creates a new ValueHolder object holding a default value passed to + // this ThreadLocal's constructor and returns it. It is the caller's + // responsibility not to call this when the ThreadLocal instance already + // has a value on the current thread. + virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0; + + protected: + ThreadLocalBase() {} + virtual ~ThreadLocalBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase); +}; + +// Maps a thread to a set of ThreadLocals that have values instantiated on that +// thread and notifies them when the thread exits. A ThreadLocal instance is +// expected to persist until all threads it has values on have terminated. +class GTEST_API_ ThreadLocalRegistry { + public: + // Registers thread_local_instance as having value on the current thread. + // Returns a value that can be used to identify the thread from other threads. + static ThreadLocalValueHolderBase* GetValueOnCurrentThread( + const ThreadLocalBase* thread_local_instance); + + // Invoked when a ThreadLocal instance is destroyed. + static void OnThreadLocalDestroyed( + const ThreadLocalBase* thread_local_instance); +}; + +class GTEST_API_ ThreadWithParamBase { + public: + void Join(); + + protected: + class Runnable { + public: + virtual ~Runnable() {} + virtual void Run() = 0; + }; + + ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start); + virtual ~ThreadWithParamBase(); + + private: + AutoHandle thread_; +}; + +// Helper class for testing Google Test's multi-threading constructs. +template +class ThreadWithParam : public ThreadWithParamBase { + public: + typedef void UserThreadFunc(T); + + ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) + : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) { + } + virtual ~ThreadWithParam() {} + + private: + class RunnableImpl : public Runnable { + public: + RunnableImpl(UserThreadFunc* func, T param) + : func_(func), + param_(param) { + } + virtual ~RunnableImpl() {} + virtual void Run() { + func_(param_); + } + + private: + UserThreadFunc* const func_; + const T param_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl); + }; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); +}; + +// Implements thread-local storage on Windows systems. +// +// // Thread 1 +// ThreadLocal tl(100); // 100 is the default value for each thread. +// +// // Thread 2 +// tl.set(150); // Changes the value for thread 2 only. +// EXPECT_EQ(150, tl.get()); +// +// // Thread 1 +// EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value. +// tl.set(200); +// EXPECT_EQ(200, tl.get()); +// +// The template type argument T must have a public copy constructor. +// In addition, the default ThreadLocal constructor requires T to have +// a public default constructor. +// +// The users of a TheadLocal instance have to make sure that all but one +// threads (including the main one) using that instance have exited before +// destroying it. Otherwise, the per-thread objects managed for them by the +// ThreadLocal instance are not guaranteed to be destroyed on all platforms. +// +// Google Test only uses global ThreadLocal objects. That means they +// will die after main() has returned. Therefore, no per-thread +// object managed by Google Test will be leaked as long as all threads +// using Google Test have exited when main() returns. +template +class ThreadLocal : public ThreadLocalBase { + public: + ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {} + explicit ThreadLocal(const T& value) + : default_factory_(new InstanceValueHolderFactory(value)) {} + + ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); } + + T* pointer() { return GetOrCreateValue(); } + const T* pointer() const { return GetOrCreateValue(); } + const T& get() const { return *pointer(); } + void set(const T& value) { *pointer() = value; } + + private: + // Holds a value of T. Can be deleted via its base class without the caller + // knowing the type of T. + class ValueHolder : public ThreadLocalValueHolderBase { + public: + ValueHolder() : value_() {} + explicit ValueHolder(const T& value) : value_(value) {} + + T* pointer() { return &value_; } + + private: + T value_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + }; + + + T* GetOrCreateValue() const { + return static_cast( + ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer(); + } + + virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const { + return default_factory_->MakeNewHolder(); + } + + class ValueHolderFactory { + public: + ValueHolderFactory() {} + virtual ~ValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const = 0; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + }; + + class DefaultValueHolderFactory : public ValueHolderFactory { + public: + DefaultValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + }; + + class InstanceValueHolderFactory : public ValueHolderFactory { + public: + explicit InstanceValueHolderFactory(const T& value) : value_(value) {} + virtual ValueHolder* MakeNewHolder() const { + return new ValueHolder(value_); + } + + private: + const T value_; // The value for each thread. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + }; + + scoped_ptr default_factory_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); +}; + +# elif GTEST_HAS_PTHREAD + +// MutexBase and Mutex implement mutex on pthreads-based platforms. +class MutexBase { + public: + // Acquires this mutex. + void Lock() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_)); + owner_ = pthread_self(); + has_owner_ = true; + } + + // Releases this mutex. + void Unlock() { + // Since the lock is being released the owner_ field should no longer be + // considered valid. We don't protect writing to has_owner_ here, as it's + // the caller's responsibility to ensure that the current thread holds the + // mutex when this is called. + has_owner_ = false; + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_)); + } + + // Does nothing if the current thread holds the mutex. Otherwise, crashes + // with high probability. + void AssertHeld() const { + GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self())) + << "The current thread is not holding the mutex @" << this; + } + + // A static mutex may be used before main() is entered. It may even + // be used before the dynamic initialization stage. Therefore we + // must be able to initialize a static mutex object at link time. + // This means MutexBase has to be a POD and its member variables + // have to be public. + public: + pthread_mutex_t mutex_; // The underlying pthread mutex. + // has_owner_ indicates whether the owner_ field below contains a valid thread + // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All + // accesses to the owner_ field should be protected by a check of this field. + // An alternative might be to memset() owner_ to all zeros, but there's no + // guarantee that a zero'd pthread_t is necessarily invalid or even different + // from pthread_self(). + bool has_owner_; + pthread_t owner_; // The thread holding the mutex. +}; + +// Forward-declares a static mutex. +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::MutexBase mutex + +// Defines and statically (i.e. at link time) initializes a static mutex. +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ + ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false, pthread_t() } + +// The Mutex class can only be used for mutexes created at runtime. It +// shares its API with MutexBase otherwise. +class Mutex : public MutexBase { + public: + Mutex() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); + has_owner_ = false; + } + ~Mutex() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); +}; + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(MutexBase* mutex) + : mutex_(mutex) { mutex_->Lock(); } + + ~GTestMutexLock() { mutex_->Unlock(); } + + private: + MutexBase* const mutex_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); +}; + +typedef GTestMutexLock MutexLock; + +// Helpers for ThreadLocal. + +// pthread_key_create() requires DeleteThreadLocalValue() to have +// C-linkage. Therefore it cannot be templatized to access +// ThreadLocal. Hence the need for class +// ThreadLocalValueHolderBase. +class ThreadLocalValueHolderBase { + public: + virtual ~ThreadLocalValueHolderBase() {} +}; + +// Called by pthread to delete thread-local data stored by +// pthread_setspecific(). +extern "C" inline void DeleteThreadLocalValue(void* value_holder) { + delete static_cast(value_holder); +} + +// Implements thread-local storage on pthreads-based systems. +template +class ThreadLocal { + public: + ThreadLocal() + : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {} + explicit ThreadLocal(const T& value) + : key_(CreateKey()), + default_factory_(new InstanceValueHolderFactory(value)) {} + + ~ThreadLocal() { + // Destroys the managed object for the current thread, if any. + DeleteThreadLocalValue(pthread_getspecific(key_)); + + // Releases resources associated with the key. This will *not* + // delete managed objects for other threads. + GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_)); + } + + T* pointer() { return GetOrCreateValue(); } + const T* pointer() const { return GetOrCreateValue(); } + const T& get() const { return *pointer(); } + void set(const T& value) { *pointer() = value; } + + private: + // Holds a value of type T. + class ValueHolder : public ThreadLocalValueHolderBase { + public: + ValueHolder() : value_() {} + explicit ValueHolder(const T& value) : value_(value) {} + + T* pointer() { return &value_; } + + private: + T value_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + }; + + static pthread_key_t CreateKey() { + pthread_key_t key; + // When a thread exits, DeleteThreadLocalValue() will be called on + // the object managed for that thread. + GTEST_CHECK_POSIX_SUCCESS_( + pthread_key_create(&key, &DeleteThreadLocalValue)); + return key; + } + + T* GetOrCreateValue() const { + ThreadLocalValueHolderBase* const holder = + static_cast(pthread_getspecific(key_)); + if (holder != NULL) { + return CheckedDowncastToActualType(holder)->pointer(); + } + + ValueHolder* const new_holder = default_factory_->MakeNewHolder(); + ThreadLocalValueHolderBase* const holder_base = new_holder; + GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base)); + return new_holder->pointer(); + } + + class ValueHolderFactory { + public: + ValueHolderFactory() {} + virtual ~ValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const = 0; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + }; + + class DefaultValueHolderFactory : public ValueHolderFactory { + public: + DefaultValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + }; + + class InstanceValueHolderFactory : public ValueHolderFactory { + public: + explicit InstanceValueHolderFactory(const T& value) : value_(value) {} + virtual ValueHolder* MakeNewHolder() const { + return new ValueHolder(value_); + } + + private: + const T value_; // The value for each thread. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + }; + + // A key pthreads uses for looking up per-thread values. + const pthread_key_t key_; + scoped_ptr default_factory_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); +}; + +# endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ + +#else // GTEST_IS_THREADSAFE + +// A dummy implementation of synchronization primitives (mutex, lock, +// and thread-local variable). Necessary for compiling Google Test where +// mutex is not supported - using Google Test in multiple threads is not +// supported on such platforms. + +class Mutex { + public: + Mutex() {} + void Lock() {} + void Unlock() {} + void AssertHeld() const {} +}; + +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::Mutex mutex + +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(Mutex*) {} // NOLINT +}; + +typedef GTestMutexLock MutexLock; + +template +class ThreadLocal { + public: + ThreadLocal() : value_() {} + explicit ThreadLocal(const T& value) : value_(value) {} + T* pointer() { return &value_; } + const T* pointer() const { return &value_; } + const T& get() const { return value_; } + void set(const T& value) { value_ = value; } + private: + T value_; +}; + +#endif // GTEST_IS_THREADSAFE + +// Returns the number of threads running in the process, or 0 to indicate that +// we cannot detect it. +GTEST_API_ size_t GetThreadCount(); + +// Passing non-POD classes through ellipsis (...) crashes the ARM +// compiler and generates a warning in Sun Studio. The Nokia Symbian +// and the IBM XL C/C++ compiler try to instantiate a copy constructor +// for objects passed through ellipsis (...), failing for uncopyable +// objects. We define this to ensure that only POD is passed through +// ellipsis on these systems. +#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) +// We lose support for NULL detection where the compiler doesn't like +// passing non-POD classes through ellipsis (...). +# define GTEST_ELLIPSIS_NEEDS_POD_ 1 +#else +# define GTEST_CAN_COMPARE_NULL 1 +#endif + +// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between +// const T& and const T* in a function template. These compilers +// _can_ decide between class template specializations for T and T*, +// so a tr1::type_traits-like is_pointer works. +#if defined(__SYMBIAN32__) || defined(__IBMCPP__) +# define GTEST_NEEDS_IS_POINTER_ 1 +#endif + +template +struct bool_constant { + typedef bool_constant type; + static const bool value = bool_value; +}; +template const bool bool_constant::value; + +typedef bool_constant false_type; +typedef bool_constant true_type; + +template +struct is_pointer : public false_type {}; + +template +struct is_pointer : public true_type {}; + +template +struct IteratorTraits { + typedef typename Iterator::value_type value_type; +}; + +template +struct IteratorTraits { + typedef T value_type; +}; + +template +struct IteratorTraits { + typedef T value_type; +}; + +#if GTEST_OS_WINDOWS +# define GTEST_PATH_SEP_ "\\" +# define GTEST_HAS_ALT_PATH_SEP_ 1 +// The biggest signed integer type the compiler supports. +typedef __int64 BiggestInt; +#else +# define GTEST_PATH_SEP_ "/" +# define GTEST_HAS_ALT_PATH_SEP_ 0 +typedef long long BiggestInt; // NOLINT +#endif // GTEST_OS_WINDOWS + +// Utilities for char. + +// isspace(int ch) and friends accept an unsigned char or EOF. char +// may be signed, depending on the compiler (or compiler flags). +// Therefore we need to cast a char to unsigned char before calling +// isspace(), etc. + +inline bool IsAlpha(char ch) { + return isalpha(static_cast(ch)) != 0; +} +inline bool IsAlNum(char ch) { + return isalnum(static_cast(ch)) != 0; +} +inline bool IsDigit(char ch) { + return isdigit(static_cast(ch)) != 0; +} +inline bool IsLower(char ch) { + return islower(static_cast(ch)) != 0; +} +inline bool IsSpace(char ch) { + return isspace(static_cast(ch)) != 0; +} +inline bool IsUpper(char ch) { + return isupper(static_cast(ch)) != 0; +} +inline bool IsXDigit(char ch) { + return isxdigit(static_cast(ch)) != 0; +} +inline bool IsXDigit(wchar_t ch) { + const unsigned char low_byte = static_cast(ch); + return ch == low_byte && isxdigit(low_byte) != 0; +} + +inline char ToLower(char ch) { + return static_cast(tolower(static_cast(ch))); +} +inline char ToUpper(char ch) { + return static_cast(toupper(static_cast(ch))); +} + +inline std::string StripTrailingSpaces(std::string str) { + std::string::iterator it = str.end(); + while (it != str.begin() && IsSpace(*--it)) + it = str.erase(it); + return str; +} + +// The testing::internal::posix namespace holds wrappers for common +// POSIX functions. These wrappers hide the differences between +// Windows/MSVC and POSIX systems. Since some compilers define these +// standard functions as macros, the wrapper cannot have the same name +// as the wrapped function. + +namespace posix { + +// Functions with a different name on Windows. + +#if GTEST_OS_WINDOWS + +typedef struct _stat StatStruct; + +# ifdef __BORLANDC__ +inline int IsATTY(int fd) { return isatty(fd); } +inline int StrCaseCmp(const char* s1, const char* s2) { + return stricmp(s1, s2); +} +inline char* StrDup(const char* src) { return strdup(src); } +# else // !__BORLANDC__ +# if GTEST_OS_WINDOWS_MOBILE +inline int IsATTY(int /* fd */) { return 0; } +# else +inline int IsATTY(int fd) { return _isatty(fd); } +# endif // GTEST_OS_WINDOWS_MOBILE +inline int StrCaseCmp(const char* s1, const char* s2) { + return _stricmp(s1, s2); +} +inline char* StrDup(const char* src) { return _strdup(src); } +# endif // __BORLANDC__ + +# if GTEST_OS_WINDOWS_MOBILE +inline int FileNo(FILE* file) { return reinterpret_cast(_fileno(file)); } +// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this +// time and thus not defined there. +# else +inline int FileNo(FILE* file) { return _fileno(file); } +inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } +inline int RmDir(const char* dir) { return _rmdir(dir); } +inline bool IsDir(const StatStruct& st) { + return (_S_IFDIR & st.st_mode) != 0; +} +# endif // GTEST_OS_WINDOWS_MOBILE + +#else + +typedef struct stat StatStruct; + +inline int FileNo(FILE* file) { return fileno(file); } +inline int IsATTY(int fd) { return isatty(fd); } +inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } +inline int StrCaseCmp(const char* s1, const char* s2) { + return strcasecmp(s1, s2); +} +inline char* StrDup(const char* src) { return strdup(src); } +inline int RmDir(const char* dir) { return rmdir(dir); } +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } + +#endif // GTEST_OS_WINDOWS + +// Functions deprecated by MSVC 8.0. + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */) + +inline const char* StrNCpy(char* dest, const char* src, size_t n) { + return strncpy(dest, src, n); +} + +// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and +// StrError() aren't needed on Windows CE at this time and thus not +// defined there. + +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT +inline int ChDir(const char* dir) { return chdir(dir); } +#endif +inline FILE* FOpen(const char* path, const char* mode) { + return fopen(path, mode); +} +#if !GTEST_OS_WINDOWS_MOBILE +inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { + return freopen(path, mode, stream); +} +inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } +#endif +inline int FClose(FILE* fp) { return fclose(fp); } +#if !GTEST_OS_WINDOWS_MOBILE +inline int Read(int fd, void* buf, unsigned int count) { + return static_cast(read(fd, buf, count)); +} +inline int Write(int fd, const void* buf, unsigned int count) { + return static_cast(write(fd, buf, count)); +} +inline int Close(int fd) { return close(fd); } +inline const char* StrError(int errnum) { return strerror(errnum); } +#endif +inline const char* GetEnv(const char* name) { +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT + // We are on Windows CE, which has no environment variables. + static_cast(name); // To prevent 'unused argument' warning. + return NULL; +#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) + // Environment variables which we programmatically clear will be set to the + // empty string rather than unset (NULL). Handle that case. + const char* const env = getenv(name); + return (env != NULL && env[0] != '\0') ? env : NULL; +#else + return getenv(name); +#endif +} + +GTEST_DISABLE_MSC_WARNINGS_POP_() + +#if GTEST_OS_WINDOWS_MOBILE +// Windows CE has no C library. The abort() function is used in +// several places in Google Test. This implementation provides a reasonable +// imitation of standard behaviour. +void Abort(); +#else +inline void Abort() { abort(); } +#endif // GTEST_OS_WINDOWS_MOBILE + +} // namespace posix + +// MSVC "deprecates" snprintf and issues warnings wherever it is used. In +// order to avoid these warnings, we need to use _snprintf or _snprintf_s on +// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate +// function in order to achieve that. We use macro definition here because +// snprintf is a variadic function. +#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE +// MSVC 2005 and above support variadic macros. +# define GTEST_SNPRINTF_(buffer, size, format, ...) \ + _snprintf_s(buffer, size, size, format, __VA_ARGS__) +#elif defined(_MSC_VER) +// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't +// complain about _snprintf. +# define GTEST_SNPRINTF_ _snprintf +#else +# define GTEST_SNPRINTF_ snprintf +#endif + +// The maximum number a BiggestInt can represent. This definition +// works no matter BiggestInt is represented in one's complement or +// two's complement. +// +// We cannot rely on numeric_limits in STL, as __int64 and long long +// are not part of standard C++ and numeric_limits doesn't need to be +// defined for them. +const BiggestInt kMaxBiggestInt = + ~(static_cast(1) << (8*sizeof(BiggestInt) - 1)); + +// This template class serves as a compile-time function from size to +// type. It maps a size in bytes to a primitive type with that +// size. e.g. +// +// TypeWithSize<4>::UInt +// +// is typedef-ed to be unsigned int (unsigned integer made up of 4 +// bytes). +// +// Such functionality should belong to STL, but I cannot find it +// there. +// +// Google Test uses this class in the implementation of floating-point +// comparison. +// +// For now it only handles UInt (unsigned int) as that's all Google Test +// needs. Other types can be easily added in the future if need +// arises. +template +class TypeWithSize { + public: + // This prevents the user from using TypeWithSize with incorrect + // values of N. + typedef void UInt; +}; + +// The specialization for size 4. +template <> +class TypeWithSize<4> { + public: + // unsigned int has size 4 in both gcc and MSVC. + // + // As base/basictypes.h doesn't compile on Windows, we cannot use + // uint32, uint64, and etc here. + typedef int Int; + typedef unsigned int UInt; +}; + +// The specialization for size 8. +template <> +class TypeWithSize<8> { + public: +#if GTEST_OS_WINDOWS + typedef __int64 Int; + typedef unsigned __int64 UInt; +#else + typedef long long Int; // NOLINT + typedef unsigned long long UInt; // NOLINT +#endif // GTEST_OS_WINDOWS +}; + +// Integer types of known sizes. +typedef TypeWithSize<4>::Int Int32; +typedef TypeWithSize<4>::UInt UInt32; +typedef TypeWithSize<8>::Int Int64; +typedef TypeWithSize<8>::UInt UInt64; +typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. + +// Utilities for command line flags and environment variables. + +// Macro for referencing flags. +#if !defined(GTEST_FLAG) +# define GTEST_FLAG(name) FLAGS_gtest_##name +#endif // !defined(GTEST_FLAG) + +#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) +# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 +#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) + +#if !defined(GTEST_DECLARE_bool_) +# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver + +// Macros for declaring flags. +# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) +# define GTEST_DECLARE_int32_(name) \ + GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) +#define GTEST_DECLARE_string_(name) \ + GTEST_API_ extern ::std::string GTEST_FLAG(name) + +// Macros for defining flags. +#define GTEST_DEFINE_bool_(name, default_val, doc) \ + GTEST_API_ bool GTEST_FLAG(name) = (default_val) +#define GTEST_DEFINE_int32_(name, default_val, doc) \ + GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) +#define GTEST_DEFINE_string_(name, default_val, doc) \ + GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) + +#endif // !defined(GTEST_DECLARE_bool_) + +// Thread annotations +#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) +# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) +# define GTEST_LOCK_EXCLUDED_(locks) +#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) + +// Parses 'str' for a 32-bit signed integer. If successful, writes the result +// to *value and returns true; otherwise leaves *value unchanged and returns +// false. +// TODO(chandlerc): Find a better way to refactor flag and environment parsing +// out of both gtest-port.cc and gtest.cc to avoid exporting this utility +// function. +bool ParseInt32(const Message& src_text, const char* str, Int32* value); + +// Parses a bool/Int32/string from the environment variable +// corresponding to the given Google Test flag. +bool BoolFromGTestEnv(const char* flag, bool default_val); +GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); +std::string StringFromGTestEnv(const char* flag, const char* default_val); + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ diff --git a/TestMothur/gtest-printers.cc b/TestMothur/gtest-printers.cc new file mode 100755 index 00000000..ea12bf7c --- /dev/null +++ b/TestMothur/gtest-printers.cc @@ -0,0 +1,373 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Test - The Google C++ Testing Framework +// +// This file implements a universal value printer that can print a +// value of any type T: +// +// void ::testing::internal::UniversalPrinter::Print(value, ostream_ptr); +// +// It uses the << operator when possible, and prints the bytes in the +// object otherwise. A user can override its behavior for a class +// type Foo by defining either operator<<(::std::ostream&, const Foo&) +// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that +// defines Foo. + +#include "gtest-printers.h" +#include +#include +#include +#include // NOLINT +#include +#include "gtest-port.h" + +namespace testing { + +namespace { + +using ::std::ostream; + +// Prints a segment of bytes in the given object. +GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start, + size_t count, ostream* os) { + char text[5] = ""; + for (size_t i = 0; i != count; i++) { + const size_t j = start + i; + if (i != 0) { + // Organizes the bytes into groups of 2 for easy parsing by + // human. + if ((j % 2) == 0) + *os << ' '; + else + *os << '-'; + } + GTEST_SNPRINTF_(text, sizeof(text), "%02X", obj_bytes[j]); + *os << text; + } +} + +// Prints the bytes in the given value to the given ostream. +void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count, + ostream* os) { + // Tells the user how big the object is. + *os << count << "-byte object <"; + + const size_t kThreshold = 132; + const size_t kChunkSize = 64; + // If the object size is bigger than kThreshold, we'll have to omit + // some details by printing only the first and the last kChunkSize + // bytes. + // TODO(wan): let the user control the threshold using a flag. + if (count < kThreshold) { + PrintByteSegmentInObjectTo(obj_bytes, 0, count, os); + } else { + PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os); + *os << " ... "; + // Rounds up to 2-byte boundary. + const size_t resume_pos = (count - kChunkSize + 1)/2*2; + PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os); + } + *os << ">"; +} + +} // namespace + +namespace internal2 { + +// Delegates to PrintBytesInObjectToImpl() to print the bytes in the +// given object. The delegation simplifies the implementation, which +// uses the << operator and thus is easier done outside of the +// ::testing::internal namespace, which contains a << operator that +// sometimes conflicts with the one in STL. +void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count, + ostream* os) { + PrintBytesInObjectToImpl(obj_bytes, count, os); +} + +} // namespace internal2 + +namespace internal { + +// Depending on the value of a char (or wchar_t), we print it in one +// of three formats: +// - as is if it's a printable ASCII (e.g. 'a', '2', ' '), +// - as a hexidecimal escape sequence (e.g. '\x7F'), or +// - as a special escape sequence (e.g. '\r', '\n'). +enum CharFormat { + kAsIs, + kHexEscape, + kSpecialEscape +}; + +// Returns true if c is a printable ASCII character. We test the +// value of c directly instead of calling isprint(), which is buggy on +// Windows Mobile. +inline bool IsPrintableAscii(wchar_t c) { + return 0x20 <= c && c <= 0x7E; +} + +// Prints a wide or narrow char c as a character literal without the +// quotes, escaping it when necessary; returns how c was formatted. +// The template argument UnsignedChar is the unsigned version of Char, +// which is the type of c. +template +static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) { + switch (static_cast(c)) { + case L'\0': + *os << "\\0"; + break; + case L'\'': + *os << "\\'"; + break; + case L'\\': + *os << "\\\\"; + break; + case L'\a': + *os << "\\a"; + break; + case L'\b': + *os << "\\b"; + break; + case L'\f': + *os << "\\f"; + break; + case L'\n': + *os << "\\n"; + break; + case L'\r': + *os << "\\r"; + break; + case L'\t': + *os << "\\t"; + break; + case L'\v': + *os << "\\v"; + break; + default: + if (IsPrintableAscii(c)) { + *os << static_cast(c); + return kAsIs; + } else { + *os << "\\x" + String::FormatHexInt(static_cast(c)); + return kHexEscape; + } + } + return kSpecialEscape; +} + +// Prints a wchar_t c as if it's part of a string literal, escaping it when +// necessary; returns how c was formatted. +static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) { + switch (c) { + case L'\'': + *os << "'"; + return kAsIs; + case L'"': + *os << "\\\""; + return kSpecialEscape; + default: + return PrintAsCharLiteralTo(c, os); + } +} + +// Prints a char c as if it's part of a string literal, escaping it when +// necessary; returns how c was formatted. +static CharFormat PrintAsStringLiteralTo(char c, ostream* os) { + return PrintAsStringLiteralTo( + static_cast(static_cast(c)), os); +} + +// Prints a wide or narrow character c and its code. '\0' is printed +// as "'\\0'", other unprintable characters are also properly escaped +// using the standard C++ escape sequence. The template argument +// UnsignedChar is the unsigned version of Char, which is the type of c. +template +void PrintCharAndCodeTo(Char c, ostream* os) { + // First, print c as a literal in the most readable form we can find. + *os << ((sizeof(c) > 1) ? "L'" : "'"); + const CharFormat format = PrintAsCharLiteralTo(c, os); + *os << "'"; + + // To aid user debugging, we also print c's code in decimal, unless + // it's 0 (in which case c was printed as '\\0', making the code + // obvious). + if (c == 0) + return; + *os << " (" << static_cast(c); + + // For more convenience, we print c's code again in hexidecimal, + // unless c was already printed in the form '\x##' or the code is in + // [1, 9]. + if (format == kHexEscape || (1 <= c && c <= 9)) { + // Do nothing. + } else { + *os << ", 0x" << String::FormatHexInt(static_cast(c)); + } + *os << ")"; +} + +void PrintTo(unsigned char c, ::std::ostream* os) { + PrintCharAndCodeTo(c, os); +} +void PrintTo(signed char c, ::std::ostream* os) { + PrintCharAndCodeTo(c, os); +} + +// Prints a wchar_t as a symbol if it is printable or as its internal +// code otherwise and also as its code. L'\0' is printed as "L'\\0'". +void PrintTo(wchar_t wc, ostream* os) { + PrintCharAndCodeTo(wc, os); +} + +// Prints the given array of characters to the ostream. CharType must be either +// char or wchar_t. +// The array starts at begin, the length is len, it may include '\0' characters +// and may not be NUL-terminated. +template +GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +static void PrintCharsAsStringTo( + const CharType* begin, size_t len, ostream* os) { + const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\""; + *os << kQuoteBegin; + bool is_previous_hex = false; + for (size_t index = 0; index < len; ++index) { + const CharType cur = begin[index]; + if (is_previous_hex && IsXDigit(cur)) { + // Previous character is of '\x..' form and this character can be + // interpreted as another hexadecimal digit in its number. Break string to + // disambiguate. + *os << "\" " << kQuoteBegin; + } + is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape; + } + *os << "\""; +} + +// Prints a (const) char/wchar_t array of 'len' elements, starting at address +// 'begin'. CharType must be either char or wchar_t. +template +GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +static void UniversalPrintCharArray( + const CharType* begin, size_t len, ostream* os) { + // The code + // const char kFoo[] = "foo"; + // generates an array of 4, not 3, elements, with the last one being '\0'. + // + // Therefore when printing a char array, we don't print the last element if + // it's '\0', such that the output matches the string literal as it's + // written in the source code. + if (len > 0 && begin[len - 1] == '\0') { + PrintCharsAsStringTo(begin, len - 1, os); + return; + } + + // If, however, the last element in the array is not '\0', e.g. + // const char kFoo[] = { 'f', 'o', 'o' }; + // we must print the entire array. We also print a message to indicate + // that the array is not NUL-terminated. + PrintCharsAsStringTo(begin, len, os); + *os << " (no terminating NUL)"; +} + +// Prints a (const) char array of 'len' elements, starting at address 'begin'. +void UniversalPrintArray(const char* begin, size_t len, ostream* os) { + UniversalPrintCharArray(begin, len, os); +} + +// Prints a (const) wchar_t array of 'len' elements, starting at address +// 'begin'. +void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) { + UniversalPrintCharArray(begin, len, os); +} + +// Prints the given C string to the ostream. +void PrintTo(const char* s, ostream* os) { + if (s == NULL) { + *os << "NULL"; + } else { + *os << ImplicitCast_(s) << " pointing to "; + PrintCharsAsStringTo(s, strlen(s), os); + } +} + +// MSVC compiler can be configured to define whar_t as a typedef +// of unsigned short. Defining an overload for const wchar_t* in that case +// would cause pointers to unsigned shorts be printed as wide strings, +// possibly accessing more memory than intended and causing invalid +// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when +// wchar_t is implemented as a native type. +#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) +// Prints the given wide C string to the ostream. +void PrintTo(const wchar_t* s, ostream* os) { + if (s == NULL) { + *os << "NULL"; + } else { + *os << ImplicitCast_(s) << " pointing to "; + PrintCharsAsStringTo(s, std::wcslen(s), os); + } +} +#endif // wchar_t is native + +// Prints a ::string object. +#if GTEST_HAS_GLOBAL_STRING +void PrintStringTo(const ::string& s, ostream* os) { + PrintCharsAsStringTo(s.data(), s.size(), os); +} +#endif // GTEST_HAS_GLOBAL_STRING + +void PrintStringTo(const ::std::string& s, ostream* os) { + PrintCharsAsStringTo(s.data(), s.size(), os); +} + +// Prints a ::wstring object. +#if GTEST_HAS_GLOBAL_WSTRING +void PrintWideStringTo(const ::wstring& s, ostream* os) { + PrintCharsAsStringTo(s.data(), s.size(), os); +} +#endif // GTEST_HAS_GLOBAL_WSTRING + +#if GTEST_HAS_STD_WSTRING +void PrintWideStringTo(const ::std::wstring& s, ostream* os) { + PrintCharsAsStringTo(s.data(), s.size(), os); +} +#endif // GTEST_HAS_STD_WSTRING + +} // namespace internal + +} // namespace testing diff --git a/TestMothur/gtest-printers.h b/TestMothur/gtest-printers.h new file mode 100755 index 00000000..92fda09a --- /dev/null +++ b/TestMothur/gtest-printers.h @@ -0,0 +1,993 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Google Test - The Google C++ Testing Framework +// +// This file implements a universal value printer that can print a +// value of any type T: +// +// void ::testing::internal::UniversalPrinter::Print(value, ostream_ptr); +// +// A user can teach this function how to print a class type T by +// defining either operator<<() or PrintTo() in the namespace that +// defines T. More specifically, the FIRST defined function in the +// following list will be used (assuming T is defined in namespace +// foo): +// +// 1. foo::PrintTo(const T&, ostream*) +// 2. operator<<(ostream&, const T&) defined in either foo or the +// global namespace. +// +// If none of the above is defined, it will print the debug string of +// the value if it is a protocol buffer, or print the raw bytes in the +// value otherwise. +// +// To aid debugging: when T is a reference type, the address of the +// value is also printed; when T is a (const) char pointer, both the +// pointer value and the NUL-terminated string it points to are +// printed. +// +// We also provide some convenient wrappers: +// +// // Prints a value to a string. For a (const or not) char +// // pointer, the NUL-terminated string (but not the pointer) is +// // printed. +// std::string ::testing::PrintToString(const T& value); +// +// // Prints a value tersely: for a reference type, the referenced +// // value (but not the address) is printed; for a (const or not) char +// // pointer, the NUL-terminated string (but not the pointer) is +// // printed. +// void ::testing::internal::UniversalTersePrint(const T& value, ostream*); +// +// // Prints value using the type inferred by the compiler. The difference +// // from UniversalTersePrint() is that this function prints both the +// // pointer and the NUL-terminated string for a (const or not) char pointer. +// void ::testing::internal::UniversalPrint(const T& value, ostream*); +// +// // Prints the fields of a tuple tersely to a string vector, one +// // element for each field. Tuple support must be enabled in +// // gtest-port.h. +// std::vector UniversalTersePrintTupleFieldsToStrings( +// const Tuple& value); +// +// Known limitation: +// +// The print primitives print the elements of an STL-style container +// using the compiler-inferred type of *iter where iter is a +// const_iterator of the container. When const_iterator is an input +// iterator but not a forward iterator, this inferred type may not +// match value_type, and the print output may be incorrect. In +// practice, this is rarely a problem as for most containers +// const_iterator is a forward iterator. We'll fix this if there's an +// actual need for it. Note that this fix cannot rely on value_type +// being defined as many user-defined container types don't have +// value_type. + +#ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ +#define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ + +#include // NOLINT +#include +#include +#include +#include +#include "gtest-port.h" +#include "gtest-internal.h" + +#if GTEST_HAS_STD_TUPLE_ +# include +#endif + +namespace testing { + +// Definitions in the 'internal' and 'internal2' name spaces are +// subject to change without notice. DO NOT USE THEM IN USER CODE! +namespace internal2 { + +// Prints the given number of bytes in the given object to the given +// ostream. +GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes, + size_t count, + ::std::ostream* os); + +// For selecting which printer to use when a given type has neither << +// nor PrintTo(). +enum TypeKind { + kProtobuf, // a protobuf type + kConvertibleToInteger, // a type implicitly convertible to BiggestInt + // (e.g. a named or unnamed enum type) + kOtherType // anything else +}; + +// TypeWithoutFormatter::PrintValue(value, os) is called +// by the universal printer to print a value of type T when neither +// operator<< nor PrintTo() is defined for T, where kTypeKind is the +// "kind" of T as defined by enum TypeKind. +template +class TypeWithoutFormatter { + public: + // This default version is called when kTypeKind is kOtherType. + static void PrintValue(const T& value, ::std::ostream* os) { + PrintBytesInObjectTo(reinterpret_cast(&value), + sizeof(value), os); + } +}; + +// We print a protobuf using its ShortDebugString() when the string +// doesn't exceed this many characters; otherwise we print it using +// DebugString() for better readability. +const size_t kProtobufOneLinerMaxLength = 50; + +template +class TypeWithoutFormatter { + public: + static void PrintValue(const T& value, ::std::ostream* os) { + const ::testing::internal::string short_str = value.ShortDebugString(); + const ::testing::internal::string pretty_str = + short_str.length() <= kProtobufOneLinerMaxLength ? + short_str : ("\n" + value.DebugString()); + *os << ("<" + pretty_str + ">"); + } +}; + +template +class TypeWithoutFormatter { + public: + // Since T has no << operator or PrintTo() but can be implicitly + // converted to BiggestInt, we print it as a BiggestInt. + // + // Most likely T is an enum type (either named or unnamed), in which + // case printing it as an integer is the desired behavior. In case + // T is not an enum, printing it as an integer is the best we can do + // given that it has no user-defined printer. + static void PrintValue(const T& value, ::std::ostream* os) { + const internal::BiggestInt kBigInt = value; + *os << kBigInt; + } +}; + +// Prints the given value to the given ostream. If the value is a +// protocol message, its debug string is printed; if it's an enum or +// of a type implicitly convertible to BiggestInt, it's printed as an +// integer; otherwise the bytes in the value are printed. This is +// what UniversalPrinter::Print() does when it knows nothing about +// type T and T has neither << operator nor PrintTo(). +// +// A user can override this behavior for a class type Foo by defining +// a << operator in the namespace where Foo is defined. +// +// We put this operator in namespace 'internal2' instead of 'internal' +// to simplify the implementation, as much code in 'internal' needs to +// use << in STL, which would conflict with our own << were it defined +// in 'internal'. +// +// Note that this operator<< takes a generic std::basic_ostream type instead of the more restricted std::ostream. If +// we define it to take an std::ostream instead, we'll get an +// "ambiguous overloads" compiler error when trying to print a type +// Foo that supports streaming to std::basic_ostream, as the compiler cannot tell whether +// operator<<(std::ostream&, const T&) or +// operator<<(std::basic_stream, const Foo&) is more +// specific. +template +::std::basic_ostream& operator<<( + ::std::basic_ostream& os, const T& x) { + TypeWithoutFormatter::value ? kProtobuf : + internal::ImplicitlyConvertible::value ? + kConvertibleToInteger : kOtherType)>::PrintValue(x, &os); + return os; +} + +} // namespace internal2 +} // namespace testing + +// This namespace MUST NOT BE NESTED IN ::testing, or the name look-up +// magic needed for implementing UniversalPrinter won't work. +namespace testing_internal { + +// Used to print a value that is not an STL-style container when the +// user doesn't define PrintTo() for it. +template +void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) { + // With the following statement, during unqualified name lookup, + // testing::internal2::operator<< appears as if it was declared in + // the nearest enclosing namespace that contains both + // ::testing_internal and ::testing::internal2, i.e. the global + // namespace. For more details, refer to the C++ Standard section + // 7.3.4-1 [namespace.udir]. This allows us to fall back onto + // testing::internal2::operator<< in case T doesn't come with a << + // operator. + // + // We cannot write 'using ::testing::internal2::operator<<;', which + // gcc 3.3 fails to compile due to a compiler bug. + using namespace ::testing::internal2; // NOLINT + + // Assuming T is defined in namespace foo, in the next statement, + // the compiler will consider all of: + // + // 1. foo::operator<< (thanks to Koenig look-up), + // 2. ::operator<< (as the current namespace is enclosed in ::), + // 3. testing::internal2::operator<< (thanks to the using statement above). + // + // The operator<< whose type matches T best will be picked. + // + // We deliberately allow #2 to be a candidate, as sometimes it's + // impossible to define #1 (e.g. when foo is ::std, defining + // anything in it is undefined behavior unless you are a compiler + // vendor.). + *os << value; +} + +} // namespace testing_internal + +namespace testing { +namespace internal { + +// FormatForComparison::Format(value) formats a +// value of type ToPrint that is an operand of a comparison assertion +// (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in +// the comparison, and is used to help determine the best way to +// format the value. In particular, when the value is a C string +// (char pointer) and the other operand is an STL string object, we +// want to format the C string as a string, since we know it is +// compared by value with the string object. If the value is a char +// pointer but the other operand is not an STL string object, we don't +// know whether the pointer is supposed to point to a NUL-terminated +// string, and thus want to print it as a pointer to be safe. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + +// The default case. +template +class FormatForComparison { + public: + static ::std::string Format(const ToPrint& value) { + return ::testing::PrintToString(value); + } +}; + +// Array. +template +class FormatForComparison { + public: + static ::std::string Format(const ToPrint* value) { + return FormatForComparison::Format(value); + } +}; + +// By default, print C string as pointers to be safe, as we don't know +// whether they actually point to a NUL-terminated string. + +#define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \ + template \ + class FormatForComparison { \ + public: \ + static ::std::string Format(CharType* value) { \ + return ::testing::PrintToString(static_cast(value)); \ + } \ + } + +GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char); +GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char); +GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t); +GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t); + +#undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_ + +// If a C string is compared with an STL string object, we know it's meant +// to point to a NUL-terminated string, and thus can print it as a string. + +#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \ + template <> \ + class FormatForComparison { \ + public: \ + static ::std::string Format(CharType* value) { \ + return ::testing::PrintToString(value); \ + } \ + } + +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string); +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string); + +#if GTEST_HAS_GLOBAL_STRING +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string); +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string); +#endif + +#if GTEST_HAS_GLOBAL_WSTRING +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring); +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring); +#endif + +#if GTEST_HAS_STD_WSTRING +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring); +GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring); +#endif + +#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_ + +// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) +// operand to be used in a failure message. The type (but not value) +// of the other operand may affect the format. This allows us to +// print a char* as a raw pointer when it is compared against another +// char* or void*, and print it as a C string when it is compared +// against an std::string object, for example. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +template +std::string FormatForComparisonFailureMessage( + const T1& value, const T2& /* other_operand */) { + return FormatForComparison::Format(value); +} + +// UniversalPrinter::Print(value, ostream_ptr) prints the given +// value to the given ostream. The caller must ensure that +// 'ostream_ptr' is not NULL, or the behavior is undefined. +// +// We define UniversalPrinter as a class template (as opposed to a +// function template), as we need to partially specialize it for +// reference types, which cannot be done with function templates. +template +class UniversalPrinter; + +template +void UniversalPrint(const T& value, ::std::ostream* os); + +// Used to print an STL-style container when the user doesn't define +// a PrintTo() for it. +template +void DefaultPrintTo(IsContainer /* dummy */, + false_type /* is not a pointer */, + const C& container, ::std::ostream* os) { + const size_t kMaxCount = 32; // The maximum number of elements to print. + *os << '{'; + size_t count = 0; + for (typename C::const_iterator it = container.begin(); + it != container.end(); ++it, ++count) { + if (count > 0) { + *os << ','; + if (count == kMaxCount) { // Enough has been printed. + *os << " ..."; + break; + } + } + *os << ' '; + // We cannot call PrintTo(*it, os) here as PrintTo() doesn't + // handle *it being a native array. + internal::UniversalPrint(*it, os); + } + + if (count > 0) { + *os << ' '; + } + *os << '}'; +} + +// Used to print a pointer that is neither a char pointer nor a member +// pointer, when the user doesn't define PrintTo() for it. (A member +// variable pointer or member function pointer doesn't really point to +// a location in the address space. Their representation is +// implementation-defined. Therefore they will be printed as raw +// bytes.) +template +void DefaultPrintTo(IsNotContainer /* dummy */, + true_type /* is a pointer */, + T* p, ::std::ostream* os) { + if (p == NULL) { + *os << "NULL"; + } else { + // C++ doesn't allow casting from a function pointer to any object + // pointer. + // + // IsTrue() silences warnings: "Condition is always true", + // "unreachable code". + if (IsTrue(ImplicitlyConvertible::value)) { + // T is not a function type. We just call << to print p, + // relying on ADL to pick up user-defined << for their pointer + // types, if any. + *os << p; + } else { + // T is a function type, so '*os << p' doesn't do what we want + // (it just prints p as bool). We want to print p as a const + // void*. However, we cannot cast it to const void* directly, + // even using reinterpret_cast, as earlier versions of gcc + // (e.g. 3.4.5) cannot compile the cast when p is a function + // pointer. Casting to UInt64 first solves the problem. + *os << reinterpret_cast( + reinterpret_cast(p)); + } + } +} + +// Used to print a non-container, non-pointer value when the user +// doesn't define PrintTo() for it. +template +void DefaultPrintTo(IsNotContainer /* dummy */, + false_type /* is not a pointer */, + const T& value, ::std::ostream* os) { + ::testing_internal::DefaultPrintNonContainerTo(value, os); +} + +// Prints the given value using the << operator if it has one; +// otherwise prints the bytes in it. This is what +// UniversalPrinter::Print() does when PrintTo() is not specialized +// or overloaded for type T. +// +// A user can override this behavior for a class type Foo by defining +// an overload of PrintTo() in the namespace where Foo is defined. We +// give the user this option as sometimes defining a << operator for +// Foo is not desirable (e.g. the coding style may prevent doing it, +// or there is already a << operator but it doesn't do what the user +// wants). +template +void PrintTo(const T& value, ::std::ostream* os) { + // DefaultPrintTo() is overloaded. The type of its first two + // arguments determine which version will be picked. If T is an + // STL-style container, the version for container will be called; if + // T is a pointer, the pointer version will be called; otherwise the + // generic version will be called. + // + // Note that we check for container types here, prior to we check + // for protocol message types in our operator<<. The rationale is: + // + // For protocol messages, we want to give people a chance to + // override Google Mock's format by defining a PrintTo() or + // operator<<. For STL containers, other formats can be + // incompatible with Google Mock's format for the container + // elements; therefore we check for container types here to ensure + // that our format is used. + // + // The second argument of DefaultPrintTo() is needed to bypass a bug + // in Symbian's C++ compiler that prevents it from picking the right + // overload between: + // + // PrintTo(const T& x, ...); + // PrintTo(T* x, ...); + DefaultPrintTo(IsContainerTest(0), is_pointer(), value, os); +} + +// The following list of PrintTo() overloads tells +// UniversalPrinter::Print() how to print standard types (built-in +// types, strings, plain arrays, and pointers). + +// Overloads for various char types. +GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os); +GTEST_API_ void PrintTo(signed char c, ::std::ostream* os); +inline void PrintTo(char c, ::std::ostream* os) { + // When printing a plain char, we always treat it as unsigned. This + // way, the output won't be affected by whether the compiler thinks + // char is signed or not. + PrintTo(static_cast(c), os); +} + +// Overloads for other simple built-in types. +inline void PrintTo(bool x, ::std::ostream* os) { + *os << (x ? "true" : "false"); +} + +// Overload for wchar_t type. +// Prints a wchar_t as a symbol if it is printable or as its internal +// code otherwise and also as its decimal code (except for L'\0'). +// The L'\0' char is printed as "L'\\0'". The decimal code is printed +// as signed integer when wchar_t is implemented by the compiler +// as a signed type and is printed as an unsigned integer when wchar_t +// is implemented as an unsigned type. +GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os); + +// Overloads for C strings. +GTEST_API_ void PrintTo(const char* s, ::std::ostream* os); +inline void PrintTo(char* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} + +// signed/unsigned char is often used for representing binary data, so +// we print pointers to it as void* to be safe. +inline void PrintTo(const signed char* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(signed char* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(const unsigned char* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(unsigned char* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} + +// MSVC can be configured to define wchar_t as a typedef of unsigned +// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native +// type. When wchar_t is a typedef, defining an overload for const +// wchar_t* would cause unsigned short* be printed as a wide string, +// possibly causing invalid memory accesses. +#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) +// Overloads for wide C strings +GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os); +inline void PrintTo(wchar_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +#endif + +// Overload for C arrays. Multi-dimensional arrays are printed +// properly. + +// Prints the given number of elements in an array, without printing +// the curly braces. +template +void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) { + UniversalPrint(a[0], os); + for (size_t i = 1; i != count; i++) { + *os << ", "; + UniversalPrint(a[i], os); + } +} + +// Overloads for ::string and ::std::string. +#if GTEST_HAS_GLOBAL_STRING +GTEST_API_ void PrintStringTo(const ::string&s, ::std::ostream* os); +inline void PrintTo(const ::string& s, ::std::ostream* os) { + PrintStringTo(s, os); +} +#endif // GTEST_HAS_GLOBAL_STRING + +GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os); +inline void PrintTo(const ::std::string& s, ::std::ostream* os) { + PrintStringTo(s, os); +} + +// Overloads for ::wstring and ::std::wstring. +#if GTEST_HAS_GLOBAL_WSTRING +GTEST_API_ void PrintWideStringTo(const ::wstring&s, ::std::ostream* os); +inline void PrintTo(const ::wstring& s, ::std::ostream* os) { + PrintWideStringTo(s, os); +} +#endif // GTEST_HAS_GLOBAL_WSTRING + +#if GTEST_HAS_STD_WSTRING +GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); +inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { + PrintWideStringTo(s, os); +} +#endif // GTEST_HAS_STD_WSTRING + +#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ +// Helper function for printing a tuple. T must be instantiated with +// a tuple type. +template +void PrintTupleTo(const T& t, ::std::ostream* os); +#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ + +#if GTEST_HAS_TR1_TUPLE +// Overload for ::std::tr1::tuple. Needed for printing function arguments, +// which are packed as tuples. + +// Overloaded PrintTo() for tuples of various arities. We support +// tuples of up-to 10 fields. The following implementation works +// regardless of whether tr1::tuple is implemented using the +// non-standard variadic template feature or not. + +inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo(const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} + +template +void PrintTo( + const ::std::tr1::tuple& t, + ::std::ostream* os) { + PrintTupleTo(t, os); +} +#endif // GTEST_HAS_TR1_TUPLE + +#if GTEST_HAS_STD_TUPLE_ +template +void PrintTo(const ::std::tuple& t, ::std::ostream* os) { + PrintTupleTo(t, os); +} +#endif // GTEST_HAS_STD_TUPLE_ + +// Overload for std::pair. +template +void PrintTo(const ::std::pair& value, ::std::ostream* os) { + *os << '('; + // We cannot use UniversalPrint(value.first, os) here, as T1 may be + // a reference type. The same for printing value.second. + UniversalPrinter::Print(value.first, os); + *os << ", "; + UniversalPrinter::Print(value.second, os); + *os << ')'; +} + +// Implements printing a non-reference type T by letting the compiler +// pick the right overload of PrintTo() for T. +template +class UniversalPrinter { + public: + // MSVC warns about adding const to a function type, so we want to + // disable the warning. + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180) + + // Note: we deliberately don't call this PrintTo(), as that name + // conflicts with ::testing::internal::PrintTo in the body of the + // function. + static void Print(const T& value, ::std::ostream* os) { + // By default, ::testing::internal::PrintTo() is used for printing + // the value. + // + // Thanks to Koenig look-up, if T is a class and has its own + // PrintTo() function defined in its namespace, that function will + // be visible here. Since it is more specific than the generic ones + // in ::testing::internal, it will be picked by the compiler in the + // following statement - exactly what we want. + PrintTo(value, os); + } + + GTEST_DISABLE_MSC_WARNINGS_POP_() +}; + +// UniversalPrintArray(begin, len, os) prints an array of 'len' +// elements, starting at address 'begin'. +template +void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { + if (len == 0) { + *os << "{}"; + } else { + *os << "{ "; + const size_t kThreshold = 18; + const size_t kChunkSize = 8; + // If the array has more than kThreshold elements, we'll have to + // omit some details by printing only the first and the last + // kChunkSize elements. + // TODO(wan@google.com): let the user control the threshold using a flag. + if (len <= kThreshold) { + PrintRawArrayTo(begin, len, os); + } else { + PrintRawArrayTo(begin, kChunkSize, os); + *os << ", ..., "; + PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os); + } + *os << " }"; + } +} +// This overload prints a (const) char array compactly. +GTEST_API_ void UniversalPrintArray( + const char* begin, size_t len, ::std::ostream* os); + +// This overload prints a (const) wchar_t array compactly. +GTEST_API_ void UniversalPrintArray( + const wchar_t* begin, size_t len, ::std::ostream* os); + +// Implements printing an array type T[N]. +template +class UniversalPrinter { + public: + // Prints the given array, omitting some elements when there are too + // many. + static void Print(const T (&a)[N], ::std::ostream* os) { + UniversalPrintArray(a, N, os); + } +}; + +// Implements printing a reference type T&. +template +class UniversalPrinter { + public: + // MSVC warns about adding const to a function type, so we want to + // disable the warning. + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4180) + + static void Print(const T& value, ::std::ostream* os) { + // Prints the address of the value. We use reinterpret_cast here + // as static_cast doesn't compile when T is a function type. + *os << "@" << reinterpret_cast(&value) << " "; + + // Then prints the value itself. + UniversalPrint(value, os); + } + + GTEST_DISABLE_MSC_WARNINGS_POP_() +}; + +// Prints a value tersely: for a reference type, the referenced value +// (but not the address) is printed; for a (const) char pointer, the +// NUL-terminated string (but not the pointer) is printed. + +template +class UniversalTersePrinter { + public: + static void Print(const T& value, ::std::ostream* os) { + UniversalPrint(value, os); + } +}; +template +class UniversalTersePrinter { + public: + static void Print(const T& value, ::std::ostream* os) { + UniversalPrint(value, os); + } +}; +template +class UniversalTersePrinter { + public: + static void Print(const T (&value)[N], ::std::ostream* os) { + UniversalPrinter::Print(value, os); + } +}; +template <> +class UniversalTersePrinter { + public: + static void Print(const char* str, ::std::ostream* os) { + if (str == NULL) { + *os << "NULL"; + } else { + UniversalPrint(string(str), os); + } + } +}; +template <> +class UniversalTersePrinter { + public: + static void Print(char* str, ::std::ostream* os) { + UniversalTersePrinter::Print(str, os); + } +}; + +#if GTEST_HAS_STD_WSTRING +template <> +class UniversalTersePrinter { + public: + static void Print(const wchar_t* str, ::std::ostream* os) { + if (str == NULL) { + *os << "NULL"; + } else { + UniversalPrint(::std::wstring(str), os); + } + } +}; +#endif + +template <> +class UniversalTersePrinter { + public: + static void Print(wchar_t* str, ::std::ostream* os) { + UniversalTersePrinter::Print(str, os); + } +}; + +template +void UniversalTersePrint(const T& value, ::std::ostream* os) { + UniversalTersePrinter::Print(value, os); +} + +// Prints a value using the type inferred by the compiler. The +// difference between this and UniversalTersePrint() is that for a +// (const) char pointer, this prints both the pointer and the +// NUL-terminated string. +template +void UniversalPrint(const T& value, ::std::ostream* os) { + // A workarond for the bug in VC++ 7.1 that prevents us from instantiating + // UniversalPrinter with T directly. + typedef T T1; + UniversalPrinter::Print(value, os); +} + +typedef ::std::vector Strings; + +// TuplePolicy must provide: +// - tuple_size +// size of tuple TupleT. +// - get(const TupleT& t) +// static function extracting element I of tuple TupleT. +// - tuple_element::type +// type of element I of tuple TupleT. +template +struct TuplePolicy; + +#if GTEST_HAS_TR1_TUPLE +template +struct TuplePolicy { + typedef TupleT Tuple; + static const size_t tuple_size = ::std::tr1::tuple_size::value; + + template + struct tuple_element : ::std::tr1::tuple_element {}; + + template + static typename AddReference< + const typename ::std::tr1::tuple_element::type>::type get( + const Tuple& tuple) { + return ::std::tr1::get(tuple); + } +}; +template +const size_t TuplePolicy::tuple_size; +#endif // GTEST_HAS_TR1_TUPLE + +#if GTEST_HAS_STD_TUPLE_ +template +struct TuplePolicy< ::std::tuple > { + typedef ::std::tuple Tuple; + static const size_t tuple_size = ::std::tuple_size::value; + + template + struct tuple_element : ::std::tuple_element {}; + + template + static const typename ::std::tuple_element::type& get( + const Tuple& tuple) { + return ::std::get(tuple); + } +}; +template +const size_t TuplePolicy< ::std::tuple >::tuple_size; +#endif // GTEST_HAS_STD_TUPLE_ + +#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ +// This helper template allows PrintTo() for tuples and +// UniversalTersePrintTupleFieldsToStrings() to be defined by +// induction on the number of tuple fields. The idea is that +// TuplePrefixPrinter::PrintPrefixTo(t, os) prints the first N +// fields in tuple t, and can be defined in terms of +// TuplePrefixPrinter. +// +// The inductive case. +template +struct TuplePrefixPrinter { + // Prints the first N fields of a tuple. + template + static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) { + TuplePrefixPrinter::PrintPrefixTo(t, os); + GTEST_INTENTIONAL_CONST_COND_PUSH_() + if (N > 1) { + GTEST_INTENTIONAL_CONST_COND_POP_() + *os << ", "; + } + UniversalPrinter< + typename TuplePolicy::template tuple_element::type> + ::Print(TuplePolicy::template get(t), os); + } + + // Tersely prints the first N fields of a tuple to a string vector, + // one element for each field. + template + static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) { + TuplePrefixPrinter::TersePrintPrefixToStrings(t, strings); + ::std::stringstream ss; + UniversalTersePrint(TuplePolicy::template get(t), &ss); + strings->push_back(ss.str()); + } +}; + +// Base case. +template <> +struct TuplePrefixPrinter<0> { + template + static void PrintPrefixTo(const Tuple&, ::std::ostream*) {} + + template + static void TersePrintPrefixToStrings(const Tuple&, Strings*) {} +}; + +// Helper function for printing a tuple. +// Tuple must be either std::tr1::tuple or std::tuple type. +template +void PrintTupleTo(const Tuple& t, ::std::ostream* os) { + *os << "("; + TuplePrefixPrinter::tuple_size>::PrintPrefixTo(t, os); + *os << ")"; +} + +// Prints the fields of a tuple tersely to a string vector, one +// element for each field. See the comment before +// UniversalTersePrint() for how we define "tersely". +template +Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { + Strings result; + TuplePrefixPrinter::tuple_size>:: + TersePrintPrefixToStrings(value, &result); + return result; +} +#endif // GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ + +} // namespace internal + +template +::std::string PrintToString(const T& value) { + ::std::stringstream ss; + internal::UniversalTersePrinter::Print(value, &ss); + return ss.str(); +} + +} // namespace testing + +// Include any custom printer added by the local installation. +// We must include this header at the end to make sure it can use the +// declarations from this file. +#include "custom/gtest-printers.h" + +#endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ diff --git a/TestMothur/gtest-spi.h b/TestMothur/gtest-spi.h new file mode 100755 index 00000000..e0384f8f --- /dev/null +++ b/TestMothur/gtest-spi.h @@ -0,0 +1,232 @@ +// Copyright 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// Utilities for testing Google Test itself and code that uses Google Test +// (e.g. frameworks built on top of Google Test). + +#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_ +#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_ + +#include "gtest.h" + +namespace testing { + +// This helper class can be used to mock out Google Test failure reporting +// so that we can test Google Test or code that builds on Google Test. +// +// An object of this class appends a TestPartResult object to the +// TestPartResultArray object given in the constructor whenever a Google Test +// failure is reported. It can either intercept only failures that are +// generated in the same thread that created this object or it can intercept +// all generated failures. The scope of this mock object can be controlled with +// the second argument to the two arguments constructor. +class GTEST_API_ ScopedFakeTestPartResultReporter + : public TestPartResultReporterInterface { + public: + // The two possible mocking modes of this object. + enum InterceptMode { + INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures. + INTERCEPT_ALL_THREADS // Intercepts all failures. + }; + + // The c'tor sets this object as the test part result reporter used + // by Google Test. The 'result' parameter specifies where to report the + // results. This reporter will only catch failures generated in the current + // thread. DEPRECATED + explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result); + + // Same as above, but you can choose the interception scope of this object. + ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, + TestPartResultArray* result); + + // The d'tor restores the previous test part result reporter. + virtual ~ScopedFakeTestPartResultReporter(); + + // Appends the TestPartResult object to the TestPartResultArray + // received in the constructor. + // + // This method is from the TestPartResultReporterInterface + // interface. + virtual void ReportTestPartResult(const TestPartResult& result); + private: + void Init(); + + const InterceptMode intercept_mode_; + TestPartResultReporterInterface* old_reporter_; + TestPartResultArray* const result_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); +}; + +namespace internal { + +// A helper class for implementing EXPECT_FATAL_FAILURE() and +// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given +// TestPartResultArray contains exactly one failure that has the given +// type and contains the given substring. If that's not the case, a +// non-fatal failure will be generated. +class GTEST_API_ SingleFailureChecker { + public: + // The constructor remembers the arguments. + SingleFailureChecker(const TestPartResultArray* results, + TestPartResult::Type type, + const string& substr); + ~SingleFailureChecker(); + private: + const TestPartResultArray* const results_; + const TestPartResult::Type type_; + const string substr_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); +}; + +} // namespace internal + +} // namespace testing + +// A set of macros for testing Google Test assertions or code that's expected +// to generate Google Test fatal failures. It verifies that the given +// statement will cause exactly one fatal Google Test failure with 'substr' +// being part of the failure message. +// +// There are two different versions of this macro. EXPECT_FATAL_FAILURE only +// affects and considers failures generated in the current thread and +// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. +// +// The verification of the assertion is done correctly even when the statement +// throws an exception or aborts the current function. +// +// Known restrictions: +// - 'statement' cannot reference local non-static variables or +// non-static members of the current object. +// - 'statement' cannot return a value. +// - You cannot stream a failure message to this macro. +// +// Note that even though the implementations of the following two +// macros are much alike, we cannot refactor them to use a common +// helper macro, due to some peculiarity in how the preprocessor +// works. The AcceptsMacroThatExpandsToUnprotectedComma test in +// gtest_unittest.cc will fail to compile if we do that. +#define EXPECT_FATAL_FAILURE(statement, substr) \ + do { \ + class GTestExpectFatalFailureHelper {\ + public:\ + static void Execute() { statement; }\ + };\ + ::testing::TestPartResultArray gtest_failures;\ + ::testing::internal::SingleFailureChecker gtest_checker(\ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ + {\ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ + ::testing::ScopedFakeTestPartResultReporter:: \ + INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ + GTestExpectFatalFailureHelper::Execute();\ + }\ + } while (::testing::internal::AlwaysFalse()) + +#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ + do { \ + class GTestExpectFatalFailureHelper {\ + public:\ + static void Execute() { statement; }\ + };\ + ::testing::TestPartResultArray gtest_failures;\ + ::testing::internal::SingleFailureChecker gtest_checker(\ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ + {\ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ + ::testing::ScopedFakeTestPartResultReporter:: \ + INTERCEPT_ALL_THREADS, >est_failures);\ + GTestExpectFatalFailureHelper::Execute();\ + }\ + } while (::testing::internal::AlwaysFalse()) + +// A macro for testing Google Test assertions or code that's expected to +// generate Google Test non-fatal failures. It asserts that the given +// statement will cause exactly one non-fatal Google Test failure with 'substr' +// being part of the failure message. +// +// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only +// affects and considers failures generated in the current thread and +// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads. +// +// 'statement' is allowed to reference local variables and members of +// the current object. +// +// The verification of the assertion is done correctly even when the statement +// throws an exception or aborts the current function. +// +// Known restrictions: +// - You cannot stream a failure message to this macro. +// +// Note that even though the implementations of the following two +// macros are much alike, we cannot refactor them to use a common +// helper macro, due to some peculiarity in how the preprocessor +// works. If we do that, the code won't compile when the user gives +// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that +// expands to code containing an unprotected comma. The +// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc +// catches that. +// +// For the same reason, we have to write +// if (::testing::internal::AlwaysTrue()) { statement; } +// instead of +// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) +// to avoid an MSVC warning on unreachable code. +#define EXPECT_NONFATAL_FAILURE(statement, substr) \ + do {\ + ::testing::TestPartResultArray gtest_failures;\ + ::testing::internal::SingleFailureChecker gtest_checker(\ + >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ + (substr));\ + {\ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ + ::testing::ScopedFakeTestPartResultReporter:: \ + INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ + if (::testing::internal::AlwaysTrue()) { statement; }\ + }\ + } while (::testing::internal::AlwaysFalse()) + +#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ + do {\ + ::testing::TestPartResultArray gtest_failures;\ + ::testing::internal::SingleFailureChecker gtest_checker(\ + >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ + (substr));\ + {\ + ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ + ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \ + >est_failures);\ + if (::testing::internal::AlwaysTrue()) { statement; }\ + }\ + } while (::testing::internal::AlwaysFalse()) + +#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_ diff --git a/TestMothur/gtest-string.h b/TestMothur/gtest-string.h new file mode 100755 index 00000000..e4aaf09c --- /dev/null +++ b/TestMothur/gtest-string.h @@ -0,0 +1,167 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file declares the String class and functions used internally by +// Google Test. They are subject to change without notice. They should not used +// by code external to Google Test. +// +// This header file is #included by . +// It should not be #included by other files. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ + +#ifdef __BORLANDC__ +// string.h is not guaranteed to provide strcpy on C++ Builder. +# include +#endif + +#include +#include + +#include "gtest-port.h" + +namespace testing { +namespace internal { + +// String - an abstract class holding static string utilities. +class GTEST_API_ String { + public: + // Static utility methods + + // Clones a 0-terminated C string, allocating memory using new. The + // caller is responsible for deleting the return value using + // delete[]. Returns the cloned string, or NULL if the input is + // NULL. + // + // This is different from strdup() in string.h, which allocates + // memory using malloc(). + static const char* CloneCString(const char* c_str); + +#if GTEST_OS_WINDOWS_MOBILE + // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be + // able to pass strings to Win32 APIs on CE we need to convert them + // to 'Unicode', UTF-16. + + // Creates a UTF-16 wide string from the given ANSI string, allocating + // memory using new. The caller is responsible for deleting the return + // value using delete[]. Returns the wide string, or NULL if the + // input is NULL. + // + // The wide string is created using the ANSI codepage (CP_ACP) to + // match the behaviour of the ANSI versions of Win32 calls and the + // C runtime. + static LPCWSTR AnsiToUtf16(const char* c_str); + + // Creates an ANSI string from the given wide string, allocating + // memory using new. The caller is responsible for deleting the return + // value using delete[]. Returns the ANSI string, or NULL if the + // input is NULL. + // + // The returned string is created using the ANSI codepage (CP_ACP) to + // match the behaviour of the ANSI versions of Win32 calls and the + // C runtime. + static const char* Utf16ToAnsi(LPCWSTR utf16_str); +#endif + + // Compares two C strings. Returns true iff they have the same content. + // + // Unlike strcmp(), this function can handle NULL argument(s). A + // NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool CStringEquals(const char* lhs, const char* rhs); + + // Converts a wide C string to a String using the UTF-8 encoding. + // NULL will be converted to "(null)". If an error occurred during + // the conversion, "(failed to convert from wide string)" is + // returned. + static std::string ShowWideCString(const wchar_t* wide_c_str); + + // Compares two wide C strings. Returns true iff they have the same + // content. + // + // Unlike wcscmp(), this function can handle NULL argument(s). A + // NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); + + // Compares two C strings, ignoring case. Returns true iff they + // have the same content. + // + // Unlike strcasecmp(), this function can handle NULL argument(s). + // A NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool CaseInsensitiveCStringEquals(const char* lhs, + const char* rhs); + + // Compares two wide C strings, ignoring case. Returns true iff they + // have the same content. + // + // Unlike wcscasecmp(), this function can handle NULL argument(s). + // A NULL C string is considered different to any non-NULL wide C string, + // including the empty string. + // NB: The implementations on different platforms slightly differ. + // On windows, this method uses _wcsicmp which compares according to LC_CTYPE + // environment variable. On GNU platform this method uses wcscasecmp + // which compares according to LC_CTYPE category of the current locale. + // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the + // current locale. + static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, + const wchar_t* rhs); + + // Returns true iff the given string ends with the given suffix, ignoring + // case. Any string is considered to end with an empty suffix. + static bool EndsWithCaseInsensitive( + const std::string& str, const std::string& suffix); + + // Formats an int value as "%02d". + static std::string FormatIntWidth2(int value); // "%02d" for width == 2 + + // Formats an int value as "%X". + static std::string FormatHexInt(int value); + + // Formats a byte as "%02X". + static std::string FormatByte(unsigned char value); + + private: + String(); // Not meant to be instantiated. +}; // class String + +// Gets the content of the stringstream's buffer as an std::string. Each '\0' +// character in the buffer is replaced with "\\0". +GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ diff --git a/TestMothur/gtest-test-part.cc b/TestMothur/gtest-test-part.cc new file mode 100755 index 00000000..8d083dfb --- /dev/null +++ b/TestMothur/gtest-test-part.cc @@ -0,0 +1,110 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: mheule@google.com (Markus Heule) +// +// The Google C++ Testing Framework (Google Test) + +#include "gtest-test-part.h" + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick exists to +// prevent the accidental inclusion of gtest-internal-inl.h in the +// user's code. +#define GTEST_IMPLEMENTATION_ 1 +#include "gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ + +namespace testing { + +using internal::GetUnitTestImpl; + +// Gets the summary of the failure message by omitting the stack trace +// in it. +std::string TestPartResult::ExtractSummary(const char* message) { + const char* const stack_trace = strstr(message, internal::kStackTraceMarker); + return stack_trace == NULL ? message : + std::string(message, stack_trace); +} + +// Prints a TestPartResult object. +std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { + return os + << result.file_name() << ":" << result.line_number() << ": " + << (result.type() == TestPartResult::kSuccess ? "Success" : + result.type() == TestPartResult::kFatalFailure ? "Fatal failure" : + "Non-fatal failure") << ":\n" + << result.message() << std::endl; +} + +// Appends a TestPartResult to the array. +void TestPartResultArray::Append(const TestPartResult& result) { + array_.push_back(result); +} + +// Returns the TestPartResult at the given index (0-based). +const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { + if (index < 0 || index >= size()) { + printf("\nInvalid index (%d) into TestPartResultArray.\n", index); + internal::posix::Abort(); + } + + return array_[index]; +} + +// Returns the number of TestPartResult objects in the array. +int TestPartResultArray::size() const { + return static_cast(array_.size()); +} + +namespace internal { + +HasNewFatalFailureHelper::HasNewFatalFailureHelper() + : has_new_fatal_failure_(false), + original_reporter_(GetUnitTestImpl()-> + GetTestPartResultReporterForCurrentThread()) { + GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); +} + +HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { + GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( + original_reporter_); +} + +void HasNewFatalFailureHelper::ReportTestPartResult( + const TestPartResult& result) { + if (result.fatally_failed()) + has_new_fatal_failure_ = true; + original_reporter_->ReportTestPartResult(result); +} + +} // namespace internal + +} // namespace testing diff --git a/TestMothur/gtest-test-part.h b/TestMothur/gtest-test-part.h new file mode 100755 index 00000000..70f774c7 --- /dev/null +++ b/TestMothur/gtest-test-part.h @@ -0,0 +1,179 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: mheule@google.com (Markus Heule) +// + +#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ +#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ + +#include +#include +#include "gtest-internal.h" +#include "gtest-string.h" + +namespace testing { + +// A copyable object representing the result of a test part (i.e. an +// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). +// +// Don't inherit from TestPartResult as its destructor is not virtual. +class GTEST_API_ TestPartResult { + public: + // The possible outcomes of a test part (i.e. an assertion or an + // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). + enum Type { + kSuccess, // Succeeded. + kNonFatalFailure, // Failed but the test can continue. + kFatalFailure // Failed and the test should be terminated. + }; + + // C'tor. TestPartResult does NOT have a default constructor. + // Always use this constructor (with parameters) to create a + // TestPartResult object. + TestPartResult(Type a_type, + const char* a_file_name, + int a_line_number, + const char* a_message) + : type_(a_type), + file_name_(a_file_name == NULL ? "" : a_file_name), + line_number_(a_line_number), + summary_(ExtractSummary(a_message)), + message_(a_message) { + } + + // Gets the outcome of the test part. + Type type() const { return type_; } + + // Gets the name of the source file where the test part took place, or + // NULL if it's unknown. + const char* file_name() const { + return file_name_.empty() ? NULL : file_name_.c_str(); + } + + // Gets the line in the source file where the test part took place, + // or -1 if it's unknown. + int line_number() const { return line_number_; } + + // Gets the summary of the failure message. + const char* summary() const { return summary_.c_str(); } + + // Gets the message associated with the test part. + const char* message() const { return message_.c_str(); } + + // Returns true iff the test part passed. + bool passed() const { return type_ == kSuccess; } + + // Returns true iff the test part failed. + bool failed() const { return type_ != kSuccess; } + + // Returns true iff the test part non-fatally failed. + bool nonfatally_failed() const { return type_ == kNonFatalFailure; } + + // Returns true iff the test part fatally failed. + bool fatally_failed() const { return type_ == kFatalFailure; } + + private: + Type type_; + + // Gets the summary of the failure message by omitting the stack + // trace in it. + static std::string ExtractSummary(const char* message); + + // The name of the source file where the test part took place, or + // "" if the source file is unknown. + std::string file_name_; + // The line in the source file where the test part took place, or -1 + // if the line number is unknown. + int line_number_; + std::string summary_; // The test failure summary. + std::string message_; // The test failure message. +}; + +// Prints a TestPartResult object. +std::ostream& operator<<(std::ostream& os, const TestPartResult& result); + +// An array of TestPartResult objects. +// +// Don't inherit from TestPartResultArray as its destructor is not +// virtual. +class GTEST_API_ TestPartResultArray { + public: + TestPartResultArray() {} + + // Appends the given TestPartResult to the array. + void Append(const TestPartResult& result); + + // Returns the TestPartResult at the given index (0-based). + const TestPartResult& GetTestPartResult(int index) const; + + // Returns the number of TestPartResult objects in the array. + int size() const; + + private: + std::vector array_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); +}; + +// This interface knows how to report a test part result. +class TestPartResultReporterInterface { + public: + virtual ~TestPartResultReporterInterface() {} + + virtual void ReportTestPartResult(const TestPartResult& result) = 0; +}; + +namespace internal { + +// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a +// statement generates new fatal failures. To do so it registers itself as the +// current test part result reporter. Besides checking if fatal failures were +// reported, it only delegates the reporting to the former result reporter. +// The original result reporter is restored in the destructor. +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +class GTEST_API_ HasNewFatalFailureHelper + : public TestPartResultReporterInterface { + public: + HasNewFatalFailureHelper(); + virtual ~HasNewFatalFailureHelper(); + virtual void ReportTestPartResult(const TestPartResult& result); + bool has_new_fatal_failure() const { return has_new_fatal_failure_; } + private: + bool has_new_fatal_failure_; + TestPartResultReporterInterface* original_reporter_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); +}; + +} // namespace internal + +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ diff --git a/TestMothur/gtest-tuple.h b/TestMothur/gtest-tuple.h new file mode 100755 index 00000000..e9b40534 --- /dev/null +++ b/TestMothur/gtest-tuple.h @@ -0,0 +1,1020 @@ +// This file was GENERATED by command: +// pump.py gtest-tuple.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2009 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Implements a subset of TR1 tuple needed by Google Test and Google Mock. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ + +#include // For ::std::pair. + +// The compiler used in Symbian has a bug that prevents us from declaring the +// tuple template as a friend (it complains that tuple is redefined). This +// hack bypasses the bug by declaring the members that should otherwise be +// private as public. +// Sun Studio versions < 12 also have the above bug. +#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: +#else +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ + template friend class tuple; \ + private: +#endif + +// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict +// with our own definitions. Therefore using our own tuple does not work on +// those compilers. +#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */ +# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \ +GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers." +#endif + +// GTEST_n_TUPLE_(T) is the type of an n-tuple. +#define GTEST_0_TUPLE_(T) tuple<> +#define GTEST_1_TUPLE_(T) tuple +#define GTEST_2_TUPLE_(T) tuple +#define GTEST_3_TUPLE_(T) tuple +#define GTEST_4_TUPLE_(T) tuple +#define GTEST_5_TUPLE_(T) tuple +#define GTEST_6_TUPLE_(T) tuple +#define GTEST_7_TUPLE_(T) tuple +#define GTEST_8_TUPLE_(T) tuple +#define GTEST_9_TUPLE_(T) tuple +#define GTEST_10_TUPLE_(T) tuple + +// GTEST_n_TYPENAMES_(T) declares a list of n typenames. +#define GTEST_0_TYPENAMES_(T) +#define GTEST_1_TYPENAMES_(T) typename T##0 +#define GTEST_2_TYPENAMES_(T) typename T##0, typename T##1 +#define GTEST_3_TYPENAMES_(T) typename T##0, typename T##1, typename T##2 +#define GTEST_4_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3 +#define GTEST_5_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4 +#define GTEST_6_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4, typename T##5 +#define GTEST_7_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4, typename T##5, typename T##6 +#define GTEST_8_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4, typename T##5, typename T##6, typename T##7 +#define GTEST_9_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4, typename T##5, typename T##6, \ + typename T##7, typename T##8 +#define GTEST_10_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \ + typename T##3, typename T##4, typename T##5, typename T##6, \ + typename T##7, typename T##8, typename T##9 + +// In theory, defining stuff in the ::std namespace is undefined +// behavior. We can do this as we are playing the role of a standard +// library vendor. +namespace std { +namespace tr1 { + +template +class tuple; + +// Anything in namespace gtest_internal is Google Test's INTERNAL +// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code. +namespace gtest_internal { + +// ByRef::type is T if T is a reference; otherwise it's const T&. +template +struct ByRef { typedef const T& type; }; // NOLINT +template +struct ByRef { typedef T& type; }; // NOLINT + +// A handy wrapper for ByRef. +#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef::type + +// AddRef::type is T if T is a reference; otherwise it's T&. This +// is the same as tr1::add_reference::type. +template +struct AddRef { typedef T& type; }; // NOLINT +template +struct AddRef { typedef T& type; }; // NOLINT + +// A handy wrapper for AddRef. +#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef::type + +// A helper for implementing get(). +template class Get; + +// A helper for implementing tuple_element. kIndexValid is true +// iff k < the number of fields in tuple type T. +template +struct TupleElement; + +template +struct TupleElement { + typedef T0 type; +}; + +template +struct TupleElement { + typedef T1 type; +}; + +template +struct TupleElement { + typedef T2 type; +}; + +template +struct TupleElement { + typedef T3 type; +}; + +template +struct TupleElement { + typedef T4 type; +}; + +template +struct TupleElement { + typedef T5 type; +}; + +template +struct TupleElement { + typedef T6 type; +}; + +template +struct TupleElement { + typedef T7 type; +}; + +template +struct TupleElement { + typedef T8 type; +}; + +template +struct TupleElement { + typedef T9 type; +}; + +} // namespace gtest_internal + +template <> +class tuple<> { + public: + tuple() {} + tuple(const tuple& /* t */) {} + tuple& operator=(const tuple& /* t */) { return *this; } +}; + +template +class GTEST_1_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {} + + tuple(const tuple& t) : f0_(t.f0_) {} + + template + tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_1_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_1_TUPLE_(U)& t) { + f0_ = t.f0_; + return *this; + } + + T0 f0_; +}; + +template +class GTEST_2_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0), + f1_(f1) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {} + + template + tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {} + template + tuple(const ::std::pair& p) : f0_(p.first), f1_(p.second) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_2_TUPLE_(U)& t) { + return CopyFrom(t); + } + template + tuple& operator=(const ::std::pair& p) { + f0_ = p.first; + f1_ = p.second; + return *this; + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_2_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + return *this; + } + + T0 f0_; + T1 f1_; +}; + +template +class GTEST_3_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {} + + template + tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_3_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_3_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; +}; + +template +class GTEST_4_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f2), + f3_(f3) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {} + + template + tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_4_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_4_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; +}; + +template +class GTEST_5_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, + GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_) {} + + template + tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_5_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_5_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; +}; + +template +class GTEST_6_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, + GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), + f5_(f5) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_), f5_(t.f5_) {} + + template + tuple(const GTEST_6_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_), f5_(t.f5_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_6_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_6_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + f5_ = t.f5_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; + T5 f5_; +}; + +template +class GTEST_7_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, + GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f2), + f3_(f3), f4_(f4), f5_(f5), f6_(f6) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {} + + template + tuple(const GTEST_7_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_7_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_7_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + f5_ = t.f5_; + f6_ = t.f6_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; + T5 f5_; + T6 f6_; +}; + +template +class GTEST_8_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, + GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, + GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), + f5_(f5), f6_(f6), f7_(f7) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {} + + template + tuple(const GTEST_8_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_8_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_8_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + f5_ = t.f5_; + f6_ = t.f6_; + f7_ = t.f7_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; + T5 f5_; + T6 f6_; + T7 f7_; +}; + +template +class GTEST_9_TUPLE_(T) { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, + GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7, + GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), + f5_(f5), f6_(f6), f7_(f7), f8_(f8) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {} + + template + tuple(const GTEST_9_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_9_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_9_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + f5_ = t.f5_; + f6_ = t.f6_; + f7_ = t.f7_; + f8_ = t.f8_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; + T5 f5_; + T6 f6_; + T7 f7_; + T8 f8_; +}; + +template +class tuple { + public: + template friend class gtest_internal::Get; + + tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(), + f9_() {} + + explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, + GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, + GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7, + GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f2), + f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {} + + tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), + f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_) {} + + template + tuple(const GTEST_10_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), + f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), + f9_(t.f9_) {} + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_10_TUPLE_(U)& t) { + return CopyFrom(t); + } + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_10_TUPLE_(U)& t) { + f0_ = t.f0_; + f1_ = t.f1_; + f2_ = t.f2_; + f3_ = t.f3_; + f4_ = t.f4_; + f5_ = t.f5_; + f6_ = t.f6_; + f7_ = t.f7_; + f8_ = t.f8_; + f9_ = t.f9_; + return *this; + } + + T0 f0_; + T1 f1_; + T2 f2_; + T3 f3_; + T4 f4_; + T5 f5_; + T6 f6_; + T7 f7_; + T8 f8_; + T9 f9_; +}; + +// 6.1.3.2 Tuple creation functions. + +// Known limitations: we don't support passing an +// std::tr1::reference_wrapper to make_tuple(). And we don't +// implement tie(). + +inline tuple<> make_tuple() { return tuple<>(); } + +template +inline GTEST_1_TUPLE_(T) make_tuple(const T0& f0) { + return GTEST_1_TUPLE_(T)(f0); +} + +template +inline GTEST_2_TUPLE_(T) make_tuple(const T0& f0, const T1& f1) { + return GTEST_2_TUPLE_(T)(f0, f1); +} + +template +inline GTEST_3_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2) { + return GTEST_3_TUPLE_(T)(f0, f1, f2); +} + +template +inline GTEST_4_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3) { + return GTEST_4_TUPLE_(T)(f0, f1, f2, f3); +} + +template +inline GTEST_5_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4) { + return GTEST_5_TUPLE_(T)(f0, f1, f2, f3, f4); +} + +template +inline GTEST_6_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4, const T5& f5) { + return GTEST_6_TUPLE_(T)(f0, f1, f2, f3, f4, f5); +} + +template +inline GTEST_7_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4, const T5& f5, const T6& f6) { + return GTEST_7_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6); +} + +template +inline GTEST_8_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7) { + return GTEST_8_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7); +} + +template +inline GTEST_9_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7, + const T8& f8) { + return GTEST_9_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8); +} + +template +inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2, + const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7, + const T8& f8, const T9& f9) { + return GTEST_10_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9); +} + +// 6.1.3.3 Tuple helper classes. + +template struct tuple_size; + +template +struct tuple_size { + static const int value = 0; +}; + +template +struct tuple_size { + static const int value = 1; +}; + +template +struct tuple_size { + static const int value = 2; +}; + +template +struct tuple_size { + static const int value = 3; +}; + +template +struct tuple_size { + static const int value = 4; +}; + +template +struct tuple_size { + static const int value = 5; +}; + +template +struct tuple_size { + static const int value = 6; +}; + +template +struct tuple_size { + static const int value = 7; +}; + +template +struct tuple_size { + static const int value = 8; +}; + +template +struct tuple_size { + static const int value = 9; +}; + +template +struct tuple_size { + static const int value = 10; +}; + +template +struct tuple_element { + typedef typename gtest_internal::TupleElement< + k < (tuple_size::value), k, Tuple>::type type; +}; + +#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element::type + +// 6.1.3.4 Element access. + +namespace gtest_internal { + +template <> +class Get<0> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple)) + Field(Tuple& t) { return t.f0_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple)) + ConstField(const Tuple& t) { return t.f0_; } +}; + +template <> +class Get<1> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple)) + Field(Tuple& t) { return t.f1_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple)) + ConstField(const Tuple& t) { return t.f1_; } +}; + +template <> +class Get<2> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple)) + Field(Tuple& t) { return t.f2_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple)) + ConstField(const Tuple& t) { return t.f2_; } +}; + +template <> +class Get<3> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple)) + Field(Tuple& t) { return t.f3_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple)) + ConstField(const Tuple& t) { return t.f3_; } +}; + +template <> +class Get<4> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple)) + Field(Tuple& t) { return t.f4_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple)) + ConstField(const Tuple& t) { return t.f4_; } +}; + +template <> +class Get<5> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple)) + Field(Tuple& t) { return t.f5_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple)) + ConstField(const Tuple& t) { return t.f5_; } +}; + +template <> +class Get<6> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple)) + Field(Tuple& t) { return t.f6_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple)) + ConstField(const Tuple& t) { return t.f6_; } +}; + +template <> +class Get<7> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple)) + Field(Tuple& t) { return t.f7_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple)) + ConstField(const Tuple& t) { return t.f7_; } +}; + +template <> +class Get<8> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple)) + Field(Tuple& t) { return t.f8_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple)) + ConstField(const Tuple& t) { return t.f8_; } +}; + +template <> +class Get<9> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple)) + Field(Tuple& t) { return t.f9_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple)) + ConstField(const Tuple& t) { return t.f9_; } +}; + +} // namespace gtest_internal + +template +GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T))) +get(GTEST_10_TUPLE_(T)& t) { + return gtest_internal::Get::Field(t); +} + +template +GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T))) +get(const GTEST_10_TUPLE_(T)& t) { + return gtest_internal::Get::ConstField(t); +} + +// 6.1.3.5 Relational operators + +// We only implement == and !=, as we don't have a need for the rest yet. + +namespace gtest_internal { + +// SameSizeTuplePrefixComparator::Eq(t1, t2) returns true if the +// first k fields of t1 equals the first k fields of t2. +// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if +// k1 != k2. +template +struct SameSizeTuplePrefixComparator; + +template <> +struct SameSizeTuplePrefixComparator<0, 0> { + template + static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) { + return true; + } +}; + +template +struct SameSizeTuplePrefixComparator { + template + static bool Eq(const Tuple1& t1, const Tuple2& t2) { + return SameSizeTuplePrefixComparator::Eq(t1, t2) && + ::std::tr1::get(t1) == ::std::tr1::get(t2); + } +}; + +} // namespace gtest_internal + +template +inline bool operator==(const GTEST_10_TUPLE_(T)& t, + const GTEST_10_TUPLE_(U)& u) { + return gtest_internal::SameSizeTuplePrefixComparator< + tuple_size::value, + tuple_size::value>::Eq(t, u); +} + +template +inline bool operator!=(const GTEST_10_TUPLE_(T)& t, + const GTEST_10_TUPLE_(U)& u) { return !(t == u); } + +// 6.1.4 Pairs. +// Unimplemented. + +} // namespace tr1 +} // namespace std + +#undef GTEST_0_TUPLE_ +#undef GTEST_1_TUPLE_ +#undef GTEST_2_TUPLE_ +#undef GTEST_3_TUPLE_ +#undef GTEST_4_TUPLE_ +#undef GTEST_5_TUPLE_ +#undef GTEST_6_TUPLE_ +#undef GTEST_7_TUPLE_ +#undef GTEST_8_TUPLE_ +#undef GTEST_9_TUPLE_ +#undef GTEST_10_TUPLE_ + +#undef GTEST_0_TYPENAMES_ +#undef GTEST_1_TYPENAMES_ +#undef GTEST_2_TYPENAMES_ +#undef GTEST_3_TYPENAMES_ +#undef GTEST_4_TYPENAMES_ +#undef GTEST_5_TYPENAMES_ +#undef GTEST_6_TYPENAMES_ +#undef GTEST_7_TYPENAMES_ +#undef GTEST_8_TYPENAMES_ +#undef GTEST_9_TYPENAMES_ +#undef GTEST_10_TYPENAMES_ + +#undef GTEST_DECLARE_TUPLE_AS_FRIEND_ +#undef GTEST_BY_REF_ +#undef GTEST_ADD_REF_ +#undef GTEST_TUPLE_ELEMENT_ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ diff --git a/TestMothur/gtest-tuple.h.pump b/TestMothur/gtest-tuple.h.pump new file mode 100755 index 00000000..429ddfee --- /dev/null +++ b/TestMothur/gtest-tuple.h.pump @@ -0,0 +1,347 @@ +$$ -*- mode: c++; -*- +$var n = 10 $$ Maximum number of tuple fields we want to support. +$$ This meta comment fixes auto-indentation in Emacs. }} +// Copyright 2009 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Implements a subset of TR1 tuple needed by Google Test and Google Mock. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ + +#include // For ::std::pair. + +// The compiler used in Symbian has a bug that prevents us from declaring the +// tuple template as a friend (it complains that tuple is redefined). This +// hack bypasses the bug by declaring the members that should otherwise be +// private as public. +// Sun Studio versions < 12 also have the above bug. +#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: +#else +# define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ + template friend class tuple; \ + private: +#endif + +// Visual Studio 2010, 2012, and 2013 define symbols in std::tr1 that conflict +// with our own definitions. Therefore using our own tuple does not work on +// those compilers. +#if defined(_MSC_VER) && _MSC_VER >= 1600 /* 1600 is Visual Studio 2010 */ +# error "gtest's tuple doesn't compile on Visual Studio 2010 or later. \ +GTEST_USE_OWN_TR1_TUPLE must be set to 0 on those compilers." +#endif + + +$range i 0..n-1 +$range j 0..n +$range k 1..n +// GTEST_n_TUPLE_(T) is the type of an n-tuple. +#define GTEST_0_TUPLE_(T) tuple<> + +$for k [[ +$range m 0..k-1 +$range m2 k..n-1 +#define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]> + +]] + +// GTEST_n_TYPENAMES_(T) declares a list of n typenames. + +$for j [[ +$range m 0..j-1 +#define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]] + + +]] + +// In theory, defining stuff in the ::std namespace is undefined +// behavior. We can do this as we are playing the role of a standard +// library vendor. +namespace std { +namespace tr1 { + +template <$for i, [[typename T$i = void]]> +class tuple; + +// Anything in namespace gtest_internal is Google Test's INTERNAL +// IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code. +namespace gtest_internal { + +// ByRef::type is T if T is a reference; otherwise it's const T&. +template +struct ByRef { typedef const T& type; }; // NOLINT +template +struct ByRef { typedef T& type; }; // NOLINT + +// A handy wrapper for ByRef. +#define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef::type + +// AddRef::type is T if T is a reference; otherwise it's T&. This +// is the same as tr1::add_reference::type. +template +struct AddRef { typedef T& type; }; // NOLINT +template +struct AddRef { typedef T& type; }; // NOLINT + +// A handy wrapper for AddRef. +#define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef::type + +// A helper for implementing get(). +template class Get; + +// A helper for implementing tuple_element. kIndexValid is true +// iff k < the number of fields in tuple type T. +template +struct TupleElement; + + +$for i [[ +template +struct TupleElement { + typedef T$i type; +}; + + +]] +} // namespace gtest_internal + +template <> +class tuple<> { + public: + tuple() {} + tuple(const tuple& /* t */) {} + tuple& operator=(const tuple& /* t */) { return *this; } +}; + + +$for k [[ +$range m 0..k-1 +template +class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] { + public: + template friend class gtest_internal::Get; + + tuple() : $for m, [[f$(m)_()]] {} + + explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]] +$for m, [[f$(m)_(f$m)]] {} + + tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} + + template + tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {} + +$if k == 2 [[ + template + tuple(const ::std::pair& p) : f0_(p.first), f1_(p.second) {} + +]] + + tuple& operator=(const tuple& t) { return CopyFrom(t); } + + template + tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) { + return CopyFrom(t); + } + +$if k == 2 [[ + template + tuple& operator=(const ::std::pair& p) { + f0_ = p.first; + f1_ = p.second; + return *this; + } + +]] + + GTEST_DECLARE_TUPLE_AS_FRIEND_ + + template + tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) { + +$for m [[ + f$(m)_ = t.f$(m)_; + +]] + return *this; + } + + +$for m [[ + T$m f$(m)_; + +]] +}; + + +]] +// 6.1.3.2 Tuple creation functions. + +// Known limitations: we don't support passing an +// std::tr1::reference_wrapper to make_tuple(). And we don't +// implement tie(). + +inline tuple<> make_tuple() { return tuple<>(); } + +$for k [[ +$range m 0..k-1 + +template +inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) { + return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]); +} + +]] + +// 6.1.3.3 Tuple helper classes. + +template struct tuple_size; + + +$for j [[ +template +struct tuple_size { + static const int value = $j; +}; + + +]] +template +struct tuple_element { + typedef typename gtest_internal::TupleElement< + k < (tuple_size::value), k, Tuple>::type type; +}; + +#define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element::type + +// 6.1.3.4 Element access. + +namespace gtest_internal { + + +$for i [[ +template <> +class Get<$i> { + public: + template + static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) + Field(Tuple& t) { return t.f$(i)_; } // NOLINT + + template + static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple)) + ConstField(const Tuple& t) { return t.f$(i)_; } +}; + + +]] +} // namespace gtest_internal + +template +GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) +get(GTEST_$(n)_TUPLE_(T)& t) { + return gtest_internal::Get::Field(t); +} + +template +GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T))) +get(const GTEST_$(n)_TUPLE_(T)& t) { + return gtest_internal::Get::ConstField(t); +} + +// 6.1.3.5 Relational operators + +// We only implement == and !=, as we don't have a need for the rest yet. + +namespace gtest_internal { + +// SameSizeTuplePrefixComparator::Eq(t1, t2) returns true if the +// first k fields of t1 equals the first k fields of t2. +// SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if +// k1 != k2. +template +struct SameSizeTuplePrefixComparator; + +template <> +struct SameSizeTuplePrefixComparator<0, 0> { + template + static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) { + return true; + } +}; + +template +struct SameSizeTuplePrefixComparator { + template + static bool Eq(const Tuple1& t1, const Tuple2& t2) { + return SameSizeTuplePrefixComparator::Eq(t1, t2) && + ::std::tr1::get(t1) == ::std::tr1::get(t2); + } +}; + +} // namespace gtest_internal + +template +inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t, + const GTEST_$(n)_TUPLE_(U)& u) { + return gtest_internal::SameSizeTuplePrefixComparator< + tuple_size::value, + tuple_size::value>::Eq(t, u); +} + +template +inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t, + const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); } + +// 6.1.4 Pairs. +// Unimplemented. + +} // namespace tr1 +} // namespace std + + +$for j [[ +#undef GTEST_$(j)_TUPLE_ + +]] + + +$for j [[ +#undef GTEST_$(j)_TYPENAMES_ + +]] + +#undef GTEST_DECLARE_TUPLE_AS_FRIEND_ +#undef GTEST_BY_REF_ +#undef GTEST_ADD_REF_ +#undef GTEST_TUPLE_ELEMENT_ + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ diff --git a/TestMothur/gtest-type-util.h b/TestMothur/gtest-type-util.h new file mode 100755 index 00000000..248362df --- /dev/null +++ b/TestMothur/gtest-type-util.h @@ -0,0 +1,3331 @@ +// This file was GENERATED by command: +// pump.py gtest-type-util.h.pump +// DO NOT EDIT BY HAND!!! + +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Type utilities needed for implementing typed and type-parameterized +// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +// Currently we support at most 50 types in a list, and at most 50 +// type-parameterized tests in one type-parameterized test case. +// Please contact googletestframework@googlegroups.com if you need +// more. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ + +#include "gtest-port.h" + +// #ifdef __GNUC__ is too general here. It is possible to use gcc without using +// libstdc++ (which is where cxxabi.h comes from). +# if GTEST_HAS_CXXABI_H_ +# include +# elif defined(__HP_aCC) +# include +# endif // GTEST_HASH_CXXABI_H_ + +namespace testing { +namespace internal { + +// GetTypeName() returns a human-readable name of type T. +// NB: This function is also used in Google Mock, so don't move it inside of +// the typed-test-only section below. +template +std::string GetTypeName() { +# if GTEST_HAS_RTTI + + const char* const name = typeid(T).name(); +# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) + int status = 0; + // gcc's implementation of typeid(T).name() mangles the type name, + // so we have to demangle it. +# if GTEST_HAS_CXXABI_H_ + using abi::__cxa_demangle; +# endif // GTEST_HAS_CXXABI_H_ + char* const readable_name = __cxa_demangle(name, 0, 0, &status); + const std::string name_str(status == 0 ? readable_name : name); + free(readable_name); + return name_str; +# else + return name; +# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC + +# else + + return ""; + +# endif // GTEST_HAS_RTTI +} + +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// AssertyTypeEq::type is defined iff T1 and T2 are the same +// type. This can be used as a compile-time assertion to ensure that +// two types are equal. + +template +struct AssertTypeEq; + +template +struct AssertTypeEq { + typedef bool type; +}; + +// A unique type used as the default value for the arguments of class +// template Types. This allows us to simulate variadic templates +// (e.g. Types, Type, and etc), which C++ doesn't +// support directly. +struct None {}; + +// The following family of struct and struct templates are used to +// represent type lists. In particular, TypesN +// represents a type list with N types (T1, T2, ..., and TN) in it. +// Except for Types0, every struct in the family has two member types: +// Head for the first type in the list, and Tail for the rest of the +// list. + +// The empty type list. +struct Types0 {}; + +// Type lists of length 1, 2, 3, and so on. + +template +struct Types1 { + typedef T1 Head; + typedef Types0 Tail; +}; +template +struct Types2 { + typedef T1 Head; + typedef Types1 Tail; +}; + +template +struct Types3 { + typedef T1 Head; + typedef Types2 Tail; +}; + +template +struct Types4 { + typedef T1 Head; + typedef Types3 Tail; +}; + +template +struct Types5 { + typedef T1 Head; + typedef Types4 Tail; +}; + +template +struct Types6 { + typedef T1 Head; + typedef Types5 Tail; +}; + +template +struct Types7 { + typedef T1 Head; + typedef Types6 Tail; +}; + +template +struct Types8 { + typedef T1 Head; + typedef Types7 Tail; +}; + +template +struct Types9 { + typedef T1 Head; + typedef Types8 Tail; +}; + +template +struct Types10 { + typedef T1 Head; + typedef Types9 Tail; +}; + +template +struct Types11 { + typedef T1 Head; + typedef Types10 Tail; +}; + +template +struct Types12 { + typedef T1 Head; + typedef Types11 Tail; +}; + +template +struct Types13 { + typedef T1 Head; + typedef Types12 Tail; +}; + +template +struct Types14 { + typedef T1 Head; + typedef Types13 Tail; +}; + +template +struct Types15 { + typedef T1 Head; + typedef Types14 Tail; +}; + +template +struct Types16 { + typedef T1 Head; + typedef Types15 Tail; +}; + +template +struct Types17 { + typedef T1 Head; + typedef Types16 Tail; +}; + +template +struct Types18 { + typedef T1 Head; + typedef Types17 Tail; +}; + +template +struct Types19 { + typedef T1 Head; + typedef Types18 Tail; +}; + +template +struct Types20 { + typedef T1 Head; + typedef Types19 Tail; +}; + +template +struct Types21 { + typedef T1 Head; + typedef Types20 Tail; +}; + +template +struct Types22 { + typedef T1 Head; + typedef Types21 Tail; +}; + +template +struct Types23 { + typedef T1 Head; + typedef Types22 Tail; +}; + +template +struct Types24 { + typedef T1 Head; + typedef Types23 Tail; +}; + +template +struct Types25 { + typedef T1 Head; + typedef Types24 Tail; +}; + +template +struct Types26 { + typedef T1 Head; + typedef Types25 Tail; +}; + +template +struct Types27 { + typedef T1 Head; + typedef Types26 Tail; +}; + +template +struct Types28 { + typedef T1 Head; + typedef Types27 Tail; +}; + +template +struct Types29 { + typedef T1 Head; + typedef Types28 Tail; +}; + +template +struct Types30 { + typedef T1 Head; + typedef Types29 Tail; +}; + +template +struct Types31 { + typedef T1 Head; + typedef Types30 Tail; +}; + +template +struct Types32 { + typedef T1 Head; + typedef Types31 Tail; +}; + +template +struct Types33 { + typedef T1 Head; + typedef Types32 Tail; +}; + +template +struct Types34 { + typedef T1 Head; + typedef Types33 Tail; +}; + +template +struct Types35 { + typedef T1 Head; + typedef Types34 Tail; +}; + +template +struct Types36 { + typedef T1 Head; + typedef Types35 Tail; +}; + +template +struct Types37 { + typedef T1 Head; + typedef Types36 Tail; +}; + +template +struct Types38 { + typedef T1 Head; + typedef Types37 Tail; +}; + +template +struct Types39 { + typedef T1 Head; + typedef Types38 Tail; +}; + +template +struct Types40 { + typedef T1 Head; + typedef Types39 Tail; +}; + +template +struct Types41 { + typedef T1 Head; + typedef Types40 Tail; +}; + +template +struct Types42 { + typedef T1 Head; + typedef Types41 Tail; +}; + +template +struct Types43 { + typedef T1 Head; + typedef Types42 Tail; +}; + +template +struct Types44 { + typedef T1 Head; + typedef Types43 Tail; +}; + +template +struct Types45 { + typedef T1 Head; + typedef Types44 Tail; +}; + +template +struct Types46 { + typedef T1 Head; + typedef Types45 Tail; +}; + +template +struct Types47 { + typedef T1 Head; + typedef Types46 Tail; +}; + +template +struct Types48 { + typedef T1 Head; + typedef Types47 Tail; +}; + +template +struct Types49 { + typedef T1 Head; + typedef Types48 Tail; +}; + +template +struct Types50 { + typedef T1 Head; + typedef Types49 Tail; +}; + + +} // namespace internal + +// We don't want to require the users to write TypesN<...> directly, +// as that would require them to count the length. Types<...> is much +// easier to write, but generates horrible messages when there is a +// compiler error, as gcc insists on printing out each template +// argument, even if it has the default value (this means Types +// will appear as Types in the compiler +// errors). +// +// Our solution is to combine the best part of the two approaches: a +// user would write Types, and Google Test will translate +// that to TypesN internally to make error messages +// readable. The translation is done by the 'type' member of the +// Types template. +template +struct Types { + typedef internal::Types50 type; +}; + +template <> +struct Types { + typedef internal::Types0 type; +}; +template +struct Types { + typedef internal::Types1 type; +}; +template +struct Types { + typedef internal::Types2 type; +}; +template +struct Types { + typedef internal::Types3 type; +}; +template +struct Types { + typedef internal::Types4 type; +}; +template +struct Types { + typedef internal::Types5 type; +}; +template +struct Types { + typedef internal::Types6 type; +}; +template +struct Types { + typedef internal::Types7 type; +}; +template +struct Types { + typedef internal::Types8 type; +}; +template +struct Types { + typedef internal::Types9 type; +}; +template +struct Types { + typedef internal::Types10 type; +}; +template +struct Types { + typedef internal::Types11 type; +}; +template +struct Types { + typedef internal::Types12 type; +}; +template +struct Types { + typedef internal::Types13 type; +}; +template +struct Types { + typedef internal::Types14 type; +}; +template +struct Types { + typedef internal::Types15 type; +}; +template +struct Types { + typedef internal::Types16 type; +}; +template +struct Types { + typedef internal::Types17 type; +}; +template +struct Types { + typedef internal::Types18 type; +}; +template +struct Types { + typedef internal::Types19 type; +}; +template +struct Types { + typedef internal::Types20 type; +}; +template +struct Types { + typedef internal::Types21 type; +}; +template +struct Types { + typedef internal::Types22 type; +}; +template +struct Types { + typedef internal::Types23 type; +}; +template +struct Types { + typedef internal::Types24 type; +}; +template +struct Types { + typedef internal::Types25 type; +}; +template +struct Types { + typedef internal::Types26 type; +}; +template +struct Types { + typedef internal::Types27 type; +}; +template +struct Types { + typedef internal::Types28 type; +}; +template +struct Types { + typedef internal::Types29 type; +}; +template +struct Types { + typedef internal::Types30 type; +}; +template +struct Types { + typedef internal::Types31 type; +}; +template +struct Types { + typedef internal::Types32 type; +}; +template +struct Types { + typedef internal::Types33 type; +}; +template +struct Types { + typedef internal::Types34 type; +}; +template +struct Types { + typedef internal::Types35 type; +}; +template +struct Types { + typedef internal::Types36 type; +}; +template +struct Types { + typedef internal::Types37 type; +}; +template +struct Types { + typedef internal::Types38 type; +}; +template +struct Types { + typedef internal::Types39 type; +}; +template +struct Types { + typedef internal::Types40 type; +}; +template +struct Types { + typedef internal::Types41 type; +}; +template +struct Types { + typedef internal::Types42 type; +}; +template +struct Types { + typedef internal::Types43 type; +}; +template +struct Types { + typedef internal::Types44 type; +}; +template +struct Types { + typedef internal::Types45 type; +}; +template +struct Types { + typedef internal::Types46 type; +}; +template +struct Types { + typedef internal::Types47 type; +}; +template +struct Types { + typedef internal::Types48 type; +}; +template +struct Types { + typedef internal::Types49 type; +}; + +namespace internal { + +# define GTEST_TEMPLATE_ template class + +// The template "selector" struct TemplateSel is used to +// represent Tmpl, which must be a class template with one type +// parameter, as a type. TemplateSel::Bind::type is defined +// as the type Tmpl. This allows us to actually instantiate the +// template "selected" by TemplateSel. +// +// This trick is necessary for simulating typedef for class templates, +// which C++ doesn't support directly. +template +struct TemplateSel { + template + struct Bind { + typedef Tmpl type; + }; +}; + +# define GTEST_BIND_(TmplSel, T) \ + TmplSel::template Bind::type + +// A unique struct template used as the default value for the +// arguments of class template Templates. This allows us to simulate +// variadic templates (e.g. Templates, Templates, +// and etc), which C++ doesn't support directly. +template +struct NoneT {}; + +// The following family of struct and struct templates are used to +// represent template lists. In particular, TemplatesN represents a list of N templates (T1, T2, ..., and TN). Except +// for Templates0, every struct in the family has two member types: +// Head for the selector of the first template in the list, and Tail +// for the rest of the list. + +// The empty template list. +struct Templates0 {}; + +// Template lists of length 1, 2, 3, and so on. + +template +struct Templates1 { + typedef TemplateSel Head; + typedef Templates0 Tail; +}; +template +struct Templates2 { + typedef TemplateSel Head; + typedef Templates1 Tail; +}; + +template +struct Templates3 { + typedef TemplateSel Head; + typedef Templates2 Tail; +}; + +template +struct Templates4 { + typedef TemplateSel Head; + typedef Templates3 Tail; +}; + +template +struct Templates5 { + typedef TemplateSel Head; + typedef Templates4 Tail; +}; + +template +struct Templates6 { + typedef TemplateSel Head; + typedef Templates5 Tail; +}; + +template +struct Templates7 { + typedef TemplateSel Head; + typedef Templates6 Tail; +}; + +template +struct Templates8 { + typedef TemplateSel Head; + typedef Templates7 Tail; +}; + +template +struct Templates9 { + typedef TemplateSel Head; + typedef Templates8 Tail; +}; + +template +struct Templates10 { + typedef TemplateSel Head; + typedef Templates9 Tail; +}; + +template +struct Templates11 { + typedef TemplateSel Head; + typedef Templates10 Tail; +}; + +template +struct Templates12 { + typedef TemplateSel Head; + typedef Templates11 Tail; +}; + +template +struct Templates13 { + typedef TemplateSel Head; + typedef Templates12 Tail; +}; + +template +struct Templates14 { + typedef TemplateSel Head; + typedef Templates13 Tail; +}; + +template +struct Templates15 { + typedef TemplateSel Head; + typedef Templates14 Tail; +}; + +template +struct Templates16 { + typedef TemplateSel Head; + typedef Templates15 Tail; +}; + +template +struct Templates17 { + typedef TemplateSel Head; + typedef Templates16 Tail; +}; + +template +struct Templates18 { + typedef TemplateSel Head; + typedef Templates17 Tail; +}; + +template +struct Templates19 { + typedef TemplateSel Head; + typedef Templates18 Tail; +}; + +template +struct Templates20 { + typedef TemplateSel Head; + typedef Templates19 Tail; +}; + +template +struct Templates21 { + typedef TemplateSel Head; + typedef Templates20 Tail; +}; + +template +struct Templates22 { + typedef TemplateSel Head; + typedef Templates21 Tail; +}; + +template +struct Templates23 { + typedef TemplateSel Head; + typedef Templates22 Tail; +}; + +template +struct Templates24 { + typedef TemplateSel Head; + typedef Templates23 Tail; +}; + +template +struct Templates25 { + typedef TemplateSel Head; + typedef Templates24 Tail; +}; + +template +struct Templates26 { + typedef TemplateSel Head; + typedef Templates25 Tail; +}; + +template +struct Templates27 { + typedef TemplateSel Head; + typedef Templates26 Tail; +}; + +template +struct Templates28 { + typedef TemplateSel Head; + typedef Templates27 Tail; +}; + +template +struct Templates29 { + typedef TemplateSel Head; + typedef Templates28 Tail; +}; + +template +struct Templates30 { + typedef TemplateSel Head; + typedef Templates29 Tail; +}; + +template +struct Templates31 { + typedef TemplateSel Head; + typedef Templates30 Tail; +}; + +template +struct Templates32 { + typedef TemplateSel Head; + typedef Templates31 Tail; +}; + +template +struct Templates33 { + typedef TemplateSel Head; + typedef Templates32 Tail; +}; + +template +struct Templates34 { + typedef TemplateSel Head; + typedef Templates33 Tail; +}; + +template +struct Templates35 { + typedef TemplateSel Head; + typedef Templates34 Tail; +}; + +template +struct Templates36 { + typedef TemplateSel Head; + typedef Templates35 Tail; +}; + +template +struct Templates37 { + typedef TemplateSel Head; + typedef Templates36 Tail; +}; + +template +struct Templates38 { + typedef TemplateSel Head; + typedef Templates37 Tail; +}; + +template +struct Templates39 { + typedef TemplateSel Head; + typedef Templates38 Tail; +}; + +template +struct Templates40 { + typedef TemplateSel Head; + typedef Templates39 Tail; +}; + +template +struct Templates41 { + typedef TemplateSel Head; + typedef Templates40 Tail; +}; + +template +struct Templates42 { + typedef TemplateSel Head; + typedef Templates41 Tail; +}; + +template +struct Templates43 { + typedef TemplateSel Head; + typedef Templates42 Tail; +}; + +template +struct Templates44 { + typedef TemplateSel Head; + typedef Templates43 Tail; +}; + +template +struct Templates45 { + typedef TemplateSel Head; + typedef Templates44 Tail; +}; + +template +struct Templates46 { + typedef TemplateSel Head; + typedef Templates45 Tail; +}; + +template +struct Templates47 { + typedef TemplateSel Head; + typedef Templates46 Tail; +}; + +template +struct Templates48 { + typedef TemplateSel Head; + typedef Templates47 Tail; +}; + +template +struct Templates49 { + typedef TemplateSel Head; + typedef Templates48 Tail; +}; + +template +struct Templates50 { + typedef TemplateSel Head; + typedef Templates49 Tail; +}; + + +// We don't want to require the users to write TemplatesN<...> directly, +// as that would require them to count the length. Templates<...> is much +// easier to write, but generates horrible messages when there is a +// compiler error, as gcc insists on printing out each template +// argument, even if it has the default value (this means Templates +// will appear as Templates in the compiler +// errors). +// +// Our solution is to combine the best part of the two approaches: a +// user would write Templates, and Google Test will translate +// that to TemplatesN internally to make error messages +// readable. The translation is done by the 'type' member of the +// Templates template. +template +struct Templates { + typedef Templates50 type; +}; + +template <> +struct Templates { + typedef Templates0 type; +}; +template +struct Templates { + typedef Templates1 type; +}; +template +struct Templates { + typedef Templates2 type; +}; +template +struct Templates { + typedef Templates3 type; +}; +template +struct Templates { + typedef Templates4 type; +}; +template +struct Templates { + typedef Templates5 type; +}; +template +struct Templates { + typedef Templates6 type; +}; +template +struct Templates { + typedef Templates7 type; +}; +template +struct Templates { + typedef Templates8 type; +}; +template +struct Templates { + typedef Templates9 type; +}; +template +struct Templates { + typedef Templates10 type; +}; +template +struct Templates { + typedef Templates11 type; +}; +template +struct Templates { + typedef Templates12 type; +}; +template +struct Templates { + typedef Templates13 type; +}; +template +struct Templates { + typedef Templates14 type; +}; +template +struct Templates { + typedef Templates15 type; +}; +template +struct Templates { + typedef Templates16 type; +}; +template +struct Templates { + typedef Templates17 type; +}; +template +struct Templates { + typedef Templates18 type; +}; +template +struct Templates { + typedef Templates19 type; +}; +template +struct Templates { + typedef Templates20 type; +}; +template +struct Templates { + typedef Templates21 type; +}; +template +struct Templates { + typedef Templates22 type; +}; +template +struct Templates { + typedef Templates23 type; +}; +template +struct Templates { + typedef Templates24 type; +}; +template +struct Templates { + typedef Templates25 type; +}; +template +struct Templates { + typedef Templates26 type; +}; +template +struct Templates { + typedef Templates27 type; +}; +template +struct Templates { + typedef Templates28 type; +}; +template +struct Templates { + typedef Templates29 type; +}; +template +struct Templates { + typedef Templates30 type; +}; +template +struct Templates { + typedef Templates31 type; +}; +template +struct Templates { + typedef Templates32 type; +}; +template +struct Templates { + typedef Templates33 type; +}; +template +struct Templates { + typedef Templates34 type; +}; +template +struct Templates { + typedef Templates35 type; +}; +template +struct Templates { + typedef Templates36 type; +}; +template +struct Templates { + typedef Templates37 type; +}; +template +struct Templates { + typedef Templates38 type; +}; +template +struct Templates { + typedef Templates39 type; +}; +template +struct Templates { + typedef Templates40 type; +}; +template +struct Templates { + typedef Templates41 type; +}; +template +struct Templates { + typedef Templates42 type; +}; +template +struct Templates { + typedef Templates43 type; +}; +template +struct Templates { + typedef Templates44 type; +}; +template +struct Templates { + typedef Templates45 type; +}; +template +struct Templates { + typedef Templates46 type; +}; +template +struct Templates { + typedef Templates47 type; +}; +template +struct Templates { + typedef Templates48 type; +}; +template +struct Templates { + typedef Templates49 type; +}; + +// The TypeList template makes it possible to use either a single type +// or a Types<...> list in TYPED_TEST_CASE() and +// INSTANTIATE_TYPED_TEST_CASE_P(). + +template +struct TypeList { + typedef Types1 type; +}; + +template +struct TypeList > { + typedef typename Types::type type; +}; + +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ diff --git a/TestMothur/gtest-type-util.h.pump b/TestMothur/gtest-type-util.h.pump new file mode 100755 index 00000000..66ee98c3 --- /dev/null +++ b/TestMothur/gtest-type-util.h.pump @@ -0,0 +1,297 @@ +$$ -*- mode: c++; -*- +$var n = 50 $$ Maximum length of type lists we want to support. +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +// Type utilities needed for implementing typed and type-parameterized +// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! +// +// Currently we support at most $n types in a list, and at most $n +// type-parameterized tests in one type-parameterized test case. +// Please contact googletestframework@googlegroups.com if you need +// more. + +#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ +#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ + +#include "gtest-port.h" + +// #ifdef __GNUC__ is too general here. It is possible to use gcc without using +// libstdc++ (which is where cxxabi.h comes from). +# if GTEST_HAS_CXXABI_H_ +# include +# elif defined(__HP_aCC) +# include +# endif // GTEST_HASH_CXXABI_H_ + +namespace testing { +namespace internal { + +// GetTypeName() returns a human-readable name of type T. +// NB: This function is also used in Google Mock, so don't move it inside of +// the typed-test-only section below. +template +std::string GetTypeName() { +# if GTEST_HAS_RTTI + + const char* const name = typeid(T).name(); +# if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) + int status = 0; + // gcc's implementation of typeid(T).name() mangles the type name, + // so we have to demangle it. +# if GTEST_HAS_CXXABI_H_ + using abi::__cxa_demangle; +# endif // GTEST_HAS_CXXABI_H_ + char* const readable_name = __cxa_demangle(name, 0, 0, &status); + const std::string name_str(status == 0 ? readable_name : name); + free(readable_name); + return name_str; +# else + return name; +# endif // GTEST_HAS_CXXABI_H_ || __HP_aCC + +# else + + return ""; + +# endif // GTEST_HAS_RTTI +} + +#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +// AssertyTypeEq::type is defined iff T1 and T2 are the same +// type. This can be used as a compile-time assertion to ensure that +// two types are equal. + +template +struct AssertTypeEq; + +template +struct AssertTypeEq { + typedef bool type; +}; + +// A unique type used as the default value for the arguments of class +// template Types. This allows us to simulate variadic templates +// (e.g. Types, Type, and etc), which C++ doesn't +// support directly. +struct None {}; + +// The following family of struct and struct templates are used to +// represent type lists. In particular, TypesN +// represents a type list with N types (T1, T2, ..., and TN) in it. +// Except for Types0, every struct in the family has two member types: +// Head for the first type in the list, and Tail for the rest of the +// list. + +// The empty type list. +struct Types0 {}; + +// Type lists of length 1, 2, 3, and so on. + +template +struct Types1 { + typedef T1 Head; + typedef Types0 Tail; +}; + +$range i 2..n + +$for i [[ +$range j 1..i +$range k 2..i +template <$for j, [[typename T$j]]> +struct Types$i { + typedef T1 Head; + typedef Types$(i-1)<$for k, [[T$k]]> Tail; +}; + + +]] + +} // namespace internal + +// We don't want to require the users to write TypesN<...> directly, +// as that would require them to count the length. Types<...> is much +// easier to write, but generates horrible messages when there is a +// compiler error, as gcc insists on printing out each template +// argument, even if it has the default value (this means Types +// will appear as Types in the compiler +// errors). +// +// Our solution is to combine the best part of the two approaches: a +// user would write Types, and Google Test will translate +// that to TypesN internally to make error messages +// readable. The translation is done by the 'type' member of the +// Types template. + +$range i 1..n +template <$for i, [[typename T$i = internal::None]]> +struct Types { + typedef internal::Types$n<$for i, [[T$i]]> type; +}; + +template <> +struct Types<$for i, [[internal::None]]> { + typedef internal::Types0 type; +}; + +$range i 1..n-1 +$for i [[ +$range j 1..i +$range k i+1..n +template <$for j, [[typename T$j]]> +struct Types<$for j, [[T$j]]$for k[[, internal::None]]> { + typedef internal::Types$i<$for j, [[T$j]]> type; +}; + +]] + +namespace internal { + +# define GTEST_TEMPLATE_ template class + +// The template "selector" struct TemplateSel is used to +// represent Tmpl, which must be a class template with one type +// parameter, as a type. TemplateSel::Bind::type is defined +// as the type Tmpl. This allows us to actually instantiate the +// template "selected" by TemplateSel. +// +// This trick is necessary for simulating typedef for class templates, +// which C++ doesn't support directly. +template +struct TemplateSel { + template + struct Bind { + typedef Tmpl type; + }; +}; + +# define GTEST_BIND_(TmplSel, T) \ + TmplSel::template Bind::type + +// A unique struct template used as the default value for the +// arguments of class template Templates. This allows us to simulate +// variadic templates (e.g. Templates, Templates, +// and etc), which C++ doesn't support directly. +template +struct NoneT {}; + +// The following family of struct and struct templates are used to +// represent template lists. In particular, TemplatesN represents a list of N templates (T1, T2, ..., and TN). Except +// for Templates0, every struct in the family has two member types: +// Head for the selector of the first template in the list, and Tail +// for the rest of the list. + +// The empty template list. +struct Templates0 {}; + +// Template lists of length 1, 2, 3, and so on. + +template +struct Templates1 { + typedef TemplateSel Head; + typedef Templates0 Tail; +}; + +$range i 2..n + +$for i [[ +$range j 1..i +$range k 2..i +template <$for j, [[GTEST_TEMPLATE_ T$j]]> +struct Templates$i { + typedef TemplateSel Head; + typedef Templates$(i-1)<$for k, [[T$k]]> Tail; +}; + + +]] + +// We don't want to require the users to write TemplatesN<...> directly, +// as that would require them to count the length. Templates<...> is much +// easier to write, but generates horrible messages when there is a +// compiler error, as gcc insists on printing out each template +// argument, even if it has the default value (this means Templates +// will appear as Templates in the compiler +// errors). +// +// Our solution is to combine the best part of the two approaches: a +// user would write Templates, and Google Test will translate +// that to TemplatesN internally to make error messages +// readable. The translation is done by the 'type' member of the +// Templates template. + +$range i 1..n +template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]> +struct Templates { + typedef Templates$n<$for i, [[T$i]]> type; +}; + +template <> +struct Templates<$for i, [[NoneT]]> { + typedef Templates0 type; +}; + +$range i 1..n-1 +$for i [[ +$range j 1..i +$range k i+1..n +template <$for j, [[GTEST_TEMPLATE_ T$j]]> +struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> { + typedef Templates$i<$for j, [[T$j]]> type; +}; + +]] + +// The TypeList template makes it possible to use either a single type +// or a Types<...> list in TYPED_TEST_CASE() and +// INSTANTIATE_TYPED_TEST_CASE_P(). + +template +struct TypeList { + typedef Types1 type; +}; + + +$range i 1..n +template <$for i, [[typename T$i]]> +struct TypeList > { + typedef typename Types<$for i, [[T$i]]>::type type; +}; + +#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P + +} // namespace internal +} // namespace testing + +#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ diff --git a/TestMothur/gtest-typed-test.cc b/TestMothur/gtest-typed-test.cc new file mode 100755 index 00000000..4fc6f39d --- /dev/null +++ b/TestMothur/gtest-typed-test.cc @@ -0,0 +1,118 @@ +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +#include "gtest-typed-test.h" +#include "gtest.h" + +namespace testing { +namespace internal { + +#if GTEST_HAS_TYPED_TEST_P + +// Skips to the first non-space char in str. Returns an empty string if str +// contains only whitespace characters. +static const char* SkipSpaces(const char* str) { + while (IsSpace(*str)) + str++; + return str; +} + +static std::vector SplitIntoTestNames(const char* src) { + std::vector name_vec; + src = SkipSpaces(src); + for (; src != NULL; src = SkipComma(src)) { + name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); + } + return name_vec; +} + +// Verifies that registered_tests match the test names in +// registered_tests_; returns registered_tests if successful, or +// aborts the program otherwise. +const char* TypedTestCasePState::VerifyRegisteredTestNames( + const char* file, int line, const char* registered_tests) { + typedef RegisteredTestsMap::const_iterator RegisteredTestIter; + registered_ = true; + + std::vector name_vec = SplitIntoTestNames(registered_tests); + + Message errors; + + std::set tests; + for (std::vector::const_iterator name_it = name_vec.begin(); + name_it != name_vec.end(); ++name_it) { + const std::string& name = *name_it; + if (tests.count(name) != 0) { + errors << "Test " << name << " is listed more than once.\n"; + continue; + } + + bool found = false; + for (RegisteredTestIter it = registered_tests_.begin(); + it != registered_tests_.end(); + ++it) { + if (name == it->first) { + found = true; + break; + } + } + + if (found) { + tests.insert(name); + } else { + errors << "No test named " << name + << " can be found in this test case.\n"; + } + } + + for (RegisteredTestIter it = registered_tests_.begin(); + it != registered_tests_.end(); + ++it) { + if (tests.count(it->first) == 0) { + errors << "You forgot to list test " << it->first << ".\n"; + } + } + + const std::string& errors_str = errors.GetString(); + if (errors_str != "") { + fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), + errors_str.c_str()); + fflush(stderr); + posix::Abort(); + } + + return registered_tests; +} + +#endif // GTEST_HAS_TYPED_TEST_P + +} // namespace internal +} // namespace testing diff --git a/TestMothur/gtest-typed-test.h b/TestMothur/gtest-typed-test.h new file mode 100755 index 00000000..364d4ee8 --- /dev/null +++ b/TestMothur/gtest-typed-test.h @@ -0,0 +1,263 @@ +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) + +#ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ +#define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ + +// This header implements typed tests and type-parameterized tests. + +// Typed (aka type-driven) tests repeat the same test for types in a +// list. You must know which types you want to test with when writing +// typed tests. Here's how you do it: + +#if 0 + +// First, define a fixture class template. It should be parameterized +// by a type. Remember to derive it from testing::Test. +template +class FooTest : public testing::Test { + public: + ... + typedef std::list List; + static T shared_; + T value_; +}; + +// Next, associate a list of types with the test case, which will be +// repeated for each type in the list. The typedef is necessary for +// the macro to parse correctly. +typedef testing::Types MyTypes; +TYPED_TEST_CASE(FooTest, MyTypes); + +// If the type list contains only one type, you can write that type +// directly without Types<...>: +// TYPED_TEST_CASE(FooTest, int); + +// Then, use TYPED_TEST() instead of TEST_F() to define as many typed +// tests for this test case as you want. +TYPED_TEST(FooTest, DoesBlah) { + // Inside a test, refer to TypeParam to get the type parameter. + // Since we are inside a derived class template, C++ requires use to + // visit the members of FooTest via 'this'. + TypeParam n = this->value_; + + // To visit static members of the fixture, add the TestFixture:: + // prefix. + n += TestFixture::shared_; + + // To refer to typedefs in the fixture, add the "typename + // TestFixture::" prefix. + typename TestFixture::List values; + values.push_back(n); + ... +} + +TYPED_TEST(FooTest, HasPropertyA) { ... } + +#endif // 0 + +// Type-parameterized tests are abstract test patterns parameterized +// by a type. Compared with typed tests, type-parameterized tests +// allow you to define the test pattern without knowing what the type +// parameters are. The defined pattern can be instantiated with +// different types any number of times, in any number of translation +// units. +// +// If you are designing an interface or concept, you can define a +// suite of type-parameterized tests to verify properties that any +// valid implementation of the interface/concept should have. Then, +// each implementation can easily instantiate the test suite to verify +// that it conforms to the requirements, without having to write +// similar tests repeatedly. Here's an example: + +#if 0 + +// First, define a fixture class template. It should be parameterized +// by a type. Remember to derive it from testing::Test. +template +class FooTest : public testing::Test { + ... +}; + +// Next, declare that you will define a type-parameterized test case +// (the _P suffix is for "parameterized" or "pattern", whichever you +// prefer): +TYPED_TEST_CASE_P(FooTest); + +// Then, use TYPED_TEST_P() to define as many type-parameterized tests +// for this type-parameterized test case as you want. +TYPED_TEST_P(FooTest, DoesBlah) { + // Inside a test, refer to TypeParam to get the type parameter. + TypeParam n = 0; + ... +} + +TYPED_TEST_P(FooTest, HasPropertyA) { ... } + +// Now the tricky part: you need to register all test patterns before +// you can instantiate them. The first argument of the macro is the +// test case name; the rest are the names of the tests in this test +// case. +REGISTER_TYPED_TEST_CASE_P(FooTest, + DoesBlah, HasPropertyA); + +// Finally, you are free to instantiate the pattern with the types you +// want. If you put the above code in a header file, you can #include +// it in multiple C++ source files and instantiate it multiple times. +// +// To distinguish different instances of the pattern, the first +// argument to the INSTANTIATE_* macro is a prefix that will be added +// to the actual test case name. Remember to pick unique prefixes for +// different instances. +typedef testing::Types MyTypes; +INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); + +// If the type list contains only one type, you can write that type +// directly without Types<...>: +// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int); + +#endif // 0 + +#include "gtest-port.h" +#include "gtest-type-util.h" + +// Implements typed tests. + +#if GTEST_HAS_TYPED_TEST + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Expands to the name of the typedef for the type parameters of the +// given test case. +# define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_ + +// The 'Types' template argument below must have spaces around it +// since some compilers may choke on '>>' when passing a template +// instance (e.g. Types) +# define TYPED_TEST_CASE(CaseName, Types) \ + typedef ::testing::internal::TypeList< Types >::type \ + GTEST_TYPE_PARAMS_(CaseName) + +# define TYPED_TEST(CaseName, TestName) \ + template \ + class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ + : public CaseName { \ + private: \ + typedef CaseName TestFixture; \ + typedef gtest_TypeParam_ TypeParam; \ + virtual void TestBody(); \ + }; \ + bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \ + ::testing::internal::TypeParameterizedTest< \ + CaseName, \ + ::testing::internal::TemplateSel< \ + GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \ + GTEST_TYPE_PARAMS_(CaseName)>::Register(\ + "", ::testing::internal::CodeLocation(__FILE__, __LINE__), \ + #CaseName, #TestName, 0); \ + template \ + void GTEST_TEST_CLASS_NAME_(CaseName, TestName)::TestBody() + +#endif // GTEST_HAS_TYPED_TEST + +// Implements type-parameterized tests. + +#if GTEST_HAS_TYPED_TEST_P + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Expands to the namespace name that the type-parameterized tests for +// the given type-parameterized test case are defined in. The exact +// name of the namespace is subject to change without notice. +# define GTEST_CASE_NAMESPACE_(TestCaseName) \ + gtest_case_##TestCaseName##_ + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Expands to the name of the variable used to remember the names of +// the defined tests in the given test case. +# define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \ + gtest_typed_test_case_p_state_##TestCaseName##_ + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY. +// +// Expands to the name of the variable used to remember the names of +// the registered tests in the given test case. +# define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \ + gtest_registered_test_names_##TestCaseName##_ + +// The variables defined in the type-parameterized test macros are +// static as typically these macros are used in a .h file that can be +// #included in multiple translation units linked together. +# define TYPED_TEST_CASE_P(CaseName) \ + static ::testing::internal::TypedTestCasePState \ + GTEST_TYPED_TEST_CASE_P_STATE_(CaseName) + +# define TYPED_TEST_P(CaseName, TestName) \ + namespace GTEST_CASE_NAMESPACE_(CaseName) { \ + template \ + class TestName : public CaseName { \ + private: \ + typedef CaseName TestFixture; \ + typedef gtest_TypeParam_ TypeParam; \ + virtual void TestBody(); \ + }; \ + static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \ + GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\ + __FILE__, __LINE__, #CaseName, #TestName); \ + } \ + template \ + void GTEST_CASE_NAMESPACE_(CaseName)::TestName::TestBody() + +# define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \ + namespace GTEST_CASE_NAMESPACE_(CaseName) { \ + typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \ + } \ + static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \ + GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\ + __FILE__, __LINE__, #__VA_ARGS__) + +// The 'Types' template argument below must have spaces around it +// since some compilers may choke on '>>' when passing a template +// instance (e.g. Types) +# define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ + bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \ + ::testing::internal::TypeParameterizedTestCase::type>::Register(\ + #Prefix, \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), \ + >EST_TYPED_TEST_CASE_P_STATE_(CaseName), \ + #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName)) + +#endif // GTEST_HAS_TYPED_TEST_P + +#endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ diff --git a/TestMothur/gtest.cc b/TestMothur/gtest.cc new file mode 100755 index 00000000..7b7a8643 --- /dev/null +++ b/TestMothur/gtest.cc @@ -0,0 +1,5388 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// The Google C++ Testing Framework (Google Test) + +#include "gtest.h" +#include "custom/gtest.h" +#include "gtest-spi.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include // NOLINT +#include +#include + +#if GTEST_OS_LINUX + +// TODO(kenton@google.com): Use autoconf to detect availability of +// gettimeofday(). +# define GTEST_HAS_GETTIMEOFDAY_ 1 + +# include // NOLINT +# include // NOLINT +# include // NOLINT +// Declares vsnprintf(). This header is not available on Windows. +# include // NOLINT +# include // NOLINT +# include // NOLINT +# include // NOLINT +# include + +#elif GTEST_OS_SYMBIAN +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include // NOLINT + +#elif GTEST_OS_ZOS +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include // NOLINT + +// On z/OS we additionally need strings.h for strcasecmp. +# include // NOLINT + +#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. + +# include // NOLINT +# undef min + +#elif GTEST_OS_WINDOWS // We are on Windows proper. + +# include // NOLINT +# include // NOLINT +# include // NOLINT +# include // NOLINT + +# if GTEST_OS_WINDOWS_MINGW +// MinGW has gettimeofday() but not _ftime64(). +// TODO(kenton@google.com): Use autoconf to detect availability of +// gettimeofday(). +// TODO(kenton@google.com): There are other ways to get the time on +// Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW +// supports these. consider using them instead. +# define GTEST_HAS_GETTIMEOFDAY_ 1 +# include // NOLINT +# endif // GTEST_OS_WINDOWS_MINGW + +// cpplint thinks that the header is already included, so we want to +// silence it. +# include // NOLINT +# undef min + +#else + +// Assume other platforms have gettimeofday(). +// TODO(kenton@google.com): Use autoconf to detect availability of +// gettimeofday(). +# define GTEST_HAS_GETTIMEOFDAY_ 1 + +// cpplint thinks that the header is already included, so we want to +// silence it. +# include // NOLINT +# include // NOLINT + +#endif // GTEST_OS_LINUX + +#if GTEST_HAS_EXCEPTIONS +# include +#endif + +#if GTEST_CAN_STREAM_RESULTS_ +# include // NOLINT +# include // NOLINT +# include // NOLINT +# include // NOLINT +#endif + +// Indicates that this translation unit is part of Google Test's +// implementation. It must come before gtest-internal-inl.h is +// included, or there will be a compiler error. This trick is to +// prevent a user from accidentally including gtest-internal-inl.h in +// his code. +#define GTEST_IMPLEMENTATION_ 1 +#include "gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_ + +#if GTEST_OS_WINDOWS +# define vsnprintf _vsnprintf +#endif // GTEST_OS_WINDOWS + +namespace testing { + +using internal::CountIf; +using internal::ForEach; +using internal::GetElementOr; +using internal::Shuffle; + +// Constants. + +// A test whose test case name or test name matches this filter is +// disabled and not run. +static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*"; + +// A test case whose name matches this filter is considered a death +// test case and will be run before test cases whose name doesn't +// match this filter. +static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*"; + +// A test filter that matches everything. +static const char kUniversalFilter[] = "*"; + +// The default output file for XML output. +static const char kDefaultOutputFile[] = "test_detail.xml"; + +// The environment variable name for the test shard index. +static const char kTestShardIndex[] = "GTEST_SHARD_INDEX"; +// The environment variable name for the total number of test shards. +static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS"; +// The environment variable name for the test shard status file. +static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE"; + +namespace internal { + +// The text used in failure messages to indicate the start of the +// stack trace. +const char kStackTraceMarker[] = "\nStack trace:\n"; + +// g_help_flag is true iff the --help flag or an equivalent form is +// specified on the command line. +bool g_help_flag = false; + +} // namespace internal + +static const char* GetDefaultFilter() { +#ifdef GTEST_TEST_FILTER_ENV_VAR_ + const char* const testbridge_test_only = getenv(GTEST_TEST_FILTER_ENV_VAR_); + if (testbridge_test_only != NULL) { + return testbridge_test_only; + } +#endif // GTEST_TEST_FILTER_ENV_VAR_ + return kUniversalFilter; +} + +GTEST_DEFINE_bool_( + also_run_disabled_tests, + internal::BoolFromGTestEnv("also_run_disabled_tests", false), + "Run disabled tests too, in addition to the tests normally being run."); + +GTEST_DEFINE_bool_( + break_on_failure, + internal::BoolFromGTestEnv("break_on_failure", false), + "True iff a failed assertion should be a debugger break-point."); + +GTEST_DEFINE_bool_( + catch_exceptions, + internal::BoolFromGTestEnv("catch_exceptions", true), + "True iff " GTEST_NAME_ + " should catch exceptions and treat them as test failures."); + +GTEST_DEFINE_string_( + color, + internal::StringFromGTestEnv("color", "auto"), + "Whether to use colors in the output. Valid values: yes, no, " + "and auto. 'auto' means to use colors if the output is " + "being sent to a terminal and the TERM environment variable " + "is set to a terminal type that supports colors."); + +GTEST_DEFINE_string_( + filter, + internal::StringFromGTestEnv("filter", GetDefaultFilter()), + "A colon-separated list of glob (not regex) patterns " + "for filtering the tests to run, optionally followed by a " + "'-' and a : separated list of negative patterns (tests to " + "exclude). A test is run if it matches one of the positive " + "patterns and does not match any of the negative patterns."); + +GTEST_DEFINE_bool_(list_tests, false, + "List all tests without running them."); + +GTEST_DEFINE_string_( + output, + internal::StringFromGTestEnv("output", ""), + "A format (currently must be \"xml\"), optionally followed " + "by a colon and an output file name or directory. A directory " + "is indicated by a trailing pathname separator. " + "Examples: \"xml:filename.xml\", \"xml::directoryname/\". " + "If a directory is specified, output files will be created " + "within that directory, with file-names based on the test " + "executable's name and, if necessary, made unique by adding " + "digits."); + +GTEST_DEFINE_bool_( + print_time, + internal::BoolFromGTestEnv("print_time", true), + "True iff " GTEST_NAME_ + " should display elapsed time in text output."); + +GTEST_DEFINE_int32_( + random_seed, + internal::Int32FromGTestEnv("random_seed", 0), + "Random number seed to use when shuffling test orders. Must be in range " + "[1, 99999], or 0 to use a seed based on the current time."); + +GTEST_DEFINE_int32_( + repeat, + internal::Int32FromGTestEnv("repeat", 1), + "How many times to repeat each test. Specify a negative number " + "for repeating forever. Useful for shaking out flaky tests."); + +GTEST_DEFINE_bool_( + show_internal_stack_frames, false, + "True iff " GTEST_NAME_ " should include internal stack frames when " + "printing test failure stack traces."); + +GTEST_DEFINE_bool_( + shuffle, + internal::BoolFromGTestEnv("shuffle", false), + "True iff " GTEST_NAME_ + " should randomize tests' order on every run."); + +GTEST_DEFINE_int32_( + stack_trace_depth, + internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth), + "The maximum number of stack frames to print when an " + "assertion fails. The valid range is 0 through 100, inclusive."); + +GTEST_DEFINE_string_( + stream_result_to, + internal::StringFromGTestEnv("stream_result_to", ""), + "This flag specifies the host name and the port number on which to stream " + "test results. Example: \"localhost:555\". The flag is effective only on " + "Linux."); + +GTEST_DEFINE_bool_( + throw_on_failure, + internal::BoolFromGTestEnv("throw_on_failure", false), + "When this flag is specified, a failed assertion will throw an exception " + "if exceptions are enabled or exit the program with a non-zero code " + "otherwise."); + +#if GTEST_USE_OWN_FLAGFILE_FLAG_ +GTEST_DEFINE_string_( + flagfile, + internal::StringFromGTestEnv("flagfile", ""), + "This flag specifies the flagfile to read command-line flags from."); +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ + +namespace internal { + +// Generates a random number from [0, range), using a Linear +// Congruential Generator (LCG). Crashes if 'range' is 0 or greater +// than kMaxRange. +UInt32 Random::Generate(UInt32 range) { + // These constants are the same as are used in glibc's rand(3). + state_ = (1103515245U*state_ + 12345U) % kMaxRange; + + GTEST_CHECK_(range > 0) + << "Cannot generate a number in the range [0, 0)."; + GTEST_CHECK_(range <= kMaxRange) + << "Generation of a number in [0, " << range << ") was requested, " + << "but this can only generate numbers in [0, " << kMaxRange << ")."; + + // Converting via modulus introduces a bit of downward bias, but + // it's simple, and a linear congruential generator isn't too good + // to begin with. + return state_ % range; +} + +// GTestIsInitialized() returns true iff the user has initialized +// Google Test. Useful for catching the user mistake of not initializing +// Google Test before calling RUN_ALL_TESTS(). +static bool GTestIsInitialized() { return GetArgvs().size() > 0; } + +// Iterates over a vector of TestCases, keeping a running sum of the +// results of calling a given int-returning method on each. +// Returns the sum. +static int SumOverTestCaseList(const std::vector& case_list, + int (TestCase::*method)() const) { + int sum = 0; + for (size_t i = 0; i < case_list.size(); i++) { + sum += (case_list[i]->*method)(); + } + return sum; +} + +// Returns true iff the test case passed. +static bool TestCasePassed(const TestCase* test_case) { + return test_case->should_run() && test_case->Passed(); +} + +// Returns true iff the test case failed. +static bool TestCaseFailed(const TestCase* test_case) { + return test_case->should_run() && test_case->Failed(); +} + +// Returns true iff test_case contains at least one test that should +// run. +static bool ShouldRunTestCase(const TestCase* test_case) { + return test_case->should_run(); +} + +// AssertHelper constructor. +AssertHelper::AssertHelper(TestPartResult::Type type, + const char* file, + int line, + const char* message) + : data_(new AssertHelperData(type, file, line, message)) { +} + +AssertHelper::~AssertHelper() { + delete data_; +} + +// Message assignment, for assertion streaming support. +void AssertHelper::operator=(const Message& message) const { + UnitTest::GetInstance()-> + AddTestPartResult(data_->type, data_->file, data_->line, + AppendUserMessage(data_->message, message), + UnitTest::GetInstance()->impl() + ->CurrentOsStackTraceExceptTop(1) + // Skips the stack frame for this function itself. + ); // NOLINT +} + +// Mutex for linked pointers. +GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex); + +// A copy of all command line arguments. Set by InitGoogleTest(). +::std::vector g_argvs; + +const ::std::vector& GetArgvs() { +#if defined(GTEST_CUSTOM_GET_ARGVS_) + return GTEST_CUSTOM_GET_ARGVS_(); +#else // defined(GTEST_CUSTOM_GET_ARGVS_) + return g_argvs; +#endif // defined(GTEST_CUSTOM_GET_ARGVS_) +} + +// Returns the current application's name, removing directory path if that +// is present. +FilePath GetCurrentExecutableName() { + FilePath result; + +#if GTEST_OS_WINDOWS + result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe")); +#else + result.Set(FilePath(GetArgvs()[0])); +#endif // GTEST_OS_WINDOWS + + return result.RemoveDirectoryName(); +} + +// Functions for processing the gtest_output flag. + +// Returns the output format, or "" for normal printed output. +std::string UnitTestOptions::GetOutputFormat() { + const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); + if (gtest_output_flag == NULL) return std::string(""); + + const char* const colon = strchr(gtest_output_flag, ':'); + return (colon == NULL) ? + std::string(gtest_output_flag) : + std::string(gtest_output_flag, colon - gtest_output_flag); +} + +// Returns the name of the requested output file, or the default if none +// was explicitly specified. +std::string UnitTestOptions::GetAbsolutePathToOutputFile() { + const char* const gtest_output_flag = GTEST_FLAG(output).c_str(); + if (gtest_output_flag == NULL) + return ""; + + const char* const colon = strchr(gtest_output_flag, ':'); + if (colon == NULL) + return internal::FilePath::ConcatPaths( + internal::FilePath( + UnitTest::GetInstance()->original_working_dir()), + internal::FilePath(kDefaultOutputFile)).string(); + + internal::FilePath output_name(colon + 1); + if (!output_name.IsAbsolutePath()) + // TODO(wan@google.com): on Windows \some\path is not an absolute + // path (as its meaning depends on the current drive), yet the + // following logic for turning it into an absolute path is wrong. + // Fix it. + output_name = internal::FilePath::ConcatPaths( + internal::FilePath(UnitTest::GetInstance()->original_working_dir()), + internal::FilePath(colon + 1)); + + if (!output_name.IsDirectory()) + return output_name.string(); + + internal::FilePath result(internal::FilePath::GenerateUniqueFileName( + output_name, internal::GetCurrentExecutableName(), + GetOutputFormat().c_str())); + return result.string(); +} + +// Returns true iff the wildcard pattern matches the string. The +// first ':' or '\0' character in pattern marks the end of it. +// +// This recursive algorithm isn't very efficient, but is clear and +// works well enough for matching test names, which are short. +bool UnitTestOptions::PatternMatchesString(const char *pattern, + const char *str) { + switch (*pattern) { + case '\0': + case ':': // Either ':' or '\0' marks the end of the pattern. + return *str == '\0'; + case '?': // Matches any single character. + return *str != '\0' && PatternMatchesString(pattern + 1, str + 1); + case '*': // Matches any string (possibly empty) of characters. + return (*str != '\0' && PatternMatchesString(pattern, str + 1)) || + PatternMatchesString(pattern + 1, str); + default: // Non-special character. Matches itself. + return *pattern == *str && + PatternMatchesString(pattern + 1, str + 1); + } +} + +bool UnitTestOptions::MatchesFilter( + const std::string& name, const char* filter) { + const char *cur_pattern = filter; + for (;;) { + if (PatternMatchesString(cur_pattern, name.c_str())) { + return true; + } + + // Finds the next pattern in the filter. + cur_pattern = strchr(cur_pattern, ':'); + + // Returns if no more pattern can be found. + if (cur_pattern == NULL) { + return false; + } + + // Skips the pattern separater (the ':' character). + cur_pattern++; + } +} + +// Returns true iff the user-specified filter matches the test case +// name and the test name. +bool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name, + const std::string &test_name) { + const std::string& full_name = test_case_name + "." + test_name.c_str(); + + // Split --gtest_filter at '-', if there is one, to separate into + // positive filter and negative filter portions + const char* const p = GTEST_FLAG(filter).c_str(); + const char* const dash = strchr(p, '-'); + std::string positive; + std::string negative; + if (dash == NULL) { + positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter + negative = ""; + } else { + positive = std::string(p, dash); // Everything up to the dash + negative = std::string(dash + 1); // Everything after the dash + if (positive.empty()) { + // Treat '-test1' as the same as '*-test1' + positive = kUniversalFilter; + } + } + + // A filter is a colon-separated list of patterns. It matches a + // test if any pattern in it matches the test. + return (MatchesFilter(full_name, positive.c_str()) && + !MatchesFilter(full_name, negative.c_str())); +} + +#if GTEST_HAS_SEH +// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the +// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise. +// This function is useful as an __except condition. +int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) { + // Google Test should handle a SEH exception if: + // 1. the user wants it to, AND + // 2. this is not a breakpoint exception, AND + // 3. this is not a C++ exception (VC++ implements them via SEH, + // apparently). + // + // SEH exception code for C++ exceptions. + // (see http://support.microsoft.com/kb/185294 for more information). + const DWORD kCxxExceptionCode = 0xe06d7363; + + bool should_handle = true; + + if (!GTEST_FLAG(catch_exceptions)) + should_handle = false; + else if (exception_code == EXCEPTION_BREAKPOINT) + should_handle = false; + else if (exception_code == kCxxExceptionCode) + should_handle = false; + + return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH; +} +#endif // GTEST_HAS_SEH + +} // namespace internal + +// The c'tor sets this object as the test part result reporter used by +// Google Test. The 'result' parameter specifies where to report the +// results. Intercepts only failures from the current thread. +ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter( + TestPartResultArray* result) + : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD), + result_(result) { + Init(); +} + +// The c'tor sets this object as the test part result reporter used by +// Google Test. The 'result' parameter specifies where to report the +// results. +ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter( + InterceptMode intercept_mode, TestPartResultArray* result) + : intercept_mode_(intercept_mode), + result_(result) { + Init(); +} + +void ScopedFakeTestPartResultReporter::Init() { + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + if (intercept_mode_ == INTERCEPT_ALL_THREADS) { + old_reporter_ = impl->GetGlobalTestPartResultReporter(); + impl->SetGlobalTestPartResultReporter(this); + } else { + old_reporter_ = impl->GetTestPartResultReporterForCurrentThread(); + impl->SetTestPartResultReporterForCurrentThread(this); + } +} + +// The d'tor restores the test part result reporter used by Google Test +// before. +ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() { + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + if (intercept_mode_ == INTERCEPT_ALL_THREADS) { + impl->SetGlobalTestPartResultReporter(old_reporter_); + } else { + impl->SetTestPartResultReporterForCurrentThread(old_reporter_); + } +} + +// Increments the test part result count and remembers the result. +// This method is from the TestPartResultReporterInterface interface. +void ScopedFakeTestPartResultReporter::ReportTestPartResult( + const TestPartResult& result) { + result_->Append(result); +} + +namespace internal { + +// Returns the type ID of ::testing::Test. We should always call this +// instead of GetTypeId< ::testing::Test>() to get the type ID of +// testing::Test. This is to work around a suspected linker bug when +// using Google Test as a framework on Mac OS X. The bug causes +// GetTypeId< ::testing::Test>() to return different values depending +// on whether the call is from the Google Test framework itself or +// from user test code. GetTestTypeId() is guaranteed to always +// return the same value, as it always calls GetTypeId<>() from the +// gtest.cc, which is within the Google Test framework. +TypeId GetTestTypeId() { + return GetTypeId(); +} + +// The value of GetTestTypeId() as seen from within the Google Test +// library. This is solely for testing GetTestTypeId(). +extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId(); + +// This predicate-formatter checks that 'results' contains a test part +// failure of the given type and that the failure message contains the +// given substring. +AssertionResult HasOneFailure(const char* /* results_expr */, + const char* /* type_expr */, + const char* /* substr_expr */, + const TestPartResultArray& results, + TestPartResult::Type type, + const string& substr) { + const std::string expected(type == TestPartResult::kFatalFailure ? + "1 fatal failure" : + "1 non-fatal failure"); + Message msg; + if (results.size() != 1) { + msg << "Expected: " << expected << "\n" + << " Actual: " << results.size() << " failures"; + for (int i = 0; i < results.size(); i++) { + msg << "\n" << results.GetTestPartResult(i); + } + return AssertionFailure() << msg; + } + + const TestPartResult& r = results.GetTestPartResult(0); + if (r.type() != type) { + return AssertionFailure() << "Expected: " << expected << "\n" + << " Actual:\n" + << r; + } + + if (strstr(r.message(), substr.c_str()) == NULL) { + return AssertionFailure() << "Expected: " << expected << " containing \"" + << substr << "\"\n" + << " Actual:\n" + << r; + } + + return AssertionSuccess(); +} + +// The constructor of SingleFailureChecker remembers where to look up +// test part results, what type of failure we expect, and what +// substring the failure message should contain. +SingleFailureChecker:: SingleFailureChecker( + const TestPartResultArray* results, + TestPartResult::Type type, + const string& substr) + : results_(results), + type_(type), + substr_(substr) {} + +// The destructor of SingleFailureChecker verifies that the given +// TestPartResultArray contains exactly one failure that has the given +// type and contains the given substring. If that's not the case, a +// non-fatal failure will be generated. +SingleFailureChecker::~SingleFailureChecker() { + EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_); +} + +DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter( + UnitTestImpl* unit_test) : unit_test_(unit_test) {} + +void DefaultGlobalTestPartResultReporter::ReportTestPartResult( + const TestPartResult& result) { + unit_test_->current_test_result()->AddTestPartResult(result); + unit_test_->listeners()->repeater()->OnTestPartResult(result); +} + +DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter( + UnitTestImpl* unit_test) : unit_test_(unit_test) {} + +void DefaultPerThreadTestPartResultReporter::ReportTestPartResult( + const TestPartResult& result) { + unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result); +} + +// Returns the global test part result reporter. +TestPartResultReporterInterface* +UnitTestImpl::GetGlobalTestPartResultReporter() { + internal::MutexLock lock(&global_test_part_result_reporter_mutex_); + return global_test_part_result_repoter_; +} + +// Sets the global test part result reporter. +void UnitTestImpl::SetGlobalTestPartResultReporter( + TestPartResultReporterInterface* reporter) { + internal::MutexLock lock(&global_test_part_result_reporter_mutex_); + global_test_part_result_repoter_ = reporter; +} + +// Returns the test part result reporter for the current thread. +TestPartResultReporterInterface* +UnitTestImpl::GetTestPartResultReporterForCurrentThread() { + return per_thread_test_part_result_reporter_.get(); +} + +// Sets the test part result reporter for the current thread. +void UnitTestImpl::SetTestPartResultReporterForCurrentThread( + TestPartResultReporterInterface* reporter) { + per_thread_test_part_result_reporter_.set(reporter); +} + +// Gets the number of successful test cases. +int UnitTestImpl::successful_test_case_count() const { + return CountIf(test_cases_, TestCasePassed); +} + +// Gets the number of failed test cases. +int UnitTestImpl::failed_test_case_count() const { + return CountIf(test_cases_, TestCaseFailed); +} + +// Gets the number of all test cases. +int UnitTestImpl::total_test_case_count() const { + return static_cast(test_cases_.size()); +} + +// Gets the number of all test cases that contain at least one test +// that should run. +int UnitTestImpl::test_case_to_run_count() const { + return CountIf(test_cases_, ShouldRunTestCase); +} + +// Gets the number of successful tests. +int UnitTestImpl::successful_test_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count); +} + +// Gets the number of failed tests. +int UnitTestImpl::failed_test_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count); +} + +// Gets the number of disabled tests that will be reported in the XML report. +int UnitTestImpl::reportable_disabled_test_count() const { + return SumOverTestCaseList(test_cases_, + &TestCase::reportable_disabled_test_count); +} + +// Gets the number of disabled tests. +int UnitTestImpl::disabled_test_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count); +} + +// Gets the number of tests to be printed in the XML report. +int UnitTestImpl::reportable_test_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::reportable_test_count); +} + +// Gets the number of all tests. +int UnitTestImpl::total_test_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::total_test_count); +} + +// Gets the number of tests that should run. +int UnitTestImpl::test_to_run_count() const { + return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count); +} + +// Returns the current OS stack trace as an std::string. +// +// The maximum number of stack frames to be included is specified by +// the gtest_stack_trace_depth flag. The skip_count parameter +// specifies the number of top frames to be skipped, which doesn't +// count against the number of frames to be included. +// +// For example, if Foo() calls Bar(), which in turn calls +// CurrentOsStackTraceExceptTop(1), Foo() will be included in the +// trace but Bar() and CurrentOsStackTraceExceptTop() won't. +std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) { + return os_stack_trace_getter()->CurrentStackTrace( + static_cast(GTEST_FLAG(stack_trace_depth)), + skip_count + 1 + // Skips the user-specified number of frames plus this function + // itself. + ); // NOLINT +} + +// Returns the current time in milliseconds. +TimeInMillis GetTimeInMillis() { +#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) + // Difference between 1970-01-01 and 1601-01-01 in milliseconds. + // http://analogous.blogspot.com/2005/04/epoch.html + const TimeInMillis kJavaEpochToWinFileTimeDelta = + static_cast(116444736UL) * 100000UL; + const DWORD kTenthMicrosInMilliSecond = 10000; + + SYSTEMTIME now_systime; + FILETIME now_filetime; + ULARGE_INTEGER now_int64; + // TODO(kenton@google.com): Shouldn't this just use + // GetSystemTimeAsFileTime()? + GetSystemTime(&now_systime); + if (SystemTimeToFileTime(&now_systime, &now_filetime)) { + now_int64.LowPart = now_filetime.dwLowDateTime; + now_int64.HighPart = now_filetime.dwHighDateTime; + now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) - + kJavaEpochToWinFileTimeDelta; + return now_int64.QuadPart; + } + return 0; +#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ + __timeb64 now; + + // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996 + // (deprecated function) there. + // TODO(kenton@google.com): Use GetTickCount()? Or use + // SystemTimeToFileTime() + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) + _ftime64(&now); + GTEST_DISABLE_MSC_WARNINGS_POP_() + + return static_cast(now.time) * 1000 + now.millitm; +#elif GTEST_HAS_GETTIMEOFDAY_ + struct timeval now; + gettimeofday(&now, NULL); + return static_cast(now.tv_sec) * 1000 + now.tv_usec / 1000; +#else +# error "Don't know how to get the current time on your system." +#endif +} + +// Utilities + +// class String. + +#if GTEST_OS_WINDOWS_MOBILE +// Creates a UTF-16 wide string from the given ANSI string, allocating +// memory using new. The caller is responsible for deleting the return +// value using delete[]. Returns the wide string, or NULL if the +// input is NULL. +LPCWSTR String::AnsiToUtf16(const char* ansi) { + if (!ansi) return NULL; + const int length = strlen(ansi); + const int unicode_length = + MultiByteToWideChar(CP_ACP, 0, ansi, length, + NULL, 0); + WCHAR* unicode = new WCHAR[unicode_length + 1]; + MultiByteToWideChar(CP_ACP, 0, ansi, length, + unicode, unicode_length); + unicode[unicode_length] = 0; + return unicode; +} + +// Creates an ANSI string from the given wide string, allocating +// memory using new. The caller is responsible for deleting the return +// value using delete[]. Returns the ANSI string, or NULL if the +// input is NULL. +const char* String::Utf16ToAnsi(LPCWSTR utf16_str) { + if (!utf16_str) return NULL; + const int ansi_length = + WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, + NULL, 0, NULL, NULL); + char* ansi = new char[ansi_length + 1]; + WideCharToMultiByte(CP_ACP, 0, utf16_str, -1, + ansi, ansi_length, NULL, NULL); + ansi[ansi_length] = 0; + return ansi; +} + +#endif // GTEST_OS_WINDOWS_MOBILE + +// Compares two C strings. Returns true iff they have the same content. +// +// Unlike strcmp(), this function can handle NULL argument(s). A NULL +// C string is considered different to any non-NULL C string, +// including the empty string. +bool String::CStringEquals(const char * lhs, const char * rhs) { + if ( lhs == NULL ) return rhs == NULL; + + if ( rhs == NULL ) return false; + + return strcmp(lhs, rhs) == 0; +} + +#if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING + +// Converts an array of wide chars to a narrow string using the UTF-8 +// encoding, and streams the result to the given Message object. +static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length, + Message* msg) { + for (size_t i = 0; i != length; ) { // NOLINT + if (wstr[i] != L'\0') { + *msg << WideStringToUtf8(wstr + i, static_cast(length - i)); + while (i != length && wstr[i] != L'\0') + i++; + } else { + *msg << '\0'; + i++; + } + } +} + +#endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING + +void SplitString(const ::std::string& str, char delimiter, + ::std::vector< ::std::string>* dest) { + ::std::vector< ::std::string> parsed; + ::std::string::size_type pos = 0; + while (::testing::internal::AlwaysTrue()) { + const ::std::string::size_type colon = str.find(delimiter, pos); + if (colon == ::std::string::npos) { + parsed.push_back(str.substr(pos)); + break; + } else { + parsed.push_back(str.substr(pos, colon - pos)); + pos = colon + 1; + } + } + dest->swap(parsed); +} + +} // namespace internal + +// Constructs an empty Message. +// We allocate the stringstream separately because otherwise each use of +// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's +// stack frame leading to huge stack frames in some cases; gcc does not reuse +// the stack space. +Message::Message() : ss_(new ::std::stringstream) { + // By default, we want there to be enough precision when printing + // a double to a Message. + *ss_ << std::setprecision(std::numeric_limits::digits10 + 2); +} + +// These two overloads allow streaming a wide C string to a Message +// using the UTF-8 encoding. +Message& Message::operator <<(const wchar_t* wide_c_str) { + return *this << internal::String::ShowWideCString(wide_c_str); +} +Message& Message::operator <<(wchar_t* wide_c_str) { + return *this << internal::String::ShowWideCString(wide_c_str); +} + +#if GTEST_HAS_STD_WSTRING +// Converts the given wide string to a narrow string using the UTF-8 +// encoding, and streams the result to this Message object. +Message& Message::operator <<(const ::std::wstring& wstr) { + internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this); + return *this; +} +#endif // GTEST_HAS_STD_WSTRING + +#if GTEST_HAS_GLOBAL_WSTRING +// Converts the given wide string to a narrow string using the UTF-8 +// encoding, and streams the result to this Message object. +Message& Message::operator <<(const ::wstring& wstr) { + internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this); + return *this; +} +#endif // GTEST_HAS_GLOBAL_WSTRING + +// Gets the text streamed to this object so far as an std::string. +// Each '\0' character in the buffer is replaced with "\\0". +std::string Message::GetString() const { + return internal::StringStreamToString(ss_.get()); +} + +// AssertionResult constructors. +// Used in EXPECT_TRUE/FALSE(assertion_result). +AssertionResult::AssertionResult(const AssertionResult& other) + : success_(other.success_), + message_(other.message_.get() != NULL ? + new ::std::string(*other.message_) : + static_cast< ::std::string*>(NULL)) { +} + +// Swaps two AssertionResults. +void AssertionResult::swap(AssertionResult& other) { + using std::swap; + swap(success_, other.success_); + swap(message_, other.message_); +} + +// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. +AssertionResult AssertionResult::operator!() const { + AssertionResult negation(!success_); + if (message_.get() != NULL) + negation << *message_; + return negation; +} + +// Makes a successful assertion result. +AssertionResult AssertionSuccess() { + return AssertionResult(true); +} + +// Makes a failed assertion result. +AssertionResult AssertionFailure() { + return AssertionResult(false); +} + +// Makes a failed assertion result with the given failure message. +// Deprecated; use AssertionFailure() << message. +AssertionResult AssertionFailure(const Message& message) { + return AssertionFailure() << message; +} + +namespace internal { + +namespace edit_distance { +std::vector CalculateOptimalEdits(const std::vector& left, + const std::vector& right) { + std::vector > costs( + left.size() + 1, std::vector(right.size() + 1)); + std::vector > best_move( + left.size() + 1, std::vector(right.size() + 1)); + + // Populate for empty right. + for (size_t l_i = 0; l_i < costs.size(); ++l_i) { + costs[l_i][0] = static_cast(l_i); + best_move[l_i][0] = kRemove; + } + // Populate for empty left. + for (size_t r_i = 1; r_i < costs[0].size(); ++r_i) { + costs[0][r_i] = static_cast(r_i); + best_move[0][r_i] = kAdd; + } + + for (size_t l_i = 0; l_i < left.size(); ++l_i) { + for (size_t r_i = 0; r_i < right.size(); ++r_i) { + if (left[l_i] == right[r_i]) { + // Found a match. Consume it. + costs[l_i + 1][r_i + 1] = costs[l_i][r_i]; + best_move[l_i + 1][r_i + 1] = kMatch; + continue; + } + + const double add = costs[l_i + 1][r_i]; + const double remove = costs[l_i][r_i + 1]; + const double replace = costs[l_i][r_i]; + if (add < remove && add < replace) { + costs[l_i + 1][r_i + 1] = add + 1; + best_move[l_i + 1][r_i + 1] = kAdd; + } else if (remove < add && remove < replace) { + costs[l_i + 1][r_i + 1] = remove + 1; + best_move[l_i + 1][r_i + 1] = kRemove; + } else { + // We make replace a little more expensive than add/remove to lower + // their priority. + costs[l_i + 1][r_i + 1] = replace + 1.00001; + best_move[l_i + 1][r_i + 1] = kReplace; + } + } + } + + // Reconstruct the best path. We do it in reverse order. + std::vector best_path; + for (size_t l_i = left.size(), r_i = right.size(); l_i > 0 || r_i > 0;) { + EditType move = best_move[l_i][r_i]; + best_path.push_back(move); + l_i -= move != kAdd; + r_i -= move != kRemove; + } + std::reverse(best_path.begin(), best_path.end()); + return best_path; +} + +namespace { + +// Helper class to convert string into ids with deduplication. +class InternalStrings { + public: + size_t GetId(const std::string& str) { + IdMap::iterator it = ids_.find(str); + if (it != ids_.end()) return it->second; + size_t id = ids_.size(); + return ids_[str] = id; + } + + private: + typedef std::map IdMap; + IdMap ids_; +}; + +} // namespace + +std::vector CalculateOptimalEdits( + const std::vector& left, + const std::vector& right) { + std::vector left_ids, right_ids; + { + InternalStrings intern_table; + for (size_t i = 0; i < left.size(); ++i) { + left_ids.push_back(intern_table.GetId(left[i])); + } + for (size_t i = 0; i < right.size(); ++i) { + right_ids.push_back(intern_table.GetId(right[i])); + } + } + return CalculateOptimalEdits(left_ids, right_ids); +} + +namespace { + +// Helper class that holds the state for one hunk and prints it out to the +// stream. +// It reorders adds/removes when possible to group all removes before all +// adds. It also adds the hunk header before printint into the stream. +class Hunk { + public: + Hunk(size_t left_start, size_t right_start) + : left_start_(left_start), + right_start_(right_start), + adds_(), + removes_(), + common_() {} + + void PushLine(char edit, const char* line) { + switch (edit) { + case ' ': + ++common_; + FlushEdits(); + hunk_.push_back(std::make_pair(' ', line)); + break; + case '-': + ++removes_; + hunk_removes_.push_back(std::make_pair('-', line)); + break; + case '+': + ++adds_; + hunk_adds_.push_back(std::make_pair('+', line)); + break; + } + } + + void PrintTo(std::ostream* os) { + PrintHeader(os); + FlushEdits(); + for (std::list >::const_iterator it = + hunk_.begin(); + it != hunk_.end(); ++it) { + *os << it->first << it->second << "\n"; + } + } + + bool has_edits() const { return adds_ || removes_; } + + private: + void FlushEdits() { + hunk_.splice(hunk_.end(), hunk_removes_); + hunk_.splice(hunk_.end(), hunk_adds_); + } + + // Print a unified diff header for one hunk. + // The format is + // "@@ -, +, @@" + // where the left/right parts are ommitted if unnecessary. + void PrintHeader(std::ostream* ss) const { + *ss << "@@ "; + if (removes_) { + *ss << "-" << left_start_ << "," << (removes_ + common_); + } + if (removes_ && adds_) { + *ss << " "; + } + if (adds_) { + *ss << "+" << right_start_ << "," << (adds_ + common_); + } + *ss << " @@\n"; + } + + size_t left_start_, right_start_; + size_t adds_, removes_, common_; + std::list > hunk_, hunk_adds_, hunk_removes_; +}; + +} // namespace + +// Create a list of diff hunks in Unified diff format. +// Each hunk has a header generated by PrintHeader above plus a body with +// lines prefixed with ' ' for no change, '-' for deletion and '+' for +// addition. +// 'context' represents the desired unchanged prefix/suffix around the diff. +// If two hunks are close enough that their contexts overlap, then they are +// joined into one hunk. +std::string CreateUnifiedDiff(const std::vector& left, + const std::vector& right, + size_t context) { + const std::vector edits = CalculateOptimalEdits(left, right); + + size_t l_i = 0, r_i = 0, edit_i = 0; + std::stringstream ss; + while (edit_i < edits.size()) { + // Find first edit. + while (edit_i < edits.size() && edits[edit_i] == kMatch) { + ++l_i; + ++r_i; + ++edit_i; + } + + // Find the first line to include in the hunk. + const size_t prefix_context = std::min(l_i, context); + Hunk hunk(l_i - prefix_context + 1, r_i - prefix_context + 1); + for (size_t i = prefix_context; i > 0; --i) { + hunk.PushLine(' ', left[l_i - i].c_str()); + } + + // Iterate the edits until we found enough suffix for the hunk or the input + // is over. + size_t n_suffix = 0; + for (; edit_i < edits.size(); ++edit_i) { + if (n_suffix >= context) { + // Continue only if the next hunk is very close. + std::vector::const_iterator it = edits.begin() + edit_i; + while (it != edits.end() && *it == kMatch) ++it; + if (it == edits.end() || (it - edits.begin()) - edit_i >= context) { + // There is no next edit or it is too far away. + break; + } + } + + EditType edit = edits[edit_i]; + // Reset count when a non match is found. + n_suffix = edit == kMatch ? n_suffix + 1 : 0; + + if (edit == kMatch || edit == kRemove || edit == kReplace) { + hunk.PushLine(edit == kMatch ? ' ' : '-', left[l_i].c_str()); + } + if (edit == kAdd || edit == kReplace) { + hunk.PushLine('+', right[r_i].c_str()); + } + + // Advance indices, depending on edit type. + l_i += edit != kAdd; + r_i += edit != kRemove; + } + + if (!hunk.has_edits()) { + // We are done. We don't want this hunk. + break; + } + + hunk.PrintTo(&ss); + } + return ss.str(); +} + +} // namespace edit_distance + +namespace { + +// The string representation of the values received in EqFailure() are already +// escaped. Split them on escaped '\n' boundaries. Leave all other escaped +// characters the same. +std::vector SplitEscapedString(const std::string& str) { + std::vector lines; + size_t start = 0, end = str.size(); + if (end > 2 && str[0] == '"' && str[end - 1] == '"') { + ++start; + --end; + } + bool escaped = false; + for (size_t i = start; i + 1 < end; ++i) { + if (escaped) { + escaped = false; + if (str[i] == 'n') { + lines.push_back(str.substr(start, i - start - 1)); + start = i + 1; + } + } else { + escaped = str[i] == '\\'; + } + } + lines.push_back(str.substr(start, end - start)); + return lines; +} + +} // namespace + +// Constructs and returns the message for an equality assertion +// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. +// +// The first four parameters are the expressions used in the assertion +// and their values, as strings. For example, for ASSERT_EQ(foo, bar) +// where foo is 5 and bar is 6, we have: +// +// lhs_expression: "foo" +// rhs_expression: "bar" +// lhs_value: "5" +// rhs_value: "6" +// +// The ignoring_case parameter is true iff the assertion is a +// *_STRCASEEQ*. When it's true, the string "Ignoring case" will +// be inserted into the message. +AssertionResult EqFailure(const char* lhs_expression, + const char* rhs_expression, + const std::string& lhs_value, + const std::string& rhs_value, + bool ignoring_case) { + Message msg; + msg << " Expected: " << lhs_expression; + if (lhs_value != lhs_expression) { + msg << "\n Which is: " << lhs_value; + } + msg << "\nTo be equal to: " << rhs_expression; + if (rhs_value != rhs_expression) { + msg << "\n Which is: " << rhs_value; + } + + if (ignoring_case) { + msg << "\nIgnoring case"; + } + + if (!lhs_value.empty() && !rhs_value.empty()) { + const std::vector lhs_lines = + SplitEscapedString(lhs_value); + const std::vector rhs_lines = + SplitEscapedString(rhs_value); + if (lhs_lines.size() > 1 || rhs_lines.size() > 1) { + msg << "\nWith diff:\n" + << edit_distance::CreateUnifiedDiff(lhs_lines, rhs_lines); + } + } + + return AssertionFailure() << msg; +} + +// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. +std::string GetBoolAssertionFailureMessage( + const AssertionResult& assertion_result, + const char* expression_text, + const char* actual_predicate_value, + const char* expected_predicate_value) { + const char* actual_message = assertion_result.message(); + Message msg; + msg << "Value of: " << expression_text + << "\n Actual: " << actual_predicate_value; + if (actual_message[0] != '\0') + msg << " (" << actual_message << ")"; + msg << "\nExpected: " << expected_predicate_value; + return msg.GetString(); +} + +// Helper function for implementing ASSERT_NEAR. +AssertionResult DoubleNearPredFormat(const char* expr1, + const char* expr2, + const char* abs_error_expr, + double val1, + double val2, + double abs_error) { + const double diff = fabs(val1 - val2); + if (diff <= abs_error) return AssertionSuccess(); + + // TODO(wan): do not print the value of an expression if it's + // already a literal. + return AssertionFailure() + << "The difference between " << expr1 << " and " << expr2 + << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n" + << expr1 << " evaluates to " << val1 << ",\n" + << expr2 << " evaluates to " << val2 << ", and\n" + << abs_error_expr << " evaluates to " << abs_error << "."; +} + + +// Helper template for implementing FloatLE() and DoubleLE(). +template +AssertionResult FloatingPointLE(const char* expr1, + const char* expr2, + RawType val1, + RawType val2) { + // Returns success if val1 is less than val2, + if (val1 < val2) { + return AssertionSuccess(); + } + + // or if val1 is almost equal to val2. + const FloatingPoint lhs(val1), rhs(val2); + if (lhs.AlmostEquals(rhs)) { + return AssertionSuccess(); + } + + // Note that the above two checks will both fail if either val1 or + // val2 is NaN, as the IEEE floating-point standard requires that + // any predicate involving a NaN must return false. + + ::std::stringstream val1_ss; + val1_ss << std::setprecision(std::numeric_limits::digits10 + 2) + << val1; + + ::std::stringstream val2_ss; + val2_ss << std::setprecision(std::numeric_limits::digits10 + 2) + << val2; + + return AssertionFailure() + << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n" + << " Actual: " << StringStreamToString(&val1_ss) << " vs " + << StringStreamToString(&val2_ss); +} + +} // namespace internal + +// Asserts that val1 is less than, or almost equal to, val2. Fails +// otherwise. In particular, it fails if either val1 or val2 is NaN. +AssertionResult FloatLE(const char* expr1, const char* expr2, + float val1, float val2) { + return internal::FloatingPointLE(expr1, expr2, val1, val2); +} + +// Asserts that val1 is less than, or almost equal to, val2. Fails +// otherwise. In particular, it fails if either val1 or val2 is NaN. +AssertionResult DoubleLE(const char* expr1, const char* expr2, + double val1, double val2) { + return internal::FloatingPointLE(expr1, expr2, val1, val2); +} + +namespace internal { + +// The helper function for {ASSERT|EXPECT}_EQ with int or enum +// arguments. +AssertionResult CmpHelperEQ(const char* lhs_expression, + const char* rhs_expression, + BiggestInt lhs, + BiggestInt rhs) { + if (lhs == rhs) { + return AssertionSuccess(); + } + + return EqFailure(lhs_expression, + rhs_expression, + FormatForComparisonFailureMessage(lhs, rhs), + FormatForComparisonFailureMessage(rhs, lhs), + false); +} + +// A macro for implementing the helper functions needed to implement +// ASSERT_?? and EXPECT_?? with integer or enum arguments. It is here +// just to avoid copy-and-paste of similar code. +#define GTEST_IMPL_CMP_HELPER_(op_name, op)\ +AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ + BiggestInt val1, BiggestInt val2) {\ + if (val1 op val2) {\ + return AssertionSuccess();\ + } else {\ + return AssertionFailure() \ + << "Expected: (" << expr1 << ") " #op " (" << expr2\ + << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ + << " vs " << FormatForComparisonFailureMessage(val2, val1);\ + }\ +} + +// Implements the helper function for {ASSERT|EXPECT}_NE with int or +// enum arguments. +GTEST_IMPL_CMP_HELPER_(NE, !=) +// Implements the helper function for {ASSERT|EXPECT}_LE with int or +// enum arguments. +GTEST_IMPL_CMP_HELPER_(LE, <=) +// Implements the helper function for {ASSERT|EXPECT}_LT with int or +// enum arguments. +GTEST_IMPL_CMP_HELPER_(LT, < ) +// Implements the helper function for {ASSERT|EXPECT}_GE with int or +// enum arguments. +GTEST_IMPL_CMP_HELPER_(GE, >=) +// Implements the helper function for {ASSERT|EXPECT}_GT with int or +// enum arguments. +GTEST_IMPL_CMP_HELPER_(GT, > ) + +#undef GTEST_IMPL_CMP_HELPER_ + +// The helper function for {ASSERT|EXPECT}_STREQ. +AssertionResult CmpHelperSTREQ(const char* lhs_expression, + const char* rhs_expression, + const char* lhs, + const char* rhs) { + if (String::CStringEquals(lhs, rhs)) { + return AssertionSuccess(); + } + + return EqFailure(lhs_expression, + rhs_expression, + PrintToString(lhs), + PrintToString(rhs), + false); +} + +// The helper function for {ASSERT|EXPECT}_STRCASEEQ. +AssertionResult CmpHelperSTRCASEEQ(const char* lhs_expression, + const char* rhs_expression, + const char* lhs, + const char* rhs) { + if (String::CaseInsensitiveCStringEquals(lhs, rhs)) { + return AssertionSuccess(); + } + + return EqFailure(lhs_expression, + rhs_expression, + PrintToString(lhs), + PrintToString(rhs), + true); +} + +// The helper function for {ASSERT|EXPECT}_STRNE. +AssertionResult CmpHelperSTRNE(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2) { + if (!String::CStringEquals(s1, s2)) { + return AssertionSuccess(); + } else { + return AssertionFailure() << "Expected: (" << s1_expression << ") != (" + << s2_expression << "), actual: \"" + << s1 << "\" vs \"" << s2 << "\""; + } +} + +// The helper function for {ASSERT|EXPECT}_STRCASENE. +AssertionResult CmpHelperSTRCASENE(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2) { + if (!String::CaseInsensitiveCStringEquals(s1, s2)) { + return AssertionSuccess(); + } else { + return AssertionFailure() + << "Expected: (" << s1_expression << ") != (" + << s2_expression << ") (ignoring case), actual: \"" + << s1 << "\" vs \"" << s2 << "\""; + } +} + +} // namespace internal + +namespace { + +// Helper functions for implementing IsSubString() and IsNotSubstring(). + +// This group of overloaded functions return true iff needle is a +// substring of haystack. NULL is considered a substring of itself +// only. + +bool IsSubstringPred(const char* needle, const char* haystack) { + if (needle == NULL || haystack == NULL) + return needle == haystack; + + return strstr(haystack, needle) != NULL; +} + +bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) { + if (needle == NULL || haystack == NULL) + return needle == haystack; + + return wcsstr(haystack, needle) != NULL; +} + +// StringType here can be either ::std::string or ::std::wstring. +template +bool IsSubstringPred(const StringType& needle, + const StringType& haystack) { + return haystack.find(needle) != StringType::npos; +} + +// This function implements either IsSubstring() or IsNotSubstring(), +// depending on the value of the expected_to_be_substring parameter. +// StringType here can be const char*, const wchar_t*, ::std::string, +// or ::std::wstring. +template +AssertionResult IsSubstringImpl( + bool expected_to_be_substring, + const char* needle_expr, const char* haystack_expr, + const StringType& needle, const StringType& haystack) { + if (IsSubstringPred(needle, haystack) == expected_to_be_substring) + return AssertionSuccess(); + + const bool is_wide_string = sizeof(needle[0]) > 1; + const char* const begin_string_quote = is_wide_string ? "L\"" : "\""; + return AssertionFailure() + << "Value of: " << needle_expr << "\n" + << " Actual: " << begin_string_quote << needle << "\"\n" + << "Expected: " << (expected_to_be_substring ? "" : "not ") + << "a substring of " << haystack_expr << "\n" + << "Which is: " << begin_string_quote << haystack << "\""; +} + +} // namespace + +// IsSubstring() and IsNotSubstring() check whether needle is a +// substring of haystack (NULL is considered a substring of itself +// only), and return an appropriate error message when they fail. + +AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const char* needle, const char* haystack) { + return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const wchar_t* needle, const wchar_t* haystack) { + return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const char* needle, const char* haystack) { + return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const wchar_t* needle, const wchar_t* haystack) { + return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::string& needle, const ::std::string& haystack) { + return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::string& needle, const ::std::string& haystack) { + return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); +} + +#if GTEST_HAS_STD_WSTRING +AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::wstring& needle, const ::std::wstring& haystack) { + return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack); +} + +AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::wstring& needle, const ::std::wstring& haystack) { + return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack); +} +#endif // GTEST_HAS_STD_WSTRING + +namespace internal { + +#if GTEST_OS_WINDOWS + +namespace { + +// Helper function for IsHRESULT{SuccessFailure} predicates +AssertionResult HRESULTFailureHelper(const char* expr, + const char* expected, + long hr) { // NOLINT +# if GTEST_OS_WINDOWS_MOBILE + + // Windows CE doesn't support FormatMessage. + const char error_text[] = ""; + +# else + + // Looks up the human-readable system message for the HRESULT code + // and since we're not passing any params to FormatMessage, we don't + // want inserts expanded. + const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS; + const DWORD kBufSize = 4096; + // Gets the system's human readable message string for this HRESULT. + char error_text[kBufSize] = { '\0' }; + DWORD message_length = ::FormatMessageA(kFlags, + 0, // no source, we're asking system + hr, // the error + 0, // no line width restrictions + error_text, // output buffer + kBufSize, // buf size + NULL); // no arguments for inserts + // Trims tailing white space (FormatMessage leaves a trailing CR-LF) + for (; message_length && IsSpace(error_text[message_length - 1]); + --message_length) { + error_text[message_length - 1] = '\0'; + } + +# endif // GTEST_OS_WINDOWS_MOBILE + + const std::string error_hex("0x" + String::FormatHexInt(hr)); + return ::testing::AssertionFailure() + << "Expected: " << expr << " " << expected << ".\n" + << " Actual: " << error_hex << " " << error_text << "\n"; +} + +} // namespace + +AssertionResult IsHRESULTSuccess(const char* expr, long hr) { // NOLINT + if (SUCCEEDED(hr)) { + return AssertionSuccess(); + } + return HRESULTFailureHelper(expr, "succeeds", hr); +} + +AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT + if (FAILED(hr)) { + return AssertionSuccess(); + } + return HRESULTFailureHelper(expr, "fails", hr); +} + +#endif // GTEST_OS_WINDOWS + +// Utility functions for encoding Unicode text (wide strings) in +// UTF-8. + +// A Unicode code-point can have upto 21 bits, and is encoded in UTF-8 +// like this: +// +// Code-point length Encoding +// 0 - 7 bits 0xxxxxxx +// 8 - 11 bits 110xxxxx 10xxxxxx +// 12 - 16 bits 1110xxxx 10xxxxxx 10xxxxxx +// 17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + +// The maximum code-point a one-byte UTF-8 sequence can represent. +const UInt32 kMaxCodePoint1 = (static_cast(1) << 7) - 1; + +// The maximum code-point a two-byte UTF-8 sequence can represent. +const UInt32 kMaxCodePoint2 = (static_cast(1) << (5 + 6)) - 1; + +// The maximum code-point a three-byte UTF-8 sequence can represent. +const UInt32 kMaxCodePoint3 = (static_cast(1) << (4 + 2*6)) - 1; + +// The maximum code-point a four-byte UTF-8 sequence can represent. +const UInt32 kMaxCodePoint4 = (static_cast(1) << (3 + 3*6)) - 1; + +// Chops off the n lowest bits from a bit pattern. Returns the n +// lowest bits. As a side effect, the original bit pattern will be +// shifted to the right by n bits. +inline UInt32 ChopLowBits(UInt32* bits, int n) { + const UInt32 low_bits = *bits & ((static_cast(1) << n) - 1); + *bits >>= n; + return low_bits; +} + +// Converts a Unicode code point to a narrow string in UTF-8 encoding. +// code_point parameter is of type UInt32 because wchar_t may not be +// wide enough to contain a code point. +// If the code_point is not a valid Unicode code point +// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted +// to "(Invalid Unicode 0xXXXXXXXX)". +std::string CodePointToUtf8(UInt32 code_point) { + if (code_point > kMaxCodePoint4) { + return "(Invalid Unicode 0x" + String::FormatHexInt(code_point) + ")"; + } + + char str[5]; // Big enough for the largest valid code point. + if (code_point <= kMaxCodePoint1) { + str[1] = '\0'; + str[0] = static_cast(code_point); // 0xxxxxxx + } else if (code_point <= kMaxCodePoint2) { + str[2] = '\0'; + str[1] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[0] = static_cast(0xC0 | code_point); // 110xxxxx + } else if (code_point <= kMaxCodePoint3) { + str[3] = '\0'; + str[2] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[1] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[0] = static_cast(0xE0 | code_point); // 1110xxxx + } else { // code_point <= kMaxCodePoint4 + str[4] = '\0'; + str[3] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[2] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[1] = static_cast(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx + str[0] = static_cast(0xF0 | code_point); // 11110xxx + } + return str; +} + +// The following two functions only make sense if the the system +// uses UTF-16 for wide string encoding. All supported systems +// with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16. + +// Determines if the arguments constitute UTF-16 surrogate pair +// and thus should be combined into a single Unicode code point +// using CreateCodePointFromUtf16SurrogatePair. +inline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) { + return sizeof(wchar_t) == 2 && + (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00; +} + +// Creates a Unicode code point from UTF16 surrogate pair. +inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first, + wchar_t second) { + const UInt32 mask = (1 << 10) - 1; + return (sizeof(wchar_t) == 2) ? + (((first & mask) << 10) | (second & mask)) + 0x10000 : + // This function should not be called when the condition is + // false, but we provide a sensible default in case it is. + static_cast(first); +} + +// Converts a wide string to a narrow string in UTF-8 encoding. +// The wide string is assumed to have the following encoding: +// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS) +// UTF-32 if sizeof(wchar_t) == 4 (on Linux) +// Parameter str points to a null-terminated wide string. +// Parameter num_chars may additionally limit the number +// of wchar_t characters processed. -1 is used when the entire string +// should be processed. +// If the string contains code points that are not valid Unicode code points +// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output +// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding +// and contains invalid UTF-16 surrogate pairs, values in those pairs +// will be encoded as individual Unicode characters from Basic Normal Plane. +std::string WideStringToUtf8(const wchar_t* str, int num_chars) { + if (num_chars == -1) + num_chars = static_cast(wcslen(str)); + + ::std::stringstream stream; + for (int i = 0; i < num_chars; ++i) { + UInt32 unicode_code_point; + + if (str[i] == L'\0') { + break; + } else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) { + unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i], + str[i + 1]); + i++; + } else { + unicode_code_point = static_cast(str[i]); + } + + stream << CodePointToUtf8(unicode_code_point); + } + return StringStreamToString(&stream); +} + +// Converts a wide C string to an std::string using the UTF-8 encoding. +// NULL will be converted to "(null)". +std::string String::ShowWideCString(const wchar_t * wide_c_str) { + if (wide_c_str == NULL) return "(null)"; + + return internal::WideStringToUtf8(wide_c_str, -1); +} + +// Compares two wide C strings. Returns true iff they have the same +// content. +// +// Unlike wcscmp(), this function can handle NULL argument(s). A NULL +// C string is considered different to any non-NULL C string, +// including the empty string. +bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) { + if (lhs == NULL) return rhs == NULL; + + if (rhs == NULL) return false; + + return wcscmp(lhs, rhs) == 0; +} + +// Helper function for *_STREQ on wide strings. +AssertionResult CmpHelperSTREQ(const char* lhs_expression, + const char* rhs_expression, + const wchar_t* lhs, + const wchar_t* rhs) { + if (String::WideCStringEquals(lhs, rhs)) { + return AssertionSuccess(); + } + + return EqFailure(lhs_expression, + rhs_expression, + PrintToString(lhs), + PrintToString(rhs), + false); +} + +// Helper function for *_STRNE on wide strings. +AssertionResult CmpHelperSTRNE(const char* s1_expression, + const char* s2_expression, + const wchar_t* s1, + const wchar_t* s2) { + if (!String::WideCStringEquals(s1, s2)) { + return AssertionSuccess(); + } + + return AssertionFailure() << "Expected: (" << s1_expression << ") != (" + << s2_expression << "), actual: " + << PrintToString(s1) + << " vs " << PrintToString(s2); +} + +// Compares two C strings, ignoring case. Returns true iff they have +// the same content. +// +// Unlike strcasecmp(), this function can handle NULL argument(s). A +// NULL C string is considered different to any non-NULL C string, +// including the empty string. +bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) { + if (lhs == NULL) + return rhs == NULL; + if (rhs == NULL) + return false; + return posix::StrCaseCmp(lhs, rhs) == 0; +} + + // Compares two wide C strings, ignoring case. Returns true iff they + // have the same content. + // + // Unlike wcscasecmp(), this function can handle NULL argument(s). + // A NULL C string is considered different to any non-NULL wide C string, + // including the empty string. + // NB: The implementations on different platforms slightly differ. + // On windows, this method uses _wcsicmp which compares according to LC_CTYPE + // environment variable. On GNU platform this method uses wcscasecmp + // which compares according to LC_CTYPE category of the current locale. + // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the + // current locale. +bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, + const wchar_t* rhs) { + if (lhs == NULL) return rhs == NULL; + + if (rhs == NULL) return false; + +#if GTEST_OS_WINDOWS + return _wcsicmp(lhs, rhs) == 0; +#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID + return wcscasecmp(lhs, rhs) == 0; +#else + // Android, Mac OS X and Cygwin don't define wcscasecmp. + // Other unknown OSes may not define it either. + wint_t left, right; + do { + left = towlower(*lhs++); + right = towlower(*rhs++); + } while (left && left == right); + return left == right; +#endif // OS selector +} + +// Returns true iff str ends with the given suffix, ignoring case. +// Any string is considered to end with an empty suffix. +bool String::EndsWithCaseInsensitive( + const std::string& str, const std::string& suffix) { + const size_t str_len = str.length(); + const size_t suffix_len = suffix.length(); + return (str_len >= suffix_len) && + CaseInsensitiveCStringEquals(str.c_str() + str_len - suffix_len, + suffix.c_str()); +} + +// Formats an int value as "%02d". +std::string String::FormatIntWidth2(int value) { + std::stringstream ss; + ss << std::setfill('0') << std::setw(2) << value; + return ss.str(); +} + +// Formats an int value as "%X". +std::string String::FormatHexInt(int value) { + std::stringstream ss; + ss << std::hex << std::uppercase << value; + return ss.str(); +} + +// Formats a byte as "%02X". +std::string String::FormatByte(unsigned char value) { + std::stringstream ss; + ss << std::setfill('0') << std::setw(2) << std::hex << std::uppercase + << static_cast(value); + return ss.str(); +} + +// Converts the buffer in a stringstream to an std::string, converting NUL +// bytes to "\\0" along the way. +std::string StringStreamToString(::std::stringstream* ss) { + const ::std::string& str = ss->str(); + const char* const start = str.c_str(); + const char* const end = start + str.length(); + + std::string result; + result.reserve(2 * (end - start)); + for (const char* ch = start; ch != end; ++ch) { + if (*ch == '\0') { + result += "\\0"; // Replaces NUL with "\\0"; + } else { + result += *ch; + } + } + + return result; +} + +// Appends the user-supplied message to the Google-Test-generated message. +std::string AppendUserMessage(const std::string& gtest_msg, + const Message& user_msg) { + // Appends the user message if it's non-empty. + const std::string user_msg_string = user_msg.GetString(); + if (user_msg_string.empty()) { + return gtest_msg; + } + + return gtest_msg + "\n" + user_msg_string; +} + +} // namespace internal + +// class TestResult + +// Creates an empty TestResult. +TestResult::TestResult() + : death_test_count_(0), + elapsed_time_(0) { +} + +// D'tor. +TestResult::~TestResult() { +} + +// Returns the i-th test part result among all the results. i can +// range from 0 to total_part_count() - 1. If i is not in that range, +// aborts the program. +const TestPartResult& TestResult::GetTestPartResult(int i) const { + if (i < 0 || i >= total_part_count()) + internal::posix::Abort(); + return test_part_results_.at(i); +} + +// Returns the i-th test property. i can range from 0 to +// test_property_count() - 1. If i is not in that range, aborts the +// program. +const TestProperty& TestResult::GetTestProperty(int i) const { + if (i < 0 || i >= test_property_count()) + internal::posix::Abort(); + return test_properties_.at(i); +} + +// Clears the test part results. +void TestResult::ClearTestPartResults() { + test_part_results_.clear(); +} + +// Adds a test part result to the list. +void TestResult::AddTestPartResult(const TestPartResult& test_part_result) { + test_part_results_.push_back(test_part_result); +} + +// Adds a test property to the list. If a property with the same key as the +// supplied property is already represented, the value of this test_property +// replaces the old value for that key. +void TestResult::RecordProperty(const std::string& xml_element, + const TestProperty& test_property) { + if (!ValidateTestProperty(xml_element, test_property)) { + return; + } + internal::MutexLock lock(&test_properites_mutex_); + const std::vector::iterator property_with_matching_key = + std::find_if(test_properties_.begin(), test_properties_.end(), + internal::TestPropertyKeyIs(test_property.key())); + if (property_with_matching_key == test_properties_.end()) { + test_properties_.push_back(test_property); + return; + } + property_with_matching_key->SetValue(test_property.value()); +} + +// The list of reserved attributes used in the element of XML +// output. +static const char* const kReservedTestSuitesAttributes[] = { + "disabled", + "errors", + "failures", + "name", + "random_seed", + "tests", + "time", + "timestamp" +}; + +// The list of reserved attributes used in the element of XML +// output. +static const char* const kReservedTestSuiteAttributes[] = { + "disabled", + "errors", + "failures", + "name", + "tests", + "time" +}; + +// The list of reserved attributes used in the element of XML output. +static const char* const kReservedTestCaseAttributes[] = { + "classname", + "name", + "status", + "time", + "type_param", + "value_param" +}; + +template +std::vector ArrayAsVector(const char* const (&array)[kSize]) { + return std::vector(array, array + kSize); +} + +static std::vector GetReservedAttributesForElement( + const std::string& xml_element) { + if (xml_element == "testsuites") { + return ArrayAsVector(kReservedTestSuitesAttributes); + } else if (xml_element == "testsuite") { + return ArrayAsVector(kReservedTestSuiteAttributes); + } else if (xml_element == "testcase") { + return ArrayAsVector(kReservedTestCaseAttributes); + } else { + GTEST_CHECK_(false) << "Unrecognized xml_element provided: " << xml_element; + } + // This code is unreachable but some compilers may not realizes that. + return std::vector(); +} + +static std::string FormatWordList(const std::vector& words) { + Message word_list; + for (size_t i = 0; i < words.size(); ++i) { + if (i > 0 && words.size() > 2) { + word_list << ", "; + } + if (i == words.size() - 1) { + word_list << "and "; + } + word_list << "'" << words[i] << "'"; + } + return word_list.GetString(); +} + +bool ValidateTestPropertyName(const std::string& property_name, + const std::vector& reserved_names) { + if (std::find(reserved_names.begin(), reserved_names.end(), property_name) != + reserved_names.end()) { + ADD_FAILURE() << "Reserved key used in RecordProperty(): " << property_name + << " (" << FormatWordList(reserved_names) + << " are reserved by " << GTEST_NAME_ << ")"; + return false; + } + return true; +} + +// Adds a failure if the key is a reserved attribute of the element named +// xml_element. Returns true if the property is valid. +bool TestResult::ValidateTestProperty(const std::string& xml_element, + const TestProperty& test_property) { + return ValidateTestPropertyName(test_property.key(), + GetReservedAttributesForElement(xml_element)); +} + +// Clears the object. +void TestResult::Clear() { + test_part_results_.clear(); + test_properties_.clear(); + death_test_count_ = 0; + elapsed_time_ = 0; +} + +// Returns true iff the test failed. +bool TestResult::Failed() const { + for (int i = 0; i < total_part_count(); ++i) { + if (GetTestPartResult(i).failed()) + return true; + } + return false; +} + +// Returns true iff the test part fatally failed. +static bool TestPartFatallyFailed(const TestPartResult& result) { + return result.fatally_failed(); +} + +// Returns true iff the test fatally failed. +bool TestResult::HasFatalFailure() const { + return CountIf(test_part_results_, TestPartFatallyFailed) > 0; +} + +// Returns true iff the test part non-fatally failed. +static bool TestPartNonfatallyFailed(const TestPartResult& result) { + return result.nonfatally_failed(); +} + +// Returns true iff the test has a non-fatal failure. +bool TestResult::HasNonfatalFailure() const { + return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0; +} + +// Gets the number of all test parts. This is the sum of the number +// of successful test parts and the number of failed test parts. +int TestResult::total_part_count() const { + return static_cast(test_part_results_.size()); +} + +// Returns the number of the test properties. +int TestResult::test_property_count() const { + return static_cast(test_properties_.size()); +} + +// class Test + +// Creates a Test object. + +// The c'tor saves the states of all flags. +Test::Test() + : gtest_flag_saver_(new GTEST_FLAG_SAVER_) { +} + +// The d'tor restores the states of all flags. The actual work is +// done by the d'tor of the gtest_flag_saver_ field, and thus not +// visible here. +Test::~Test() { +} + +// Sets up the test fixture. +// +// A sub-class may override this. +void Test::SetUp() { +} + +// Tears down the test fixture. +// +// A sub-class may override this. +void Test::TearDown() { +} + +// Allows user supplied key value pairs to be recorded for later output. +void Test::RecordProperty(const std::string& key, const std::string& value) { + UnitTest::GetInstance()->RecordProperty(key, value); +} + +// Allows user supplied key value pairs to be recorded for later output. +void Test::RecordProperty(const std::string& key, int value) { + Message value_message; + value_message << value; + RecordProperty(key, value_message.GetString().c_str()); +} + +namespace internal { + +void ReportFailureInUnknownLocation(TestPartResult::Type result_type, + const std::string& message) { + // This function is a friend of UnitTest and as such has access to + // AddTestPartResult. + UnitTest::GetInstance()->AddTestPartResult( + result_type, + NULL, // No info about the source file where the exception occurred. + -1, // We have no info on which line caused the exception. + message, + ""); // No stack trace, either. +} + +} // namespace internal + +// Google Test requires all tests in the same test case to use the same test +// fixture class. This function checks if the current test has the +// same fixture class as the first test in the current test case. If +// yes, it returns true; otherwise it generates a Google Test failure and +// returns false. +bool Test::HasSameFixtureClass() { + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + const TestCase* const test_case = impl->current_test_case(); + + // Info about the first test in the current test case. + const TestInfo* const first_test_info = test_case->test_info_list()[0]; + const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_; + const char* const first_test_name = first_test_info->name(); + + // Info about the current test. + const TestInfo* const this_test_info = impl->current_test_info(); + const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_; + const char* const this_test_name = this_test_info->name(); + + if (this_fixture_id != first_fixture_id) { + // Is the first test defined using TEST? + const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId(); + // Is this test defined using TEST? + const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId(); + + if (first_is_TEST || this_is_TEST) { + // Both TEST and TEST_F appear in same test case, which is incorrect. + // Tell the user how to fix this. + + // Gets the name of the TEST and the name of the TEST_F. Note + // that first_is_TEST and this_is_TEST cannot both be true, as + // the fixture IDs are different for the two tests. + const char* const TEST_name = + first_is_TEST ? first_test_name : this_test_name; + const char* const TEST_F_name = + first_is_TEST ? this_test_name : first_test_name; + + ADD_FAILURE() + << "All tests in the same test case must use the same test fixture\n" + << "class, so mixing TEST_F and TEST in the same test case is\n" + << "illegal. In test case " << this_test_info->test_case_name() + << ",\n" + << "test " << TEST_F_name << " is defined using TEST_F but\n" + << "test " << TEST_name << " is defined using TEST. You probably\n" + << "want to change the TEST to TEST_F or move it to another test\n" + << "case."; + } else { + // Two fixture classes with the same name appear in two different + // namespaces, which is not allowed. Tell the user how to fix this. + ADD_FAILURE() + << "All tests in the same test case must use the same test fixture\n" + << "class. However, in test case " + << this_test_info->test_case_name() << ",\n" + << "you defined test " << first_test_name + << " and test " << this_test_name << "\n" + << "using two different test fixture classes. This can happen if\n" + << "the two classes are from different namespaces or translation\n" + << "units and have the same name. You should probably rename one\n" + << "of the classes to put the tests into different test cases."; + } + return false; + } + + return true; +} + +#if GTEST_HAS_SEH + +// Adds an "exception thrown" fatal failure to the current test. This +// function returns its result via an output parameter pointer because VC++ +// prohibits creation of objects with destructors on stack in functions +// using __try (see error C2712). +static std::string* FormatSehExceptionMessage(DWORD exception_code, + const char* location) { + Message message; + message << "SEH exception with code 0x" << std::setbase(16) << + exception_code << std::setbase(10) << " thrown in " << location << "."; + + return new std::string(message.GetString()); +} + +#endif // GTEST_HAS_SEH + +namespace internal { + +#if GTEST_HAS_EXCEPTIONS + +// Adds an "exception thrown" fatal failure to the current test. +static std::string FormatCxxExceptionMessage(const char* description, + const char* location) { + Message message; + if (description != NULL) { + message << "C++ exception with description \"" << description << "\""; + } else { + message << "Unknown C++ exception"; + } + message << " thrown in " << location << "."; + + return message.GetString(); +} + +static std::string PrintTestPartResultToString( + const TestPartResult& test_part_result); + +GoogleTestFailureException::GoogleTestFailureException( + const TestPartResult& failure) + : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {} + +#endif // GTEST_HAS_EXCEPTIONS + +// We put these helper functions in the internal namespace as IBM's xlC +// compiler rejects the code if they were declared static. + +// Runs the given method and handles SEH exceptions it throws, when +// SEH is supported; returns the 0-value for type Result in case of an +// SEH exception. (Microsoft compilers cannot handle SEH and C++ +// exceptions in the same function. Therefore, we provide a separate +// wrapper function for handling SEH exceptions.) +template +Result HandleSehExceptionsInMethodIfSupported( + T* object, Result (T::*method)(), const char* location) { +#if GTEST_HAS_SEH + __try { + return (object->*method)(); + } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT + GetExceptionCode())) { + // We create the exception message on the heap because VC++ prohibits + // creation of objects with destructors on stack in functions using __try + // (see error C2712). + std::string* exception_message = FormatSehExceptionMessage( + GetExceptionCode(), location); + internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure, + *exception_message); + delete exception_message; + return static_cast(0); + } +#else + (void)location; + return (object->*method)(); +#endif // GTEST_HAS_SEH +} + +// Runs the given method and catches and reports C++ and/or SEH-style +// exceptions, if they are supported; returns the 0-value for type +// Result in case of an SEH exception. +template +Result HandleExceptionsInMethodIfSupported( + T* object, Result (T::*method)(), const char* location) { + // NOTE: The user code can affect the way in which Google Test handles + // exceptions by setting GTEST_FLAG(catch_exceptions), but only before + // RUN_ALL_TESTS() starts. It is technically possible to check the flag + // after the exception is caught and either report or re-throw the + // exception based on the flag's value: + // + // try { + // // Perform the test method. + // } catch (...) { + // if (GTEST_FLAG(catch_exceptions)) + // // Report the exception as failure. + // else + // throw; // Re-throws the original exception. + // } + // + // However, the purpose of this flag is to allow the program to drop into + // the debugger when the exception is thrown. On most platforms, once the + // control enters the catch block, the exception origin information is + // lost and the debugger will stop the program at the point of the + // re-throw in this function -- instead of at the point of the original + // throw statement in the code under test. For this reason, we perform + // the check early, sacrificing the ability to affect Google Test's + // exception handling in the method where the exception is thrown. + if (internal::GetUnitTestImpl()->catch_exceptions()) { +#if GTEST_HAS_EXCEPTIONS + try { + return HandleSehExceptionsInMethodIfSupported(object, method, location); + } catch (const internal::GoogleTestFailureException&) { // NOLINT + // This exception type can only be thrown by a failed Google + // Test assertion with the intention of letting another testing + // framework catch it. Therefore we just re-throw it. + throw; + } catch (const std::exception& e) { // NOLINT + internal::ReportFailureInUnknownLocation( + TestPartResult::kFatalFailure, + FormatCxxExceptionMessage(e.what(), location)); + } catch (...) { // NOLINT + internal::ReportFailureInUnknownLocation( + TestPartResult::kFatalFailure, + FormatCxxExceptionMessage(NULL, location)); + } + return static_cast(0); +#else + return HandleSehExceptionsInMethodIfSupported(object, method, location); +#endif // GTEST_HAS_EXCEPTIONS + } else { + return (object->*method)(); + } +} + +} // namespace internal + +// Runs the test and updates the test result. +void Test::Run() { + if (!HasSameFixtureClass()) return; + + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported(this, &Test::SetUp, "SetUp()"); + // We will run the test only if SetUp() was successful. + if (!HasFatalFailure()) { + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported( + this, &Test::TestBody, "the test body"); + } + + // However, we want to clean up as much as possible. Hence we will + // always call TearDown(), even if SetUp() or the test body has + // failed. + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported( + this, &Test::TearDown, "TearDown()"); +} + +// Returns true iff the current test has a fatal failure. +bool Test::HasFatalFailure() { + return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure(); +} + +// Returns true iff the current test has a non-fatal failure. +bool Test::HasNonfatalFailure() { + return internal::GetUnitTestImpl()->current_test_result()-> + HasNonfatalFailure(); +} + +// class TestInfo + +// Constructs a TestInfo object. It assumes ownership of the test factory +// object. +TestInfo::TestInfo(const std::string& a_test_case_name, + const std::string& a_name, + const char* a_type_param, + const char* a_value_param, + internal::CodeLocation a_code_location, + internal::TypeId fixture_class_id, + internal::TestFactoryBase* factory) + : test_case_name_(a_test_case_name), + name_(a_name), + type_param_(a_type_param ? new std::string(a_type_param) : NULL), + value_param_(a_value_param ? new std::string(a_value_param) : NULL), + location_(a_code_location), + fixture_class_id_(fixture_class_id), + should_run_(false), + is_disabled_(false), + matches_filter_(false), + factory_(factory), + result_() {} + +// Destructs a TestInfo object. +TestInfo::~TestInfo() { delete factory_; } + +namespace internal { + +// Creates a new TestInfo object and registers it with Google Test; +// returns the created object. +// +// Arguments: +// +// test_case_name: name of the test case +// name: name of the test +// type_param: the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param: text representation of the test's value parameter, +// or NULL if this is not a value-parameterized test. +// code_location: code location where the test is defined +// fixture_class_id: ID of the test fixture class +// set_up_tc: pointer to the function that sets up the test case +// tear_down_tc: pointer to the function that tears down the test case +// factory: pointer to the factory that creates a test object. +// The newly created TestInfo instance will assume +// ownership of the factory object. +TestInfo* MakeAndRegisterTestInfo( + const char* test_case_name, + const char* name, + const char* type_param, + const char* value_param, + CodeLocation code_location, + TypeId fixture_class_id, + SetUpTestCaseFunc set_up_tc, + TearDownTestCaseFunc tear_down_tc, + TestFactoryBase* factory) { + TestInfo* const test_info = + new TestInfo(test_case_name, name, type_param, value_param, + code_location, fixture_class_id, factory); + GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info); + return test_info; +} + +#if GTEST_HAS_PARAM_TEST +void ReportInvalidTestCaseType(const char* test_case_name, + CodeLocation code_location) { + Message errors; + errors + << "Attempted redefinition of test case " << test_case_name << ".\n" + << "All tests in the same test case must use the same test fixture\n" + << "class. However, in test case " << test_case_name << ", you tried\n" + << "to define a test using a fixture class different from the one\n" + << "used earlier. This can happen if the two fixture classes are\n" + << "from different namespaces and have the same name. You should\n" + << "probably rename one of the classes to put the tests into different\n" + << "test cases."; + + fprintf(stderr, "%s %s", + FormatFileLocation(code_location.file.c_str(), + code_location.line).c_str(), + errors.GetString().c_str()); +} +#endif // GTEST_HAS_PARAM_TEST + +} // namespace internal + +namespace { + +// A predicate that checks the test name of a TestInfo against a known +// value. +// +// This is used for implementation of the TestCase class only. We put +// it in the anonymous namespace to prevent polluting the outer +// namespace. +// +// TestNameIs is copyable. +class TestNameIs { + public: + // Constructor. + // + // TestNameIs has NO default constructor. + explicit TestNameIs(const char* name) + : name_(name) {} + + // Returns true iff the test name of test_info matches name_. + bool operator()(const TestInfo * test_info) const { + return test_info && test_info->name() == name_; + } + + private: + std::string name_; +}; + +} // namespace + +namespace internal { + +// This method expands all parameterized tests registered with macros TEST_P +// and INSTANTIATE_TEST_CASE_P into regular tests and registers those. +// This will be done just once during the program runtime. +void UnitTestImpl::RegisterParameterizedTests() { +#if GTEST_HAS_PARAM_TEST + if (!parameterized_tests_registered_) { + parameterized_test_registry_.RegisterTests(); + parameterized_tests_registered_ = true; + } +#endif +} + +} // namespace internal + +// Creates the test object, runs it, records its result, and then +// deletes it. +void TestInfo::Run() { + if (!should_run_) return; + + // Tells UnitTest where to store test result. + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + impl->set_current_test_info(this); + + TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); + + // Notifies the unit test event listeners that a test is about to start. + repeater->OnTestStart(*this); + + const TimeInMillis start = internal::GetTimeInMillis(); + + impl->os_stack_trace_getter()->UponLeavingGTest(); + + // Creates the test object. + Test* const test = internal::HandleExceptionsInMethodIfSupported( + factory_, &internal::TestFactoryBase::CreateTest, + "the test fixture's constructor"); + + // Runs the test only if the test object was created and its + // constructor didn't generate a fatal failure. + if ((test != NULL) && !Test::HasFatalFailure()) { + // This doesn't throw as all user code that can throw are wrapped into + // exception handling code. + test->Run(); + } + + // Deletes the test object. + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported( + test, &Test::DeleteSelf_, "the test fixture's destructor"); + + result_.set_elapsed_time(internal::GetTimeInMillis() - start); + + // Notifies the unit test event listener that a test has just finished. + repeater->OnTestEnd(*this); + + // Tells UnitTest to stop associating assertion results to this + // test. + impl->set_current_test_info(NULL); +} + +// class TestCase + +// Gets the number of successful tests in this test case. +int TestCase::successful_test_count() const { + return CountIf(test_info_list_, TestPassed); +} + +// Gets the number of failed tests in this test case. +int TestCase::failed_test_count() const { + return CountIf(test_info_list_, TestFailed); +} + +// Gets the number of disabled tests that will be reported in the XML report. +int TestCase::reportable_disabled_test_count() const { + return CountIf(test_info_list_, TestReportableDisabled); +} + +// Gets the number of disabled tests in this test case. +int TestCase::disabled_test_count() const { + return CountIf(test_info_list_, TestDisabled); +} + +// Gets the number of tests to be printed in the XML report. +int TestCase::reportable_test_count() const { + return CountIf(test_info_list_, TestReportable); +} + +// Get the number of tests in this test case that should run. +int TestCase::test_to_run_count() const { + return CountIf(test_info_list_, ShouldRunTest); +} + +// Gets the number of all tests. +int TestCase::total_test_count() const { + return static_cast(test_info_list_.size()); +} + +// Creates a TestCase with the given name. +// +// Arguments: +// +// name: name of the test case +// a_type_param: the name of the test case's type parameter, or NULL if +// this is not a typed or a type-parameterized test case. +// set_up_tc: pointer to the function that sets up the test case +// tear_down_tc: pointer to the function that tears down the test case +TestCase::TestCase(const char* a_name, const char* a_type_param, + Test::SetUpTestCaseFunc set_up_tc, + Test::TearDownTestCaseFunc tear_down_tc) + : name_(a_name), + type_param_(a_type_param ? new std::string(a_type_param) : NULL), + set_up_tc_(set_up_tc), + tear_down_tc_(tear_down_tc), + should_run_(false), + elapsed_time_(0) { +} + +// Destructor of TestCase. +TestCase::~TestCase() { + // Deletes every Test in the collection. + ForEach(test_info_list_, internal::Delete); +} + +// Returns the i-th test among all the tests. i can range from 0 to +// total_test_count() - 1. If i is not in that range, returns NULL. +const TestInfo* TestCase::GetTestInfo(int i) const { + const int index = GetElementOr(test_indices_, i, -1); + return index < 0 ? NULL : test_info_list_[index]; +} + +// Returns the i-th test among all the tests. i can range from 0 to +// total_test_count() - 1. If i is not in that range, returns NULL. +TestInfo* TestCase::GetMutableTestInfo(int i) { + const int index = GetElementOr(test_indices_, i, -1); + return index < 0 ? NULL : test_info_list_[index]; +} + +// Adds a test to this test case. Will delete the test upon +// destruction of the TestCase object. +void TestCase::AddTestInfo(TestInfo * test_info) { + test_info_list_.push_back(test_info); + test_indices_.push_back(static_cast(test_indices_.size())); +} + +// Runs every test in this TestCase. +void TestCase::Run() { + if (!should_run_) return; + + internal::UnitTestImpl* const impl = internal::GetUnitTestImpl(); + impl->set_current_test_case(this); + + TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater(); + + repeater->OnTestCaseStart(*this); + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported( + this, &TestCase::RunSetUpTestCase, "SetUpTestCase()"); + + const internal::TimeInMillis start = internal::GetTimeInMillis(); + for (int i = 0; i < total_test_count(); i++) { + GetMutableTestInfo(i)->Run(); + } + elapsed_time_ = internal::GetTimeInMillis() - start; + + impl->os_stack_trace_getter()->UponLeavingGTest(); + internal::HandleExceptionsInMethodIfSupported( + this, &TestCase::RunTearDownTestCase, "TearDownTestCase()"); + + repeater->OnTestCaseEnd(*this); + impl->set_current_test_case(NULL); +} + +// Clears the results of all tests in this test case. +void TestCase::ClearResult() { + ad_hoc_test_result_.Clear(); + ForEach(test_info_list_, TestInfo::ClearTestResult); +} + +// Shuffles the tests in this test case. +void TestCase::ShuffleTests(internal::Random* random) { + Shuffle(random, &test_indices_); +} + +// Restores the test order to before the first shuffle. +void TestCase::UnshuffleTests() { + for (size_t i = 0; i < test_indices_.size(); i++) { + test_indices_[i] = static_cast(i); + } +} + +// Formats a countable noun. Depending on its quantity, either the +// singular form or the plural form is used. e.g. +// +// FormatCountableNoun(1, "formula", "formuli") returns "1 formula". +// FormatCountableNoun(5, "book", "books") returns "5 books". +static std::string FormatCountableNoun(int count, + const char * singular_form, + const char * plural_form) { + return internal::StreamableToString(count) + " " + + (count == 1 ? singular_form : plural_form); +} + +// Formats the count of tests. +static std::string FormatTestCount(int test_count) { + return FormatCountableNoun(test_count, "test", "tests"); +} + +// Formats the count of test cases. +static std::string FormatTestCaseCount(int test_case_count) { + return FormatCountableNoun(test_case_count, "test case", "test cases"); +} + +// Converts a TestPartResult::Type enum to human-friendly string +// representation. Both kNonFatalFailure and kFatalFailure are translated +// to "Failure", as the user usually doesn't care about the difference +// between the two when viewing the test result. +static const char * TestPartResultTypeToString(TestPartResult::Type type) { + switch (type) { + case TestPartResult::kSuccess: + return "Success"; + + case TestPartResult::kNonFatalFailure: + case TestPartResult::kFatalFailure: +#ifdef _MSC_VER + return "error: "; +#else + return "Failure\n"; +#endif + default: + return "Unknown result type"; + } +} + +namespace internal { + +// Prints a TestPartResult to an std::string. +static std::string PrintTestPartResultToString( + const TestPartResult& test_part_result) { + return (Message() + << internal::FormatFileLocation(test_part_result.file_name(), + test_part_result.line_number()) + << " " << TestPartResultTypeToString(test_part_result.type()) + << test_part_result.message()).GetString(); +} + +// Prints a TestPartResult. +static void PrintTestPartResult(const TestPartResult& test_part_result) { + const std::string& result = + PrintTestPartResultToString(test_part_result); + printf("%s\n", result.c_str()); + fflush(stdout); + // If the test program runs in Visual Studio or a debugger, the + // following statements add the test part result message to the Output + // window such that the user can double-click on it to jump to the + // corresponding source code location; otherwise they do nothing. +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE + // We don't call OutputDebugString*() on Windows Mobile, as printing + // to stdout is done by OutputDebugString() there already - we don't + // want the same message printed twice. + ::OutputDebugStringA(result.c_str()); + ::OutputDebugStringA("\n"); +#endif +} + +// class PrettyUnitTestResultPrinter + +enum GTestColor { + COLOR_DEFAULT, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW +}; + +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ + !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + +// Returns the character attribute for the given color. +WORD GetColorAttribute(GTestColor color) { + switch (color) { + case COLOR_RED: return FOREGROUND_RED; + case COLOR_GREEN: return FOREGROUND_GREEN; + case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN; + default: return 0; + } +} + +#else + +// Returns the ANSI color code for the given color. COLOR_DEFAULT is +// an invalid input. +const char* GetAnsiColorCode(GTestColor color) { + switch (color) { + case COLOR_RED: return "1"; + case COLOR_GREEN: return "2"; + case COLOR_YELLOW: return "3"; + default: return NULL; + }; +} + +#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE + +// Returns true iff Google Test should use colors in the output. +bool ShouldUseColor(bool stdout_is_tty) { + const char* const gtest_color = GTEST_FLAG(color).c_str(); + + if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) { +#if GTEST_OS_WINDOWS + // On Windows the TERM variable is usually not set, but the + // console there does support colors. + return stdout_is_tty; +#else + // On non-Windows platforms, we rely on the TERM variable. + const char* const term = posix::GetEnv("TERM"); + const bool term_supports_color = + String::CStringEquals(term, "xterm") || + String::CStringEquals(term, "xterm-color") || + String::CStringEquals(term, "xterm-256color") || + String::CStringEquals(term, "screen") || + String::CStringEquals(term, "screen-256color") || + String::CStringEquals(term, "tmux") || + String::CStringEquals(term, "tmux-256color") || + String::CStringEquals(term, "rxvt-unicode") || + String::CStringEquals(term, "rxvt-unicode-256color") || + String::CStringEquals(term, "linux") || + String::CStringEquals(term, "cygwin"); + return stdout_is_tty && term_supports_color; +#endif // GTEST_OS_WINDOWS + } + + return String::CaseInsensitiveCStringEquals(gtest_color, "yes") || + String::CaseInsensitiveCStringEquals(gtest_color, "true") || + String::CaseInsensitiveCStringEquals(gtest_color, "t") || + String::CStringEquals(gtest_color, "1"); + // We take "yes", "true", "t", and "1" as meaning "yes". If the + // value is neither one of these nor "auto", we treat it as "no" to + // be conservative. +} + +// Helpers for printing colored strings to stdout. Note that on Windows, we +// cannot simply emit special characters and have the terminal change colors. +// This routine must actually emit the characters rather than return a string +// that would be colored when printed, as can be done on Linux. +void ColoredPrintf(GTestColor color, const char* fmt, ...) { + va_list args; + va_start(args, fmt); + +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || \ + GTEST_OS_IOS || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT + const bool use_color = AlwaysFalse(); +#else + static const bool in_color_mode = + ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0); + const bool use_color = in_color_mode && (color != COLOR_DEFAULT); +#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS + // The '!= 0' comparison is necessary to satisfy MSVC 7.1. + + if (!use_color) { + vprintf(fmt, args); + va_end(args); + return; + } + +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \ + !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); + + // Gets the current text color. + CONSOLE_SCREEN_BUFFER_INFO buffer_info; + GetConsoleScreenBufferInfo(stdout_handle, &buffer_info); + const WORD old_color_attrs = buffer_info.wAttributes; + + // We need to flush the stream buffers into the console before each + // SetConsoleTextAttribute call lest it affect the text that is already + // printed but has not yet reached the console. + fflush(stdout); + SetConsoleTextAttribute(stdout_handle, + GetColorAttribute(color) | FOREGROUND_INTENSITY); + vprintf(fmt, args); + + fflush(stdout); + // Restores the text color. + SetConsoleTextAttribute(stdout_handle, old_color_attrs); +#else + printf("\033[0;3%sm", GetAnsiColorCode(color)); + vprintf(fmt, args); + printf("\033[m"); // Resets the terminal to default. +#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE + va_end(args); +} + +// Text printed in Google Test's text output and --gunit_list_tests +// output to label the type parameter and value parameter for a test. +static const char kTypeParamLabel[] = "TypeParam"; +static const char kValueParamLabel[] = "GetParam()"; + +void PrintFullTestCommentIfPresent(const TestInfo& test_info) { + const char* const type_param = test_info.type_param(); + const char* const value_param = test_info.value_param(); + + if (type_param != NULL || value_param != NULL) { + printf(", where "); + if (type_param != NULL) { + printf("%s = %s", kTypeParamLabel, type_param); + if (value_param != NULL) + printf(" and "); + } + if (value_param != NULL) { + printf("%s = %s", kValueParamLabel, value_param); + } + } +} + +// This class implements the TestEventListener interface. +// +// Class PrettyUnitTestResultPrinter is copyable. +class PrettyUnitTestResultPrinter : public TestEventListener { + public: + PrettyUnitTestResultPrinter() {} + static void PrintTestName(const char * test_case, const char * test) { + printf("%s.%s", test_case, test); + } + + // The following methods override what's in the TestEventListener class. + virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {} + virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration); + virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test); + virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {} + virtual void OnTestCaseStart(const TestCase& test_case); + virtual void OnTestStart(const TestInfo& test_info); + virtual void OnTestPartResult(const TestPartResult& result); + virtual void OnTestEnd(const TestInfo& test_info); + virtual void OnTestCaseEnd(const TestCase& test_case); + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test); + virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {} + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration); + virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} + + private: + static void PrintFailedTests(const UnitTest& unit_test); +}; + + // Fired before each iteration of tests starts. +void PrettyUnitTestResultPrinter::OnTestIterationStart( + const UnitTest& unit_test, int iteration) { + if (GTEST_FLAG(repeat) != 1) + printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1); + + const char* const filter = GTEST_FLAG(filter).c_str(); + + // Prints the filter if it's not *. This reminds the user that some + // tests may be skipped. + if (!String::CStringEquals(filter, kUniversalFilter)) { + ColoredPrintf(COLOR_YELLOW, + "Note: %s filter = %s\n", GTEST_NAME_, filter); + } + + if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) { + const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1); + ColoredPrintf(COLOR_YELLOW, + "Note: This is test shard %d of %s.\n", + static_cast(shard_index) + 1, + internal::posix::GetEnv(kTestTotalShards)); + } + + if (GTEST_FLAG(shuffle)) { + ColoredPrintf(COLOR_YELLOW, + "Note: Randomizing tests' orders with a seed of %d .\n", + unit_test.random_seed()); + } + + ColoredPrintf(COLOR_GREEN, "[==========] "); + printf("Running %s from %s.\n", + FormatTestCount(unit_test.test_to_run_count()).c_str(), + FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str()); + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart( + const UnitTest& /*unit_test*/) { + ColoredPrintf(COLOR_GREEN, "[----------] "); + printf("Global test environment set-up.\n"); + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) { + const std::string counts = + FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); + ColoredPrintf(COLOR_GREEN, "[----------] "); + printf("%s from %s", counts.c_str(), test_case.name()); + if (test_case.type_param() == NULL) { + printf("\n"); + } else { + printf(", where %s = %s\n", kTypeParamLabel, test_case.type_param()); + } + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) { + ColoredPrintf(COLOR_GREEN, "[ RUN ] "); + PrintTestName(test_info.test_case_name(), test_info.name()); + printf("\n"); + fflush(stdout); +} + +// Called after an assertion failure. +void PrettyUnitTestResultPrinter::OnTestPartResult( + const TestPartResult& result) { + // If the test part succeeded, we don't need to do anything. + if (result.type() == TestPartResult::kSuccess) + return; + + // Print failure message from the assertion (e.g. expected this and got that). + PrintTestPartResult(result); + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) { + if (test_info.result()->Passed()) { + ColoredPrintf(COLOR_GREEN, "[ OK ] "); + } else { + ColoredPrintf(COLOR_RED, "[ FAILED ] "); + } + PrintTestName(test_info.test_case_name(), test_info.name()); + if (test_info.result()->Failed()) + PrintFullTestCommentIfPresent(test_info); + + if (GTEST_FLAG(print_time)) { + printf(" (%s ms)\n", internal::StreamableToString( + test_info.result()->elapsed_time()).c_str()); + } else { + printf("\n"); + } + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) { + if (!GTEST_FLAG(print_time)) return; + + const std::string counts = + FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); + ColoredPrintf(COLOR_GREEN, "[----------] "); + printf("%s from %s (%s ms total)\n\n", + counts.c_str(), test_case.name(), + internal::StreamableToString(test_case.elapsed_time()).c_str()); + fflush(stdout); +} + +void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart( + const UnitTest& /*unit_test*/) { + ColoredPrintf(COLOR_GREEN, "[----------] "); + printf("Global test environment tear-down\n"); + fflush(stdout); +} + +// Internal helper for printing the list of failed tests. +void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) { + const int failed_test_count = unit_test.failed_test_count(); + if (failed_test_count == 0) { + return; + } + + for (int i = 0; i < unit_test.total_test_case_count(); ++i) { + const TestCase& test_case = *unit_test.GetTestCase(i); + if (!test_case.should_run() || (test_case.failed_test_count() == 0)) { + continue; + } + for (int j = 0; j < test_case.total_test_count(); ++j) { + const TestInfo& test_info = *test_case.GetTestInfo(j); + if (!test_info.should_run() || test_info.result()->Passed()) { + continue; + } + ColoredPrintf(COLOR_RED, "[ FAILED ] "); + printf("%s.%s", test_case.name(), test_info.name()); + PrintFullTestCommentIfPresent(test_info); + printf("\n"); + } + } +} + +void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, + int /*iteration*/) { + ColoredPrintf(COLOR_GREEN, "[==========] "); + printf("%s from %s ran.", + FormatTestCount(unit_test.test_to_run_count()).c_str(), + FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str()); + if (GTEST_FLAG(print_time)) { + printf(" (%s ms total)", + internal::StreamableToString(unit_test.elapsed_time()).c_str()); + } + printf("\n"); + ColoredPrintf(COLOR_GREEN, "[ PASSED ] "); + printf("%s.\n", FormatTestCount(unit_test.successful_test_count()).c_str()); + + int num_failures = unit_test.failed_test_count(); + if (!unit_test.Passed()) { + const int failed_test_count = unit_test.failed_test_count(); + ColoredPrintf(COLOR_RED, "[ FAILED ] "); + printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str()); + PrintFailedTests(unit_test); + printf("\n%2d FAILED %s\n", num_failures, + num_failures == 1 ? "TEST" : "TESTS"); + } + + int num_disabled = unit_test.reportable_disabled_test_count(); + if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) { + if (!num_failures) { + printf("\n"); // Add a spacer if no FAILURE banner is displayed. + } + ColoredPrintf(COLOR_YELLOW, + " YOU HAVE %d DISABLED %s\n\n", + num_disabled, + num_disabled == 1 ? "TEST" : "TESTS"); + } + // Ensure that Google Test output is printed before, e.g., heapchecker output. + fflush(stdout); +} + +// End PrettyUnitTestResultPrinter + +// class TestEventRepeater +// +// This class forwards events to other event listeners. +class TestEventRepeater : public TestEventListener { + public: + TestEventRepeater() : forwarding_enabled_(true) {} + virtual ~TestEventRepeater(); + void Append(TestEventListener *listener); + TestEventListener* Release(TestEventListener* listener); + + // Controls whether events will be forwarded to listeners_. Set to false + // in death test child processes. + bool forwarding_enabled() const { return forwarding_enabled_; } + void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; } + + virtual void OnTestProgramStart(const UnitTest& unit_test); + virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration); + virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test); + virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test); + virtual void OnTestCaseStart(const TestCase& test_case); + virtual void OnTestStart(const TestInfo& test_info); + virtual void OnTestPartResult(const TestPartResult& result); + virtual void OnTestEnd(const TestInfo& test_info); + virtual void OnTestCaseEnd(const TestCase& test_case); + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test); + virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test); + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration); + virtual void OnTestProgramEnd(const UnitTest& unit_test); + + private: + // Controls whether events will be forwarded to listeners_. Set to false + // in death test child processes. + bool forwarding_enabled_; + // The list of listeners that receive events. + std::vector listeners_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater); +}; + +TestEventRepeater::~TestEventRepeater() { + ForEach(listeners_, Delete); +} + +void TestEventRepeater::Append(TestEventListener *listener) { + listeners_.push_back(listener); +} + +// TODO(vladl@google.com): Factor the search functionality into Vector::Find. +TestEventListener* TestEventRepeater::Release(TestEventListener *listener) { + for (size_t i = 0; i < listeners_.size(); ++i) { + if (listeners_[i] == listener) { + listeners_.erase(listeners_.begin() + i); + return listener; + } + } + + return NULL; +} + +// Since most methods are very similar, use macros to reduce boilerplate. +// This defines a member that forwards the call to all listeners. +#define GTEST_REPEATER_METHOD_(Name, Type) \ +void TestEventRepeater::Name(const Type& parameter) { \ + if (forwarding_enabled_) { \ + for (size_t i = 0; i < listeners_.size(); i++) { \ + listeners_[i]->Name(parameter); \ + } \ + } \ +} +// This defines a member that forwards the call to all listeners in reverse +// order. +#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \ +void TestEventRepeater::Name(const Type& parameter) { \ + if (forwarding_enabled_) { \ + for (int i = static_cast(listeners_.size()) - 1; i >= 0; i--) { \ + listeners_[i]->Name(parameter); \ + } \ + } \ +} + +GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest) +GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest) +GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase) +GTEST_REPEATER_METHOD_(OnTestStart, TestInfo) +GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult) +GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest) +GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest) +GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest) +GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo) +GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase) +GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest) + +#undef GTEST_REPEATER_METHOD_ +#undef GTEST_REVERSE_REPEATER_METHOD_ + +void TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test, + int iteration) { + if (forwarding_enabled_) { + for (size_t i = 0; i < listeners_.size(); i++) { + listeners_[i]->OnTestIterationStart(unit_test, iteration); + } + } +} + +void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test, + int iteration) { + if (forwarding_enabled_) { + for (int i = static_cast(listeners_.size()) - 1; i >= 0; i--) { + listeners_[i]->OnTestIterationEnd(unit_test, iteration); + } + } +} + +// End TestEventRepeater + +// This class generates an XML output file. +class XmlUnitTestResultPrinter : public EmptyTestEventListener { + public: + explicit XmlUnitTestResultPrinter(const char* output_file); + + virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration); + + private: + // Is c a whitespace character that is normalized to a space character + // when it appears in an XML attribute value? + static bool IsNormalizableWhitespace(char c) { + return c == 0x9 || c == 0xA || c == 0xD; + } + + // May c appear in a well-formed XML document? + static bool IsValidXmlCharacter(char c) { + return IsNormalizableWhitespace(c) || c >= 0x20; + } + + // Returns an XML-escaped copy of the input string str. If + // is_attribute is true, the text is meant to appear as an attribute + // value, and normalizable whitespace is preserved by replacing it + // with character references. + static std::string EscapeXml(const std::string& str, bool is_attribute); + + // Returns the given string with all characters invalid in XML removed. + static std::string RemoveInvalidXmlCharacters(const std::string& str); + + // Convenience wrapper around EscapeXml when str is an attribute value. + static std::string EscapeXmlAttribute(const std::string& str) { + return EscapeXml(str, true); + } + + // Convenience wrapper around EscapeXml when str is not an attribute value. + static std::string EscapeXmlText(const char* str) { + return EscapeXml(str, false); + } + + // Verifies that the given attribute belongs to the given element and + // streams the attribute as XML. + static void OutputXmlAttribute(std::ostream* stream, + const std::string& element_name, + const std::string& name, + const std::string& value); + + // Streams an XML CDATA section, escaping invalid CDATA sequences as needed. + static void OutputXmlCDataSection(::std::ostream* stream, const char* data); + + // Streams an XML representation of a TestInfo object. + static void OutputXmlTestInfo(::std::ostream* stream, + const char* test_case_name, + const TestInfo& test_info); + + // Prints an XML representation of a TestCase object + static void PrintXmlTestCase(::std::ostream* stream, + const TestCase& test_case); + + // Prints an XML summary of unit_test to output stream out. + static void PrintXmlUnitTest(::std::ostream* stream, + const UnitTest& unit_test); + + // Produces a string representing the test properties in a result as space + // delimited XML attributes based on the property key="value" pairs. + // When the std::string is not empty, it includes a space at the beginning, + // to delimit this attribute from prior attributes. + static std::string TestPropertiesAsXmlAttributes(const TestResult& result); + + // The output file. + const std::string output_file_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter); +}; + +// Creates a new XmlUnitTestResultPrinter. +XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file) + : output_file_(output_file) { + if (output_file_.c_str() == NULL || output_file_.empty()) { + fprintf(stderr, "XML output file may not be null\n"); + fflush(stderr); + exit(EXIT_FAILURE); + } +} + +// Called after the unit test ends. +void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test, + int /*iteration*/) { + FILE* xmlout = NULL; + FilePath output_file(output_file_); + FilePath output_dir(output_file.RemoveFileName()); + + if (output_dir.CreateDirectoriesRecursively()) { + xmlout = posix::FOpen(output_file_.c_str(), "w"); + } + if (xmlout == NULL) { + // TODO(wan): report the reason of the failure. + // + // We don't do it for now as: + // + // 1. There is no urgent need for it. + // 2. It's a bit involved to make the errno variable thread-safe on + // all three operating systems (Linux, Windows, and Mac OS). + // 3. To interpret the meaning of errno in a thread-safe way, + // we need the strerror_r() function, which is not available on + // Windows. + fprintf(stderr, + "Unable to open file \"%s\"\n", + output_file_.c_str()); + fflush(stderr); + exit(EXIT_FAILURE); + } + std::stringstream stream; + PrintXmlUnitTest(&stream, unit_test); + fprintf(xmlout, "%s", StringStreamToString(&stream).c_str()); + fclose(xmlout); +} + +// Returns an XML-escaped copy of the input string str. If is_attribute +// is true, the text is meant to appear as an attribute value, and +// normalizable whitespace is preserved by replacing it with character +// references. +// +// Invalid XML characters in str, if any, are stripped from the output. +// It is expected that most, if not all, of the text processed by this +// module will consist of ordinary English text. +// If this module is ever modified to produce version 1.1 XML output, +// most invalid characters can be retained using character references. +// TODO(wan): It might be nice to have a minimally invasive, human-readable +// escaping scheme for invalid characters, rather than dropping them. +std::string XmlUnitTestResultPrinter::EscapeXml( + const std::string& str, bool is_attribute) { + Message m; + + for (size_t i = 0; i < str.size(); ++i) { + const char ch = str[i]; + switch (ch) { + case '<': + m << "<"; + break; + case '>': + m << ">"; + break; + case '&': + m << "&"; + break; + case '\'': + if (is_attribute) + m << "'"; + else + m << '\''; + break; + case '"': + if (is_attribute) + m << """; + else + m << '"'; + break; + default: + if (IsValidXmlCharacter(ch)) { + if (is_attribute && IsNormalizableWhitespace(ch)) + m << "&#x" << String::FormatByte(static_cast(ch)) + << ";"; + else + m << ch; + } + break; + } + } + + return m.GetString(); +} + +// Returns the given string with all characters invalid in XML removed. +// Currently invalid characters are dropped from the string. An +// alternative is to replace them with certain characters such as . or ?. +std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters( + const std::string& str) { + std::string output; + output.reserve(str.size()); + for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) + if (IsValidXmlCharacter(*it)) + output.push_back(*it); + + return output; +} + +// The following routines generate an XML representation of a UnitTest +// object. +// +// This is how Google Test concepts map to the DTD: +// +// <-- corresponds to a UnitTest object +// <-- corresponds to a TestCase object +// <-- corresponds to a TestInfo object +// ... +// ... +// ... +// <-- individual assertion failures +// +// +// + +// Formats the given time in milliseconds as seconds. +std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) { + ::std::stringstream ss; + ss << (static_cast(ms) * 1e-3); + return ss.str(); +} + +static bool PortableLocaltime(time_t seconds, struct tm* out) { +#if defined(_MSC_VER) + return localtime_s(out, &seconds) == 0; +#elif defined(__MINGW32__) || defined(__MINGW64__) + // MINGW provides neither localtime_r nor localtime_s, but uses + // Windows' localtime(), which has a thread-local tm buffer. + struct tm* tm_ptr = localtime(&seconds); // NOLINT + if (tm_ptr == NULL) + return false; + *out = *tm_ptr; + return true; +#else + return localtime_r(&seconds, out) != NULL; +#endif +} + +// Converts the given epoch time in milliseconds to a date string in the ISO +// 8601 format, without the timezone information. +std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms) { + struct tm time_struct; + if (!PortableLocaltime(static_cast(ms / 1000), &time_struct)) + return ""; + // YYYY-MM-DDThh:mm:ss + return StreamableToString(time_struct.tm_year + 1900) + "-" + + String::FormatIntWidth2(time_struct.tm_mon + 1) + "-" + + String::FormatIntWidth2(time_struct.tm_mday) + "T" + + String::FormatIntWidth2(time_struct.tm_hour) + ":" + + String::FormatIntWidth2(time_struct.tm_min) + ":" + + String::FormatIntWidth2(time_struct.tm_sec); +} + +// Streams an XML CDATA section, escaping invalid CDATA sequences as needed. +void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream, + const char* data) { + const char* segment = data; + *stream << ""); + if (next_segment != NULL) { + stream->write( + segment, static_cast(next_segment - segment)); + *stream << "]]>]]>"); + } else { + *stream << segment; + break; + } + } + *stream << "]]>"; +} + +void XmlUnitTestResultPrinter::OutputXmlAttribute( + std::ostream* stream, + const std::string& element_name, + const std::string& name, + const std::string& value) { + const std::vector& allowed_names = + GetReservedAttributesForElement(element_name); + + GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != + allowed_names.end()) + << "Attribute " << name << " is not allowed for element <" << element_name + << ">."; + + *stream << " " << name << "=\"" << EscapeXmlAttribute(value) << "\""; +} + +// Prints an XML representation of a TestInfo object. +// TODO(wan): There is also value in printing properties with the plain printer. +void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, + const char* test_case_name, + const TestInfo& test_info) { + const TestResult& result = *test_info.result(); + const std::string kTestcase = "testcase"; + + *stream << " \n"; + } + const string location = internal::FormatCompilerIndependentFileLocation( + part.file_name(), part.line_number()); + const string summary = location + "\n" + part.summary(); + *stream << " "; + const string detail = location + "\n" + part.message(); + OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str()); + *stream << "\n"; + } + } + + if (failures == 0) + *stream << " />\n"; + else + *stream << " \n"; +} + +// Prints an XML representation of a TestCase object +void XmlUnitTestResultPrinter::PrintXmlTestCase(std::ostream* stream, + const TestCase& test_case) { + const std::string kTestsuite = "testsuite"; + *stream << " <" << kTestsuite; + OutputXmlAttribute(stream, kTestsuite, "name", test_case.name()); + OutputXmlAttribute(stream, kTestsuite, "tests", + StreamableToString(test_case.reportable_test_count())); + OutputXmlAttribute(stream, kTestsuite, "failures", + StreamableToString(test_case.failed_test_count())); + OutputXmlAttribute( + stream, kTestsuite, "disabled", + StreamableToString(test_case.reportable_disabled_test_count())); + OutputXmlAttribute(stream, kTestsuite, "errors", "0"); + OutputXmlAttribute(stream, kTestsuite, "time", + FormatTimeInMillisAsSeconds(test_case.elapsed_time())); + *stream << TestPropertiesAsXmlAttributes(test_case.ad_hoc_test_result()) + << ">\n"; + + for (int i = 0; i < test_case.total_test_count(); ++i) { + if (test_case.GetTestInfo(i)->is_reportable()) + OutputXmlTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i)); + } + *stream << " \n"; +} + +// Prints an XML summary of unit_test to output stream out. +void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream, + const UnitTest& unit_test) { + const std::string kTestsuites = "testsuites"; + + *stream << "\n"; + *stream << "<" << kTestsuites; + + OutputXmlAttribute(stream, kTestsuites, "tests", + StreamableToString(unit_test.reportable_test_count())); + OutputXmlAttribute(stream, kTestsuites, "failures", + StreamableToString(unit_test.failed_test_count())); + OutputXmlAttribute( + stream, kTestsuites, "disabled", + StreamableToString(unit_test.reportable_disabled_test_count())); + OutputXmlAttribute(stream, kTestsuites, "errors", "0"); + OutputXmlAttribute( + stream, kTestsuites, "timestamp", + FormatEpochTimeInMillisAsIso8601(unit_test.start_timestamp())); + OutputXmlAttribute(stream, kTestsuites, "time", + FormatTimeInMillisAsSeconds(unit_test.elapsed_time())); + + if (GTEST_FLAG(shuffle)) { + OutputXmlAttribute(stream, kTestsuites, "random_seed", + StreamableToString(unit_test.random_seed())); + } + + *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result()); + + OutputXmlAttribute(stream, kTestsuites, "name", "AllTests"); + *stream << ">\n"; + + for (int i = 0; i < unit_test.total_test_case_count(); ++i) { + if (unit_test.GetTestCase(i)->reportable_test_count() > 0) + PrintXmlTestCase(stream, *unit_test.GetTestCase(i)); + } + *stream << "\n"; +} + +// Produces a string representing the test properties in a result as space +// delimited XML attributes based on the property key="value" pairs. +std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes( + const TestResult& result) { + Message attributes; + for (int i = 0; i < result.test_property_count(); ++i) { + const TestProperty& property = result.GetTestProperty(i); + attributes << " " << property.key() << "=" + << "\"" << EscapeXmlAttribute(property.value()) << "\""; + } + return attributes.GetString(); +} + +// End XmlUnitTestResultPrinter + +#if GTEST_CAN_STREAM_RESULTS_ + +// Checks if str contains '=', '&', '%' or '\n' characters. If yes, +// replaces them by "%xx" where xx is their hexadecimal value. For +// example, replaces "=" with "%3D". This algorithm is O(strlen(str)) +// in both time and space -- important as the input str may contain an +// arbitrarily long test failure message and stack trace. +string StreamingListener::UrlEncode(const char* str) { + string result; + result.reserve(strlen(str) + 1); + for (char ch = *str; ch != '\0'; ch = *++str) { + switch (ch) { + case '%': + case '=': + case '&': + case '\n': + result.append("%" + String::FormatByte(static_cast(ch))); + break; + default: + result.push_back(ch); + break; + } + } + return result; +} + +void StreamingListener::SocketWriter::MakeConnection() { + GTEST_CHECK_(sockfd_ == -1) + << "MakeConnection() can't be called when there is already a connection."; + + addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses. + hints.ai_socktype = SOCK_STREAM; + addrinfo* servinfo = NULL; + + // Use the getaddrinfo() to get a linked list of IP addresses for + // the given host name. + const int error_num = getaddrinfo( + host_name_.c_str(), port_num_.c_str(), &hints, &servinfo); + if (error_num != 0) { + GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: " + << gai_strerror(error_num); + } + + // Loop through all the results and connect to the first we can. + for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL; + cur_addr = cur_addr->ai_next) { + sockfd_ = socket( + cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol); + if (sockfd_ != -1) { + // Connect the client socket to the server socket. + if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) { + close(sockfd_); + sockfd_ = -1; + } + } + } + + freeaddrinfo(servinfo); // all done with this structure + + if (sockfd_ == -1) { + GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to " + << host_name_ << ":" << port_num_; + } +} + +// End of class Streaming Listener +#endif // GTEST_CAN_STREAM_RESULTS__ + +// Class ScopedTrace + +// Pushes the given source file location and message onto a per-thread +// trace stack maintained by Google Test. +ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) + GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) { + TraceInfo trace; + trace.file = file; + trace.line = line; + trace.message = message.GetString(); + + UnitTest::GetInstance()->PushGTestTrace(trace); +} + +// Pops the info pushed by the c'tor. +ScopedTrace::~ScopedTrace() + GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) { + UnitTest::GetInstance()->PopGTestTrace(); +} + + +// class OsStackTraceGetter + +const char* const OsStackTraceGetterInterface::kElidedFramesMarker = + "... " GTEST_NAME_ " internal frames ..."; + +string OsStackTraceGetter::CurrentStackTrace(int /*max_depth*/, + int /*skip_count*/) { + return ""; +} + +void OsStackTraceGetter::UponLeavingGTest() {} + +// A helper class that creates the premature-exit file in its +// constructor and deletes the file in its destructor. +class ScopedPrematureExitFile { + public: + explicit ScopedPrematureExitFile(const char* premature_exit_filepath) + : premature_exit_filepath_(premature_exit_filepath) { + // If a path to the premature-exit file is specified... + if (premature_exit_filepath != NULL && *premature_exit_filepath != '\0') { + // create the file with a single "0" character in it. I/O + // errors are ignored as there's nothing better we can do and we + // don't want to fail the test because of this. + FILE* pfile = posix::FOpen(premature_exit_filepath, "w"); + fwrite("0", 1, 1, pfile); + fclose(pfile); + } + } + + ~ScopedPrematureExitFile() { + if (premature_exit_filepath_ != NULL && *premature_exit_filepath_ != '\0') { + remove(premature_exit_filepath_); + } + } + + private: + const char* const premature_exit_filepath_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile); +}; + +} // namespace internal + +// class TestEventListeners + +TestEventListeners::TestEventListeners() + : repeater_(new internal::TestEventRepeater()), + default_result_printer_(NULL), + default_xml_generator_(NULL) { +} + +TestEventListeners::~TestEventListeners() { delete repeater_; } + +// Returns the standard listener responsible for the default console +// output. Can be removed from the listeners list to shut down default +// console output. Note that removing this object from the listener list +// with Release transfers its ownership to the user. +void TestEventListeners::Append(TestEventListener* listener) { + repeater_->Append(listener); +} + +// Removes the given event listener from the list and returns it. It then +// becomes the caller's responsibility to delete the listener. Returns +// NULL if the listener is not found in the list. +TestEventListener* TestEventListeners::Release(TestEventListener* listener) { + if (listener == default_result_printer_) + default_result_printer_ = NULL; + else if (listener == default_xml_generator_) + default_xml_generator_ = NULL; + return repeater_->Release(listener); +} + +// Returns repeater that broadcasts the TestEventListener events to all +// subscribers. +TestEventListener* TestEventListeners::repeater() { return repeater_; } + +// Sets the default_result_printer attribute to the provided listener. +// The listener is also added to the listener list and previous +// default_result_printer is removed from it and deleted. The listener can +// also be NULL in which case it will not be added to the list. Does +// nothing if the previous and the current listener objects are the same. +void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) { + if (default_result_printer_ != listener) { + // It is an error to pass this method a listener that is already in the + // list. + delete Release(default_result_printer_); + default_result_printer_ = listener; + if (listener != NULL) + Append(listener); + } +} + +// Sets the default_xml_generator attribute to the provided listener. The +// listener is also added to the listener list and previous +// default_xml_generator is removed from it and deleted. The listener can +// also be NULL in which case it will not be added to the list. Does +// nothing if the previous and the current listener objects are the same. +void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) { + if (default_xml_generator_ != listener) { + // It is an error to pass this method a listener that is already in the + // list. + delete Release(default_xml_generator_); + default_xml_generator_ = listener; + if (listener != NULL) + Append(listener); + } +} + +// Controls whether events will be forwarded by the repeater to the +// listeners in the list. +bool TestEventListeners::EventForwardingEnabled() const { + return repeater_->forwarding_enabled(); +} + +void TestEventListeners::SuppressEventForwarding() { + repeater_->set_forwarding_enabled(false); +} + +// class UnitTest + +// Gets the singleton UnitTest object. The first time this method is +// called, a UnitTest object is constructed and returned. Consecutive +// calls will return the same object. +// +// We don't protect this under mutex_ as a user is not supposed to +// call this before main() starts, from which point on the return +// value will never change. +UnitTest* UnitTest::GetInstance() { + // When compiled with MSVC 7.1 in optimized mode, destroying the + // UnitTest object upon exiting the program messes up the exit code, + // causing successful tests to appear failed. We have to use a + // different implementation in this case to bypass the compiler bug. + // This implementation makes the compiler happy, at the cost of + // leaking the UnitTest object. + + // CodeGear C++Builder insists on a public destructor for the + // default implementation. Use this implementation to keep good OO + // design with private destructor. + +#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) + static UnitTest* const instance = new UnitTest; + return instance; +#else + static UnitTest instance; + return &instance; +#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__) +} + +// Gets the number of successful test cases. +int UnitTest::successful_test_case_count() const { + return impl()->successful_test_case_count(); +} + +// Gets the number of failed test cases. +int UnitTest::failed_test_case_count() const { + return impl()->failed_test_case_count(); +} + +// Gets the number of all test cases. +int UnitTest::total_test_case_count() const { + return impl()->total_test_case_count(); +} + +// Gets the number of all test cases that contain at least one test +// that should run. +int UnitTest::test_case_to_run_count() const { + return impl()->test_case_to_run_count(); +} + +// Gets the number of successful tests. +int UnitTest::successful_test_count() const { + return impl()->successful_test_count(); +} + +// Gets the number of failed tests. +int UnitTest::failed_test_count() const { return impl()->failed_test_count(); } + +// Gets the number of disabled tests that will be reported in the XML report. +int UnitTest::reportable_disabled_test_count() const { + return impl()->reportable_disabled_test_count(); +} + +// Gets the number of disabled tests. +int UnitTest::disabled_test_count() const { + return impl()->disabled_test_count(); +} + +// Gets the number of tests to be printed in the XML report. +int UnitTest::reportable_test_count() const { + return impl()->reportable_test_count(); +} + +// Gets the number of all tests. +int UnitTest::total_test_count() const { return impl()->total_test_count(); } + +// Gets the number of tests that should run. +int UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); } + +// Gets the time of the test program start, in ms from the start of the +// UNIX epoch. +internal::TimeInMillis UnitTest::start_timestamp() const { + return impl()->start_timestamp(); +} + +// Gets the elapsed time, in milliseconds. +internal::TimeInMillis UnitTest::elapsed_time() const { + return impl()->elapsed_time(); +} + +// Returns true iff the unit test passed (i.e. all test cases passed). +bool UnitTest::Passed() const { return impl()->Passed(); } + +// Returns true iff the unit test failed (i.e. some test case failed +// or something outside of all tests failed). +bool UnitTest::Failed() const { return impl()->Failed(); } + +// Gets the i-th test case among all the test cases. i can range from 0 to +// total_test_case_count() - 1. If i is not in that range, returns NULL. +const TestCase* UnitTest::GetTestCase(int i) const { + return impl()->GetTestCase(i); +} + +// Returns the TestResult containing information on test failures and +// properties logged outside of individual test cases. +const TestResult& UnitTest::ad_hoc_test_result() const { + return *impl()->ad_hoc_test_result(); +} + +// Gets the i-th test case among all the test cases. i can range from 0 to +// total_test_case_count() - 1. If i is not in that range, returns NULL. +TestCase* UnitTest::GetMutableTestCase(int i) { + return impl()->GetMutableTestCase(i); +} + +// Returns the list of event listeners that can be used to track events +// inside Google Test. +TestEventListeners& UnitTest::listeners() { + return *impl()->listeners(); +} + +// Registers and returns a global test environment. When a test +// program is run, all global test environments will be set-up in the +// order they were registered. After all tests in the program have +// finished, all global test environments will be torn-down in the +// *reverse* order they were registered. +// +// The UnitTest object takes ownership of the given environment. +// +// We don't protect this under mutex_, as we only support calling it +// from the main thread. +Environment* UnitTest::AddEnvironment(Environment* env) { + if (env == NULL) { + return NULL; + } + + impl_->environments().push_back(env); + return env; +} + +// Adds a TestPartResult to the current TestResult object. All Google Test +// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call +// this to report their results. The user code should use the +// assertion macros instead of calling this directly. +void UnitTest::AddTestPartResult( + TestPartResult::Type result_type, + const char* file_name, + int line_number, + const std::string& message, + const std::string& os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_) { + Message msg; + msg << message; + + internal::MutexLock lock(&mutex_); + if (impl_->gtest_trace_stack().size() > 0) { + msg << "\n" << GTEST_NAME_ << " trace:"; + + for (int i = static_cast(impl_->gtest_trace_stack().size()); + i > 0; --i) { + const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1]; + msg << "\n" << internal::FormatFileLocation(trace.file, trace.line) + << " " << trace.message; + } + } + + if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) { + msg << internal::kStackTraceMarker << os_stack_trace; + } + + const TestPartResult result = + TestPartResult(result_type, file_name, line_number, + msg.GetString().c_str()); + impl_->GetTestPartResultReporterForCurrentThread()-> + ReportTestPartResult(result); + + if (result_type != TestPartResult::kSuccess) { + // gtest_break_on_failure takes precedence over + // gtest_throw_on_failure. This allows a user to set the latter + // in the code (perhaps in order to use Google Test assertions + // with another testing framework) and specify the former on the + // command line for debugging. + if (GTEST_FLAG(break_on_failure)) { +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + // Using DebugBreak on Windows allows gtest to still break into a debugger + // when a failure happens and both the --gtest_break_on_failure and + // the --gtest_catch_exceptions flags are specified. + DebugBreak(); +#else + // Dereference NULL through a volatile pointer to prevent the compiler + // from removing. We use this rather than abort() or __builtin_trap() for + // portability: Symbian doesn't implement abort() well, and some debuggers + // don't correctly trap abort(). + *static_cast(NULL) = 1; +#endif // GTEST_OS_WINDOWS + } else if (GTEST_FLAG(throw_on_failure)) { +#if GTEST_HAS_EXCEPTIONS + throw internal::GoogleTestFailureException(result); +#else + // We cannot call abort() as it generates a pop-up in debug mode + // that cannot be suppressed in VC 7.1 or below. + exit(1); +#endif + } + } +} + +// Adds a TestProperty to the current TestResult object when invoked from +// inside a test, to current TestCase's ad_hoc_test_result_ when invoked +// from SetUpTestCase or TearDownTestCase, or to the global property set +// when invoked elsewhere. If the result already contains a property with +// the same key, the value will be updated. +void UnitTest::RecordProperty(const std::string& key, + const std::string& value) { + impl_->RecordProperty(TestProperty(key, value)); +} + +// Runs all tests in this UnitTest object and prints the result. +// Returns 0 if successful, or 1 otherwise. +// +// We don't protect this under mutex_, as we only support calling it +// from the main thread. +int UnitTest::Run() { + const bool in_death_test_child_process = + internal::GTEST_FLAG(internal_run_death_test).length() > 0; + + // Google Test implements this protocol for catching that a test + // program exits before returning control to Google Test: + // + // 1. Upon start, Google Test creates a file whose absolute path + // is specified by the environment variable + // TEST_PREMATURE_EXIT_FILE. + // 2. When Google Test has finished its work, it deletes the file. + // + // This allows a test runner to set TEST_PREMATURE_EXIT_FILE before + // running a Google-Test-based test program and check the existence + // of the file at the end of the test execution to see if it has + // exited prematurely. + + // If we are in the child process of a death test, don't + // create/delete the premature exit file, as doing so is unnecessary + // and will confuse the parent process. Otherwise, create/delete + // the file upon entering/leaving this function. If the program + // somehow exits before this function has a chance to return, the + // premature-exit file will be left undeleted, causing a test runner + // that understands the premature-exit-file protocol to report the + // test as having failed. + const internal::ScopedPrematureExitFile premature_exit_file( + in_death_test_child_process ? + NULL : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE")); + + // Captures the value of GTEST_FLAG(catch_exceptions). This value will be + // used for the duration of the program. + impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions)); + +#if GTEST_HAS_SEH + // Either the user wants Google Test to catch exceptions thrown by the + // tests or this is executing in the context of death test child + // process. In either case the user does not want to see pop-up dialogs + // about crashes - they are expected. + if (impl()->catch_exceptions() || in_death_test_child_process) { +# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + // SetErrorMode doesn't exist on CE. + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | + SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); +# endif // !GTEST_OS_WINDOWS_MOBILE + +# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE + // Death test children can be terminated with _abort(). On Windows, + // _abort() can show a dialog with a warning message. This forces the + // abort message to go to stderr instead. + _set_error_mode(_OUT_TO_STDERR); +# endif + +# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE + // In the debug version, Visual Studio pops up a separate dialog + // offering a choice to debug the aborted program. We need to suppress + // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement + // executed. Google Test will notify the user of any unexpected + // failure via stderr. + // + // VC++ doesn't define _set_abort_behavior() prior to the version 8.0. + // Users of prior VC versions shall suffer the agony and pain of + // clicking through the countless debug dialogs. + // TODO(vladl@google.com): find a way to suppress the abort dialog() in the + // debug mode when compiled with VC 7.1 or lower. + if (!GTEST_FLAG(break_on_failure)) + _set_abort_behavior( + 0x0, // Clear the following flags: + _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump. +# endif + } +#endif // GTEST_HAS_SEH + + return internal::HandleExceptionsInMethodIfSupported( + impl(), + &internal::UnitTestImpl::RunAllTests, + "auxiliary test code (environments or event listeners)") ? 0 : 1; +} + +// Returns the working directory when the first TEST() or TEST_F() was +// executed. +const char* UnitTest::original_working_dir() const { + return impl_->original_working_dir_.c_str(); +} + +// Returns the TestCase object for the test that's currently running, +// or NULL if no test is running. +const TestCase* UnitTest::current_test_case() const + GTEST_LOCK_EXCLUDED_(mutex_) { + internal::MutexLock lock(&mutex_); + return impl_->current_test_case(); +} + +// Returns the TestInfo object for the test that's currently running, +// or NULL if no test is running. +const TestInfo* UnitTest::current_test_info() const + GTEST_LOCK_EXCLUDED_(mutex_) { + internal::MutexLock lock(&mutex_); + return impl_->current_test_info(); +} + +// Returns the random seed used at the start of the current test run. +int UnitTest::random_seed() const { return impl_->random_seed(); } + +#if GTEST_HAS_PARAM_TEST +// Returns ParameterizedTestCaseRegistry object used to keep track of +// value-parameterized tests and instantiate and register them. +internal::ParameterizedTestCaseRegistry& + UnitTest::parameterized_test_registry() + GTEST_LOCK_EXCLUDED_(mutex_) { + return impl_->parameterized_test_registry(); +} +#endif // GTEST_HAS_PARAM_TEST + +// Creates an empty UnitTest. +UnitTest::UnitTest() { + impl_ = new internal::UnitTestImpl(this); +} + +// Destructor of UnitTest. +UnitTest::~UnitTest() { + delete impl_; +} + +// Pushes a trace defined by SCOPED_TRACE() on to the per-thread +// Google Test trace stack. +void UnitTest::PushGTestTrace(const internal::TraceInfo& trace) + GTEST_LOCK_EXCLUDED_(mutex_) { + internal::MutexLock lock(&mutex_); + impl_->gtest_trace_stack().push_back(trace); +} + +// Pops a trace from the per-thread Google Test trace stack. +void UnitTest::PopGTestTrace() + GTEST_LOCK_EXCLUDED_(mutex_) { + internal::MutexLock lock(&mutex_); + impl_->gtest_trace_stack().pop_back(); +} + +namespace internal { + +UnitTestImpl::UnitTestImpl(UnitTest* parent) + : parent_(parent), + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4355 /* using this in initializer */) + default_global_test_part_result_reporter_(this), + default_per_thread_test_part_result_reporter_(this), + GTEST_DISABLE_MSC_WARNINGS_POP_() + global_test_part_result_repoter_( + &default_global_test_part_result_reporter_), + per_thread_test_part_result_reporter_( + &default_per_thread_test_part_result_reporter_), +#if GTEST_HAS_PARAM_TEST + parameterized_test_registry_(), + parameterized_tests_registered_(false), +#endif // GTEST_HAS_PARAM_TEST + last_death_test_case_(-1), + current_test_case_(NULL), + current_test_info_(NULL), + ad_hoc_test_result_(), + os_stack_trace_getter_(NULL), + post_flag_parse_init_performed_(false), + random_seed_(0), // Will be overridden by the flag before first use. + random_(0), // Will be reseeded before first use. + start_timestamp_(0), + elapsed_time_(0), +#if GTEST_HAS_DEATH_TEST + death_test_factory_(new DefaultDeathTestFactory), +#endif + // Will be overridden by the flag before first use. + catch_exceptions_(false) { + listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter); +} + +UnitTestImpl::~UnitTestImpl() { + // Deletes every TestCase. + ForEach(test_cases_, internal::Delete); + + // Deletes every Environment. + ForEach(environments_, internal::Delete); + + delete os_stack_trace_getter_; +} + +// Adds a TestProperty to the current TestResult object when invoked in a +// context of a test, to current test case's ad_hoc_test_result when invoke +// from SetUpTestCase/TearDownTestCase, or to the global property set +// otherwise. If the result already contains a property with the same key, +// the value will be updated. +void UnitTestImpl::RecordProperty(const TestProperty& test_property) { + std::string xml_element; + TestResult* test_result; // TestResult appropriate for property recording. + + if (current_test_info_ != NULL) { + xml_element = "testcase"; + test_result = &(current_test_info_->result_); + } else if (current_test_case_ != NULL) { + xml_element = "testsuite"; + test_result = &(current_test_case_->ad_hoc_test_result_); + } else { + xml_element = "testsuites"; + test_result = &ad_hoc_test_result_; + } + test_result->RecordProperty(xml_element, test_property); +} + +#if GTEST_HAS_DEATH_TEST +// Disables event forwarding if the control is currently in a death test +// subprocess. Must not be called before InitGoogleTest. +void UnitTestImpl::SuppressTestEventsIfInSubprocess() { + if (internal_run_death_test_flag_.get() != NULL) + listeners()->SuppressEventForwarding(); +} +#endif // GTEST_HAS_DEATH_TEST + +// Initializes event listeners performing XML output as specified by +// UnitTestOptions. Must not be called before InitGoogleTest. +void UnitTestImpl::ConfigureXmlOutput() { + const std::string& output_format = UnitTestOptions::GetOutputFormat(); + if (output_format == "xml") { + listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter( + UnitTestOptions::GetAbsolutePathToOutputFile().c_str())); + } else if (output_format != "") { + printf("WARNING: unrecognized output format \"%s\" ignored.\n", + output_format.c_str()); + fflush(stdout); + } +} + +#if GTEST_CAN_STREAM_RESULTS_ +// Initializes event listeners for streaming test results in string form. +// Must not be called before InitGoogleTest. +void UnitTestImpl::ConfigureStreamingOutput() { + const std::string& target = GTEST_FLAG(stream_result_to); + if (!target.empty()) { + const size_t pos = target.find(':'); + if (pos != std::string::npos) { + listeners()->Append(new StreamingListener(target.substr(0, pos), + target.substr(pos+1))); + } else { + printf("WARNING: unrecognized streaming target \"%s\" ignored.\n", + target.c_str()); + fflush(stdout); + } + } +} +#endif // GTEST_CAN_STREAM_RESULTS_ + +// Performs initialization dependent upon flag values obtained in +// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to +// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest +// this function is also called from RunAllTests. Since this function can be +// called more than once, it has to be idempotent. +void UnitTestImpl::PostFlagParsingInit() { + // Ensures that this function does not execute more than once. + if (!post_flag_parse_init_performed_) { + post_flag_parse_init_performed_ = true; + +#if defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) + // Register to send notifications about key process state changes. + listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_()); +#endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_) + +#if GTEST_HAS_DEATH_TEST + InitDeathTestSubprocessControlInfo(); + SuppressTestEventsIfInSubprocess(); +#endif // GTEST_HAS_DEATH_TEST + + // Registers parameterized tests. This makes parameterized tests + // available to the UnitTest reflection API without running + // RUN_ALL_TESTS. + RegisterParameterizedTests(); + + // Configures listeners for XML output. This makes it possible for users + // to shut down the default XML output before invoking RUN_ALL_TESTS. + ConfigureXmlOutput(); + +#if GTEST_CAN_STREAM_RESULTS_ + // Configures listeners for streaming test results to the specified server. + ConfigureStreamingOutput(); +#endif // GTEST_CAN_STREAM_RESULTS_ + } +} + +// A predicate that checks the name of a TestCase against a known +// value. +// +// This is used for implementation of the UnitTest class only. We put +// it in the anonymous namespace to prevent polluting the outer +// namespace. +// +// TestCaseNameIs is copyable. +class TestCaseNameIs { + public: + // Constructor. + explicit TestCaseNameIs(const std::string& name) + : name_(name) {} + + // Returns true iff the name of test_case matches name_. + bool operator()(const TestCase* test_case) const { + return test_case != NULL && strcmp(test_case->name(), name_.c_str()) == 0; + } + + private: + std::string name_; +}; + +// Finds and returns a TestCase with the given name. If one doesn't +// exist, creates one and returns it. It's the CALLER'S +// RESPONSIBILITY to ensure that this function is only called WHEN THE +// TESTS ARE NOT SHUFFLED. +// +// Arguments: +// +// test_case_name: name of the test case +// type_param: the name of the test case's type parameter, or NULL if +// this is not a typed or a type-parameterized test case. +// set_up_tc: pointer to the function that sets up the test case +// tear_down_tc: pointer to the function that tears down the test case +TestCase* UnitTestImpl::GetTestCase(const char* test_case_name, + const char* type_param, + Test::SetUpTestCaseFunc set_up_tc, + Test::TearDownTestCaseFunc tear_down_tc) { + // Can we find a TestCase with the given name? + const std::vector::const_iterator test_case = + std::find_if(test_cases_.begin(), test_cases_.end(), + TestCaseNameIs(test_case_name)); + + if (test_case != test_cases_.end()) + return *test_case; + + // No. Let's create one. + TestCase* const new_test_case = + new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc); + + // Is this a death test case? + if (internal::UnitTestOptions::MatchesFilter(test_case_name, + kDeathTestCaseFilter)) { + // Yes. Inserts the test case after the last death test case + // defined so far. This only works when the test cases haven't + // been shuffled. Otherwise we may end up running a death test + // after a non-death test. + ++last_death_test_case_; + test_cases_.insert(test_cases_.begin() + last_death_test_case_, + new_test_case); + } else { + // No. Appends to the end of the list. + test_cases_.push_back(new_test_case); + } + + test_case_indices_.push_back(static_cast(test_case_indices_.size())); + return new_test_case; +} + +// Helpers for setting up / tearing down the given environment. They +// are for use in the ForEach() function. +static void SetUpEnvironment(Environment* env) { env->SetUp(); } +static void TearDownEnvironment(Environment* env) { env->TearDown(); } + +// Runs all tests in this UnitTest object, prints the result, and +// returns true if all tests are successful. If any exception is +// thrown during a test, the test is considered to be failed, but the +// rest of the tests will still be run. +// +// When parameterized tests are enabled, it expands and registers +// parameterized tests first in RegisterParameterizedTests(). +// All other functions called from RunAllTests() may safely assume that +// parameterized tests are ready to be counted and run. +bool UnitTestImpl::RunAllTests() { + // Makes sure InitGoogleTest() was called. + if (!GTestIsInitialized()) { + printf("%s", + "\nThis test program did NOT call ::testing::InitGoogleTest " + "before calling RUN_ALL_TESTS(). Please fix it.\n"); + return false; + } + + // Do not run any test if the --help flag was specified. + if (g_help_flag) + return true; + + // Repeats the call to the post-flag parsing initialization in case the + // user didn't call InitGoogleTest. + PostFlagParsingInit(); + + // Even if sharding is not on, test runners may want to use the + // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding + // protocol. + internal::WriteToShardStatusFileIfNeeded(); + + // True iff we are in a subprocess for running a thread-safe-style + // death test. + bool in_subprocess_for_death_test = false; + +#if GTEST_HAS_DEATH_TEST + in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL); +# if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) + if (in_subprocess_for_death_test) { + GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_(); + } +# endif // defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_) +#endif // GTEST_HAS_DEATH_TEST + + const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex, + in_subprocess_for_death_test); + + // Compares the full test names with the filter to decide which + // tests to run. + const bool has_tests_to_run = FilterTests(should_shard + ? HONOR_SHARDING_PROTOCOL + : IGNORE_SHARDING_PROTOCOL) > 0; + + // Lists the tests and exits if the --gtest_list_tests flag was specified. + if (GTEST_FLAG(list_tests)) { + // This must be called *after* FilterTests() has been called. + ListTestsMatchingFilter(); + return true; + } + + random_seed_ = GTEST_FLAG(shuffle) ? + GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0; + + // True iff at least one test has failed. + bool failed = false; + + TestEventListener* repeater = listeners()->repeater(); + + start_timestamp_ = GetTimeInMillis(); + repeater->OnTestProgramStart(*parent_); + + // How many times to repeat the tests? We don't want to repeat them + // when we are inside the subprocess of a death test. + const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat); + // Repeats forever if the repeat count is negative. + const bool forever = repeat < 0; + for (int i = 0; forever || i != repeat; i++) { + // We want to preserve failures generated by ad-hoc test + // assertions executed before RUN_ALL_TESTS(). + ClearNonAdHocTestResult(); + + const TimeInMillis start = GetTimeInMillis(); + + // Shuffles test cases and tests if requested. + if (has_tests_to_run && GTEST_FLAG(shuffle)) { + random()->Reseed(random_seed_); + // This should be done before calling OnTestIterationStart(), + // such that a test event listener can see the actual test order + // in the event. + ShuffleTests(); + } + + // Tells the unit test event listeners that the tests are about to start. + repeater->OnTestIterationStart(*parent_, i); + + // Runs each test case if there is at least one test to run. + if (has_tests_to_run) { + // Sets up all environments beforehand. + repeater->OnEnvironmentsSetUpStart(*parent_); + ForEach(environments_, SetUpEnvironment); + repeater->OnEnvironmentsSetUpEnd(*parent_); + + // Runs the tests only if there was no fatal failure during global + // set-up. + if (!Test::HasFatalFailure()) { + for (int test_index = 0; test_index < total_test_case_count(); + test_index++) { + GetMutableTestCase(test_index)->Run(); + } + } + + // Tears down all environments in reverse order afterwards. + repeater->OnEnvironmentsTearDownStart(*parent_); + std::for_each(environments_.rbegin(), environments_.rend(), + TearDownEnvironment); + repeater->OnEnvironmentsTearDownEnd(*parent_); + } + + elapsed_time_ = GetTimeInMillis() - start; + + // Tells the unit test event listener that the tests have just finished. + repeater->OnTestIterationEnd(*parent_, i); + + // Gets the result and clears it. + if (!Passed()) { + failed = true; + } + + // Restores the original test order after the iteration. This + // allows the user to quickly repro a failure that happens in the + // N-th iteration without repeating the first (N - 1) iterations. + // This is not enclosed in "if (GTEST_FLAG(shuffle)) { ... }", in + // case the user somehow changes the value of the flag somewhere + // (it's always safe to unshuffle the tests). + UnshuffleTests(); + + if (GTEST_FLAG(shuffle)) { + // Picks a new random seed for each iteration. + random_seed_ = GetNextRandomSeed(random_seed_); + } + } + + repeater->OnTestProgramEnd(*parent_); + + return !failed; +} + +// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file +// if the variable is present. If a file already exists at this location, this +// function will write over it. If the variable is present, but the file cannot +// be created, prints an error and exits. +void WriteToShardStatusFileIfNeeded() { + const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile); + if (test_shard_file != NULL) { + FILE* const file = posix::FOpen(test_shard_file, "w"); + if (file == NULL) { + ColoredPrintf(COLOR_RED, + "Could not write to the test shard status file \"%s\" " + "specified by the %s environment variable.\n", + test_shard_file, kTestShardStatusFile); + fflush(stdout); + exit(EXIT_FAILURE); + } + fclose(file); + } +} + +// Checks whether sharding is enabled by examining the relevant +// environment variable values. If the variables are present, +// but inconsistent (i.e., shard_index >= total_shards), prints +// an error and exits. If in_subprocess_for_death_test, sharding is +// disabled because it must only be applied to the original test +// process. Otherwise, we could filter out death tests we intended to execute. +bool ShouldShard(const char* total_shards_env, + const char* shard_index_env, + bool in_subprocess_for_death_test) { + if (in_subprocess_for_death_test) { + return false; + } + + const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1); + const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1); + + if (total_shards == -1 && shard_index == -1) { + return false; + } else if (total_shards == -1 && shard_index != -1) { + const Message msg = Message() + << "Invalid environment variables: you have " + << kTestShardIndex << " = " << shard_index + << ", but have left " << kTestTotalShards << " unset.\n"; + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + fflush(stdout); + exit(EXIT_FAILURE); + } else if (total_shards != -1 && shard_index == -1) { + const Message msg = Message() + << "Invalid environment variables: you have " + << kTestTotalShards << " = " << total_shards + << ", but have left " << kTestShardIndex << " unset.\n"; + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + fflush(stdout); + exit(EXIT_FAILURE); + } else if (shard_index < 0 || shard_index >= total_shards) { + const Message msg = Message() + << "Invalid environment variables: we require 0 <= " + << kTestShardIndex << " < " << kTestTotalShards + << ", but you have " << kTestShardIndex << "=" << shard_index + << ", " << kTestTotalShards << "=" << total_shards << ".\n"; + ColoredPrintf(COLOR_RED, msg.GetString().c_str()); + fflush(stdout); + exit(EXIT_FAILURE); + } + + return total_shards > 1; +} + +// Parses the environment variable var as an Int32. If it is unset, +// returns default_val. If it is not an Int32, prints an error +// and aborts. +Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) { + const char* str_val = posix::GetEnv(var); + if (str_val == NULL) { + return default_val; + } + + Int32 result; + if (!ParseInt32(Message() << "The value of environment variable " << var, + str_val, &result)) { + exit(EXIT_FAILURE); + } + return result; +} + +// Given the total number of shards, the shard index, and the test id, +// returns true iff the test should be run on this shard. The test id is +// some arbitrary but unique non-negative integer assigned to each test +// method. Assumes that 0 <= shard_index < total_shards. +bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { + return (test_id % total_shards) == shard_index; +} + +// Compares the name of each test with the user-specified filter to +// decide whether the test should be run, then records the result in +// each TestCase and TestInfo object. +// If shard_tests == true, further filters tests based on sharding +// variables in the environment - see +// http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide. +// Returns the number of tests that should run. +int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { + const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? + Int32FromEnvOrDie(kTestTotalShards, -1) : -1; + const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ? + Int32FromEnvOrDie(kTestShardIndex, -1) : -1; + + // num_runnable_tests are the number of tests that will + // run across all shards (i.e., match filter and are not disabled). + // num_selected_tests are the number of tests to be run on + // this shard. + int num_runnable_tests = 0; + int num_selected_tests = 0; + for (size_t i = 0; i < test_cases_.size(); i++) { + TestCase* const test_case = test_cases_[i]; + const std::string &test_case_name = test_case->name(); + test_case->set_should_run(false); + + for (size_t j = 0; j < test_case->test_info_list().size(); j++) { + TestInfo* const test_info = test_case->test_info_list()[j]; + const std::string test_name(test_info->name()); + // A test is disabled if test case name or test name matches + // kDisableTestFilter. + const bool is_disabled = + internal::UnitTestOptions::MatchesFilter(test_case_name, + kDisableTestFilter) || + internal::UnitTestOptions::MatchesFilter(test_name, + kDisableTestFilter); + test_info->is_disabled_ = is_disabled; + + const bool matches_filter = + internal::UnitTestOptions::FilterMatchesTest(test_case_name, + test_name); + test_info->matches_filter_ = matches_filter; + + const bool is_runnable = + (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) && + matches_filter; + + const bool is_selected = is_runnable && + (shard_tests == IGNORE_SHARDING_PROTOCOL || + ShouldRunTestOnShard(total_shards, shard_index, + num_runnable_tests)); + + num_runnable_tests += is_runnable; + num_selected_tests += is_selected; + + test_info->should_run_ = is_selected; + test_case->set_should_run(test_case->should_run() || is_selected); + } + } + return num_selected_tests; +} + +// Prints the given C-string on a single line by replacing all '\n' +// characters with string "\\n". If the output takes more than +// max_length characters, only prints the first max_length characters +// and "...". +static void PrintOnOneLine(const char* str, int max_length) { + if (str != NULL) { + for (int i = 0; *str != '\0'; ++str) { + if (i >= max_length) { + printf("..."); + break; + } + if (*str == '\n') { + printf("\\n"); + i += 2; + } else { + printf("%c", *str); + ++i; + } + } + } +} + +// Prints the names of the tests matching the user-specified filter flag. +void UnitTestImpl::ListTestsMatchingFilter() { + // Print at most this many characters for each type/value parameter. + const int kMaxParamLength = 250; + + for (size_t i = 0; i < test_cases_.size(); i++) { + const TestCase* const test_case = test_cases_[i]; + bool printed_test_case_name = false; + + for (size_t j = 0; j < test_case->test_info_list().size(); j++) { + const TestInfo* const test_info = + test_case->test_info_list()[j]; + if (test_info->matches_filter_) { + if (!printed_test_case_name) { + printed_test_case_name = true; + printf("%s.", test_case->name()); + if (test_case->type_param() != NULL) { + printf(" # %s = ", kTypeParamLabel); + // We print the type parameter on a single line to make + // the output easy to parse by a program. + PrintOnOneLine(test_case->type_param(), kMaxParamLength); + } + printf("\n"); + } + printf(" %s", test_info->name()); + if (test_info->value_param() != NULL) { + printf(" # %s = ", kValueParamLabel); + // We print the value parameter on a single line to make the + // output easy to parse by a program. + PrintOnOneLine(test_info->value_param(), kMaxParamLength); + } + printf("\n"); + } + } + } + fflush(stdout); +} + +// Sets the OS stack trace getter. +// +// Does nothing if the input and the current OS stack trace getter are +// the same; otherwise, deletes the old getter and makes the input the +// current getter. +void UnitTestImpl::set_os_stack_trace_getter( + OsStackTraceGetterInterface* getter) { + if (os_stack_trace_getter_ != getter) { + delete os_stack_trace_getter_; + os_stack_trace_getter_ = getter; + } +} + +// Returns the current OS stack trace getter if it is not NULL; +// otherwise, creates an OsStackTraceGetter, makes it the current +// getter, and returns it. +OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() { + if (os_stack_trace_getter_ == NULL) { +#ifdef GTEST_OS_STACK_TRACE_GETTER_ + os_stack_trace_getter_ = new GTEST_OS_STACK_TRACE_GETTER_; +#else + os_stack_trace_getter_ = new OsStackTraceGetter; +#endif // GTEST_OS_STACK_TRACE_GETTER_ + } + + return os_stack_trace_getter_; +} + +// Returns the TestResult for the test that's currently running, or +// the TestResult for the ad hoc test if no test is running. +TestResult* UnitTestImpl::current_test_result() { + return current_test_info_ ? + &(current_test_info_->result_) : &ad_hoc_test_result_; +} + +// Shuffles all test cases, and the tests within each test case, +// making sure that death tests are still run first. +void UnitTestImpl::ShuffleTests() { + // Shuffles the death test cases. + ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_); + + // Shuffles the non-death test cases. + ShuffleRange(random(), last_death_test_case_ + 1, + static_cast(test_cases_.size()), &test_case_indices_); + + // Shuffles the tests inside each test case. + for (size_t i = 0; i < test_cases_.size(); i++) { + test_cases_[i]->ShuffleTests(random()); + } +} + +// Restores the test cases and tests to their order before the first shuffle. +void UnitTestImpl::UnshuffleTests() { + for (size_t i = 0; i < test_cases_.size(); i++) { + // Unshuffles the tests in each test case. + test_cases_[i]->UnshuffleTests(); + // Resets the index of each test case. + test_case_indices_[i] = static_cast(i); + } +} + +// Returns the current OS stack trace as an std::string. +// +// The maximum number of stack frames to be included is specified by +// the gtest_stack_trace_depth flag. The skip_count parameter +// specifies the number of top frames to be skipped, which doesn't +// count against the number of frames to be included. +// +// For example, if Foo() calls Bar(), which in turn calls +// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in +// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. +std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/, + int skip_count) { + // We pass skip_count + 1 to skip this wrapper function in addition + // to what the user really wants to skip. + return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1); +} + +// Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to +// suppress unreachable code warnings. +namespace { +class ClassUniqueToAlwaysTrue {}; +} + +bool IsTrue(bool condition) { return condition; } + +bool AlwaysTrue() { +#if GTEST_HAS_EXCEPTIONS + // This condition is always false so AlwaysTrue() never actually throws, + // but it makes the compiler think that it may throw. + if (IsTrue(false)) + throw ClassUniqueToAlwaysTrue(); +#endif // GTEST_HAS_EXCEPTIONS + return true; +} + +// If *pstr starts with the given prefix, modifies *pstr to be right +// past the prefix and returns true; otherwise leaves *pstr unchanged +// and returns false. None of pstr, *pstr, and prefix can be NULL. +bool SkipPrefix(const char* prefix, const char** pstr) { + const size_t prefix_len = strlen(prefix); + if (strncmp(*pstr, prefix, prefix_len) == 0) { + *pstr += prefix_len; + return true; + } + return false; +} + +// Parses a string as a command line flag. The string should have +// the format "--flag=value". When def_optional is true, the "=value" +// part can be omitted. +// +// Returns the value of the flag, or NULL if the parsing failed. +const char* ParseFlagValue(const char* str, + const char* flag, + bool def_optional) { + // str and flag must not be NULL. + if (str == NULL || flag == NULL) return NULL; + + // The flag must start with "--" followed by GTEST_FLAG_PREFIX_. + const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag; + const size_t flag_len = flag_str.length(); + if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; + + // Skips the flag name. + const char* flag_end = str + flag_len; + + // When def_optional is true, it's OK to not have a "=value" part. + if (def_optional && (flag_end[0] == '\0')) { + return flag_end; + } + + // If def_optional is true and there are more characters after the + // flag name, or if def_optional is false, there must be a '=' after + // the flag name. + if (flag_end[0] != '=') return NULL; + + // Returns the string after "=". + return flag_end + 1; +} + +// Parses a string for a bool flag, in the form of either +// "--flag=value" or "--flag". +// +// In the former case, the value is taken as true as long as it does +// not start with '0', 'f', or 'F'. +// +// In the latter case, the value is taken as true. +// +// On success, stores the value of the flag in *value, and returns +// true. On failure, returns false without changing *value. +bool ParseBoolFlag(const char* str, const char* flag, bool* value) { + // Gets the value of the flag as a string. + const char* const value_str = ParseFlagValue(str, flag, true); + + // Aborts if the parsing failed. + if (value_str == NULL) return false; + + // Converts the string value to a bool. + *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); + return true; +} + +// Parses a string for an Int32 flag, in the form of +// "--flag=value". +// +// On success, stores the value of the flag in *value, and returns +// true. On failure, returns false without changing *value. +bool ParseInt32Flag(const char* str, const char* flag, Int32* value) { + // Gets the value of the flag as a string. + const char* const value_str = ParseFlagValue(str, flag, false); + + // Aborts if the parsing failed. + if (value_str == NULL) return false; + + // Sets *value to the value of the flag. + return ParseInt32(Message() << "The value of flag --" << flag, + value_str, value); +} + +// Parses a string for a string flag, in the form of +// "--flag=value". +// +// On success, stores the value of the flag in *value, and returns +// true. On failure, returns false without changing *value. +bool ParseStringFlag(const char* str, const char* flag, std::string* value) { + // Gets the value of the flag as a string. + const char* const value_str = ParseFlagValue(str, flag, false); + + // Aborts if the parsing failed. + if (value_str == NULL) return false; + + // Sets *value to the value of the flag. + *value = value_str; + return true; +} + +// Determines whether a string has a prefix that Google Test uses for its +// flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_. +// If Google Test detects that a command line flag has its prefix but is not +// recognized, it will print its help message. Flags starting with +// GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test +// internal flags and do not trigger the help message. +static bool HasGoogleTestFlagPrefix(const char* str) { + return (SkipPrefix("--", &str) || + SkipPrefix("-", &str) || + SkipPrefix("/", &str)) && + !SkipPrefix(GTEST_FLAG_PREFIX_ "internal_", &str) && + (SkipPrefix(GTEST_FLAG_PREFIX_, &str) || + SkipPrefix(GTEST_FLAG_PREFIX_DASH_, &str)); +} + +// Prints a string containing code-encoded text. The following escape +// sequences can be used in the string to control the text color: +// +// @@ prints a single '@' character. +// @R changes the color to red. +// @G changes the color to green. +// @Y changes the color to yellow. +// @D changes to the default terminal text color. +// +// TODO(wan@google.com): Write tests for this once we add stdout +// capturing to Google Test. +static void PrintColorEncoded(const char* str) { + GTestColor color = COLOR_DEFAULT; // The current color. + + // Conceptually, we split the string into segments divided by escape + // sequences. Then we print one segment at a time. At the end of + // each iteration, the str pointer advances to the beginning of the + // next segment. + for (;;) { + const char* p = strchr(str, '@'); + if (p == NULL) { + ColoredPrintf(color, "%s", str); + return; + } + + ColoredPrintf(color, "%s", std::string(str, p).c_str()); + + const char ch = p[1]; + str = p + 2; + if (ch == '@') { + ColoredPrintf(color, "@"); + } else if (ch == 'D') { + color = COLOR_DEFAULT; + } else if (ch == 'R') { + color = COLOR_RED; + } else if (ch == 'G') { + color = COLOR_GREEN; + } else if (ch == 'Y') { + color = COLOR_YELLOW; + } else { + --str; + } + } +} + +static const char kColorEncodedHelpMessage[] = +"This program contains tests written using " GTEST_NAME_ ". You can use the\n" +"following command line flags to control its behavior:\n" +"\n" +"Test Selection:\n" +" @G--" GTEST_FLAG_PREFIX_ "list_tests@D\n" +" List the names of all tests instead of running them. The name of\n" +" TEST(Foo, Bar) is \"Foo.Bar\".\n" +" @G--" GTEST_FLAG_PREFIX_ "filter=@YPOSTIVE_PATTERNS" + "[@G-@YNEGATIVE_PATTERNS]@D\n" +" Run only the tests whose name matches one of the positive patterns but\n" +" none of the negative patterns. '?' matches any single character; '*'\n" +" matches any substring; ':' separates two patterns.\n" +" @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n" +" Run all disabled tests too.\n" +"\n" +"Test Execution:\n" +" @G--" GTEST_FLAG_PREFIX_ "repeat=@Y[COUNT]@D\n" +" Run the tests repeatedly; use a negative count to repeat forever.\n" +" @G--" GTEST_FLAG_PREFIX_ "shuffle@D\n" +" Randomize tests' orders on every iteration.\n" +" @G--" GTEST_FLAG_PREFIX_ "random_seed=@Y[NUMBER]@D\n" +" Random number seed to use for shuffling test orders (between 1 and\n" +" 99999, or 0 to use a seed based on the current time).\n" +"\n" +"Test Output:\n" +" @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n" +" Enable/disable colored output. The default is @Gauto@D.\n" +" -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n" +" Don't print the elapsed time of each test.\n" +" @G--" GTEST_FLAG_PREFIX_ "output=xml@Y[@G:@YDIRECTORY_PATH@G" + GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n" +" Generate an XML report in the given directory or with the given file\n" +" name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n" +#if GTEST_CAN_STREAM_RESULTS_ +" @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n" +" Stream test results to the given server.\n" +#endif // GTEST_CAN_STREAM_RESULTS_ +"\n" +"Assertion Behavior:\n" +#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +" @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" +" Set the default death test style.\n" +#endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS +" @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n" +" Turn assertion failures into debugger break-points.\n" +" @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n" +" Turn assertion failures into C++ exceptions.\n" +" @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n" +" Do not report exceptions as test failures. Instead, allow them\n" +" to crash the program or throw a pop-up (on Windows).\n" +"\n" +"Except for @G--" GTEST_FLAG_PREFIX_ "list_tests@D, you can alternatively set " + "the corresponding\n" +"environment variable of a flag (all letters in upper-case). For example, to\n" +"disable colored text output, you can either specify @G--" GTEST_FLAG_PREFIX_ + "color=no@D or set\n" +"the @G" GTEST_FLAG_PREFIX_UPPER_ "COLOR@D environment variable to @Gno@D.\n" +"\n" +"For more information, please read the " GTEST_NAME_ " documentation at\n" +"@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_ "\n" +"(not one in your own code or tests), please report it to\n" +"@G<" GTEST_DEV_EMAIL_ ">@D.\n"; + +bool ParseGoogleTestFlag(const char* const arg) { + return ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag, + >EST_FLAG(also_run_disabled_tests)) || + ParseBoolFlag(arg, kBreakOnFailureFlag, + >EST_FLAG(break_on_failure)) || + ParseBoolFlag(arg, kCatchExceptionsFlag, + >EST_FLAG(catch_exceptions)) || + ParseStringFlag(arg, kColorFlag, >EST_FLAG(color)) || + ParseStringFlag(arg, kDeathTestStyleFlag, + >EST_FLAG(death_test_style)) || + ParseBoolFlag(arg, kDeathTestUseFork, + >EST_FLAG(death_test_use_fork)) || + ParseStringFlag(arg, kFilterFlag, >EST_FLAG(filter)) || + ParseStringFlag(arg, kInternalRunDeathTestFlag, + >EST_FLAG(internal_run_death_test)) || + ParseBoolFlag(arg, kListTestsFlag, >EST_FLAG(list_tests)) || + ParseStringFlag(arg, kOutputFlag, >EST_FLAG(output)) || + ParseBoolFlag(arg, kPrintTimeFlag, >EST_FLAG(print_time)) || + ParseInt32Flag(arg, kRandomSeedFlag, >EST_FLAG(random_seed)) || + ParseInt32Flag(arg, kRepeatFlag, >EST_FLAG(repeat)) || + ParseBoolFlag(arg, kShuffleFlag, >EST_FLAG(shuffle)) || + ParseInt32Flag(arg, kStackTraceDepthFlag, + >EST_FLAG(stack_trace_depth)) || + ParseStringFlag(arg, kStreamResultToFlag, + >EST_FLAG(stream_result_to)) || + ParseBoolFlag(arg, kThrowOnFailureFlag, + >EST_FLAG(throw_on_failure)); +} + +#if GTEST_USE_OWN_FLAGFILE_FLAG_ +void LoadFlagsFromFile(const std::string& path) { + FILE* flagfile = posix::FOpen(path.c_str(), "r"); + if (!flagfile) { + fprintf(stderr, + "Unable to open file \"%s\"\n", + GTEST_FLAG(flagfile).c_str()); + fflush(stderr); + exit(EXIT_FAILURE); + } + std::string contents(ReadEntireFile(flagfile)); + posix::FClose(flagfile); + std::vector lines; + SplitString(contents, '\n', &lines); + for (size_t i = 0; i < lines.size(); ++i) { + if (lines[i].empty()) + continue; + if (!ParseGoogleTestFlag(lines[i].c_str())) + g_help_flag = true; + } +} +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ + +// Parses the command line for Google Test flags, without initializing +// other parts of Google Test. The type parameter CharType can be +// instantiated to either char or wchar_t. +template +void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { + for (int i = 1; i < *argc; i++) { + const std::string arg_string = StreamableToString(argv[i]); + const char* const arg = arg_string.c_str(); + + using internal::ParseBoolFlag; + using internal::ParseInt32Flag; + using internal::ParseStringFlag; + + bool remove_flag = false; + if (ParseGoogleTestFlag(arg)) { + remove_flag = true; +#if GTEST_USE_OWN_FLAGFILE_FLAG_ + } else if (ParseStringFlag(arg, kFlagfileFlag, >EST_FLAG(flagfile))) { + LoadFlagsFromFile(GTEST_FLAG(flagfile)); + remove_flag = true; +#endif // GTEST_USE_OWN_FLAGFILE_FLAG_ + } else if (arg_string == "--help" || arg_string == "-h" || + arg_string == "-?" || arg_string == "/?" || + HasGoogleTestFlagPrefix(arg)) { + // Both help flag and unrecognized Google Test flags (excluding + // internal ones) trigger help display. + g_help_flag = true; + } + + if (remove_flag) { + // Shift the remainder of the argv list left by one. Note + // that argv has (*argc + 1) elements, the last one always being + // NULL. The following loop moves the trailing NULL element as + // well. + for (int j = i; j != *argc; j++) { + argv[j] = argv[j + 1]; + } + + // Decrements the argument count. + (*argc)--; + + // We also need to decrement the iterator as we just removed + // an element. + i--; + } + } + + if (g_help_flag) { + // We print the help here instead of in RUN_ALL_TESTS(), as the + // latter may not be called at all if the user is using Google + // Test with another testing framework. + PrintColorEncoded(kColorEncodedHelpMessage); + } +} + +// Parses the command line for Google Test flags, without initializing +// other parts of Google Test. +void ParseGoogleTestFlagsOnly(int* argc, char** argv) { + ParseGoogleTestFlagsOnlyImpl(argc, argv); +} +void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) { + ParseGoogleTestFlagsOnlyImpl(argc, argv); +} + +// The internal implementation of InitGoogleTest(). +// +// The type parameter CharType can be instantiated to either char or +// wchar_t. +template +void InitGoogleTestImpl(int* argc, CharType** argv) { + // We don't want to run the initialization code twice. + if (GTestIsInitialized()) return; + + if (*argc <= 0) return; + + g_argvs.clear(); + for (int i = 0; i != *argc; i++) { + g_argvs.push_back(StreamableToString(argv[i])); + } + + ParseGoogleTestFlagsOnly(argc, argv); + GetUnitTestImpl()->PostFlagParsingInit(); +} + +} // namespace internal + +// Initializes Google Test. This must be called before calling +// RUN_ALL_TESTS(). In particular, it parses a command line for the +// flags that Google Test recognizes. Whenever a Google Test flag is +// seen, it is removed from argv, and *argc is decremented. +// +// No value is returned. Instead, the Google Test flag variables are +// updated. +// +// Calling the function for the second time has no user-visible effect. +void InitGoogleTest(int* argc, char** argv) { +#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) + GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv); +#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) + internal::InitGoogleTestImpl(argc, argv); +#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +} + +// This overloaded version can be used in Windows programs compiled in +// UNICODE mode. +void InitGoogleTest(int* argc, wchar_t** argv) { +#if defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) + GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv); +#else // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) + internal::InitGoogleTestImpl(argc, argv); +#endif // defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_) +} + +} // namespace testing diff --git a/TestMothur/gtest.h b/TestMothur/gtest.h new file mode 100755 index 00000000..1047fe17 --- /dev/null +++ b/TestMothur/gtest.h @@ -0,0 +1,2236 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// The Google C++ Testing Framework (Google Test) +// +// This header file defines the public API for Google Test. It should be +// included by any test program that uses Google Test. +// +// IMPORTANT NOTE: Due to limitation of the C++ language, we have to +// leave some internal implementation details in this header file. +// They are clearly marked by comments like this: +// +// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +// +// Such code is NOT meant to be used by a user directly, and is subject +// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user +// program! +// +// Acknowledgment: Google Test borrowed the idea of automatic test +// registration from Barthelemy Dagenais' (barthelemy@prologique.com) +// easyUnit framework. + +#ifndef GTEST_INCLUDE_GTEST_GTEST_H_ +#define GTEST_INCLUDE_GTEST_GTEST_H_ + +#include +#include +#include + +#include "gtest-internal.h" +#include "gtest-string.h" +#include "gtest-death-test.h" +#include "gtest-message.h" +#include "gtest-param-test.h" +#include "gtest-printers.h" +#include "gtest_prod.h" +#include "gtest-test-part.h" +#include "gtest-typed-test.h" + +// Depending on the platform, different string classes are available. +// On Linux, in addition to ::std::string, Google also makes use of +// class ::string, which has the same interface as ::std::string, but +// has a different implementation. +// +// You can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that +// ::string is available AND is a distinct type to ::std::string, or +// define it to 0 to indicate otherwise. +// +// If ::std::string and ::string are the same class on your platform +// due to aliasing, you should define GTEST_HAS_GLOBAL_STRING to 0. +// +// If you do not define GTEST_HAS_GLOBAL_STRING, it is defined +// heuristically. + +namespace testing { + +// Declares the flags. + +// This flag temporary enables the disabled tests. +GTEST_DECLARE_bool_(also_run_disabled_tests); + +// This flag brings the debugger on an assertion failure. +GTEST_DECLARE_bool_(break_on_failure); + +// This flag controls whether Google Test catches all test-thrown exceptions +// and logs them as failures. +GTEST_DECLARE_bool_(catch_exceptions); + +// This flag enables using colors in terminal output. Available values are +// "yes" to enable colors, "no" (disable colors), or "auto" (the default) +// to let Google Test decide. +GTEST_DECLARE_string_(color); + +// This flag sets up the filter to select by name using a glob pattern +// the tests to run. If the filter is not given all tests are executed. +GTEST_DECLARE_string_(filter); + +// This flag causes the Google Test to list tests. None of the tests listed +// are actually run if the flag is provided. +GTEST_DECLARE_bool_(list_tests); + +// This flag controls whether Google Test emits a detailed XML report to a file +// in addition to its normal textual output. +GTEST_DECLARE_string_(output); + +// This flags control whether Google Test prints the elapsed time for each +// test. +GTEST_DECLARE_bool_(print_time); + +// This flag specifies the random number seed. +GTEST_DECLARE_int32_(random_seed); + +// This flag sets how many times the tests are repeated. The default value +// is 1. If the value is -1 the tests are repeating forever. +GTEST_DECLARE_int32_(repeat); + +// This flag controls whether Google Test includes Google Test internal +// stack frames in failure stack traces. +GTEST_DECLARE_bool_(show_internal_stack_frames); + +// When this flag is specified, tests' order is randomized on every iteration. +GTEST_DECLARE_bool_(shuffle); + +// This flag specifies the maximum number of stack frames to be +// printed in a failure message. +GTEST_DECLARE_int32_(stack_trace_depth); + +// When this flag is specified, a failed assertion will throw an +// exception if exceptions are enabled, or exit the program with a +// non-zero code otherwise. +GTEST_DECLARE_bool_(throw_on_failure); + +// When this flag is set with a "host:port" string, on supported +// platforms test results are streamed to the specified port on +// the specified host machine. +GTEST_DECLARE_string_(stream_result_to); + +// The upper limit for valid stack trace depths. +const int kMaxStackTraceDepth = 100; + +namespace internal { + +class AssertHelper; +class DefaultGlobalTestPartResultReporter; +class ExecDeathTest; +class NoExecDeathTest; +class FinalSuccessChecker; +class GTestFlagSaver; +class StreamingListenerTest; +class TestResultAccessor; +class TestEventListenersAccessor; +class TestEventRepeater; +class UnitTestRecordPropertyTestHelper; +class WindowsDeathTest; +class UnitTestImpl* GetUnitTestImpl(); +void ReportFailureInUnknownLocation(TestPartResult::Type result_type, + const std::string& message); + +} // namespace internal + +// The friend relationship of some of these classes is cyclic. +// If we don't forward declare them the compiler might confuse the classes +// in friendship clauses with same named classes on the scope. +class Test; +class TestCase; +class TestInfo; +class UnitTest; + +// A class for indicating whether an assertion was successful. When +// the assertion wasn't successful, the AssertionResult object +// remembers a non-empty message that describes how it failed. +// +// To create an instance of this class, use one of the factory functions +// (AssertionSuccess() and AssertionFailure()). +// +// This class is useful for two purposes: +// 1. Defining predicate functions to be used with Boolean test assertions +// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts +// 2. Defining predicate-format functions to be +// used with predicate assertions (ASSERT_PRED_FORMAT*, etc). +// +// For example, if you define IsEven predicate: +// +// testing::AssertionResult IsEven(int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess(); +// else +// return testing::AssertionFailure() << n << " is odd"; +// } +// +// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) +// will print the message +// +// Value of: IsEven(Fib(5)) +// Actual: false (5 is odd) +// Expected: true +// +// instead of a more opaque +// +// Value of: IsEven(Fib(5)) +// Actual: false +// Expected: true +// +// in case IsEven is a simple Boolean predicate. +// +// If you expect your predicate to be reused and want to support informative +// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up +// about half as often as positive ones in our tests), supply messages for +// both success and failure cases: +// +// testing::AssertionResult IsEven(int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess() << n << " is even"; +// else +// return testing::AssertionFailure() << n << " is odd"; +// } +// +// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print +// +// Value of: IsEven(Fib(6)) +// Actual: true (8 is even) +// Expected: false +// +// NB: Predicates that support negative Boolean assertions have reduced +// performance in positive ones so be careful not to use them in tests +// that have lots (tens of thousands) of positive Boolean assertions. +// +// To use this class with EXPECT_PRED_FORMAT assertions such as: +// +// // Verifies that Foo() returns an even number. +// EXPECT_PRED_FORMAT1(IsEven, Foo()); +// +// you need to define: +// +// testing::AssertionResult IsEven(const char* expr, int n) { +// if ((n % 2) == 0) +// return testing::AssertionSuccess(); +// else +// return testing::AssertionFailure() +// << "Expected: " << expr << " is even\n Actual: it's " << n; +// } +// +// If Foo() returns 5, you will see the following message: +// +// Expected: Foo() is even +// Actual: it's 5 +// +class GTEST_API_ AssertionResult { + public: + // Copy constructor. + // Used in EXPECT_TRUE/FALSE(assertion_result). + AssertionResult(const AssertionResult& other); + + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) + + // Used in the EXPECT_TRUE/FALSE(bool_expression). + // + // T must be contextually convertible to bool. + // + // The second parameter prevents this overload from being considered if + // the argument is implicitly convertible to AssertionResult. In that case + // we want AssertionResult's copy constructor to be used. + template + explicit AssertionResult( + const T& success, + typename internal::EnableIf< + !internal::ImplicitlyConvertible::value>::type* + /*enabler*/ = NULL) + : success_(success) {} + + GTEST_DISABLE_MSC_WARNINGS_POP_() + + // Assignment operator. + AssertionResult& operator=(AssertionResult other) { + swap(other); + return *this; + } + + // Returns true iff the assertion succeeded. + operator bool() const { return success_; } // NOLINT + + // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. + AssertionResult operator!() const; + + // Returns the text streamed into this AssertionResult. Test assertions + // use it when they fail (i.e., the predicate's outcome doesn't match the + // assertion's expectation). When nothing has been streamed into the + // object, returns an empty string. + const char* message() const { + return message_.get() != NULL ? message_->c_str() : ""; + } + // TODO(vladl@google.com): Remove this after making sure no clients use it. + // Deprecated; please use message() instead. + const char* failure_message() const { return message(); } + + // Streams a custom failure message into this object. + template AssertionResult& operator<<(const T& value) { + AppendMessage(Message() << value); + return *this; + } + + // Allows streaming basic output manipulators such as endl or flush into + // this object. + AssertionResult& operator<<( + ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { + AppendMessage(Message() << basic_manipulator); + return *this; + } + + private: + // Appends the contents of message to message_. + void AppendMessage(const Message& a_message) { + if (message_.get() == NULL) + message_.reset(new ::std::string); + message_->append(a_message.GetString().c_str()); + } + + // Swap the contents of this AssertionResult with other. + void swap(AssertionResult& other); + + // Stores result of the assertion predicate. + bool success_; + // Stores the message describing the condition in case the expectation + // construct is not satisfied with the predicate's outcome. + // Referenced via a pointer to avoid taking too much stack frame space + // with test assertions. + internal::scoped_ptr< ::std::string> message_; +}; + +// Makes a successful assertion result. +GTEST_API_ AssertionResult AssertionSuccess(); + +// Makes a failed assertion result. +GTEST_API_ AssertionResult AssertionFailure(); + +// Makes a failed assertion result with the given failure message. +// Deprecated; use AssertionFailure() << msg. +GTEST_API_ AssertionResult AssertionFailure(const Message& msg); + +// The abstract class that all tests inherit from. +// +// In Google Test, a unit test program contains one or many TestCases, and +// each TestCase contains one or many Tests. +// +// When you define a test using the TEST macro, you don't need to +// explicitly derive from Test - the TEST macro automatically does +// this for you. +// +// The only time you derive from Test is when defining a test fixture +// to be used a TEST_F. For example: +// +// class FooTest : public testing::Test { +// protected: +// void SetUp() override { ... } +// void TearDown() override { ... } +// ... +// }; +// +// TEST_F(FooTest, Bar) { ... } +// TEST_F(FooTest, Baz) { ... } +// +// Test is not copyable. +class GTEST_API_ Test { + public: + friend class TestInfo; + + // Defines types for pointers to functions that set up and tear down + // a test case. + typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc; + typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc; + + // The d'tor is virtual as we intend to inherit from Test. + virtual ~Test(); + + // Sets up the stuff shared by all tests in this test case. + // + // Google Test will call Foo::SetUpTestCase() before running the first + // test in test case Foo. Hence a sub-class can define its own + // SetUpTestCase() method to shadow the one defined in the super + // class. + static void SetUpTestCase() {} + + // Tears down the stuff shared by all tests in this test case. + // + // Google Test will call Foo::TearDownTestCase() after running the last + // test in test case Foo. Hence a sub-class can define its own + // TearDownTestCase() method to shadow the one defined in the super + // class. + static void TearDownTestCase() {} + + // Returns true iff the current test has a fatal failure. + static bool HasFatalFailure(); + + // Returns true iff the current test has a non-fatal failure. + static bool HasNonfatalFailure(); + + // Returns true iff the current test has a (either fatal or + // non-fatal) failure. + static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); } + + // Logs a property for the current test, test case, or for the entire + // invocation of the test program when used outside of the context of a + // test case. Only the last value for a given key is remembered. These + // are public static so they can be called from utility functions that are + // not members of the test fixture. Calls to RecordProperty made during + // lifespan of the test (from the moment its constructor starts to the + // moment its destructor finishes) will be output in XML as attributes of + // the element. Properties recorded from fixture's + // SetUpTestCase or TearDownTestCase are logged as attributes of the + // corresponding element. Calls to RecordProperty made in the + // global context (before or after invocation of RUN_ALL_TESTS and from + // SetUp/TearDown method of Environment objects registered with Google + // Test) will be output as attributes of the element. + static void RecordProperty(const std::string& key, const std::string& value); + static void RecordProperty(const std::string& key, int value); + + protected: + // Creates a Test object. + Test(); + + // Sets up the test fixture. + virtual void SetUp(); + + // Tears down the test fixture. + virtual void TearDown(); + + private: + // Returns true iff the current test has the same fixture class as + // the first test in the current test case. + static bool HasSameFixtureClass(); + + // Runs the test after the test fixture has been set up. + // + // A sub-class must implement this to define the test logic. + // + // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM. + // Instead, use the TEST or TEST_F macro. + virtual void TestBody() = 0; + + // Sets up, executes, and tears down the test. + void Run(); + + // Deletes self. We deliberately pick an unusual name for this + // internal method to avoid clashing with names used in user TESTs. + void DeleteSelf_() { delete this; } + + const internal::scoped_ptr< GTEST_FLAG_SAVER_ > gtest_flag_saver_; + + // Often a user misspells SetUp() as Setup() and spends a long time + // wondering why it is never called by Google Test. The declaration of + // the following method is solely for catching such an error at + // compile time: + // + // - The return type is deliberately chosen to be not void, so it + // will be a conflict if void Setup() is declared in the user's + // test fixture. + // + // - This method is private, so it will be another compiler error + // if the method is called from the user's test fixture. + // + // DO NOT OVERRIDE THIS FUNCTION. + // + // If you see an error about overriding the following function or + // about it being private, you have mis-spelled SetUp() as Setup(). + struct Setup_should_be_spelled_SetUp {}; + virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } + + // We disallow copying Tests. + GTEST_DISALLOW_COPY_AND_ASSIGN_(Test); +}; + +typedef internal::TimeInMillis TimeInMillis; + +// A copyable object representing a user specified test property which can be +// output as a key/value string pair. +// +// Don't inherit from TestProperty as its destructor is not virtual. +class TestProperty { + public: + // C'tor. TestProperty does NOT have a default constructor. + // Always use this constructor (with parameters) to create a + // TestProperty object. + TestProperty(const std::string& a_key, const std::string& a_value) : + key_(a_key), value_(a_value) { + } + + // Gets the user supplied key. + const char* key() const { + return key_.c_str(); + } + + // Gets the user supplied value. + const char* value() const { + return value_.c_str(); + } + + // Sets a new value, overriding the one supplied in the constructor. + void SetValue(const std::string& new_value) { + value_ = new_value; + } + + private: + // The key supplied by the user. + std::string key_; + // The value supplied by the user. + std::string value_; +}; + +// The result of a single Test. This includes a list of +// TestPartResults, a list of TestProperties, a count of how many +// death tests there are in the Test, and how much time it took to run +// the Test. +// +// TestResult is not copyable. +class GTEST_API_ TestResult { + public: + // Creates an empty TestResult. + TestResult(); + + // D'tor. Do not inherit from TestResult. + ~TestResult(); + + // Gets the number of all test parts. This is the sum of the number + // of successful test parts and the number of failed test parts. + int total_part_count() const; + + // Returns the number of the test properties. + int test_property_count() const; + + // Returns true iff the test passed (i.e. no test part failed). + bool Passed() const { return !Failed(); } + + // Returns true iff the test failed. + bool Failed() const; + + // Returns true iff the test fatally failed. + bool HasFatalFailure() const; + + // Returns true iff the test has a non-fatal failure. + bool HasNonfatalFailure() const; + + // Returns the elapsed time, in milliseconds. + TimeInMillis elapsed_time() const { return elapsed_time_; } + + // Returns the i-th test part result among all the results. i can range + // from 0 to test_property_count() - 1. If i is not in that range, aborts + // the program. + const TestPartResult& GetTestPartResult(int i) const; + + // Returns the i-th test property. i can range from 0 to + // test_property_count() - 1. If i is not in that range, aborts the + // program. + const TestProperty& GetTestProperty(int i) const; + + private: + friend class TestInfo; + friend class TestCase; + friend class UnitTest; + friend class internal::DefaultGlobalTestPartResultReporter; + friend class internal::ExecDeathTest; + friend class internal::TestResultAccessor; + friend class internal::UnitTestImpl; + friend class internal::WindowsDeathTest; + + // Gets the vector of TestPartResults. + const std::vector& test_part_results() const { + return test_part_results_; + } + + // Gets the vector of TestProperties. + const std::vector& test_properties() const { + return test_properties_; + } + + // Sets the elapsed time. + void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; } + + // Adds a test property to the list. The property is validated and may add + // a non-fatal failure if invalid (e.g., if it conflicts with reserved + // key names). If a property is already recorded for the same key, the + // value will be updated, rather than storing multiple values for the same + // key. xml_element specifies the element for which the property is being + // recorded and is used for validation. + void RecordProperty(const std::string& xml_element, + const TestProperty& test_property); + + // Adds a failure if the key is a reserved attribute of Google Test + // testcase tags. Returns true if the property is valid. + // TODO(russr): Validate attribute names are legal and human readable. + static bool ValidateTestProperty(const std::string& xml_element, + const TestProperty& test_property); + + // Adds a test part result to the list. + void AddTestPartResult(const TestPartResult& test_part_result); + + // Returns the death test count. + int death_test_count() const { return death_test_count_; } + + // Increments the death test count, returning the new count. + int increment_death_test_count() { return ++death_test_count_; } + + // Clears the test part results. + void ClearTestPartResults(); + + // Clears the object. + void Clear(); + + // Protects mutable state of the property vector and of owned + // properties, whose values may be updated. + internal::Mutex test_properites_mutex_; + + // The vector of TestPartResults + std::vector test_part_results_; + // The vector of TestProperties + std::vector test_properties_; + // Running count of death tests. + int death_test_count_; + // The elapsed time, in milliseconds. + TimeInMillis elapsed_time_; + + // We disallow copying TestResult. + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult); +}; // class TestResult + +// A TestInfo object stores the following information about a test: +// +// Test case name +// Test name +// Whether the test should be run +// A function pointer that creates the test object when invoked +// Test result +// +// The constructor of TestInfo registers itself with the UnitTest +// singleton such that the RUN_ALL_TESTS() macro knows which tests to +// run. +class GTEST_API_ TestInfo { + public: + // Destructs a TestInfo object. This function is not virtual, so + // don't inherit from TestInfo. + ~TestInfo(); + + // Returns the test case name. + const char* test_case_name() const { return test_case_name_.c_str(); } + + // Returns the test name. + const char* name() const { return name_.c_str(); } + + // Returns the name of the parameter type, or NULL if this is not a typed + // or a type-parameterized test. + const char* type_param() const { + if (type_param_.get() != NULL) + return type_param_->c_str(); + return NULL; + } + + // Returns the text representation of the value parameter, or NULL if this + // is not a value-parameterized test. + const char* value_param() const { + if (value_param_.get() != NULL) + return value_param_->c_str(); + return NULL; + } + + // Returns the file name where this test is defined. + const char* file() const { return location_.file.c_str(); } + + // Returns the line where this test is defined. + int line() const { return location_.line; } + + // Returns true if this test should run, that is if the test is not + // disabled (or it is disabled but the also_run_disabled_tests flag has + // been specified) and its full name matches the user-specified filter. + // + // Google Test allows the user to filter the tests by their full names. + // The full name of a test Bar in test case Foo is defined as + // "Foo.Bar". Only the tests that match the filter will run. + // + // A filter is a colon-separated list of glob (not regex) patterns, + // optionally followed by a '-' and a colon-separated list of + // negative patterns (tests to exclude). A test is run if it + // matches one of the positive patterns and does not match any of + // the negative patterns. + // + // For example, *A*:Foo.* is a filter that matches any string that + // contains the character 'A' or starts with "Foo.". + bool should_run() const { return should_run_; } + + // Returns true iff this test will appear in the XML report. + bool is_reportable() const { + // For now, the XML report includes all tests matching the filter. + // In the future, we may trim tests that are excluded because of + // sharding. + return matches_filter_; + } + + // Returns the result of the test. + const TestResult* result() const { return &result_; } + + private: +#if GTEST_HAS_DEATH_TEST + friend class internal::DefaultDeathTestFactory; +#endif // GTEST_HAS_DEATH_TEST + friend class Test; + friend class TestCase; + friend class internal::UnitTestImpl; + friend class internal::StreamingListenerTest; + friend TestInfo* internal::MakeAndRegisterTestInfo( + const char* test_case_name, + const char* name, + const char* type_param, + const char* value_param, + internal::CodeLocation code_location, + internal::TypeId fixture_class_id, + Test::SetUpTestCaseFunc set_up_tc, + Test::TearDownTestCaseFunc tear_down_tc, + internal::TestFactoryBase* factory); + + // Constructs a TestInfo object. The newly constructed instance assumes + // ownership of the factory object. + TestInfo(const std::string& test_case_name, + const std::string& name, + const char* a_type_param, // NULL if not a type-parameterized test + const char* a_value_param, // NULL if not a value-parameterized test + internal::CodeLocation a_code_location, + internal::TypeId fixture_class_id, + internal::TestFactoryBase* factory); + + // Increments the number of death tests encountered in this test so + // far. + int increment_death_test_count() { + return result_.increment_death_test_count(); + } + + // Creates the test object, runs it, records its result, and then + // deletes it. + void Run(); + + static void ClearTestResult(TestInfo* test_info) { + test_info->result_.Clear(); + } + + // These fields are immutable properties of the test. + const std::string test_case_name_; // Test case name + const std::string name_; // Test name + // Name of the parameter type, or NULL if this is not a typed or a + // type-parameterized test. + const internal::scoped_ptr type_param_; + // Text representation of the value parameter, or NULL if this is not a + // value-parameterized test. + const internal::scoped_ptr value_param_; + internal::CodeLocation location_; + const internal::TypeId fixture_class_id_; // ID of the test fixture class + bool should_run_; // True iff this test should run + bool is_disabled_; // True iff this test is disabled + bool matches_filter_; // True if this test matches the + // user-specified filter. + internal::TestFactoryBase* const factory_; // The factory that creates + // the test object + + // This field is mutable and needs to be reset before running the + // test for the second time. + TestResult result_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); +}; + +// A test case, which consists of a vector of TestInfos. +// +// TestCase is not copyable. +class GTEST_API_ TestCase { + public: + // Creates a TestCase with the given name. + // + // TestCase does NOT have a default constructor. Always use this + // constructor to create a TestCase object. + // + // Arguments: + // + // name: name of the test case + // a_type_param: the name of the test's type parameter, or NULL if + // this is not a type-parameterized test. + // set_up_tc: pointer to the function that sets up the test case + // tear_down_tc: pointer to the function that tears down the test case + TestCase(const char* name, const char* a_type_param, + Test::SetUpTestCaseFunc set_up_tc, + Test::TearDownTestCaseFunc tear_down_tc); + + // Destructor of TestCase. + virtual ~TestCase(); + + // Gets the name of the TestCase. + const char* name() const { return name_.c_str(); } + + // Returns the name of the parameter type, or NULL if this is not a + // type-parameterized test case. + const char* type_param() const { + if (type_param_.get() != NULL) + return type_param_->c_str(); + return NULL; + } + + // Returns true if any test in this test case should run. + bool should_run() const { return should_run_; } + + // Gets the number of successful tests in this test case. + int successful_test_count() const; + + // Gets the number of failed tests in this test case. + int failed_test_count() const; + + // Gets the number of disabled tests that will be reported in the XML report. + int reportable_disabled_test_count() const; + + // Gets the number of disabled tests in this test case. + int disabled_test_count() const; + + // Gets the number of tests to be printed in the XML report. + int reportable_test_count() const; + + // Get the number of tests in this test case that should run. + int test_to_run_count() const; + + // Gets the number of all tests in this test case. + int total_test_count() const; + + // Returns true iff the test case passed. + bool Passed() const { return !Failed(); } + + // Returns true iff the test case failed. + bool Failed() const { return failed_test_count() > 0; } + + // Returns the elapsed time, in milliseconds. + TimeInMillis elapsed_time() const { return elapsed_time_; } + + // Returns the i-th test among all the tests. i can range from 0 to + // total_test_count() - 1. If i is not in that range, returns NULL. + const TestInfo* GetTestInfo(int i) const; + + // Returns the TestResult that holds test properties recorded during + // execution of SetUpTestCase and TearDownTestCase. + const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; } + + private: + friend class Test; + friend class internal::UnitTestImpl; + + // Gets the (mutable) vector of TestInfos in this TestCase. + std::vector& test_info_list() { return test_info_list_; } + + // Gets the (immutable) vector of TestInfos in this TestCase. + const std::vector& test_info_list() const { + return test_info_list_; + } + + // Returns the i-th test among all the tests. i can range from 0 to + // total_test_count() - 1. If i is not in that range, returns NULL. + TestInfo* GetMutableTestInfo(int i); + + // Sets the should_run member. + void set_should_run(bool should) { should_run_ = should; } + + // Adds a TestInfo to this test case. Will delete the TestInfo upon + // destruction of the TestCase object. + void AddTestInfo(TestInfo * test_info); + + // Clears the results of all tests in this test case. + void ClearResult(); + + // Clears the results of all tests in the given test case. + static void ClearTestCaseResult(TestCase* test_case) { + test_case->ClearResult(); + } + + // Runs every test in this TestCase. + void Run(); + + // Runs SetUpTestCase() for this TestCase. This wrapper is needed + // for catching exceptions thrown from SetUpTestCase(). + void RunSetUpTestCase() { (*set_up_tc_)(); } + + // Runs TearDownTestCase() for this TestCase. This wrapper is + // needed for catching exceptions thrown from TearDownTestCase(). + void RunTearDownTestCase() { (*tear_down_tc_)(); } + + // Returns true iff test passed. + static bool TestPassed(const TestInfo* test_info) { + return test_info->should_run() && test_info->result()->Passed(); + } + + // Returns true iff test failed. + static bool TestFailed(const TestInfo* test_info) { + return test_info->should_run() && test_info->result()->Failed(); + } + + // Returns true iff the test is disabled and will be reported in the XML + // report. + static bool TestReportableDisabled(const TestInfo* test_info) { + return test_info->is_reportable() && test_info->is_disabled_; + } + + // Returns true iff test is disabled. + static bool TestDisabled(const TestInfo* test_info) { + return test_info->is_disabled_; + } + + // Returns true iff this test will appear in the XML report. + static bool TestReportable(const TestInfo* test_info) { + return test_info->is_reportable(); + } + + // Returns true if the given test should run. + static bool ShouldRunTest(const TestInfo* test_info) { + return test_info->should_run(); + } + + // Shuffles the tests in this test case. + void ShuffleTests(internal::Random* random); + + // Restores the test order to before the first shuffle. + void UnshuffleTests(); + + // Name of the test case. + std::string name_; + // Name of the parameter type, or NULL if this is not a typed or a + // type-parameterized test. + const internal::scoped_ptr type_param_; + // The vector of TestInfos in their original order. It owns the + // elements in the vector. + std::vector test_info_list_; + // Provides a level of indirection for the test list to allow easy + // shuffling and restoring the test order. The i-th element in this + // vector is the index of the i-th test in the shuffled test list. + std::vector test_indices_; + // Pointer to the function that sets up the test case. + Test::SetUpTestCaseFunc set_up_tc_; + // Pointer to the function that tears down the test case. + Test::TearDownTestCaseFunc tear_down_tc_; + // True iff any test in this test case should run. + bool should_run_; + // Elapsed time, in milliseconds. + TimeInMillis elapsed_time_; + // Holds test properties recorded during execution of SetUpTestCase and + // TearDownTestCase. + TestResult ad_hoc_test_result_; + + // We disallow copying TestCases. + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase); +}; + +// An Environment object is capable of setting up and tearing down an +// environment. You should subclass this to define your own +// environment(s). +// +// An Environment object does the set-up and tear-down in virtual +// methods SetUp() and TearDown() instead of the constructor and the +// destructor, as: +// +// 1. You cannot safely throw from a destructor. This is a problem +// as in some cases Google Test is used where exceptions are enabled, and +// we may want to implement ASSERT_* using exceptions where they are +// available. +// 2. You cannot use ASSERT_* directly in a constructor or +// destructor. +class Environment { + public: + // The d'tor is virtual as we need to subclass Environment. + virtual ~Environment() {} + + // Override this to define how to set up the environment. + virtual void SetUp() {} + + // Override this to define how to tear down the environment. + virtual void TearDown() {} + private: + // If you see an error about overriding the following function or + // about it being private, you have mis-spelled SetUp() as Setup(). + struct Setup_should_be_spelled_SetUp {}; + virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; } +}; + +// The interface for tracing execution of tests. The methods are organized in +// the order the corresponding events are fired. +class TestEventListener { + public: + virtual ~TestEventListener() {} + + // Fired before any test activity starts. + virtual void OnTestProgramStart(const UnitTest& unit_test) = 0; + + // Fired before each iteration of tests starts. There may be more than + // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration + // index, starting from 0. + virtual void OnTestIterationStart(const UnitTest& unit_test, + int iteration) = 0; + + // Fired before environment set-up for each iteration of tests starts. + virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0; + + // Fired after environment set-up for each iteration of tests ends. + virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0; + + // Fired before the test case starts. + virtual void OnTestCaseStart(const TestCase& test_case) = 0; + + // Fired before the test starts. + virtual void OnTestStart(const TestInfo& test_info) = 0; + + // Fired after a failed assertion or a SUCCEED() invocation. + virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; + + // Fired after the test ends. + virtual void OnTestEnd(const TestInfo& test_info) = 0; + + // Fired after the test case ends. + virtual void OnTestCaseEnd(const TestCase& test_case) = 0; + + // Fired before environment tear-down for each iteration of tests starts. + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; + + // Fired after environment tear-down for each iteration of tests ends. + virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; + + // Fired after each iteration of tests finishes. + virtual void OnTestIterationEnd(const UnitTest& unit_test, + int iteration) = 0; + + // Fired after all test activities have ended. + virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; +}; + +// The convenience class for users who need to override just one or two +// methods and are not concerned that a possible change to a signature of +// the methods they override will not be caught during the build. For +// comments about each method please see the definition of TestEventListener +// above. +class EmptyTestEventListener : public TestEventListener { + public: + virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {} + virtual void OnTestIterationStart(const UnitTest& /*unit_test*/, + int /*iteration*/) {} + virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {} + virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {} + virtual void OnTestCaseStart(const TestCase& /*test_case*/) {} + virtual void OnTestStart(const TestInfo& /*test_info*/) {} + virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {} + virtual void OnTestEnd(const TestInfo& /*test_info*/) {} + virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} + virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {} + virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {} + virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/, + int /*iteration*/) {} + virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} +}; + +// TestEventListeners lets users add listeners to track events in Google Test. +class GTEST_API_ TestEventListeners { + public: + TestEventListeners(); + ~TestEventListeners(); + + // Appends an event listener to the end of the list. Google Test assumes + // the ownership of the listener (i.e. it will delete the listener when + // the test program finishes). + void Append(TestEventListener* listener); + + // Removes the given event listener from the list and returns it. It then + // becomes the caller's responsibility to delete the listener. Returns + // NULL if the listener is not found in the list. + TestEventListener* Release(TestEventListener* listener); + + // Returns the standard listener responsible for the default console + // output. Can be removed from the listeners list to shut down default + // console output. Note that removing this object from the listener list + // with Release transfers its ownership to the caller and makes this + // function return NULL the next time. + TestEventListener* default_result_printer() const { + return default_result_printer_; + } + + // Returns the standard listener responsible for the default XML output + // controlled by the --gtest_output=xml flag. Can be removed from the + // listeners list by users who want to shut down the default XML output + // controlled by this flag and substitute it with custom one. Note that + // removing this object from the listener list with Release transfers its + // ownership to the caller and makes this function return NULL the next + // time. + TestEventListener* default_xml_generator() const { + return default_xml_generator_; + } + + private: + friend class TestCase; + friend class TestInfo; + friend class internal::DefaultGlobalTestPartResultReporter; + friend class internal::NoExecDeathTest; + friend class internal::TestEventListenersAccessor; + friend class internal::UnitTestImpl; + + // Returns repeater that broadcasts the TestEventListener events to all + // subscribers. + TestEventListener* repeater(); + + // Sets the default_result_printer attribute to the provided listener. + // The listener is also added to the listener list and previous + // default_result_printer is removed from it and deleted. The listener can + // also be NULL in which case it will not be added to the list. Does + // nothing if the previous and the current listener objects are the same. + void SetDefaultResultPrinter(TestEventListener* listener); + + // Sets the default_xml_generator attribute to the provided listener. The + // listener is also added to the listener list and previous + // default_xml_generator is removed from it and deleted. The listener can + // also be NULL in which case it will not be added to the list. Does + // nothing if the previous and the current listener objects are the same. + void SetDefaultXmlGenerator(TestEventListener* listener); + + // Controls whether events will be forwarded by the repeater to the + // listeners in the list. + bool EventForwardingEnabled() const; + void SuppressEventForwarding(); + + // The actual list of listeners. + internal::TestEventRepeater* repeater_; + // Listener responsible for the standard result output. + TestEventListener* default_result_printer_; + // Listener responsible for the creation of the XML output file. + TestEventListener* default_xml_generator_; + + // We disallow copying TestEventListeners. + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners); +}; + +// A UnitTest consists of a vector of TestCases. +// +// This is a singleton class. The only instance of UnitTest is +// created when UnitTest::GetInstance() is first called. This +// instance is never deleted. +// +// UnitTest is not copyable. +// +// This class is thread-safe as long as the methods are called +// according to their specification. +class GTEST_API_ UnitTest { + public: + // Gets the singleton UnitTest object. The first time this method + // is called, a UnitTest object is constructed and returned. + // Consecutive calls will return the same object. + static UnitTest* GetInstance(); + + // Runs all tests in this UnitTest object and prints the result. + // Returns 0 if successful, or 1 otherwise. + // + // This method can only be called from the main thread. + // + // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + int Run() GTEST_MUST_USE_RESULT_; + + // Returns the working directory when the first TEST() or TEST_F() + // was executed. The UnitTest object owns the string. + const char* original_working_dir() const; + + // Returns the TestCase object for the test that's currently running, + // or NULL if no test is running. + const TestCase* current_test_case() const + GTEST_LOCK_EXCLUDED_(mutex_); + + // Returns the TestInfo object for the test that's currently running, + // or NULL if no test is running. + const TestInfo* current_test_info() const + GTEST_LOCK_EXCLUDED_(mutex_); + + // Returns the random seed used at the start of the current test run. + int random_seed() const; + +#if GTEST_HAS_PARAM_TEST + // Returns the ParameterizedTestCaseRegistry object used to keep track of + // value-parameterized tests and instantiate and register them. + // + // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + internal::ParameterizedTestCaseRegistry& parameterized_test_registry() + GTEST_LOCK_EXCLUDED_(mutex_); +#endif // GTEST_HAS_PARAM_TEST + + // Gets the number of successful test cases. + int successful_test_case_count() const; + + // Gets the number of failed test cases. + int failed_test_case_count() const; + + // Gets the number of all test cases. + int total_test_case_count() const; + + // Gets the number of all test cases that contain at least one test + // that should run. + int test_case_to_run_count() const; + + // Gets the number of successful tests. + int successful_test_count() const; + + // Gets the number of failed tests. + int failed_test_count() const; + + // Gets the number of disabled tests that will be reported in the XML report. + int reportable_disabled_test_count() const; + + // Gets the number of disabled tests. + int disabled_test_count() const; + + // Gets the number of tests to be printed in the XML report. + int reportable_test_count() const; + + // Gets the number of all tests. + int total_test_count() const; + + // Gets the number of tests that should run. + int test_to_run_count() const; + + // Gets the time of the test program start, in ms from the start of the + // UNIX epoch. + TimeInMillis start_timestamp() const; + + // Gets the elapsed time, in milliseconds. + TimeInMillis elapsed_time() const; + + // Returns true iff the unit test passed (i.e. all test cases passed). + bool Passed() const; + + // Returns true iff the unit test failed (i.e. some test case failed + // or something outside of all tests failed). + bool Failed() const; + + // Gets the i-th test case among all the test cases. i can range from 0 to + // total_test_case_count() - 1. If i is not in that range, returns NULL. + const TestCase* GetTestCase(int i) const; + + // Returns the TestResult containing information on test failures and + // properties logged outside of individual test cases. + const TestResult& ad_hoc_test_result() const; + + // Returns the list of event listeners that can be used to track events + // inside Google Test. + TestEventListeners& listeners(); + + private: + // Registers and returns a global test environment. When a test + // program is run, all global test environments will be set-up in + // the order they were registered. After all tests in the program + // have finished, all global test environments will be torn-down in + // the *reverse* order they were registered. + // + // The UnitTest object takes ownership of the given environment. + // + // This method can only be called from the main thread. + Environment* AddEnvironment(Environment* env); + + // Adds a TestPartResult to the current TestResult object. All + // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) + // eventually call this to report their results. The user code + // should use the assertion macros instead of calling this directly. + void AddTestPartResult(TestPartResult::Type result_type, + const char* file_name, + int line_number, + const std::string& message, + const std::string& os_stack_trace) + GTEST_LOCK_EXCLUDED_(mutex_); + + // Adds a TestProperty to the current TestResult object when invoked from + // inside a test, to current TestCase's ad_hoc_test_result_ when invoked + // from SetUpTestCase or TearDownTestCase, or to the global property set + // when invoked elsewhere. If the result already contains a property with + // the same key, the value will be updated. + void RecordProperty(const std::string& key, const std::string& value); + + // Gets the i-th test case among all the test cases. i can range from 0 to + // total_test_case_count() - 1. If i is not in that range, returns NULL. + TestCase* GetMutableTestCase(int i); + + // Accessors for the implementation object. + internal::UnitTestImpl* impl() { return impl_; } + const internal::UnitTestImpl* impl() const { return impl_; } + + // These classes and funcions are friends as they need to access private + // members of UnitTest. + friend class Test; + friend class internal::AssertHelper; + friend class internal::ScopedTrace; + friend class internal::StreamingListenerTest; + friend class internal::UnitTestRecordPropertyTestHelper; + friend Environment* AddGlobalTestEnvironment(Environment* env); + friend internal::UnitTestImpl* internal::GetUnitTestImpl(); + friend void internal::ReportFailureInUnknownLocation( + TestPartResult::Type result_type, + const std::string& message); + + // Creates an empty UnitTest. + UnitTest(); + + // D'tor + virtual ~UnitTest(); + + // Pushes a trace defined by SCOPED_TRACE() on to the per-thread + // Google Test trace stack. + void PushGTestTrace(const internal::TraceInfo& trace) + GTEST_LOCK_EXCLUDED_(mutex_); + + // Pops a trace from the per-thread Google Test trace stack. + void PopGTestTrace() + GTEST_LOCK_EXCLUDED_(mutex_); + + // Protects mutable state in *impl_. This is mutable as some const + // methods need to lock it too. + mutable internal::Mutex mutex_; + + // Opaque implementation object. This field is never changed once + // the object is constructed. We don't mark it as const here, as + // doing so will cause a warning in the constructor of UnitTest. + // Mutable state in *impl_ is protected by mutex_. + internal::UnitTestImpl* impl_; + + // We disallow copying UnitTest. + GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest); +}; + +// A convenient wrapper for adding an environment for the test +// program. +// +// You should call this before RUN_ALL_TESTS() is called, probably in +// main(). If you use gtest_main, you need to call this before main() +// starts for it to take effect. For example, you can define a global +// variable like this: +// +// testing::Environment* const foo_env = +// testing::AddGlobalTestEnvironment(new FooEnvironment); +// +// However, we strongly recommend you to write your own main() and +// call AddGlobalTestEnvironment() there, as relying on initialization +// of global variables makes the code harder to read and may cause +// problems when you register multiple environments from different +// translation units and the environments have dependencies among them +// (remember that the compiler doesn't guarantee the order in which +// global variables from different translation units are initialized). +inline Environment* AddGlobalTestEnvironment(Environment* env) { + return UnitTest::GetInstance()->AddEnvironment(env); +} + +// Initializes Google Test. This must be called before calling +// RUN_ALL_TESTS(). In particular, it parses a command line for the +// flags that Google Test recognizes. Whenever a Google Test flag is +// seen, it is removed from argv, and *argc is decremented. +// +// No value is returned. Instead, the Google Test flag variables are +// updated. +// +// Calling the function for the second time has no user-visible effect. +GTEST_API_ void InitGoogleTest(int* argc, char** argv); + +// This overloaded version can be used in Windows programs compiled in +// UNICODE mode. +GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv); + +namespace internal { + +// Separate the error generating code from the code path to reduce the stack +// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers +// when calling EXPECT_* in a tight loop. +template +AssertionResult CmpHelperEQFailure(const char* lhs_expression, + const char* rhs_expression, + const T1& lhs, const T2& rhs) { + return EqFailure(lhs_expression, + rhs_expression, + FormatForComparisonFailureMessage(lhs, rhs), + FormatForComparisonFailureMessage(rhs, lhs), + false); +} + +// The helper function for {ASSERT|EXPECT}_EQ. +template +AssertionResult CmpHelperEQ(const char* lhs_expression, + const char* rhs_expression, + const T1& lhs, + const T2& rhs) { +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4389 /* signed/unsigned mismatch */) + if (lhs == rhs) { + return AssertionSuccess(); + } +GTEST_DISABLE_MSC_WARNINGS_POP_() + + return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs); +} + +// With this overloaded version, we allow anonymous enums to be used +// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums +// can be implicitly cast to BiggestInt. +GTEST_API_ AssertionResult CmpHelperEQ(const char* lhs_expression, + const char* rhs_expression, + BiggestInt lhs, + BiggestInt rhs); + +// The helper class for {ASSERT|EXPECT}_EQ. The template argument +// lhs_is_null_literal is true iff the first argument to ASSERT_EQ() +// is a null pointer literal. The following default implementation is +// for lhs_is_null_literal being false. +template +class EqHelper { + public: + // This templatized version is for the general case. + template + static AssertionResult Compare(const char* lhs_expression, + const char* rhs_expression, + const T1& lhs, + const T2& rhs) { + return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); + } + + // With this overloaded version, we allow anonymous enums to be used + // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous + // enums can be implicitly cast to BiggestInt. + // + // Even though its body looks the same as the above version, we + // cannot merge the two, as it will make anonymous enums unhappy. + static AssertionResult Compare(const char* lhs_expression, + const char* rhs_expression, + BiggestInt lhs, + BiggestInt rhs) { + return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); + } +}; + +// This specialization is used when the first argument to ASSERT_EQ() +// is a null pointer literal, like NULL, false, or 0. +template <> +class EqHelper { + public: + // We define two overloaded versions of Compare(). The first + // version will be picked when the second argument to ASSERT_EQ() is + // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or + // EXPECT_EQ(false, a_bool). + template + static AssertionResult Compare( + const char* lhs_expression, + const char* rhs_expression, + const T1& lhs, + const T2& rhs, + // The following line prevents this overload from being considered if T2 + // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr) + // expands to Compare("", "", NULL, my_ptr), which requires a conversion + // to match the Secret* in the other overload, which would otherwise make + // this template match better. + typename EnableIf::value>::type* = 0) { + return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs); + } + + // This version will be picked when the second argument to ASSERT_EQ() is a + // pointer, e.g. ASSERT_EQ(NULL, a_pointer). + template + static AssertionResult Compare( + const char* lhs_expression, + const char* rhs_expression, + // We used to have a second template parameter instead of Secret*. That + // template parameter would deduce to 'long', making this a better match + // than the first overload even without the first overload's EnableIf. + // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to + // non-pointer argument" (even a deduced integral argument), so the old + // implementation caused warnings in user code. + Secret* /* lhs (NULL) */, + T* rhs) { + // We already know that 'lhs' is a null pointer. + return CmpHelperEQ(lhs_expression, rhs_expression, + static_cast(NULL), rhs); + } +}; + +// Separate the error generating code from the code path to reduce the stack +// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers +// when calling EXPECT_OP in a tight loop. +template +AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2, + const T1& val1, const T2& val2, + const char* op) { + return AssertionFailure() + << "Expected: (" << expr1 << ") " << op << " (" << expr2 + << "), actual: " << FormatForComparisonFailureMessage(val1, val2) + << " vs " << FormatForComparisonFailureMessage(val2, val1); +} + +// A macro for implementing the helper functions needed to implement +// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste +// of similar code. +// +// For each templatized helper function, we also define an overloaded +// version for BiggestInt in order to reduce code bloat and allow +// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled +// with gcc 4. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + +#define GTEST_IMPL_CMP_HELPER_(op_name, op)\ +template \ +AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ + const T1& val1, const T2& val2) {\ + if (val1 op val2) {\ + return AssertionSuccess();\ + } else {\ + return CmpHelperOpFailure(expr1, expr2, val1, val2, #op);\ + }\ +}\ +GTEST_API_ AssertionResult CmpHelper##op_name(\ + const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2) + +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. + +// Implements the helper function for {ASSERT|EXPECT}_NE +GTEST_IMPL_CMP_HELPER_(NE, !=); +// Implements the helper function for {ASSERT|EXPECT}_LE +GTEST_IMPL_CMP_HELPER_(LE, <=); +// Implements the helper function for {ASSERT|EXPECT}_LT +GTEST_IMPL_CMP_HELPER_(LT, <); +// Implements the helper function for {ASSERT|EXPECT}_GE +GTEST_IMPL_CMP_HELPER_(GE, >=); +// Implements the helper function for {ASSERT|EXPECT}_GT +GTEST_IMPL_CMP_HELPER_(GT, >); + +#undef GTEST_IMPL_CMP_HELPER_ + +// The helper function for {ASSERT|EXPECT}_STREQ. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2); + +// The helper function for {ASSERT|EXPECT}_STRCASEEQ. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2); + +// The helper function for {ASSERT|EXPECT}_STRNE. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2); + +// The helper function for {ASSERT|EXPECT}_STRCASENE. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression, + const char* s2_expression, + const char* s1, + const char* s2); + + +// Helper function for *_STREQ on wide strings. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTREQ(const char* s1_expression, + const char* s2_expression, + const wchar_t* s1, + const wchar_t* s2); + +// Helper function for *_STRNE on wide strings. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, + const char* s2_expression, + const wchar_t* s1, + const wchar_t* s2); + +} // namespace internal + +// IsSubstring() and IsNotSubstring() are intended to be used as the +// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by +// themselves. They check whether needle is a substring of haystack +// (NULL is considered a substring of itself only), and return an +// appropriate error message when they fail. +// +// The {needle,haystack}_expr arguments are the stringified +// expressions that generated the two real arguments. +GTEST_API_ AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const char* needle, const char* haystack); +GTEST_API_ AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const wchar_t* needle, const wchar_t* haystack); +GTEST_API_ AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const char* needle, const char* haystack); +GTEST_API_ AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const wchar_t* needle, const wchar_t* haystack); +GTEST_API_ AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::string& needle, const ::std::string& haystack); +GTEST_API_ AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::string& needle, const ::std::string& haystack); + +#if GTEST_HAS_STD_WSTRING +GTEST_API_ AssertionResult IsSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::wstring& needle, const ::std::wstring& haystack); +GTEST_API_ AssertionResult IsNotSubstring( + const char* needle_expr, const char* haystack_expr, + const ::std::wstring& needle, const ::std::wstring& haystack); +#endif // GTEST_HAS_STD_WSTRING + +namespace internal { + +// Helper template function for comparing floating-points. +// +// Template parameter: +// +// RawType: the raw floating-point type (either float or double) +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +template +AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression, + const char* rhs_expression, + RawType lhs_value, + RawType rhs_value) { + const FloatingPoint lhs(lhs_value), rhs(rhs_value); + + if (lhs.AlmostEquals(rhs)) { + return AssertionSuccess(); + } + + ::std::stringstream lhs_ss; + lhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) + << lhs_value; + + ::std::stringstream rhs_ss; + rhs_ss << std::setprecision(std::numeric_limits::digits10 + 2) + << rhs_value; + + return EqFailure(lhs_expression, + rhs_expression, + StringStreamToString(&lhs_ss), + StringStreamToString(&rhs_ss), + false); +} + +// Helper function for implementing ASSERT_NEAR. +// +// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. +GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1, + const char* expr2, + const char* abs_error_expr, + double val1, + double val2, + double abs_error); + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// A class that enables one to stream messages to assertion macros +class GTEST_API_ AssertHelper { + public: + // Constructor. + AssertHelper(TestPartResult::Type type, + const char* file, + int line, + const char* message); + ~AssertHelper(); + + // Message assignment is a semantic trick to enable assertion + // streaming; see the GTEST_MESSAGE_ macro below. + void operator=(const Message& message) const; + + private: + // We put our data in a struct so that the size of the AssertHelper class can + // be as small as possible. This is important because gcc is incapable of + // re-using stack space even for temporary variables, so every EXPECT_EQ + // reserves stack space for another AssertHelper. + struct AssertHelperData { + AssertHelperData(TestPartResult::Type t, + const char* srcfile, + int line_num, + const char* msg) + : type(t), file(srcfile), line(line_num), message(msg) { } + + TestPartResult::Type const type; + const char* const file; + int const line; + std::string const message; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData); + }; + + AssertHelperData* const data_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper); +}; + +} // namespace internal + +#if GTEST_HAS_PARAM_TEST +// The pure interface class that all value-parameterized tests inherit from. +// A value-parameterized class must inherit from both ::testing::Test and +// ::testing::WithParamInterface. In most cases that just means inheriting +// from ::testing::TestWithParam, but more complicated test hierarchies +// may need to inherit from Test and WithParamInterface at different levels. +// +// This interface has support for accessing the test parameter value via +// the GetParam() method. +// +// Use it with one of the parameter generator defining functions, like Range(), +// Values(), ValuesIn(), Bool(), and Combine(). +// +// class FooTest : public ::testing::TestWithParam { +// protected: +// FooTest() { +// // Can use GetParam() here. +// } +// virtual ~FooTest() { +// // Can use GetParam() here. +// } +// virtual void SetUp() { +// // Can use GetParam() here. +// } +// virtual void TearDown { +// // Can use GetParam() here. +// } +// }; +// TEST_P(FooTest, DoesBar) { +// // Can use GetParam() method here. +// Foo foo; +// ASSERT_TRUE(foo.DoesBar(GetParam())); +// } +// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10)); + +template +class WithParamInterface { + public: + typedef T ParamType; + virtual ~WithParamInterface() {} + + // The current parameter value. Is also available in the test fixture's + // constructor. This member function is non-static, even though it only + // references static data, to reduce the opportunity for incorrect uses + // like writing 'WithParamInterface::GetParam()' for a test that + // uses a fixture whose parameter type is int. + const ParamType& GetParam() const { + GTEST_CHECK_(parameter_ != NULL) + << "GetParam() can only be called inside a value-parameterized test " + << "-- did you intend to write TEST_P instead of TEST_F?"; + return *parameter_; + } + + private: + // Sets parameter value. The caller is responsible for making sure the value + // remains alive and unchanged throughout the current test. + static void SetParam(const ParamType* parameter) { + parameter_ = parameter; + } + + // Static value used for accessing parameter during a test lifetime. + static const ParamType* parameter_; + + // TestClass must be a subclass of WithParamInterface and Test. + template friend class internal::ParameterizedTestFactory; +}; + +template +const T* WithParamInterface::parameter_ = NULL; + +// Most value-parameterized classes can ignore the existence of +// WithParamInterface, and can just inherit from ::testing::TestWithParam. + +template +class TestWithParam : public Test, public WithParamInterface { +}; + +#endif // GTEST_HAS_PARAM_TEST + +// Macros for indicating success/failure in test code. + +// ADD_FAILURE unconditionally adds a failure to the current test. +// SUCCEED generates a success - it doesn't automatically make the +// current test successful, as a test is only successful when it has +// no failure. +// +// EXPECT_* verifies that a certain condition is satisfied. If not, +// it behaves like ADD_FAILURE. In particular: +// +// EXPECT_TRUE verifies that a Boolean condition is true. +// EXPECT_FALSE verifies that a Boolean condition is false. +// +// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except +// that they will also abort the current function on failure. People +// usually want the fail-fast behavior of FAIL and ASSERT_*, but those +// writing data-driven tests often find themselves using ADD_FAILURE +// and EXPECT_* more. + +// Generates a nonfatal failure with a generic message. +#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") + +// Generates a nonfatal failure at the given source file location with +// a generic message. +#define ADD_FAILURE_AT(file, line) \ + GTEST_MESSAGE_AT_(file, line, "Failed", \ + ::testing::TestPartResult::kNonFatalFailure) + +// Generates a fatal failure with a generic message. +#define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed") + +// Define this macro to 1 to omit the definition of FAIL(), which is a +// generic name and clashes with some other libraries. +#if !GTEST_DONT_DEFINE_FAIL +# define FAIL() GTEST_FAIL() +#endif + +// Generates a success with a generic message. +#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") + +// Define this macro to 1 to omit the definition of SUCCEED(), which +// is a generic name and clashes with some other libraries. +#if !GTEST_DONT_DEFINE_SUCCEED +# define SUCCEED() GTEST_SUCCEED() +#endif + +// Macros for testing exceptions. +// +// * {ASSERT|EXPECT}_THROW(statement, expected_exception): +// Tests that the statement throws the expected exception. +// * {ASSERT|EXPECT}_NO_THROW(statement): +// Tests that the statement doesn't throw any exception. +// * {ASSERT|EXPECT}_ANY_THROW(statement): +// Tests that the statement throws an exception. + +#define EXPECT_THROW(statement, expected_exception) \ + GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_) +#define EXPECT_NO_THROW(statement) \ + GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_) +#define EXPECT_ANY_THROW(statement) \ + GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_) +#define ASSERT_THROW(statement, expected_exception) \ + GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) +#define ASSERT_NO_THROW(statement) \ + GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) +#define ASSERT_ANY_THROW(statement) \ + GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) + +// Boolean assertions. Condition can be either a Boolean expression or an +// AssertionResult. For more information on how to use AssertionResult with +// these macros see comments on that class. +#define EXPECT_TRUE(condition) \ + GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \ + GTEST_NONFATAL_FAILURE_) +#define EXPECT_FALSE(condition) \ + GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ + GTEST_NONFATAL_FAILURE_) +#define ASSERT_TRUE(condition) \ + GTEST_TEST_BOOLEAN_((condition), #condition, false, true, \ + GTEST_FATAL_FAILURE_) +#define ASSERT_FALSE(condition) \ + GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ + GTEST_FATAL_FAILURE_) + +// Includes the auto-generated header that implements a family of +// generic predicate assertion macros. +#include "gtest_pred_impl.h" + +// Macros for testing equalities and inequalities. +// +// * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2 +// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2 +// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2 +// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2 +// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2 +// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2 +// +// When they are not, Google Test prints both the tested expressions and +// their actual values. The values must be compatible built-in types, +// or you will get a compiler error. By "compatible" we mean that the +// values can be compared by the respective operator. +// +// Note: +// +// 1. It is possible to make a user-defined type work with +// {ASSERT|EXPECT}_??(), but that requires overloading the +// comparison operators and is thus discouraged by the Google C++ +// Usage Guide. Therefore, you are advised to use the +// {ASSERT|EXPECT}_TRUE() macro to assert that two objects are +// equal. +// +// 2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on +// pointers (in particular, C strings). Therefore, if you use it +// with two C strings, you are testing how their locations in memory +// are related, not how their content is related. To compare two C +// strings by content, use {ASSERT|EXPECT}_STR*(). +// +// 3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to +// {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you +// what the actual value is when it fails, and similarly for the +// other comparisons. +// +// 4. Do not depend on the order in which {ASSERT|EXPECT}_??() +// evaluate their arguments, which is undefined. +// +// 5. These macros evaluate their arguments exactly once. +// +// Examples: +// +// EXPECT_NE(5, Foo()); +// EXPECT_EQ(NULL, a_pointer); +// ASSERT_LT(i, array_size); +// ASSERT_GT(records.size(), 0) << "There is no record left."; + +#define EXPECT_EQ(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal:: \ + EqHelper::Compare, \ + val1, val2) +#define EXPECT_NE(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) +#define EXPECT_LE(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) +#define EXPECT_LT(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) +#define EXPECT_GE(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) +#define EXPECT_GT(val1, val2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) + +#define GTEST_ASSERT_EQ(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal:: \ + EqHelper::Compare, \ + val1, val2) +#define GTEST_ASSERT_NE(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) +#define GTEST_ASSERT_LE(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) +#define GTEST_ASSERT_LT(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) +#define GTEST_ASSERT_GE(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) +#define GTEST_ASSERT_GT(val1, val2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) + +// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of +// ASSERT_XY(), which clashes with some users' own code. + +#if !GTEST_DONT_DEFINE_ASSERT_EQ +# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) +#endif + +#if !GTEST_DONT_DEFINE_ASSERT_NE +# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) +#endif + +#if !GTEST_DONT_DEFINE_ASSERT_LE +# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) +#endif + +#if !GTEST_DONT_DEFINE_ASSERT_LT +# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) +#endif + +#if !GTEST_DONT_DEFINE_ASSERT_GE +# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) +#endif + +#if !GTEST_DONT_DEFINE_ASSERT_GT +# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) +#endif + +// C-string Comparisons. All tests treat NULL and any non-NULL string +// as different. Two NULLs are equal. +// +// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 +// * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 +// * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case +// * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case +// +// For wide or narrow string objects, you can use the +// {ASSERT|EXPECT}_??() macros. +// +// Don't depend on the order in which the arguments are evaluated, +// which is undefined. +// +// These macros evaluate their arguments exactly once. + +#define EXPECT_STREQ(s1, s2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) +#define EXPECT_STRNE(s1, s2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) +#define EXPECT_STRCASEEQ(s1, s2) \ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) +#define EXPECT_STRCASENE(s1, s2)\ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) + +#define ASSERT_STREQ(s1, s2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2) +#define ASSERT_STRNE(s1, s2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2) +#define ASSERT_STRCASEEQ(s1, s2) \ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2) +#define ASSERT_STRCASENE(s1, s2)\ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2) + +// Macros for comparing floating-point numbers. +// +// * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2): +// Tests that two float values are almost equal. +// * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2): +// Tests that two double values are almost equal. +// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): +// Tests that v1 and v2 are within the given distance to each other. +// +// Google Test uses ULP-based comparison to automatically pick a default +// error bound that is appropriate for the operands. See the +// FloatingPoint template class in gtest-internal.h if you are +// interested in the implementation details. + +#define EXPECT_FLOAT_EQ(val1, val2)\ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ + val1, val2) + +#define EXPECT_DOUBLE_EQ(val1, val2)\ + EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ + val1, val2) + +#define ASSERT_FLOAT_EQ(val1, val2)\ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ + val1, val2) + +#define ASSERT_DOUBLE_EQ(val1, val2)\ + ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ, \ + val1, val2) + +#define EXPECT_NEAR(val1, val2, abs_error)\ + EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ + val1, val2, abs_error) + +#define ASSERT_NEAR(val1, val2, abs_error)\ + ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ + val1, val2, abs_error) + +// These predicate format functions work on floating-point values, and +// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. +// +// EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); + +// Asserts that val1 is less than, or almost equal to, val2. Fails +// otherwise. In particular, it fails if either val1 or val2 is NaN. +GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, + float val1, float val2); +GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, + double val1, double val2); + + +#if GTEST_OS_WINDOWS + +// Macros that test for HRESULT failure and success, these are only useful +// on Windows, and rely on Windows SDK macros and APIs to compile. +// +// * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) +// +// When expr unexpectedly fails or succeeds, Google Test prints the +// expected result and the actual result with both a human-readable +// string representation of the error, if available, as well as the +// hex result code. +# define EXPECT_HRESULT_SUCCEEDED(expr) \ + EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) + +# define ASSERT_HRESULT_SUCCEEDED(expr) \ + ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) + +# define EXPECT_HRESULT_FAILED(expr) \ + EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) + +# define ASSERT_HRESULT_FAILED(expr) \ + ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) + +#endif // GTEST_OS_WINDOWS + +// Macros that execute statement and check that it doesn't generate new fatal +// failures in the current thread. +// +// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); +// +// Examples: +// +// EXPECT_NO_FATAL_FAILURE(Process()); +// ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed"; +// +#define ASSERT_NO_FATAL_FAILURE(statement) \ + GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_) +#define EXPECT_NO_FATAL_FAILURE(statement) \ + GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_) + +// Causes a trace (including the source file path, the current line +// number, and the given message) to be included in every test failure +// message generated by code in the current scope. The effect is +// undone when the control leaves the current scope. +// +// The message argument can be anything streamable to std::ostream. +// +// In the implementation, we include the current line number as part +// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s +// to appear in the same block - as long as they are on different +// lines. +#define SCOPED_TRACE(message) \ + ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\ + __FILE__, __LINE__, ::testing::Message() << (message)) + +// Compile-time assertion for type equality. +// StaticAssertTypeEq() compiles iff type1 and type2 are +// the same type. The value it returns is not interesting. +// +// Instead of making StaticAssertTypeEq a class template, we make it a +// function template that invokes a helper class template. This +// prevents a user from misusing StaticAssertTypeEq by +// defining objects of that type. +// +// CAVEAT: +// +// When used inside a method of a class template, +// StaticAssertTypeEq() is effective ONLY IF the method is +// instantiated. For example, given: +// +// template class Foo { +// public: +// void Bar() { testing::StaticAssertTypeEq(); } +// }; +// +// the code: +// +// void Test1() { Foo foo; } +// +// will NOT generate a compiler error, as Foo::Bar() is never +// actually instantiated. Instead, you need: +// +// void Test2() { Foo foo; foo.Bar(); } +// +// to cause a compiler error. +template +bool StaticAssertTypeEq() { + (void)internal::StaticAssertTypeEqHelper(); + return true; +} + +// Defines a test. +// +// The first parameter is the name of the test case, and the second +// parameter is the name of the test within the test case. +// +// The convention is to end the test case name with "Test". For +// example, a test case for the Foo class can be named FooTest. +// +// Test code should appear between braces after an invocation of +// this macro. Example: +// +// TEST(FooTest, InitializesCorrectly) { +// Foo foo; +// EXPECT_TRUE(foo.StatusIsOK()); +// } + +// Note that we call GetTestTypeId() instead of GetTypeId< +// ::testing::Test>() here to get the type ID of testing::Test. This +// is to work around a suspected linker bug when using Google Test as +// a framework on Mac OS X. The bug causes GetTypeId< +// ::testing::Test>() to return different values depending on whether +// the call is from the Google Test framework itself or from user test +// code. GetTestTypeId() is guaranteed to always return the same +// value, as it always calls GetTypeId<>() from the Google Test +// framework. +#define GTEST_TEST(test_case_name, test_name)\ + GTEST_TEST_(test_case_name, test_name, \ + ::testing::Test, ::testing::internal::GetTestTypeId()) + +// Define this macro to 1 to omit the definition of TEST(), which +// is a generic name and clashes with some other libraries. +#if !GTEST_DONT_DEFINE_TEST +# define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name) +#endif + +// Defines a test that uses a test fixture. +// +// The first parameter is the name of the test fixture class, which +// also doubles as the test case name. The second parameter is the +// name of the test within the test case. +// +// A test fixture class must be declared earlier. The user should put +// his test code between braces after using this macro. Example: +// +// class FooTest : public testing::Test { +// protected: +// virtual void SetUp() { b_.AddElement(3); } +// +// Foo a_; +// Foo b_; +// }; +// +// TEST_F(FooTest, InitializesCorrectly) { +// EXPECT_TRUE(a_.StatusIsOK()); +// } +// +// TEST_F(FooTest, ReturnsElementCountCorrectly) { +// EXPECT_EQ(0, a_.size()); +// EXPECT_EQ(1, b_.size()); +// } + +#define TEST_F(test_fixture, test_name)\ + GTEST_TEST_(test_fixture, test_name, test_fixture, \ + ::testing::internal::GetTypeId()) + +} // namespace testing + +// Use this function in main() to run all tests. It returns 0 if all +// tests are successful, or 1 otherwise. +// +// RUN_ALL_TESTS() should be invoked after the command line has been +// parsed by InitGoogleTest(). +// +// This function was formerly a macro; thus, it is in the global +// namespace and has an all-caps name. +int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_; + +inline int RUN_ALL_TESTS() { + return ::testing::UnitTest::GetInstance()->Run(); +} + +#endif // GTEST_INCLUDE_GTEST_GTEST_H_ diff --git a/TestMothur/gtest_main.cc b/TestMothur/gtest_main.cc new file mode 100755 index 00000000..45666882 --- /dev/null +++ b/TestMothur/gtest_main.cc @@ -0,0 +1,38 @@ +// Copyright 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include "gtest.h" + +GTEST_API_ int main(int argc, char **argv) { + printf("Running main() from gtest_main.cc\n"); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/TestMothur/gtest_pred_impl.h b/TestMothur/gtest_pred_impl.h new file mode 100755 index 00000000..30ae712f --- /dev/null +++ b/TestMothur/gtest_pred_impl.h @@ -0,0 +1,358 @@ +// Copyright 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// This file is AUTOMATICALLY GENERATED on 10/31/2011 by command +// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND! +// +// Implements a family of generic predicate assertion macros. + +#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ +#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ + +// Makes sure this header is not included before gtest.h. +#ifndef GTEST_INCLUDE_GTEST_GTEST_H_ +# error Do not include gtest_pred_impl.h directly. Include gtest.h instead. +#endif // GTEST_INCLUDE_GTEST_GTEST_H_ + +// This header implements a family of generic predicate assertion +// macros: +// +// ASSERT_PRED_FORMAT1(pred_format, v1) +// ASSERT_PRED_FORMAT2(pred_format, v1, v2) +// ... +// +// where pred_format is a function or functor that takes n (in the +// case of ASSERT_PRED_FORMATn) values and their source expression +// text, and returns a testing::AssertionResult. See the definition +// of ASSERT_EQ in gtest.h for an example. +// +// If you don't care about formatting, you can use the more +// restrictive version: +// +// ASSERT_PRED1(pred, v1) +// ASSERT_PRED2(pred, v1, v2) +// ... +// +// where pred is an n-ary function or functor that returns bool, +// and the values v1, v2, ..., must support the << operator for +// streaming to std::ostream. +// +// We also define the EXPECT_* variations. +// +// For now we only support predicates whose arity is at most 5. +// Please email googletestframework@googlegroups.com if you need +// support for higher arities. + +// GTEST_ASSERT_ is the basic statement to which all of the assertions +// in this file reduce. Don't use this in your code. + +#define GTEST_ASSERT_(expression, on_failure) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (const ::testing::AssertionResult gtest_ar = (expression)) \ + ; \ + else \ + on_failure(gtest_ar.failure_message()) + + +// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use +// this in your code. +template +AssertionResult AssertPred1Helper(const char* pred_text, + const char* e1, + Pred pred, + const T1& v1) { + if (pred(v1)) return AssertionSuccess(); + + return AssertionFailure() << pred_text << "(" + << e1 << ") evaluates to false, where" + << "\n" << e1 << " evaluates to " << v1; +} + +// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1. +// Don't use this in your code. +#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ + GTEST_ASSERT_(pred_format(#v1, v1), \ + on_failure) + +// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use +// this in your code. +#define GTEST_PRED1_(pred, v1, on_failure)\ + GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \ + #v1, \ + pred, \ + v1), on_failure) + +// Unary predicate assertion macros. +#define EXPECT_PRED_FORMAT1(pred_format, v1) \ + GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED1(pred, v1) \ + GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_) +#define ASSERT_PRED_FORMAT1(pred_format, v1) \ + GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_) +#define ASSERT_PRED1(pred, v1) \ + GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_) + + + +// Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use +// this in your code. +template +AssertionResult AssertPred2Helper(const char* pred_text, + const char* e1, + const char* e2, + Pred pred, + const T1& v1, + const T2& v2) { + if (pred(v1, v2)) return AssertionSuccess(); + + return AssertionFailure() << pred_text << "(" + << e1 << ", " + << e2 << ") evaluates to false, where" + << "\n" << e1 << " evaluates to " << v1 + << "\n" << e2 << " evaluates to " << v2; +} + +// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. +// Don't use this in your code. +#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ + GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \ + on_failure) + +// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use +// this in your code. +#define GTEST_PRED2_(pred, v1, v2, on_failure)\ + GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \ + #v1, \ + #v2, \ + pred, \ + v1, \ + v2), on_failure) + +// Binary predicate assertion macros. +#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ + GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED2(pred, v1, v2) \ + GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_) +#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ + GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_) +#define ASSERT_PRED2(pred, v1, v2) \ + GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_) + + + +// Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use +// this in your code. +template +AssertionResult AssertPred3Helper(const char* pred_text, + const char* e1, + const char* e2, + const char* e3, + Pred pred, + const T1& v1, + const T2& v2, + const T3& v3) { + if (pred(v1, v2, v3)) return AssertionSuccess(); + + return AssertionFailure() << pred_text << "(" + << e1 << ", " + << e2 << ", " + << e3 << ") evaluates to false, where" + << "\n" << e1 << " evaluates to " << v1 + << "\n" << e2 << " evaluates to " << v2 + << "\n" << e3 << " evaluates to " << v3; +} + +// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3. +// Don't use this in your code. +#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \ + on_failure) + +// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use +// this in your code. +#define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\ + GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \ + #v1, \ + #v2, \ + #v3, \ + pred, \ + v1, \ + v2, \ + v3), on_failure) + +// Ternary predicate assertion macros. +#define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \ + GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED3(pred, v1, v2, v3) \ + GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_) +#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \ + GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_) +#define ASSERT_PRED3(pred, v1, v2, v3) \ + GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_) + + + +// Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use +// this in your code. +template +AssertionResult AssertPred4Helper(const char* pred_text, + const char* e1, + const char* e2, + const char* e3, + const char* e4, + Pred pred, + const T1& v1, + const T2& v2, + const T3& v3, + const T4& v4) { + if (pred(v1, v2, v3, v4)) return AssertionSuccess(); + + return AssertionFailure() << pred_text << "(" + << e1 << ", " + << e2 << ", " + << e3 << ", " + << e4 << ") evaluates to false, where" + << "\n" << e1 << " evaluates to " << v1 + << "\n" << e2 << " evaluates to " << v2 + << "\n" << e3 << " evaluates to " << v3 + << "\n" << e4 << " evaluates to " << v4; +} + +// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4. +// Don't use this in your code. +#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \ + on_failure) + +// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use +// this in your code. +#define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\ + GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \ + #v1, \ + #v2, \ + #v3, \ + #v4, \ + pred, \ + v1, \ + v2, \ + v3, \ + v4), on_failure) + +// 4-ary predicate assertion macros. +#define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ + GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED4(pred, v1, v2, v3, v4) \ + GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_) +#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \ + GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_) +#define ASSERT_PRED4(pred, v1, v2, v3, v4) \ + GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_) + + + +// Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use +// this in your code. +template +AssertionResult AssertPred5Helper(const char* pred_text, + const char* e1, + const char* e2, + const char* e3, + const char* e4, + const char* e5, + Pred pred, + const T1& v1, + const T2& v2, + const T3& v3, + const T4& v4, + const T5& v5) { + if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess(); + + return AssertionFailure() << pred_text << "(" + << e1 << ", " + << e2 << ", " + << e3 << ", " + << e4 << ", " + << e5 << ") evaluates to false, where" + << "\n" << e1 << " evaluates to " << v1 + << "\n" << e2 << " evaluates to " << v2 + << "\n" << e3 << " evaluates to " << v3 + << "\n" << e4 << " evaluates to " << v4 + << "\n" << e5 << " evaluates to " << v5; +} + +// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5. +// Don't use this in your code. +#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ + GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \ + on_failure) + +// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use +// this in your code. +#define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\ + GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \ + #v1, \ + #v2, \ + #v3, \ + #v4, \ + #v5, \ + pred, \ + v1, \ + v2, \ + v3, \ + v4, \ + v5), on_failure) + +// 5-ary predicate assertion macros. +#define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ + GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_) +#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \ + GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_) +#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \ + GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_) +#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \ + GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_) + + + +#endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ diff --git a/TestMothur/gtest_prod.h b/TestMothur/gtest_prod.h new file mode 100755 index 00000000..da80ddc6 --- /dev/null +++ b/TestMothur/gtest_prod.h @@ -0,0 +1,58 @@ +// Copyright 2006, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Author: wan@google.com (Zhanyong Wan) +// +// Google C++ Testing Framework definitions useful in production code. + +#ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_ +#define GTEST_INCLUDE_GTEST_GTEST_PROD_H_ + +// When you need to test the private or protected members of a class, +// use the FRIEND_TEST macro to declare your tests as friends of the +// class. For example: +// +// class MyClass { +// private: +// void MyMethod(); +// FRIEND_TEST(MyClassTest, MyMethod); +// }; +// +// class MyClassTest : public testing::Test { +// // ... +// }; +// +// TEST_F(MyClassTest, MyMethod) { +// // Can call MyClass::MyMethod() here. +// } + +#define FRIEND_TEST(test_case_name, test_name)\ +friend class test_case_name##_##test_name##_Test + +#endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_ diff --git a/TestMothur/main.cpp b/TestMothur/main.cpp index bf59c54f..a0548e09 100644 --- a/TestMothur/main.cpp +++ b/TestMothur/main.cpp @@ -1,3 +1,6 @@ +#ifndef MAIN_TEST +#define MAIN_TEST + // // main.cpp // TestMothur @@ -8,12 +11,13 @@ #include "mothurout.h" -#include "gtest/gtest.h" +#include "gtest.h" #define UNIT_TEST int main(int argc, char **argv) { MothurOut* m; m = MothurOut::getInstance(); + m->setTestFilePath("/Users/sarahwestcott/Desktop/mothur/TestMothur/TestFiles/"); string pathname = m->mothurProgramPath; if (pathname != "") { //add / to name if needed @@ -30,3 +34,5 @@ int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } + +#endif diff --git a/TestMothur/testclassifier/testphylotree.cpp b/TestMothur/testclassifier/testphylotree.cpp index f39c3138..085a8352 100644 --- a/TestMothur/testclassifier/testphylotree.cpp +++ b/TestMothur/testclassifier/testphylotree.cpp @@ -6,7 +6,7 @@ // Copyright © 2016 Schloss Lab. All rights reserved. // -#include "catch.hpp" + #include "testphylotree.hpp" /**************************************************************************************************/ @@ -38,7 +38,7 @@ TestPhyloTree::TestPhyloTree() { //setup } /**************************************************************************************************/ TestPhyloTree::~TestPhyloTree() {} -/**************************************************************************************************/ +/************************************************************************************************** TEST_CASE("Testing PhyloTree Class") { TestPhyloTree testPTree; @@ -126,4 +126,6 @@ TEST_CASE("Testing PhyloTree Class") { } } -/**************************************************************************************************/ +**************************************************************************************************/ + + diff --git a/TestMothur/testclustercalcs.cpp b/TestMothur/testclustercalcs.cpp new file mode 100644 index 00000000..d9f6ca0e --- /dev/null +++ b/TestMothur/testclustercalcs.cpp @@ -0,0 +1,120 @@ +// +// testclustercalcs.cpp +// Mothur +// +// Created by Sarah Westcott on 4/18/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "testclustercalcs.hpp" +#include "mcc.hpp" + +/**************************************************************************************************/ +TestClusterCalcs::TestClusterCalcs(string metricName) { //setup + m = MothurOut::getInstance(); + + if (metricName == "mcc") { metric = new MCC(); } + else if (metricName == "sens") { metric = new Sensitivity(); } + else if (metricName == "spec") { metric = new Specificity(); } + else if (metricName == "tptn") { metric = new TPTN(); } + else if (metricName == "tp") { metric = new TP(); } + else if (metricName == "tn") { metric = new TN(); } + else if (metricName == "fp") { metric = new FP(); } + else if (metricName == "fn") { metric = new FN(); } + else if (metricName == "f1score") { metric = new F1Score(); } + else if (metricName == "accuracy") { metric = new Accuracy(); } + else if (metricName == "ppv") { metric = new PPV(); } + else if (metricName == "npv") { metric = new NPV(); } + else if (metricName == "fdr") { metric = new FDR(); } + else if (metricName == "fpfn") { metric = new FPFN(); } + +} +/**************************************************************************************************/ +TestClusterCalcs::~TestClusterCalcs() { delete metric; } +/**************************************************************************************************/ + +TEST(TestClusterCalcs, mcc) { + TestClusterCalcs test("mcc"); + double result = test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn); + ASSERT_NEAR(0.791646, result, 0.0001); //metric value +} + +TEST(TestClusterCalcs, sens) { + TestClusterCalcs test("sens"); + ASSERT_NEAR(0.699235, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, spec) { + TestClusterCalcs test("spec"); + ASSERT_NEAR(0.999951, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, tptn) { + TestClusterCalcs test("tptn"); + ASSERT_NEAR(0.9997691, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, tp) { + TestClusterCalcs test("tp"); + ASSERT_NEAR(0.000423, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, tn) { + TestClusterCalcs test("tn"); + ASSERT_NEAR(0.9993461, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, fp) { + TestClusterCalcs test("fp"); + ASSERT_NEAR(0.999951, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, fn) { + TestClusterCalcs test("fn"); + ASSERT_NEAR(0.999818, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, f1score) { + TestClusterCalcs test("f1score"); + ASSERT_NEAR(0.7856801, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, accuracy) { + TestClusterCalcs test("accuracy"); + ASSERT_NEAR(0.999769, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, ppv) { + TestClusterCalcs test("ppv"); + ASSERT_NEAR(0.896514, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, npv) { + TestClusterCalcs test("npv"); + ASSERT_NEAR(0.9998179, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, fdr) { + TestClusterCalcs test("fdr"); + ASSERT_NEAR(0.896514, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +TEST(TestClusterCalcs, fpfn) { + TestClusterCalcs test("fpfn"); + ASSERT_NEAR(0.999769, test.metric->getValue(test.fake.tp,test.fake.tn,test.fake.fp,test.fake.fn), 0.0001); //metric value + +} + +/**************************************************************************************************/ diff --git a/TestMothur/testclustercalcs.hpp b/TestMothur/testclustercalcs.hpp new file mode 100644 index 00000000..d420315d --- /dev/null +++ b/TestMothur/testclustercalcs.hpp @@ -0,0 +1,47 @@ +// +// testclustercalcs.hpp +// Mothur +// +// Created by Sarah Westcott on 4/18/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef testclustercalcs_hpp +#define testclustercalcs_hpp + +#include "gtest.h" +#include "mcc.hpp" +#include "sensitivity.hpp" +#include "specificity.hpp" +#include "fdr.hpp" +#include "npv.hpp" +#include "ppv.hpp" +#include "f1score.hpp" +#include "tp.hpp" +#include "fp.hpp" +#include "fpfn.hpp" +#include "tptn.hpp" +#include "tn.hpp" +#include "fn.hpp" +#include "accuracy.hpp" +#include "fakemcc.hpp" + + +class TestClusterCalcs { + +public: + + TestClusterCalcs(string); + ~TestClusterCalcs(); + + FakeClusterCalcValues fake; + ClusterMetric* metric; + +private: + MothurOut* m; + + +}; + + +#endif /* testclustercalcs_hpp */ diff --git a/TestMothur/testcommands/testrenamefilecommand.cpp b/TestMothur/testcommands/testrenamefilecommand.cpp index 9349d81e..d28560de 100644 --- a/TestMothur/testcommands/testrenamefilecommand.cpp +++ b/TestMothur/testcommands/testrenamefilecommand.cpp @@ -14,12 +14,10 @@ TestRenameFileCommand::TestRenameFileCommand() { //setup m = MothurOut::getInstance(); TestDataSet data; - filenames = data.getSubsetFNGFiles(100); + filenames = data.getSubsetFNGFiles(); } /**************************************************************************************************/ -TestRenameFileCommand::~TestRenameFileCommand() { - for (int i = 0; i < filenames.size(); i++) { m->mothurRemove(filenames[i]); } //teardown -} +TestRenameFileCommand::~TestRenameFileCommand() {} /************************************************************************************************** TEST_CASE("Testing RenameFileCommand Class") { TestRenameFileCommand testRename; diff --git a/TestMothur/testcontainers/testoptimatrix.cpp b/TestMothur/testcontainers/testoptimatrix.cpp index 404f7d8d..d73d096a 100644 --- a/TestMothur/testcontainers/testoptimatrix.cpp +++ b/TestMothur/testcontainers/testoptimatrix.cpp @@ -14,25 +14,11 @@ TestOptiMatrix::TestOptiMatrix() { //setup m = MothurOut::getInstance(); TestDataSet data; - filenames = data.getSubsetFNGFiles(100); //Fasta, name, group returned + filenames = data.getSubsetFNGFiles(); //Fasta, name, group returned - string inputString = "fasta=" + filenames[0]; - m->mothurOut("/******************************************/"); m->mothurOutEndLine(); - m->mothurOut("Running command: dist.seqs(" + inputString + ")"); m->mothurOutEndLine(); - m->mothurCalling = true; - - Command* distCommand = new DistanceCommand(inputString); - distCommand->execute(); - - map > outputFilenames = distCommand->getOutputFiles(); - - delete distCommand; - m->mothurCalling = false; - - columnFile = outputFilenames["column"][0]; - m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + columnFile = data.getSubsetFNGDistFile(); - inputString = "fasta=" + filenames[0] + ", output=lt"; + string inputString = "fasta=" + filenames[0] + ", output=lt"; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); m->mothurOut("Running command: dist.seqs(" + inputString + ")"); m->mothurOutEndLine(); m->mothurCalling = true; @@ -40,18 +26,18 @@ TestOptiMatrix::TestOptiMatrix() { //setup Command* dist2Command = new DistanceCommand(inputString); dist2Command->execute(); - outputFilenames = dist2Command->getOutputFiles(); + map > outputFilenames = dist2Command->getOutputFiles(); delete dist2Command; m->mothurCalling = false; phylipFile = outputFilenames["phylip"][0]; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + + blastFile = m->getTestFilePath() + "bap.100.blast"; } /**************************************************************************************************/ TestOptiMatrix::~TestOptiMatrix() { - for (int i = 0; i < filenames.size(); i++) { m->mothurRemove(filenames[i]); } //teardown - m->mothurRemove(columnFile); m->mothurRemove(phylipFile); } /************************************************************************************************** @@ -98,3 +84,24 @@ TEST_CASE("Testing OptiMatrix Class") { } }*/ /**************************************************************************************************/ +TEST_F(TestOptiMatrix, readColumn) { + TestOptiMatrix testOMatrix; + OptiMatrix matrix(testOMatrix.columnFile, testOMatrix.filenames[1], "name", 0.03, false); + + EXPECT_EQ(112,(matrix.print(cout))); +} + +TEST_F(TestOptiMatrix, readPhylip) { + TestOptiMatrix testOMatrix; + OptiMatrix pmatrix(testOMatrix.phylipFile, "", "", 0.03, false); + + EXPECT_EQ(112,(pmatrix.print(cout))); +} + +TEST_F(TestOptiMatrix, readBlast) { + TestOptiMatrix testOMatrix; + OptiMatrix bmatrix(testOMatrix.blastFile, "", "", 0.03, false); + + EXPECT_EQ(46032,(bmatrix.print(cout))); +} +/**************************************************************************************************/ diff --git a/TestMothur/testcontainers/testoptimatrix.h b/TestMothur/testcontainers/testoptimatrix.h index ba7b637d..2da5bcfb 100644 --- a/TestMothur/testcontainers/testoptimatrix.h +++ b/TestMothur/testcontainers/testoptimatrix.h @@ -10,6 +10,7 @@ #define __Mothur__testoptimatrix__ #include "optimatrix.h" +#include "../../googletest/include/gtest/gtest.h" class TestOptiMatrix : public OptiMatrix { @@ -19,11 +20,12 @@ class TestOptiMatrix : public OptiMatrix { ~TestOptiMatrix(); using OptiMatrix::getCloseSeqs; - using OptiMatrix::findDistFormat; + using OptiMatrix::readBlast; + using OptiMatrix::readBlastNames; using OptiMatrix::readPhylip; using OptiMatrix::readColumn; - string columnFile, phylipFile; + string columnFile, phylipFile, blastFile; vector filenames; }; diff --git a/TestMothur/testopticluster.cpp b/TestMothur/testopticluster.cpp index cd4a533f..8332495d 100644 --- a/TestMothur/testopticluster.cpp +++ b/TestMothur/testopticluster.cpp @@ -7,91 +7,49 @@ // #include "testopticluster.h" -#include "optimatrix.h" #include "distancecommand.h" #include "dataset.h" /**************************************************************************************************/ -TestOptiCluster::TestOptiCluster() { //setup +TestOptiCluster::TestOptiCluster() { //setup m = MothurOut::getInstance(); - TestDataSet data; - filenames = data.getSubsetFNGFiles(100); //Fasta, name, group returned - - string inputString = "fasta=" + filenames[0]; - m->mothurOut("/******************************************/"); m->mothurOutEndLine(); - m->mothurOut("Running command: dist.seqs(" + inputString + ")"); m->mothurOutEndLine(); - m->mothurCalling = true; - - Command* distCommand = new DistanceCommand(inputString); - distCommand->execute(); - - map > outputFilenames = distCommand->getOutputFiles(); - - delete distCommand; - m->mothurCalling = false; - - columnFile = outputFilenames["column"][0]; - - matrix = new OptiMatrix(columnFile, filenames[1], "name", "column", 0.03, false); - - setVariables(matrix, "mcc"); + metric = new MCC(); + setVariables(&testMatrix, metric); } /**************************************************************************************************/ -TestOptiCluster::~TestOptiCluster() { - for (int i = 0; i < filenames.size(); i++) { m->mothurRemove(filenames[i]); } //teardown - m->mothurRemove(columnFile); - delete matrix; -} +TestOptiCluster::~TestOptiCluster() { delete metric; } /**************************************************************************************************/ -TEST_F(TestOptiCluster, myInitialize) { +TEST(TestOptiCluster, myInitialize) { + TestOptiCluster test; double initialMetricValue; - EXPECT_EQ(0,(initialize(initialMetricValue, true, "singleton"))); -} - -TEST_F(TestOptiCluster, calcMCC) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; - - ASSERT_DOUBLE_EQ(0.9694, calcMCC(tp,tn,fp,fn)); //metric value + EXPECT_EQ(0,(test.initialize(initialMetricValue, true, "singleton"))); } -TEST_F(TestOptiCluster, calcSens) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; +TEST(TestOptiCluster, myUpdate) { + TestOptiCluster test; + double initialMetricValue; + test.initialize(initialMetricValue, false, "singleton"); //no randomization + test.update(initialMetricValue); - ASSERT_DOUBLE_EQ(0.9615, calcSens(tp,tn,fp,fn)); //metric value -} - -TEST_F(TestOptiCluster, calcSpec) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; + //first round + ASSERT_NEAR(1, initialMetricValue, 0.00001); //metric value - ASSERT_DOUBLE_EQ(0.9990, calcSpec(tp,tn,fp,fn)); //metric value -} - -TEST_F(TestOptiCluster, calcTPTN) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; + test.update(initialMetricValue); - ASSERT_DOUBLE_EQ(0.9861, calcTPTN(tp,tn,fp,fn)); //metric value + //first round + ASSERT_NEAR(1, initialMetricValue, 0.00001); //metric value } -TEST_F(TestOptiCluster, calcFPFN) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; - - ASSERT_DOUBLE_EQ(0.9861, calcFPFN(tp,tn,fp,fn)); //metric value -} - -TEST_F(TestOptiCluster, moveAdjustTFValues) { - long long tp,tn,fp,fn; tp=5000; tn=10000; fp=10; fn=200; +TEST(TestOptiCluster, getCloseFarCounts) { + TestOptiCluster test; double initialMetricValue; - initialize(initialMetricValue, false, "singleton"); //no randomization + test.initialize(initialMetricValue, false, "singleton"); //no randomization + test.update(initialMetricValue); - ASSERT_DOUBLE_EQ(0.9700, moveAdjustTFValues(0, 10, 1, tp,tn,fp,fn)); //metric value -} - -TEST_F(TestOptiCluster, update) { - double initialMetricValue; - initialize(initialMetricValue, false, "singleton"); //no randomization - update(initialMetricValue); + vector results = test.getCloseFarCounts(0, 31); - ASSERT_DOUBLE_EQ(0.7853, initialMetricValue); //metric value + ASSERT_EQ(results[0], 0); //number of close sequences in bin 31 to seq 0 + ASSERT_EQ(results[1], 10); //number of far sequences in bin 31 to seq 0 } /**************************************************************************************************/ diff --git a/TestMothur/testopticluster.h b/TestMothur/testopticluster.h index 655ec0bc..ebfd1168 100644 --- a/TestMothur/testopticluster.h +++ b/TestMothur/testopticluster.h @@ -9,11 +9,13 @@ #ifndef __Mothur__testopticluster__ #define __Mothur__testopticluster__ + +#include "gtest.h" #include "opticluster.h" -#include "gtest/gtest.h" +#include "fakeoptimatrix.hpp" -class TestOptiCluster : public OptiCluster, ::testing::Test { +class TestOptiCluster : public OptiCluster { public: @@ -22,20 +24,18 @@ class TestOptiCluster : public OptiCluster, ::testing::Test { protected: MothurOut* m; - string columnFile, phylipFile; - vector filenames; - OptiMatrix* matrix; + ClusterMetric* metric; + FakeOptiMatrix testMatrix; - using OptiCluster::calcMCC; - using OptiCluster::calcSens; - using OptiCluster::calcSpec; - using OptiCluster::calcTPTN; - using OptiCluster::calcFPFN; - using OptiCluster::moveAdjustTFValues; using OptiCluster::setVariables; using OptiCluster::initialize; using OptiCluster::update; + using OptiCluster::getCloseFarCounts; + FRIEND_TEST(TestOptiCluster, myInitialize); + FRIEND_TEST(TestOptiCluster, getCloseFarCounts); + FRIEND_TEST(TestOptiCluster, myUpdate); + }; #endif /* defined(__Mothur__testopticluster__) */ diff --git a/TestMothur/testtrimoligos.hpp b/TestMothur/testtrimoligos.hpp index 91ef92ab..96db8605 100644 --- a/TestMothur/testtrimoligos.hpp +++ b/TestMothur/testtrimoligos.hpp @@ -10,7 +10,7 @@ #define testtrimoligos_hpp #include "trimoligos.h" -#include "sequence.hpp" + class TestTrimOligos : public TrimOligos { @@ -21,14 +21,8 @@ class TestTrimOligos : public TrimOligos { ~TestTrimOligos(); MothurOut* m; - vector seqs; - vector pairedSeqs; - - map barcodes; - map primers; - map pairedPrimers; - map pairedBarcodes; + Sequence* fseq; //using TrimOligos::compareDNASeq(string, string); //using TrimOligos::countDiffs(string, string); diff --git a/TestMothur/testvsearchfileparser.cpp b/TestMothur/testvsearchfileparser.cpp index 22b57144..0df5ffc7 100644 --- a/TestMothur/testvsearchfileparser.cpp +++ b/TestMothur/testvsearchfileparser.cpp @@ -13,13 +13,12 @@ TestVsearchFileParser::TestVsearchFileParser() { //setup m = MothurOut::getInstance(); TestDataSet data; - filenames = data.getSubsetFNGFiles(100); + filenames = data.getSubsetFNGFiles(); ct = data.getCountTable(); } /**************************************************************************************************/ TestVsearchFileParser::~TestVsearchFileParser() { delete ct; - for (int i = 0; i < filenames.size(); i++) { m->mothurRemove(filenames[i]); } //teardown } /************************************************************************************************** diff --git a/source/calculators/accuracy.cpp b/source/calculators/accuracy.cpp new file mode 100644 index 00000000..d0bfa8e5 --- /dev/null +++ b/source/calculators/accuracy.cpp @@ -0,0 +1,29 @@ +// +// accuracy.cpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "accuracy.hpp" + +/***********************************************************************/ +double Accuracy::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long p = tp + fn; + long long n = fp + tn; + double accuracy = (tp + tn) / (double) (p + n); + if(p + n == 0) { accuracy = 0; } + + if (isnan(accuracy) || isinf(accuracy)) { accuracy = 0; } + + return accuracy; + } + catch(exception& e) { + m->errorOut(e, "Accuracy", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/accuracy.hpp b/source/calculators/accuracy.hpp new file mode 100644 index 00000000..4268ed54 --- /dev/null +++ b/source/calculators/accuracy.hpp @@ -0,0 +1,30 @@ +// +// accuracy.hpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef accuracy_hpp +#define accuracy_hpp + +#include + +/***********************************************************************/ + +class Accuracy : public ClusterMetric { + +public: + Accuracy() : ClusterMetric("accuracy") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/Accuracy"; } + +private: + +}; + +/***********************************************************************/ + + +#endif /* accuracy_hpp */ diff --git a/source/calculators/calculator.cpp b/source/calculators/calculator.cpp deleted file mode 100644 index 3aa6a57a..00000000 --- a/source/calculators/calculator.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * calculator.cpp - * Dotur - * - * Created by Sarah Westcott on 11/18/08. - * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "calculator.h" - -/***********************************************************************/ -int VecCalc::sumElements(vector vec){ - return sumElements(vec,0); -} -/***********************************************************************/ -int VecCalc::sumElements(vector vec, int index){ - - int sum = 0; - for(int i = index; i < vec.size(); i++) - sum += vec.at(i); - return sum; - -} - -/***********************************************************************/ -double VecCalc::sumElements(vector vec){ - double sum = 0; - for(int i = 0; i < vec.size(); i++) - sum += vec.at(i); - return sum; - -} -/***********************************************************************/ -double VecCalc::sumElements(vector vec, int index){ - - double sum = 0; - for(int i = index; i < vec.size(); i++) - sum += vec.at(i); - return sum; - -} -/***********************************************************************/ -int VecCalc::numNZ(vector vec){ - - int numNZ = 0; - for(int i = 0; i < vec.size(); i++) - if(vec.at(i) != 0) - numNZ++; - return numNZ; - -} -/***********************************************************************/ -double VecCalc::numNZ(vector vec){ - - double numNZ = 0; - for(int i = 0; i < vec.size(); i++) - if(vec.at(i) != 0) - numNZ++; - return numNZ; - } -/***********************************************************************/ -double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom -{ - //Found on http://www.vgtu.lt/leidiniai/elektroniniai/Probability.pdf/Table%203.pdf - - //Confidence Level .90 .95 .975 .99 .995 .999 .9995 - double values[30][7] = {{3.078, 6.314, 12.706, 31.821, 63.656, 318.289, 636.578}, - {1.886, 2.920, 4.303, 6.965, 9.925, 22.328, 31.600}, - {1.638, 2.353, 3.182, 4.541, 5.841, 10.214, 12.924}, - {1.533, 2.132, 2.776, 3.747, 4.604, 7.173, 8.610}, - {1.476, 2.015, 2.571, 3.365, 4.032, 5.894, 6.869}, - {1.440, 1.943, 2.447, 3.143, 3.707, 5.208, 5.959}, - {1.415, 1.895, 2.365, 2.998, 3.499, 4.785, 5.408}, - {1.397, 1.860, 2.306, 2.896, 3.355, 4.501, 5.041}, - {1.383, 1.833, 2.262, 2.821, 3.250, 4.297, 4.781}, - {1.372, 1.812, 2.228, 2.764, 3.169, 4.144, 4.587}, - {1.363, 1.796, 2.201, 2.718, 3.106, 4.025, 4.437}, - {1.356, 1.782, 2.179, 2.681, 3.055, 3.930, 4.318}, - {1.350, 1.771, 2.160, 2.650, 3.012, 3.852, 4.221}, - {1.345, 1.761, 2.145, 2.624, 2.977, 3.787, 4.140}, - {1.341, 1.753, 2.131, 2.602, 2.947, 3.733, 4.073}, - {1.337, 1.746, 2.120, 2.583, 2.921, 3.686, 4.015}, - {1.333, 1.740, 2.110, 2.567, 2.898, 3.646, 3.965}, - {1.330, 1.734, 2.101, 2.552, 2.878, 3.610, 3.922}, - {1.328, 1.729, 2.093, 2.539, 2.861, 3.579, 3.883}, - {1.325, 1.725, 2.086, 2.528, 2.845, 3.552, 3.850}, - {1.323, 1.721, 2.080, 2.518, 2.831, 3.527, 3.819}, - {1.321, 1.717, 2.074, 2.508, 2.819, 3.505, 3.792}, - {1.319, 1.714, 2.069, 2.500, 2.807, 3.485, 3.768}, - {1.318, 1.711, 2.064, 2.492, 2.797, 3.467, 3.745}, - {1.316, 1.708, 2.060, 2.485, 2.787, 3.450, 3.725}, - {1.315, 1.706, 2.056, 2.479, 2.779, 3.435, 3.707}, - {1.314, 1.703, 2.052, 2.473, 2.771, 3.421, 3.689}, - {1.313, 1.701, 2.048, 2.467, 2.763, 3.408, 3.674}, - {1.311, 1.699, 2.045, 2.462, 2.756, 3.396, 3.660}, - {1.310, 1.697, 2.042, 2.457, 2.750, 3.385, 3.646}}; - - return values[row][col]; - -} - -/***********************************************************************/ - - - diff --git a/source/calculators/calculator.h b/source/calculators/calculator.h index 5aba3d29..ec0ad241 100644 --- a/source/calculators/calculator.h +++ b/source/calculators/calculator.h @@ -2,11 +2,9 @@ #define CALCULATOR_H -#include "mothur.h" #include "sabundvector.hpp" -#include "sharedsabundvector.h" -#include "rabundvector.hpp" -#include "uvest.h" +#include "sharedrabundvector.hpp" +#include "sequence.hpp" #include "mothurout.h" /* The calculator class is the parent class for all the different estimators implemented in mothur except the tree calculators. @@ -22,21 +20,25 @@ class Calculator { public: Calculator(){ m = MothurOut::getInstance(); needsAll = false; } + Calculator(string n, int c, bool f) : name(n), cols(c), multiple(f) { m = MothurOut::getInstance(); needsAll = false; }; + Calculator(string n, int c, bool f, bool a) : name(n), cols(c), multiple(f), needsAll(a) { m = MothurOut::getInstance(); }; virtual ~Calculator(){}; - Calculator(string n, int c, bool f) : name(n), cols(c), multiple(f) { m = MothurOut::getInstance(); needsAll = false; }; - Calculator(string n, int c, bool f, bool a) : name(n), cols(c), multiple(f), needsAll(a) { m = MothurOut::getInstance(); }; + virtual EstOutput getValues(SAbundVector*) = 0; virtual EstOutput getValues(vector) = 0; //optional calc that returns the otus labels of shared otus virtual EstOutput getValues(vector sv , vector&) { data = getValues(sv); return data; } virtual void print(ostream& f) { f.setf(ios::fixed, ios::floatfield); f.setf(ios::showpoint); f << data[0]; for(int i=1;imothurOut(getCitation()); m->mothurOutEndLine(); } + protected: MothurOut* m; EstOutput data; @@ -48,36 +50,47 @@ class Calculator { }; /**************************************************************************************************/ -/*This Class holds all of the methods that manipulate vectors. -These methods are used in the other classes. -This class must be included if any of the other classes are to be used. */ - -class VecCalc -{ - // The methods seen in the order here is how they are ordered throughout the class. - public: - VecCalc(){}; - //void printElements(vector); //This prints the values of the vector on one line with a space between each value. - //void printElements(vector); //This prints the values of the vector on one line with a space between each value. - //int findString(vector, string);//This returns the index of the given string in the given vector, if the string does not exist in the vector it returns -1. - //double mean(vector); //This returns the mean value of the vector. - //double stError(vector); //This returns the standard error of the vector. - int sumElements(vector, int); - int sumElements(vector); - double sumElements(vector); //This returns the sum of all the values in the vector. - double sumElements(vector, int); //This returns the sum of all the values in the vector excluding those whose index is before the given index. - //double findMax(vector); //This returns the maximum value in the vector. - int numNZ(vector); //This returns the number of non-zero values in the vector. - double numNZ(vector); //This returns the number of non-zero values in the vector. + + +class ClusterMetric { + +public: + ClusterMetric(){ m = MothurOut::getInstance(); } + ClusterMetric(string n){ m = MothurOut::getInstance(); name = n; } + virtual ~ClusterMetric(){}; + + virtual double getValue(long long, long long, long long, long long) = 0; //tp, tn, fp, fn + + virtual string getName() { return name; } + virtual string getCitation() = 0; + void citation() { m->mothurOut(getCitation()); m->mothurOutEndLine(); } + +protected: + MothurOut* m; + string name; + + }; + /**************************************************************************************************/ -//This Class stores the table of the confidence limits of the Student-T distribution. -class TDTable -{ - public: - double getConfLimit(int,int); + +class DistCalc { + +public: + DistCalc(){ dist = 0; m = MothurOut::getInstance(); } + DistCalc(const DistCalc& d) : dist(d.dist) { m = MothurOut::getInstance(); } + virtual ~DistCalc() {} + virtual void calcDist(Sequence, Sequence) = 0; + double getDist() { return dist; } + +protected: + double dist; + MothurOut* m; }; + /**************************************************************************************************/ + + #endif diff --git a/source/calculators/canberra.cpp b/source/calculators/canberra.cpp index 9ab6234a..0bec1f12 100644 --- a/source/calculators/canberra.cpp +++ b/source/calculators/canberra.cpp @@ -21,8 +21,8 @@ EstOutput Canberra::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); //is this otu shared if ((Aij != 0) && (Bij != 0)) { numSharedOTUS++; } diff --git a/source/calculators/dist.h b/source/calculators/dist.h deleted file mode 100644 index 1412424b..00000000 --- a/source/calculators/dist.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef DIST_H -#define DIST_H -/* - * dist.h - * Mothur - * - * Created by Sarah Westcott on 5/7/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "mothur.h" -#include "sequence.hpp" - -/**************************************************************************************************/ - -class Dist { - -public: - Dist(){ dist = 0; m = MothurOut::getInstance(); } - Dist(const Dist& d) : dist(d.dist) { m = MothurOut::getInstance(); } - virtual ~Dist() {} - virtual void calcDist(Sequence, Sequence) = 0; - double getDist() { return dist; } - -protected: - double dist; - MothurOut* m; -}; - -/**************************************************************************************************/ - -#endif diff --git a/source/calculators/eachgapdist.h b/source/calculators/eachgapdist.h index 1aca10c4..d2c27fa8 100644 --- a/source/calculators/eachgapdist.h +++ b/source/calculators/eachgapdist.h @@ -10,11 +10,11 @@ */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ -class eachGapDist : public Dist { +class eachGapDist : public DistCalc { public: diff --git a/source/calculators/eachgapdistignorens.h b/source/calculators/eachgapdistignorens.h index 9605a009..336ed2ba 100644 --- a/source/calculators/eachgapdistignorens.h +++ b/source/calculators/eachgapdistignorens.h @@ -11,11 +11,11 @@ */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ -class eachGapDistIgnoreNs : public Dist { +class eachGapDistIgnoreNs : public DistCalc { public: void calcDist(Sequence A, Sequence B){ diff --git a/source/calculators/eachgapignore.h b/source/calculators/eachgapignore.h index 2e7fbd6b..7a469c1c 100644 --- a/source/calculators/eachgapignore.h +++ b/source/calculators/eachgapignore.h @@ -10,11 +10,11 @@ */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ -class eachGapIgnoreTermGapDist : public Dist { +class eachGapIgnoreTermGapDist : public DistCalc { public: eachGapIgnoreTermGapDist() {} diff --git a/source/calculators/f1score.cpp b/source/calculators/f1score.cpp new file mode 100644 index 00000000..8bd4207f --- /dev/null +++ b/source/calculators/f1score.cpp @@ -0,0 +1,30 @@ +// +// f1score.cpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "f1score.hpp" + +/***********************************************************************/ +double F1Score::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long p = tp + fn; + long long pPrime = tp + fp; + double f1Score = 2.0 * tp / (double) (p + pPrime); + + if(p + pPrime == 0) { f1Score = 0; } + + if (isnan(f1Score) || isinf(f1Score)) { f1Score = 0; } + + return f1Score; + } + catch(exception& e) { + m->errorOut(e, "F1Score", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/f1score.hpp b/source/calculators/f1score.hpp new file mode 100644 index 00000000..0b747dca --- /dev/null +++ b/source/calculators/f1score.hpp @@ -0,0 +1,32 @@ +// +// f1score.hpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef f1score_hpp +#define f1score_hpp + +#include + +/***********************************************************************/ + +class F1Score : public ClusterMetric { + +public: + F1Score() : ClusterMetric("f1score") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/F1Score"; } + +private: + +}; + +/***********************************************************************/ + + + + +#endif /* f1score_hpp */ diff --git a/source/calculators/fdr.cpp b/source/calculators/fdr.cpp new file mode 100644 index 00000000..3aa2530a --- /dev/null +++ b/source/calculators/fdr.cpp @@ -0,0 +1,30 @@ +// +// fdr.cpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "fdr.hpp" + +/***********************************************************************/ +double FDR::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long pPrime = tp + fp; + double falseDiscoveryRate = fp / (double) pPrime; + + if(pPrime == 0) { falseDiscoveryRate = 0; } + + if (isnan(falseDiscoveryRate) || isinf(falseDiscoveryRate)) { falseDiscoveryRate = 0; } + + return (1.0-falseDiscoveryRate); + + } + catch(exception& e) { + m->errorOut(e, "FDR", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/fdr.hpp b/source/calculators/fdr.hpp new file mode 100644 index 00000000..c1342f0a --- /dev/null +++ b/source/calculators/fdr.hpp @@ -0,0 +1,31 @@ +// +// fdr.hpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fdr_hpp +#define fdr_hpp + +#include + +/***********************************************************************/ + +class FDR : public ClusterMetric { + +public: + FDR() : ClusterMetric("fdr") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/FDR"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* fdr_hpp */ diff --git a/source/calculators/fn.cpp b/source/calculators/fn.cpp new file mode 100644 index 00000000..ae918272 --- /dev/null +++ b/source/calculators/fn.cpp @@ -0,0 +1,26 @@ +// +// fn.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "fn.hpp" + +/***********************************************************************/ +double FN::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + double fnmin = fn / (double)(tp + tn + fp + fn); + + if (isnan(fnmin) || isinf(fnmin)) { fnmin = 0; } + + return (1.0 - fnmin); + } + catch(exception& e) { + m->errorOut(e, "FN", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/fn.hpp b/source/calculators/fn.hpp new file mode 100644 index 00000000..39ac9772 --- /dev/null +++ b/source/calculators/fn.hpp @@ -0,0 +1,31 @@ +// +// fn.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fn_hpp +#define fn_hpp + +#include + +/***********************************************************************/ + +class FN : public ClusterMetric { + +public: + FN() : ClusterMetric("fn") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/FN"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* fn_hpp */ diff --git a/source/calculators/fp.cpp b/source/calculators/fp.cpp new file mode 100644 index 00000000..ce601f8a --- /dev/null +++ b/source/calculators/fp.cpp @@ -0,0 +1,26 @@ +// +// fp.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "fp.hpp" + +/***********************************************************************/ +double FP::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + double fpmin = fp / (double)(tp + tn + fp + fn); + + if (isnan(fpmin) || isinf(fpmin)) { fpmin = 0; } + + return (1.0 - fpmin); + } + catch(exception& e) { + m->errorOut(e, "FP", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/fp.hpp b/source/calculators/fp.hpp new file mode 100644 index 00000000..65796108 --- /dev/null +++ b/source/calculators/fp.hpp @@ -0,0 +1,31 @@ +// +// fp.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fp_hpp +#define fp_hpp + +#include + +/***********************************************************************/ + +class FP : public ClusterMetric { + +public: + FP() : ClusterMetric("fp") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/FP"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* fp_hpp */ diff --git a/source/calculators/fpfn.cpp b/source/calculators/fpfn.cpp new file mode 100644 index 00000000..9eb93a49 --- /dev/null +++ b/source/calculators/fpfn.cpp @@ -0,0 +1,28 @@ +// +// fpfn.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "fpfn.hpp" + +/***********************************************************************/ +double FPFN::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long p = fp + fn; + + double fpfn = 1.0 - (p / (double)(tp + tn + fp + fn)); //minimize + + if (isnan(fpfn) || isinf(fpfn)) { fpfn = 0; } + + return fpfn; + } + catch(exception& e) { + m->errorOut(e, "FPFN", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/fpfn.hpp b/source/calculators/fpfn.hpp new file mode 100644 index 00000000..52b562c3 --- /dev/null +++ b/source/calculators/fpfn.hpp @@ -0,0 +1,30 @@ +// +// fpfn.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef fpfn_hpp +#define fpfn_hpp + +#include + +/***********************************************************************/ + +class FPFN : public ClusterMetric { + +public: + FPFN() : ClusterMetric("fpfn") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/FPFN"; } + +private: + +}; + +/***********************************************************************/ + + +#endif /* fpfn_hpp */ diff --git a/source/calculators/gower.cpp b/source/calculators/gower.cpp index 5f0bf68c..13581391 100644 --- a/source/calculators/gower.cpp +++ b/source/calculators/gower.cpp @@ -20,20 +20,20 @@ EstOutput Gower::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //set otus min and max to first one - minOtus[i] = shared[0]->getAbundance(i); - maxOtus[i] = shared[0]->getAbundance(i); + minOtus[i] = shared[0]->get(i); + maxOtus[i] = shared[0]->get(i); //for each group for (int j = 1; j < shared.size(); j++) { - maxOtus[i] = max(shared[j]->getAbundance(i), maxOtus[i]); - minOtus[i] = min(shared[j]->getAbundance(i), minOtus[i]); + maxOtus[i] = max(shared[j]->get(i), maxOtus[i]); + minOtus[i] = min(int(shared[j]->get(i)), minOtus[i]); } } double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); double numerator = abs(A - B); double denominator = maxOtus[i] - minOtus[i]; diff --git a/source/calculators/hamming.cpp b/source/calculators/hamming.cpp index 6131bfc9..6617505e 100644 --- a/source/calculators/hamming.cpp +++ b/source/calculators/hamming.cpp @@ -20,8 +20,8 @@ EstOutput Hamming::getValues(vector shared) { //calc the 2 denominators for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); if (A != 0) { numA++; } if (B != 0) { numB++; } diff --git a/source/calculators/hellinger.cpp b/source/calculators/hellinger.cpp index 43d33de1..a750ed5d 100644 --- a/source/calculators/hellinger.cpp +++ b/source/calculators/hellinger.cpp @@ -19,8 +19,8 @@ EstOutput Hellinger::getValues(vector shared) { //calc the 2 denominators for (int i = 0; i < shared[0]->getNumBins(); i++) { - sumA += shared[0]->getAbundance(i); - sumB += shared[1]->getAbundance(i); + sumA += shared[0]->get(i); + sumB += shared[1]->get(i); } @@ -28,8 +28,8 @@ EstOutput Hellinger::getValues(vector shared) { double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); double term1 = sqrt((Aij / sumA)); double term2 = sqrt((Bij / sumB)); diff --git a/source/calculators/ignoregaps.h b/source/calculators/ignoregaps.h index 894f92d9..759364be 100644 --- a/source/calculators/ignoregaps.h +++ b/source/calculators/ignoregaps.h @@ -9,14 +9,14 @@ * */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ // this class calculates distances by ignoring all gap characters. so if seq a has an "A" and seq // b has a '-', there is no penalty -class ignoreGaps : public Dist { +class ignoreGaps : public DistCalc { public: diff --git a/source/calculators/manhattan.cpp b/source/calculators/manhattan.cpp index 134dd912..ddbacb81 100644 --- a/source/calculators/manhattan.cpp +++ b/source/calculators/manhattan.cpp @@ -18,8 +18,8 @@ EstOutput Manhattan::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); sum += abs((Aij - Bij)); } diff --git a/source/calculators/mcc.cpp b/source/calculators/mcc.cpp new file mode 100644 index 00000000..75a294d1 --- /dev/null +++ b/source/calculators/mcc.cpp @@ -0,0 +1,33 @@ +// +// mcc.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "mcc.hpp" + +/***********************************************************************/ +double MCC::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + + long long p = tp + fn; + long long n = fp + tn; + long long pPrime = tp + fp; + long long nPrime = tn + fn; + + double matthewsCorrCoef = ((tp * tn) - (fp * fn)) / (double) sqrt(p * n * pPrime * nPrime); + if(p == 0 || n == 0 || pPrime == 0 || nPrime == 0){ matthewsCorrCoef = 0; } + + if (isnan(matthewsCorrCoef) || isinf(matthewsCorrCoef)) { matthewsCorrCoef = 0; } + + return matthewsCorrCoef; + } + catch(exception& e) { + m->errorOut(e, "MCC", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/mcc.hpp b/source/calculators/mcc.hpp new file mode 100644 index 00000000..3a944000 --- /dev/null +++ b/source/calculators/mcc.hpp @@ -0,0 +1,29 @@ +// +// mcc.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef mcc_hpp +#define mcc_hpp + +#include + +/***********************************************************************/ + +class MCC : public ClusterMetric { + +public: + MCC() : ClusterMetric("mcc") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/MCC"; } + +private: + +}; + +/***********************************************************************/ + +#endif /* mcc_hpp */ diff --git a/source/calculators/memchi2.cpp b/source/calculators/memchi2.cpp index f08b4b85..cd925775 100644 --- a/source/calculators/memchi2.cpp +++ b/source/calculators/memchi2.cpp @@ -21,14 +21,14 @@ EstOutput MemChi2::getValues(vector shared) { //for each otu for (int i = 0; i < shared[0]->getNumBins(); i++) { - if (shared[0]->getAbundance(i) != 0) { nonZeroA++; } - if (shared[1]->getAbundance(i) != 0) { nonZeroB++; } + if (shared[0]->get(i) != 0) { nonZeroA++; } + if (shared[1]->get(i) != 0) { nonZeroB++; } } double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); if (A > 0) { A = 1; } if (B > 0) { B = 1; } @@ -38,7 +38,7 @@ EstOutput MemChi2::getValues(vector shared) { int incidence = 0; for(int j=0;jgetAbundance(i) != 0){ incidence++; } + if(shared[j]->get(i) != 0){ incidence++; } } if(incidence != 0){ diff --git a/source/calculators/memchord.cpp b/source/calculators/memchord.cpp index 380ddbe3..f052413d 100644 --- a/source/calculators/memchord.cpp +++ b/source/calculators/memchord.cpp @@ -19,8 +19,8 @@ EstOutput MemChord::getValues(vector shared) { //for each otu for (int i = 0; i < shared[0]->getNumBins(); i++) { - if (shared[0]->getAbundance(i) != 0) { nonZeroA++; } - if (shared[1]->getAbundance(i) != 0) { nonZeroB++; } + if (shared[0]->get(i) != 0) { nonZeroA++; } + if (shared[1]->get(i) != 0) { nonZeroB++; } } nonZeroA = sqrt(nonZeroA); @@ -28,8 +28,8 @@ EstOutput MemChord::getValues(vector shared) { double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); if (A > 0) { A = 1; } if (B > 0) { B = 1; } diff --git a/source/calculators/memeuclidean.cpp b/source/calculators/memeuclidean.cpp index e6134738..994c271d 100644 --- a/source/calculators/memeuclidean.cpp +++ b/source/calculators/memeuclidean.cpp @@ -16,8 +16,8 @@ EstOutput MemEuclidean::getValues(vector shared) { double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); if (A > 0) { A = 1; } if (B > 0) { B = 1; } diff --git a/source/calculators/mempearson.cpp b/source/calculators/mempearson.cpp index 2503b5dc..56677cd9 100644 --- a/source/calculators/mempearson.cpp +++ b/source/calculators/mempearson.cpp @@ -20,8 +20,8 @@ EstOutput MemPearson::getValues(vector shared) { //for each otu for (int i = 0; i < shared[0]->getNumBins(); i++) { - if (shared[0]->getAbundance(i) != 0) { nonZeroA++; } - if (shared[1]->getAbundance(i) != 0) { nonZeroB++; } + if (shared[0]->get(i) != 0) { nonZeroA++; } + if (shared[1]->get(i) != 0) { nonZeroB++; } } double numTerm = 0.0; @@ -31,8 +31,8 @@ EstOutput MemPearson::getValues(vector shared) { double averageB = nonZeroB / (float) numOTUS; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); if (Aij > 0) { Aij = 1; } if (Bij > 0) { Bij = 1; } diff --git a/source/calculators/npv.cpp b/source/calculators/npv.cpp new file mode 100644 index 00000000..a932c73d --- /dev/null +++ b/source/calculators/npv.cpp @@ -0,0 +1,29 @@ +// +// npv.cpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "npv.hpp" + +/***********************************************************************/ +double NPV::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long nPrime = tn + fn; + double negativePredictiveValue = tn / (double) nPrime; + + if(nPrime == 0) { negativePredictiveValue = 0; } + + if (isnan(negativePredictiveValue) || isinf(negativePredictiveValue)) { negativePredictiveValue = 0; } + + return negativePredictiveValue; + } + catch(exception& e) { + m->errorOut(e, "NPV", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/npv.hpp b/source/calculators/npv.hpp new file mode 100644 index 00000000..32fb32a9 --- /dev/null +++ b/source/calculators/npv.hpp @@ -0,0 +1,32 @@ +// +// npv.hpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef npv_hpp +#define npv_hpp + +#include + +/***********************************************************************/ + +class NPV : public ClusterMetric { + +public: + NPV() : ClusterMetric("npv") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/NPV"; } + +private: + +}; + +/***********************************************************************/ + + + + +#endif /* npv_hpp */ diff --git a/source/calculators/nseqs.h b/source/calculators/nseqs.h index c0f9549c..12577893 100644 --- a/source/calculators/nseqs.h +++ b/source/calculators/nseqs.h @@ -35,11 +35,11 @@ class NSeqs : public Calculator { //get bin values and set sharedByAll bool sharedByAll = true; for (int j = 0; j < numGroups; j++) { - if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; } + if (shared[j]->get(i) == 0) { sharedByAll = false; } } //they are shared - if (sharedByAll == true) { for (int j = 0; j < numGroups; j++) { data[j] += shared[j]->getAbundance(i); } } + if (sharedByAll == true) { for (int j = 0; j < numGroups; j++) { data[j] += shared[j]->get(i); } } } return data; diff --git a/source/calculators/odum.cpp b/source/calculators/odum.cpp index ec432e03..13655fe2 100644 --- a/source/calculators/odum.cpp +++ b/source/calculators/odum.cpp @@ -20,8 +20,8 @@ EstOutput Odum::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); sumNum += abs(Aij - Bij); sumDenom += (Aij + Bij); diff --git a/source/calculators/onegapdist.h b/source/calculators/onegapdist.h index 3e5b6c72..c9f5d4cc 100644 --- a/source/calculators/onegapdist.h +++ b/source/calculators/onegapdist.h @@ -9,12 +9,12 @@ * */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ -class oneGapDist : public Dist { +class oneGapDist : public DistCalc { public: diff --git a/source/calculators/onegapignore.h b/source/calculators/onegapignore.h index fdbc196e..5cbc425b 100644 --- a/source/calculators/onegapignore.h +++ b/source/calculators/onegapignore.h @@ -10,11 +10,11 @@ */ -#include "dist.h" +#include "calculator.h" /**************************************************************************************************/ -class oneGapIgnoreTermGapDist : public Dist { +class oneGapIgnoreTermGapDist : public DistCalc { public: diff --git a/source/calculators/ppv.cpp b/source/calculators/ppv.cpp new file mode 100644 index 00000000..8b0f2bf5 --- /dev/null +++ b/source/calculators/ppv.cpp @@ -0,0 +1,29 @@ +// +// ppv.cpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "ppv.hpp" + +/***********************************************************************/ +double PPV::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long pPrime = tp + fp; + double positivePredictiveValue = tp / (double) pPrime; + + if(pPrime == 0) { positivePredictiveValue = 0; } + + if (isnan(positivePredictiveValue) || isinf(positivePredictiveValue)) { positivePredictiveValue = 0; } + + return positivePredictiveValue; + } + catch(exception& e) { + m->errorOut(e, "PPV", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/ppv.hpp b/source/calculators/ppv.hpp new file mode 100644 index 00000000..8578a4b1 --- /dev/null +++ b/source/calculators/ppv.hpp @@ -0,0 +1,31 @@ +// +// ppv.hpp +// Mothur +// +// Created by Sarah Westcott on 4/11/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef ppv_hpp +#define ppv_hpp + +#include + +/***********************************************************************/ + +class PPV : public ClusterMetric { + +public: + PPV() : ClusterMetric("ppv") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/PPV"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* ppv_hpp */ diff --git a/source/calculators/sensitivity.cpp b/source/calculators/sensitivity.cpp new file mode 100644 index 00000000..fb0eff54 --- /dev/null +++ b/source/calculators/sensitivity.cpp @@ -0,0 +1,29 @@ +// +// sensitivity.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "sensitivity.hpp" + +/***********************************************************************/ +double Sensitivity::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + + long long p = tp + fn; + double sensitivity = tp / (double) p; + + if(p == 0) { sensitivity = 0; } + if (isnan(sensitivity) || isinf(sensitivity)) { sensitivity = 0; } + + return sensitivity; + } + catch(exception& e) { + m->errorOut(e, "Sensitivity", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/sensitivity.hpp b/source/calculators/sensitivity.hpp new file mode 100644 index 00000000..75b9a968 --- /dev/null +++ b/source/calculators/sensitivity.hpp @@ -0,0 +1,29 @@ +// +// sensitivity.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef sensitivity_hpp +#define sensitivity_hpp + +#include + +/***********************************************************************/ + +class Sensitivity : public ClusterMetric { + +public: + Sensitivity() : ClusterMetric("sens") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); //ignores tn, fp + string getCitation() { return "http://www.mothur.org/wiki/Sensitivity"; } + +private: + +}; + +/***********************************************************************/ + +#endif /* sensitivity_hpp */ diff --git a/source/calculators/sharedace.cpp b/source/calculators/sharedace.cpp index 2a06380b..47bc22e4 100644 --- a/source/calculators/sharedace.cpp +++ b/source/calculators/sharedace.cpp @@ -34,8 +34,8 @@ EstOutput SharedAce::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if ((tempA != 0) && (tempB != 0)) {//they are shared S12++; //do both A and B have one diff --git a/source/calculators/sharedanderbergs.cpp b/source/calculators/sharedanderbergs.cpp index cbb9d300..48f9aad8 100644 --- a/source/calculators/sharedanderbergs.cpp +++ b/source/calculators/sharedanderbergs.cpp @@ -23,8 +23,8 @@ EstOutput Anderberg::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if (tempA != 0) { S1++; } if (tempB != 0) { S2++; } diff --git a/source/calculators/sharedbraycurtis.cpp b/source/calculators/sharedbraycurtis.cpp index 3711ce77..8b29749b 100644 --- a/source/calculators/sharedbraycurtis.cpp +++ b/source/calculators/sharedbraycurtis.cpp @@ -26,8 +26,8 @@ EstOutput BrayCurtis::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); sumSharedA += tempA; sumSharedB += tempB; diff --git a/source/calculators/sharedchao1.cpp b/source/calculators/sharedchao1.cpp index 8d47ad2f..3f31be9e 100644 --- a/source/calculators/sharedchao1.cpp +++ b/source/calculators/sharedchao1.cpp @@ -34,7 +34,7 @@ EstOutput SharedChao1::getValues(vector shared){ bool sharedByAll = true; temp.clear(); for (int j = 0; j < numGroups; j++) { - temp.push_back(shared[j]->getAbundance(i)); + temp.push_back(shared[j]->get(i)); if (temp[j] == 0) { sharedByAll = false; } } diff --git a/source/calculators/sharedjabund.cpp b/source/calculators/sharedjabund.cpp index d86fcb8e..07a8f6ed 100644 --- a/source/calculators/sharedjabund.cpp +++ b/source/calculators/sharedjabund.cpp @@ -8,6 +8,7 @@ */ #include "sharedjabund.h" +#include "uvest.h" /***********************************************************************/ @@ -17,7 +18,8 @@ EstOutput JAbund::getValues(vector shared) { UVest.resize(2,0); data.resize(1,0); - UVest = uv->getUVest(shared); + UVEst uv; + UVest = uv.getUVest(shared); //UVest[0] is Uest UVest[1] is Vest data[0] = 1.0-(UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1] - (UVest[0] * UVest[1]))); diff --git a/source/calculators/sharedjabund.h b/source/calculators/sharedjabund.h index 083ad239..393f64ef 100644 --- a/source/calculators/sharedjabund.h +++ b/source/calculators/sharedjabund.h @@ -25,7 +25,7 @@ class JAbund : public Calculator { EstOutput getValues(vector); string getCitation() { return "http://www.mothur.org/wiki/Jabund"; } private: - UVEst* uv; + }; diff --git a/source/calculators/sharedjackknife.cpp b/source/calculators/sharedjackknife.cpp index 0998db8f..f1044112 100644 --- a/source/calculators/sharedjackknife.cpp +++ b/source/calculators/sharedjackknife.cpp @@ -32,7 +32,7 @@ double* SharedJackknife::jackknife(){ double numInd = 0; for(int i = 0; i < numGroups; i++) for(int j = 0; j < numBins; j++) { - int curAbund = groups.at(i)->get(j+1).abundance; + int curAbund = groups.at(i)->get(j+1); cArray[j] += curAbund; numInd += (double)curAbund; } @@ -43,9 +43,9 @@ double* SharedJackknife::jackknife(){ double jackknifeEstimate = 0; for(int i = 0; i < numGroups; i++) { for(int j = 0; j < numBins-1; j++) { - int abundDiff = -groups.at(i)->get(j+1).abundance; + int abundDiff = -groups.at(i)->get(j+1); if(i > 0) - abundDiff += groups.at(i-1)->get(j+1).abundance; + abundDiff += groups.at(i-1)->get(j+1); cArray[j] += abundDiff; numInd += abundDiff; @@ -63,10 +63,9 @@ double* SharedJackknife::jackknife(){ variance /= (double)numGroups*((double)numGroups-1); double stErr = sqrt(variance); - TDTable table; double confLimit = 0; if(numGroups <= 30) - confLimit = table.getConfLimit(numGroups-1, 1); + confLimit = getConfLimit(numGroups-1, 1); else confLimit = 1.645; @@ -80,13 +79,53 @@ double* SharedJackknife::jackknife(){ return rdata; } -/************************************************************************************************ -************************************************************************************************/ +/***********************************************************************/ +double SharedJackknife::getConfLimit(int row, int col) //Rows are the degrees of freedom +{ + //Found on http://www.vgtu.lt/leidiniai/elektroniniai/Probability.pdf/Table%203.pdf + + //Confidence Level .90 .95 .975 .99 .995 .999 .9995 + double values[30][7] = {{3.078, 6.314, 12.706, 31.821, 63.656, 318.289, 636.578}, + {1.886, 2.920, 4.303, 6.965, 9.925, 22.328, 31.600}, + {1.638, 2.353, 3.182, 4.541, 5.841, 10.214, 12.924}, + {1.533, 2.132, 2.776, 3.747, 4.604, 7.173, 8.610}, + {1.476, 2.015, 2.571, 3.365, 4.032, 5.894, 6.869}, + {1.440, 1.943, 2.447, 3.143, 3.707, 5.208, 5.959}, + {1.415, 1.895, 2.365, 2.998, 3.499, 4.785, 5.408}, + {1.397, 1.860, 2.306, 2.896, 3.355, 4.501, 5.041}, + {1.383, 1.833, 2.262, 2.821, 3.250, 4.297, 4.781}, + {1.372, 1.812, 2.228, 2.764, 3.169, 4.144, 4.587}, + {1.363, 1.796, 2.201, 2.718, 3.106, 4.025, 4.437}, + {1.356, 1.782, 2.179, 2.681, 3.055, 3.930, 4.318}, + {1.350, 1.771, 2.160, 2.650, 3.012, 3.852, 4.221}, + {1.345, 1.761, 2.145, 2.624, 2.977, 3.787, 4.140}, + {1.341, 1.753, 2.131, 2.602, 2.947, 3.733, 4.073}, + {1.337, 1.746, 2.120, 2.583, 2.921, 3.686, 4.015}, + {1.333, 1.740, 2.110, 2.567, 2.898, 3.646, 3.965}, + {1.330, 1.734, 2.101, 2.552, 2.878, 3.610, 3.922}, + {1.328, 1.729, 2.093, 2.539, 2.861, 3.579, 3.883}, + {1.325, 1.725, 2.086, 2.528, 2.845, 3.552, 3.850}, + {1.323, 1.721, 2.080, 2.518, 2.831, 3.527, 3.819}, + {1.321, 1.717, 2.074, 2.508, 2.819, 3.505, 3.792}, + {1.319, 1.714, 2.069, 2.500, 2.807, 3.485, 3.768}, + {1.318, 1.711, 2.064, 2.492, 2.797, 3.467, 3.745}, + {1.316, 1.708, 2.060, 2.485, 2.787, 3.450, 3.725}, + {1.315, 1.706, 2.056, 2.479, 2.779, 3.435, 3.707}, + {1.314, 1.703, 2.052, 2.473, 2.771, 3.421, 3.689}, + {1.313, 1.701, 2.048, 2.467, 2.763, 3.408, 3.674}, + {1.311, 1.699, 2.045, 2.462, 2.756, 3.396, 3.660}, + {1.310, 1.697, 2.042, 2.457, 2.750, 3.385, 3.646}}; + + return values[row][col]; + +} + +/***********************************************************************/ + +/************************************************************************************************/ EstOutput SharedJackknife::getValues(vector vectorShared){ //Fix this for collect, mistake was that it was made with summary in mind. try { - SharedRAbundVector* shared1 = vectorShared[0]; - SharedRAbundVector* shared2 = vectorShared[1]; if(numGroups == -1) { numGroups = m->getNumGroups(); } @@ -103,9 +142,10 @@ EstOutput SharedJackknife::getValues(vector vectorShared){ } if(groups.size() != numGroups) { - if(groups.size() == 0) - groups.push_back(shared1); - groups.push_back(shared2); + if(groups.size() == 0) + groups.push_back(vectorShared[0]); + groups.push_back(vectorShared[1]); + } if(groups.size() == numGroups && callCount < numGroups) { diff --git a/source/calculators/sharedjackknife.h b/source/calculators/sharedjackknife.h index 1e9cbf53..bbf9b264 100644 --- a/source/calculators/sharedjackknife.h +++ b/source/calculators/sharedjackknife.h @@ -31,6 +31,7 @@ class SharedJackknife : public Calculator { vector groups; double simpson(vector, double, int); double* jackknife(); + double getConfLimit(int row, int col); }; /***********************************************************************/ diff --git a/source/calculators/sharedjclass.cpp b/source/calculators/sharedjclass.cpp index ed21335e..38ae72f1 100644 --- a/source/calculators/sharedjclass.cpp +++ b/source/calculators/sharedjclass.cpp @@ -23,8 +23,8 @@ EstOutput Jclass::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); //find number of bins in shared1 and shared2 if (tempA != 0) { S1++; } diff --git a/source/calculators/sharedjsd.cpp b/source/calculators/sharedjsd.cpp index 914c8755..457c8626 100644 --- a/source/calculators/sharedjsd.cpp +++ b/source/calculators/sharedjsd.cpp @@ -19,23 +19,13 @@ EstOutput JSD::getValues(vector shared) { double KLD1 = 0.0; double KLD2 = 0.0; - vector countA = shared[0]->getAbundances(); - vector countB = shared[1]->getAbundances(); - double totalA = 0; - double totalB = 0; + double totalA = shared[0]->getNumSeqs(); + double totalB = shared[1]->getNumSeqs(); - for (int i = 0; i < shared[0]->getNumBins(); i++) { - totalA += countA[i]; - totalB += countB[i]; - } - for (int i = 0; i < shared[0]->getNumBins(); i++) { - double tempA = countA[i] / totalA; - double tempB = countB[i] / totalB; + double tempA = shared[0]->get(i) / totalA; + double tempB = shared[1]->get(i) / totalB; - tempA = countA[i] / totalA; - tempB = countB[i] / totalB; - if (tempA == 0) { tempA = 0.000001; } if (tempB == 0) { tempB = 0.000001; } @@ -43,7 +33,6 @@ EstOutput JSD::getValues(vector shared) { if (tempA != 0) { KLD1 += tempA * log(tempA/denom); } //KLD(x,m) if (tempB != 0) { KLD2 += tempB * log(tempB/denom); } //KLD(y,m) - } diff --git a/source/calculators/sharedkstest.cpp b/source/calculators/sharedkstest.cpp index d9147880..76b7f303 100644 --- a/source/calculators/sharedkstest.cpp +++ b/source/calculators/sharedkstest.cpp @@ -16,13 +16,13 @@ EstOutput KSTest::getValues(vector shared){ data.resize(3,0); //Must return shared1 and shared2 to original order at conclusion of kstest - vector initData1 = shared[0]->getData(); - vector initData2 = shared[1]->getData(); - shared[0]->sortD(); - shared[1]->sortD(); + vector sortedA = shared[0]->get(); sort(sortedA.begin()+1, sortedA.end()); + vector sortedB = shared[1]->get(); sort(sortedB.begin()+1, sortedB.end()); - int numNZ1 = shared[0]->numNZ(); - int numNZ2 = shared[1]->numNZ(); + int numNZ1 = 0; + for(int i = 0; i < shared[0]->getNumBins(); i++) { if(shared[0]->get(i) != 0) { numNZ1++; } } //shared[0]->numNZ(); + int numNZ2 = 0; + for(int i = 0; i < shared[1]->getNumBins(); i++) { if(shared[1]->get(i) != 0) { numNZ2++; } } //shared[1]->numNZ(); double numInd1 = (double)shared[0]->getNumSeqs(); double numInd2 = (double)shared[1]->getNumSeqs(); @@ -31,8 +31,8 @@ EstOutput KSTest::getValues(vector shared){ double sum2 = 0; for(int i = 1; i < shared[0]->getNumBins(); i++) { - sum1 += shared[0]->get(i).abundance; - sum2 += shared[1]->get(i).abundance; + sum1 += sortedA[i]; + sum2 += sortedB[i]; double diff = fabs((double)sum1/numInd1 - (double)sum2/numInd2); if(diff > maxDiff) maxDiff = diff; @@ -43,9 +43,6 @@ EstOutput KSTest::getValues(vector shared){ //double pVal = exp(-2*pow(maxDiff/a,2)); double critVal = 1.36*a*numNZ1*numNZ2; - shared[0]->setData(initData1); - shared[1]->setData(initData2); - data[0] = DStatistic; data[1] = critVal; data[2] = 0; diff --git a/source/calculators/sharedkulczynski.cpp b/source/calculators/sharedkulczynski.cpp index 5c91ddb6..d61108b8 100644 --- a/source/calculators/sharedkulczynski.cpp +++ b/source/calculators/sharedkulczynski.cpp @@ -23,8 +23,8 @@ EstOutput Kulczynski::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if (tempA != 0) { S1++; } if (tempB != 0) { S2++; } diff --git a/source/calculators/sharedkulczynskicody.cpp b/source/calculators/sharedkulczynskicody.cpp index 8c8b7f7f..84a0e02c 100644 --- a/source/calculators/sharedkulczynskicody.cpp +++ b/source/calculators/sharedkulczynskicody.cpp @@ -23,8 +23,8 @@ EstOutput KulczynskiCody::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if (tempA != 0) { S1++; } if (tempB != 0) { S2++; } diff --git a/source/calculators/sharedlennon.cpp b/source/calculators/sharedlennon.cpp index 52192756..56006606 100644 --- a/source/calculators/sharedlennon.cpp +++ b/source/calculators/sharedlennon.cpp @@ -23,8 +23,8 @@ EstOutput Lennon::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if (tempA != 0) { S1++; } if (tempB != 0) { S2++; } diff --git a/source/calculators/sharedmarczewski.cpp b/source/calculators/sharedmarczewski.cpp index 57de5f5b..750bb111 100644 --- a/source/calculators/sharedmarczewski.cpp +++ b/source/calculators/sharedmarczewski.cpp @@ -9,20 +9,20 @@ #include "sharedmarczewski.h" -EstOutput SharedMarczewski::getValues(vector vectorShared){ +EstOutput SharedMarczewski::getValues(vector shared){ try { - SharedRAbundVector* shared1 = vectorShared[0]; - SharedRAbundVector* shared2 = vectorShared[1]; + //SharedRAbundVector* shared1 = vectorShared[0]; + //SharedRAbundVector* shared2 = vectorShared[1]; data.resize(1,0); double a = 0; double b = 0; double c = 0; - for(int i = 1; i < shared1->size(); i++) + for(int i = 1; i < shared[0]->getNumBins(); i++) { - int abund1 = shared1->get(i).abundance; - int abund2 = shared2->get(i).abundance; + int abund1 = shared[0]->get(i); + int abund2 = shared[1]->get(i); if(abund1 > 0 && abund2 > 0) a++; diff --git a/source/calculators/sharedmorisitahorn.cpp b/source/calculators/sharedmorisitahorn.cpp index 16a75908..56c42dc7 100644 --- a/source/calculators/sharedmorisitahorn.cpp +++ b/source/calculators/sharedmorisitahorn.cpp @@ -22,15 +22,15 @@ EstOutput MorHorn::getValues(vector shared) { //get the total values we need to calculate the theta denominator sums for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - Atotal += shared[0]->getAbundance(i); - Btotal += shared[1]->getAbundance(i); + Atotal += shared[0]->get(i); + Btotal += shared[1]->get(i); } //calculate the denominator sums for (int j = 0; j < shared[0]->getNumBins(); j++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(j); - tempB = shared[1]->getAbundance(j); + tempA = shared[0]->get(j); + tempB = shared[1]->get(j); float relA = tempA / Atotal; float relB = tempB / Btotal; diff --git a/source/calculators/sharedochiai.cpp b/source/calculators/sharedochiai.cpp index b49fa4a3..d5ae812e 100644 --- a/source/calculators/sharedochiai.cpp +++ b/source/calculators/sharedochiai.cpp @@ -23,8 +23,8 @@ EstOutput Ochiai::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); if (tempA != 0) { S1++; } if (tempB != 0) { S2++; } diff --git a/source/calculators/sharedrjsd.cpp b/source/calculators/sharedrjsd.cpp index 46990540..dbd257d1 100644 --- a/source/calculators/sharedrjsd.cpp +++ b/source/calculators/sharedrjsd.cpp @@ -19,22 +19,15 @@ EstOutput RJSD::getValues(vector shared) { double KLD1 = 0.0; double KLD2 = 0.0; - vector countA = shared[0]->getAbundances(); - vector countB = shared[1]->getAbundances(); - double totalA = 0; - double totalB = 0; - - for (int i = 0; i < shared[0]->getNumBins(); i++) { - totalA += countA[i]; - totalB += countB[i]; - } + double totalA = shared[0]->getNumSeqs(); + double totalB = shared[1]->getNumSeqs(); for (int i = 0; i < shared[0]->getNumBins(); i++) { - double tempA = countA[i] / totalA; - double tempB = countB[i] / totalB; + double tempA = shared[0]->get(i) / totalA; + double tempB = shared[1]->get(i) / totalB; - tempA = countA[i] / totalA; - tempB = countB[i] / totalB; + tempA = shared[0]->get(i) / totalA; + tempB = shared[1]->get(i) / totalB; if (tempA == 0) { tempA = 0.000001; } if (tempB == 0) { tempB = 0.000001; } diff --git a/source/calculators/sharedsobs.cpp b/source/calculators/sharedsobs.cpp index f9b5eddc..8bef733b 100644 --- a/source/calculators/sharedsobs.cpp +++ b/source/calculators/sharedsobs.cpp @@ -21,8 +21,8 @@ EstOutput SharedSobs::getValues(vector shared){ //loop through the species in each group for (int k = 0; k < shared[0]->getNumBins(); k++) { //if you have found a new species - if (shared[0]->getAbundance(k) != 0) { observed++; } - else if ((shared[0]->getAbundance(k) == 0) && (shared[1]->getAbundance(k) != 0)) { observed++; } + if (shared[0]->get(k) != 0) { observed++; } + else if ((shared[0]->get(k) == 0) && (shared[1]->get(k) != 0)) { observed++; } } data[0] = observed; diff --git a/source/calculators/sharedsobscollectsummary.cpp b/source/calculators/sharedsobscollectsummary.cpp index 204b61c6..f6a70330 100644 --- a/source/calculators/sharedsobscollectsummary.cpp +++ b/source/calculators/sharedsobscollectsummary.cpp @@ -23,7 +23,7 @@ EstOutput SharedSobsCS::getValues(vector shared){ //get bin values and set sharedByAll bool sharedByAll = true; for (int j = 0; j < numGroups; j++) { - if (shared[j]->getAbundance(i) == 0) { sharedByAll = false; } + if (shared[j]->get(i) == 0) { sharedByAll = false; } } //they are shared @@ -53,7 +53,7 @@ EstOutput SharedSobsCS::getValues(vector shared, vectorgetAbundance(i) == 0) { sharedByAll = false; } + if (shared[j]->get(i) == 0) { sharedByAll = false; } } //they are shared diff --git a/source/calculators/sharedsorabund.cpp b/source/calculators/sharedsorabund.cpp index 9a1bd63d..cb50a651 100644 --- a/source/calculators/sharedsorabund.cpp +++ b/source/calculators/sharedsorabund.cpp @@ -8,6 +8,7 @@ */ #include "sharedsorabund.h" +#include "uvest.h" /***********************************************************************/ @@ -17,7 +18,8 @@ EstOutput SorAbund::getValues(vector shared) { UVest.resize(2,0); data.resize(1,0); - UVest = uv->getUVest(shared); + UVEst uv; + UVest = uv.getUVest(shared); //UVest[0] is Uest, UVest[1] is Vest data[0] = (2 * UVest[0] * UVest[1]) / ((float)(UVest[0] + UVest[1])); diff --git a/source/calculators/sharedsorabund.h b/source/calculators/sharedsorabund.h index aa856226..f350e8ee 100644 --- a/source/calculators/sharedsorabund.h +++ b/source/calculators/sharedsorabund.h @@ -25,7 +25,7 @@ class SorAbund : public Calculator { EstOutput getValues(vector); string getCitation() { return "http://www.mothur.org/wiki/Sorabund"; } private: - UVEst* uv; + }; /***********************************************************************/ diff --git a/source/calculators/sharedsorclass.cpp b/source/calculators/sharedsorclass.cpp index 85609dad..eceb67fe 100644 --- a/source/calculators/sharedsorclass.cpp +++ b/source/calculators/sharedsorclass.cpp @@ -23,8 +23,8 @@ EstOutput SorClass::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); //find number of bins in shared1 and shared2 if (tempA != 0) { S1++; } diff --git a/source/calculators/sharedsorclass.h b/source/calculators/sharedsorclass.h index 49ada2d7..364d0723 100644 --- a/source/calculators/sharedsorclass.h +++ b/source/calculators/sharedsorclass.h @@ -25,6 +25,7 @@ class SorClass : public Calculator { EstOutput getValues(vector); string getCitation() { return "http://www.mothur.org/wiki/Sorclass"; } private: + }; /***********************************************************************/ diff --git a/source/calculators/sharedthetan.cpp b/source/calculators/sharedthetan.cpp index 644adee6..4fa070ce 100644 --- a/source/calculators/sharedthetan.cpp +++ b/source/calculators/sharedthetan.cpp @@ -22,15 +22,15 @@ EstOutput ThetaN::getValues(vector shared) { //get the total values we need to calculate the theta denominator sums for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - Atotal += shared[0]->getAbundance(i); - Btotal += shared[1]->getAbundance(i); + Atotal += shared[0]->get(i); + Btotal += shared[1]->get(i); } //calculate the theta denominator sums for (int j = 0; j < shared[0]->getNumBins(); j++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(j); - tempB = shared[1]->getAbundance(j); + tempA = shared[0]->get(j); + tempB = shared[1]->get(j); //they are shared if ((tempA != 0) && (tempB != 0)) { diff --git a/source/calculators/sharedthetayc.cpp b/source/calculators/sharedthetayc.cpp index 864c6e63..26f925b5 100644 --- a/source/calculators/sharedthetayc.cpp +++ b/source/calculators/sharedthetayc.cpp @@ -31,15 +31,15 @@ EstOutput ThetaYC::getValues(vector shared) { //get the total values we need to calculate the theta denominator sums for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - Atotal += (double)shared[0]->getAbundance(i); - Btotal += (double)shared[1]->getAbundance(i); + Atotal += (double)shared[0]->get(i); + Btotal += (double)shared[1]->get(i); } //calculate the theta denominator sums for (int j = 0; j < shared[0]->getNumBins(); j++) { //store in temps to avoid multiple repetitive function calls - pi = shared[0]->getAbundance(j) / Atotal; - qi = shared[1]->getAbundance(j) / Btotal; + pi = shared[0]->get(j) / Atotal; + qi = shared[1]->get(j) / Btotal; a += pi * pi; b += qi * qi; diff --git a/source/calculators/soergel.cpp b/source/calculators/soergel.cpp index b2fdf84d..1a9f1dee 100644 --- a/source/calculators/soergel.cpp +++ b/source/calculators/soergel.cpp @@ -20,8 +20,8 @@ EstOutput Soergel::getValues(vector shared) { //calc the 2 denominators for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); sumNum += abs((Aij - Bij)); sumMax += max(Aij, Bij); diff --git a/source/calculators/spearman.cpp b/source/calculators/spearman.cpp index 49d52652..29d2f3ba 100644 --- a/source/calculators/spearman.cpp +++ b/source/calculators/spearman.cpp @@ -47,8 +47,8 @@ EstOutput Spearman::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); float rankA = rankVectorA[Aij]; float rankB = rankVectorB[Bij]; diff --git a/source/calculators/speciesprofile.cpp b/source/calculators/speciesprofile.cpp index c225a8ac..e5702343 100644 --- a/source/calculators/speciesprofile.cpp +++ b/source/calculators/speciesprofile.cpp @@ -18,14 +18,14 @@ EstOutput SpeciesProfile::getValues(vector shared) { double sumB = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - sumA += shared[0]->getAbundance(i); - sumB += shared[1]->getAbundance(i); + sumA += shared[0]->get(i); + sumB += shared[1]->get(i); } double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); sum += (((A / sumA) - (B / sumB)) * ((A / sumA) - (B / sumB))); } diff --git a/source/calculators/specificity.cpp b/source/calculators/specificity.cpp new file mode 100644 index 00000000..065474e7 --- /dev/null +++ b/source/calculators/specificity.cpp @@ -0,0 +1,28 @@ +// +// specificity.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "specificity.hpp" + +/***********************************************************************/ +double Specificity::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long n = fp + tn; + double specificity = tn / (double) n; + + if(n == 0) { specificity = 0; } + if (isnan(specificity) || isinf(specificity)) { specificity = 0; } + + return specificity; + } + catch(exception& e) { + m->errorOut(e, "Specificity", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/specificity.hpp b/source/calculators/specificity.hpp new file mode 100644 index 00000000..f60ec8e8 --- /dev/null +++ b/source/calculators/specificity.hpp @@ -0,0 +1,31 @@ +// +// specificity.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef specificity_hpp +#define specificity_hpp + +#include + +/***********************************************************************/ + +class Specificity : public ClusterMetric { + +public: + Specificity() : ClusterMetric("spec") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); //ignores tp, fn + string getCitation() { return "http://www.mothur.org/wiki/Specificity"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* specificity_hpp */ diff --git a/source/calculators/structchi2.cpp b/source/calculators/structchi2.cpp index 00ec097d..d0c120c3 100644 --- a/source/calculators/structchi2.cpp +++ b/source/calculators/structchi2.cpp @@ -25,14 +25,14 @@ EstOutput StructChi2::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //for each group for (int j = 0; j < shared.size(); j++) { - sumOtus[i] += shared[j]->getAbundance(i); + sumOtus[i] += shared[j]->get(i); } } double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); double totalTerm = 1 / (float) sumOtus[i]; double Aterm = A / sumA; diff --git a/source/calculators/structchord.cpp b/source/calculators/structchord.cpp index e85846f9..4534fe83 100644 --- a/source/calculators/structchord.cpp +++ b/source/calculators/structchord.cpp @@ -20,8 +20,8 @@ EstOutput StructChord::getValues(vector shared) { //calc the 2 denominators for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); //(Aij) ^ 2 sumAj2 += (Aij * Aij); @@ -35,8 +35,8 @@ EstOutput StructChord::getValues(vector shared) { double sum = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); sum += (((Aij / sumAj2) - (Bij / sumBj2)) * ((Aij / sumAj2) - (Bij / sumBj2))); } diff --git a/source/calculators/structeuclidean.cpp b/source/calculators/structeuclidean.cpp index 17379205..94443c1b 100644 --- a/source/calculators/structeuclidean.cpp +++ b/source/calculators/structeuclidean.cpp @@ -18,8 +18,8 @@ EstOutput StructEuclidean::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); //(Aij - Bij) ^ 2 sum += ((Aij - Bij) * (Aij - Bij)); diff --git a/source/calculators/structkulczynski.cpp b/source/calculators/structkulczynski.cpp index 95180682..d3b14077 100644 --- a/source/calculators/structkulczynski.cpp +++ b/source/calculators/structkulczynski.cpp @@ -20,8 +20,8 @@ EstOutput StructKulczynski::getValues(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { - int A = shared[0]->getAbundance(i); - int B = shared[1]->getAbundance(i); + int A = shared[0]->get(i); + int B = shared[1]->get(i); sumA += A; sumB += B; diff --git a/source/calculators/structpearson.cpp b/source/calculators/structpearson.cpp index a21eb993..d912ccf8 100644 --- a/source/calculators/structpearson.cpp +++ b/source/calculators/structpearson.cpp @@ -23,8 +23,8 @@ EstOutput StructPearson::getValues(vector shared) { double denomTerm2 = 0.0; for (int i = 0; i < shared[0]->getNumBins(); i++) { - int Aij = shared[0]->getAbundance(i); - int Bij = shared[1]->getAbundance(i); + int Aij = shared[0]->get(i); + int Bij = shared[1]->get(i); numTerm += ((Aij - averageA) * (Bij - averageB)); diff --git a/source/calculators/tn.cpp b/source/calculators/tn.cpp new file mode 100644 index 00000000..7a2086cd --- /dev/null +++ b/source/calculators/tn.cpp @@ -0,0 +1,26 @@ +// +// tn.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "tn.hpp" + +/***********************************************************************/ +double TN::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + double tnmax = tn / (double)(tp + tn + fp + fn); + + if (isnan(tnmax) || isinf(tnmax)) { tnmax = 0; } + + return tnmax; + } + catch(exception& e) { + m->errorOut(e, "TN", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/tn.hpp b/source/calculators/tn.hpp new file mode 100644 index 00000000..4bbc17dc --- /dev/null +++ b/source/calculators/tn.hpp @@ -0,0 +1,32 @@ +// +// tn.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef tn_hpp +#define tn_hpp + +#include + +/***********************************************************************/ + +class TN : public ClusterMetric { + +public: + TN() : ClusterMetric("tn") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/TN"; } + +private: + +}; + +/***********************************************************************/ + + + + +#endif /* tn_hpp */ diff --git a/source/calculators/tp.cpp b/source/calculators/tp.cpp new file mode 100644 index 00000000..57721c9c --- /dev/null +++ b/source/calculators/tp.cpp @@ -0,0 +1,26 @@ +// +// tp.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "tp.hpp" + +/***********************************************************************/ +double TP::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + double tpmax = tp / (double)(tp + tn + fp + fn); + + if (isnan(tpmax) || isinf(tpmax)) { tpmax = 0; } + + return tpmax; + } + catch(exception& e) { + m->errorOut(e, "TP", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/tp.hpp b/source/calculators/tp.hpp new file mode 100644 index 00000000..bdfd3cb5 --- /dev/null +++ b/source/calculators/tp.hpp @@ -0,0 +1,31 @@ +// +// tp.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef tp_hpp +#define tp_hpp + +#include + +/***********************************************************************/ + +class TP : public ClusterMetric { + +public: + TP() : ClusterMetric("tp") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/TP"; } + +private: + +}; + +/***********************************************************************/ + + + +#endif /* tp_hpp */ diff --git a/source/calculators/tptn.cpp b/source/calculators/tptn.cpp new file mode 100644 index 00000000..25b2b9bf --- /dev/null +++ b/source/calculators/tptn.cpp @@ -0,0 +1,27 @@ +// +// tptn.cpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "tptn.hpp" + +/***********************************************************************/ +double TPTN::getValue( long long tp, long long tn, long long fp, long long fn) { + try { + long long p = tp + tn; + double tptn = p / (double)(tp + tn + fp + fn); + + if (isnan(tptn) || isinf(tptn)) { tptn = 0; } + + return tptn; + } + catch(exception& e) { + m->errorOut(e, "TPTN", "getValue"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/calculators/tptn.hpp b/source/calculators/tptn.hpp new file mode 100644 index 00000000..0277aa51 --- /dev/null +++ b/source/calculators/tptn.hpp @@ -0,0 +1,32 @@ +// +// tptn.hpp +// Mothur +// +// Created by Sarah Westcott on 4/10/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef tptn_hpp +#define tptn_hpp + +#include + +/***********************************************************************/ + +class TPTN : public ClusterMetric { + +public: + TPTN() : ClusterMetric("tptn") {}; + double getValue( long long tp, long long tn, long long fp, long long fn); + string getCitation() { return "http://www.mothur.org/wiki/TPTN"; } + +private: + +}; + +/***********************************************************************/ + + + + +#endif /* tptn_hpp */ diff --git a/source/calculators/uvest.cpp b/source/calculators/uvest.cpp index f0ca81e9..80428342 100644 --- a/source/calculators/uvest.cpp +++ b/source/calculators/uvest.cpp @@ -31,8 +31,8 @@ EstOutput UVEst::getUVest(vector shared) { for (int i = 0; i < shared[0]->getNumBins(); i++) { //store in temps to avoid multiple repetitive function calls - tempA = shared[0]->getAbundance(i); - tempB = shared[1]->getAbundance(i); + tempA = shared[0]->get(i); + tempB = shared[1]->get(i); Atotal += tempA; Btotal += tempB; diff --git a/source/calculators/uvest.h b/source/calculators/uvest.h index 384e80c3..f520d84f 100644 --- a/source/calculators/uvest.h +++ b/source/calculators/uvest.h @@ -13,8 +13,8 @@ It is used by sharedJAbund and SharedSorensonAbund. */ -#include "mothur.h" -#include "sharedrabundvector.h" +#include "mothurout.h" +#include "calculator.h" typedef vector EstOutput; @@ -22,7 +22,10 @@ typedef vector EstOutput; class UVEst { public: UVEst() { m = MothurOut::getInstance(); } - EstOutput getUVest(vector); + ~UVEst() {} + + EstOutput getUVest(vector); + private: MothurOut* m; }; diff --git a/source/calculators/whittaker.cpp b/source/calculators/whittaker.cpp index 5ab1e5dd..286adcc7 100644 --- a/source/calculators/whittaker.cpp +++ b/source/calculators/whittaker.cpp @@ -19,8 +19,8 @@ EstOutput Whittaker::getValues(vector shared){ int countB = 0; int sTotal = shared[0]->getNumBins(); for(int i=0;igetAbundance(i) != 0){ countA++; } - if(shared[1]->getAbundance(i) != 0){ countB++; } + if(shared[0]->get(i) != 0){ countA++; } + if(shared[1]->get(i) != 0){ countB++; } } data[0] = 2-2*sTotal/(float)(countA+countB); diff --git a/source/chimera/bellerophon.h b/source/chimera/bellerophon.h index 1dd65901..69fd80c2 100644 --- a/source/chimera/bellerophon.h +++ b/source/chimera/bellerophon.h @@ -14,7 +14,7 @@ #include "mothurchimera.h" #include "sparsematrix.hpp" #include "sequence.hpp" -#include "dist.h" +#include "calculator.h" typedef list::iterator MatData; typedef map SeqMap; //maps sequence to all distance for that seqeunce @@ -39,7 +39,7 @@ class Bellerophon : public MothurChimera { vector lines; - Dist* distCalculator; + DistCalc* distCalculator; vector seqs; vector< vector > pref; //pref[0] = preference scores for all seqs in window 0. string fastafile; diff --git a/source/chimera/ccode.h b/source/chimera/ccode.h index fa3a0a1d..3f2dfd03 100644 --- a/source/chimera/ccode.h +++ b/source/chimera/ccode.h @@ -11,7 +11,7 @@ */ #include "mothurchimera.h" -#include "dist.h" +#include "calculator.h" #include "decalc.h" /***********************************************************/ @@ -32,7 +32,7 @@ class Ccode : public MothurChimera { private: - Dist* distCalc; + DistCalc* distCalc; DeCalculator* decalc; int iters, window, numWanted; string fastafile, mapInfo; diff --git a/source/chimera/decalc.cpp b/source/chimera/decalc.cpp index ab7fa0f2..b48868ca 100644 --- a/source/chimera/decalc.cpp +++ b/source/chimera/decalc.cpp @@ -9,7 +9,7 @@ #include "decalc.h" #include "mothurchimera.h" -#include "dist.h" +#include "calculator.h" #include "eachgapdist.h" #include "ignoregaps.h" #include "eachgapdist.h" @@ -692,7 +692,7 @@ vector DeCalculator::findClosest(Sequence querySeq, vector& vector distsLeft; vector distsRight; - Dist* distcalculator = new eachGapDist(); + DistCalc* distcalculator = new eachGapDist(); string queryUnAligned = querySeq.getUnaligned(); int numBases = int(queryUnAligned.length() * 0.33); @@ -862,7 +862,7 @@ Sequence* DeCalculator::findClosest(Sequence* querySeq, vector db) { Sequence* seqsMatch; - Dist* distcalculator = new eachGapDist(); + DistCalc* distcalculator = new eachGapDist(); int index = 0; int smallest = 1000000; diff --git a/source/chimera/pintail.h b/source/chimera/pintail.h index 93f098c8..d19d022d 100644 --- a/source/chimera/pintail.h +++ b/source/chimera/pintail.h @@ -11,7 +11,7 @@ */ #include "mothurchimera.h" -#include "dist.h" +#include "calculator.h" #include "decalc.h" /***********************************************************/ @@ -35,7 +35,7 @@ class Pintail : public MothurChimera { private: - Dist* distcalculator; + DistCalc* distcalculator; DeCalculator* decalc; int iters, window, increment, processors; string fastafile, quanfile, consfile; diff --git a/source/chimera/slayer.cpp b/source/chimera/slayer.cpp index 437f0743..a1f4dcb6 100644 --- a/source/chimera/slayer.cpp +++ b/source/chimera/slayer.cpp @@ -283,7 +283,7 @@ vector Slayer::getSNPS(string parentA, string query, string parentB, int l int Slayer::bootstrapSNPS(vector left, vector right, float& BSA, float& BSB, int numIters) { try { - srand((unsigned)time( NULL )); + m->setRandomSeed((unsigned)time( NULL )); int count_A = 0; // sceneario QLA,QRB supported int count_B = 0; // sceneario QLB,QRA supported diff --git a/source/classifier/bayesian.cpp b/source/classifier/bayesian.cpp index 03f098f0..3b464644 100644 --- a/source/classifier/bayesian.cpp +++ b/source/classifier/bayesian.cpp @@ -338,20 +338,12 @@ int Bayesian::getMostProbableTaxonomy(vector queryKmer) { double maxProbability = -1000000.0; //find taxonomy with highest probability that this sequence is from it - - -// cout << genusNodes.size() << endl; - - - for (int k = 0; k < genusNodes.size(); k++) { + + for (int k = 0; k < genusNodes.size(); k++) { //for each taxonomy calc its probability double prob = 0.0000; - for (int i = 0; i < queryKmer.size(); i++) { - prob += wordGenusProb[queryKmer[i]][k]; - } - -// cout << phyloTree->get(genusNodes[k]).name << '\t' << prob << endl; + for (int i = 0; i < queryKmer.size(); i++) { prob += wordGenusProb[queryKmer[i]][k]; } //is this the taxonomy with the greatest probability? if (prob > maxProbability) { @@ -359,7 +351,6 @@ int Bayesian::getMostProbableTaxonomy(vector queryKmer) { maxProbability = prob; } } - return indexofGenus; } diff --git a/source/classifier/classify.cpp b/source/classifier/classify.cpp index 7628e8b7..cb8eeb0b 100644 --- a/source/classifier/classify.cpp +++ b/source/classifier/classify.cpp @@ -133,7 +133,7 @@ int Classify::readTaxonomy(string file) { phyloTree->addSeqToTree(itTax->first, itTax->second); if (m->control_pressed) { break; } } - + phyloTree->assignHeirarchyIDs(0); maxLevel = phyloTree->getMaxLevel(); diff --git a/source/collect.cpp b/source/collect.cpp index 9a89020e..6b1c8830 100644 --- a/source/collect.cpp +++ b/source/collect.cpp @@ -70,15 +70,17 @@ int Collect::getCurve(float percentFreq = 0.01){ /***********************************************************************/ int Collect::getSharedCurve(float percentFreq = 0.01){ try { - vector lookup; + vector lookup; + map indexLookup; vector subset; //create and initialize vector of sharedvectors, one for each group vector mGroups = m->getGroups(); - for (int i = 0; i < mGroups.size(); i++) { + for (int i = 0; i < mGroups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins()); temp->setLabel(sharedorder->getLabel()); temp->setGroup(mGroups[i]); + indexLookup[mGroups[i]] = i; lookup.push_back(temp); } @@ -114,16 +116,9 @@ try { //get first sample individual chosen = sharedorder->get(i); - int abundance; - - //set info for sharedvector in chosens group - for (int j = 0; j < lookup.size(); j++) { - if (chosen.group == lookup[j]->getGroup()) { - abundance = lookup[j]->getAbundance(chosen.bin); - lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); - break; - } - } + int abundance = lookup[indexLookup[chosen.group]]->get(chosen.bin); + lookup[indexLookup[chosen.group]]->set(chosen.bin, (abundance + 1)); + //calculate at 0 and the given increment if((i == 0) || (i+1) % increment == 0){ diff --git a/source/collect.h b/source/collect.h index 51712331..babefe37 100644 --- a/source/collect.h +++ b/source/collect.h @@ -4,11 +4,7 @@ #include "collectorscurvedata.h" #include "display.h" #include "ordervector.hpp" -#include "sabundvector.hpp" -#include "rabundvector.hpp" #include "sharedordervector.h" -#include "datavector.hpp" -#include "mothurout.h" /***********************************************************************/ diff --git a/source/collectdisplay.h b/source/collectdisplay.h index 781cea18..8a0542f8 100644 --- a/source/collectdisplay.h +++ b/source/collectdisplay.h @@ -1,8 +1,6 @@ #ifndef COLLECTDISPLAY_H #define COLLECTDISPLAY_H -#include "sabundvector.hpp" -#include "sharedsabundvector.h" #include "calculator.h" #include "fileoutput.h" #include "display.h" @@ -23,23 +21,23 @@ class CollectDisplay : public Display { output->output(nSeqs, data); }; - void update(vector shared, int numSeqs, int numGroups){ - timesCalled++; - data = estimate->getValues(shared); //passes estimators a shared vector from each group to be compared - - //figure out what groups are being compared in getValues - //because we randomizes the order we need to put the results in the correct column in the output file - int group1Index, group2Index, pos; - - vector mGroups = m->getGroups(); - for (int i = 0; i < mGroups.size(); i++) { - if (shared[0]->getGroup() == mGroups[i]) { group1Index = i; } - if (shared[1]->getGroup() == mGroups[i]) { group2Index = i; } - } - - numGroupComb = 0; - int n = 1; - for (int i = 0; i < (numGroups - 1); i++) { + void update(vector shared, int numSeqs, int numGroups){ + timesCalled++; + data = estimate->getValues(shared); //passes estimators a shared vector from each group to be compared + + //figure out what groups are being compared in getValues + //because we randomizes the order we need to put the results in the correct column in the output file + int group1Index, group2Index, pos; + + vector mGroups = m->getGroups(); + for (int i = 0; i < mGroups.size(); i++) { + if (shared[0]->getGroup() == mGroups[i]) { group1Index = i; } + if (shared[1]->getGroup() == mGroups[i]) { group2Index = i; } + } + + numGroupComb = 0; + int n = 1; + for (int i = 0; i < (numGroups - 1); i++) { for (int l = n; l < numGroups; l++) { if ((group1Index == i) && (group2Index == l)) { pos = numGroupComb; //pos tells you which column in the output file you are in diff --git a/source/collectorscurvedata.h b/source/collectorscurvedata.h index d32a9e06..c112c637 100644 --- a/source/collectorscurvedata.h +++ b/source/collectorscurvedata.h @@ -2,7 +2,7 @@ #define COLLECTORSCURVEDATA_H #include "sabundvector.hpp" -#include "sharedrabundvector.h" +#include "sharedrabundvectors.hpp" #include "display.h" #include "observable.h" diff --git a/source/commands/aligncommand.cpp b/source/commands/aligncommand.cpp index aa3d871a..8b707982 100644 --- a/source/commands/aligncommand.cpp +++ b/source/commands/aligncommand.cpp @@ -29,7 +29,7 @@ vector AlignCommand::setParameters(){ CommandParameter pgapopen("gapopen", "Number", "", "-5.0", "", "", "","",false,false); parameters.push_back(pgapopen); CommandParameter pgapextend("gapextend", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapextend); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); - CommandParameter pflip("flip", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pflip); + CommandParameter pflip("flip", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pflip); CommandParameter pthreshold("threshold", "Number", "", "0.50", "", "", "","",false,false); parameters.push_back(pthreshold); CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); @@ -60,7 +60,7 @@ string AlignCommand::getHelpString(){ helpString += "The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -2.0."; helpString += "The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold. The default is false."; helpString += "The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment."; - helpString += "If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported."; + helpString += "If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported. Default=t"; helpString += "The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed."; helpString += "The align.seqs command should be in the following format:"; helpString += "align.seqs(reference=yourTemplateFile, fasta=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty)"; @@ -256,7 +256,7 @@ AlignCommand::AlignCommand(string option) { m->setProcessors(temp); m->mothurConvert(temp, processors); - temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "f"; } + temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "t"; } flip = m->isTrue(temp); //this has to go after save so that if the user sets save=t and provides no reference we abort @@ -309,6 +309,9 @@ int AlignCommand::execute(){ string accnosFileName = getOutputFileName("accnos", variables); bool hasAccnos = true; + vector numFlipped; + numFlipped.push_back(0); //numflipped because reverse was better + numFlipped.push_back(0); //total number of sequences with over 50% of bases removed int numFastaSeqs = 0; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); @@ -337,9 +340,9 @@ int AlignCommand::execute(){ #endif if(processors == 1){ - numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); + numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s], numFlipped); }else{ - numFastaSeqs = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); + numFastaSeqs = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s], numFlipped); } if (m->control_pressed) { m->mothurRemove(accnosFileName); m->mothurRemove(alignFileName); m->mothurRemove(reportFileName); outputTypes.clear(); return 0; } @@ -347,10 +350,10 @@ int AlignCommand::execute(){ //delete accnos file if its blank else report to user if (m->isBlank(accnosFileName)) { m->mothurRemove(accnosFileName); hasAccnos = false; } else { - m->mothurOut("[WARNING]: Some of your sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); + m->mothurOut("[WARNING]: " + toString(numFlipped[1]) + " of your sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { - m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); - }else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); } + m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well. flip=t"); + }else{ m->mothurOut("[NOTE]: " + toString(numFlipped[0]) + " of your sequences were reversed to produce a better alignment."); } m->mothurOutEndLine(); } @@ -384,7 +387,7 @@ int AlignCommand::execute(){ } //********************************************************************************************************************** -int AlignCommand::driver(linePair* filePos, string alignFName, string reportFName, string accnosFName, string filename){ +long long AlignCommand::driver(linePair* filePos, string alignFName, string reportFName, string accnosFName, string filename, vector& numFlipped){ try { ofstream alignmentFile; m->openOutputFile(alignFName, alignmentFile); @@ -400,7 +403,9 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam inFASTA.seekg(filePos->start); bool done = false; - int count = 0; + long long count = 0; + numFlipped[0] = 0; + numFlipped[1] = 0; //moved this into driver to avoid deep copies in windows paralellized version Alignment* alignment; @@ -449,7 +454,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam //if there is a possibility that this sequence should be reversed if (candidateSeq->getNumBases() < numBasesNeeded) { - + numFlipped[1]++; string wasBetter = ""; //if the user wants you to try the reverse if (flip) { @@ -481,6 +486,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam nast = nast2; needToDeleteCopy = true; wasBetter = "\treverse complement produced a better alignment, so mothur used the reverse complement."; + numFlipped[0]++; }else{ wasBetter = "\treverse complement did NOT produce a better alignment so it was not used, please check sequence."; delete nast2; @@ -538,7 +544,7 @@ int AlignCommand::driver(linePair* filePos, string alignFName, string reportFNam } /**************************************************************************************************/ -int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) { +long long AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename, vector& numFlipped) { try { int num = 0; processIDS.resize(0); @@ -555,13 +561,14 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ - num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); + num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename, numFlipped); //pass numSeqs to parent ofstream out; string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; m->openOutputFile(tempFile, out); out << num << endl; + out << numFlipped[0] << endl << numFlipped[1] << endl; out.close(); exit(0); @@ -598,13 +605,14 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ - num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); + num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename, numFlipped); //pass numSeqs to parent ofstream out; string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; m->openOutputFile(tempFile, out); out << num << endl; + out << numFlipped[0] << endl << numFlipped[1] << endl; out.close(); exit(0); @@ -617,7 +625,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s } //do my part - num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename); + num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename, numFlipped); //force parent to wait until all the processes are done for (int i=0;iopenInputFile(tempFile, in); - if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } + if (!in.eof()) { + int tempNum = 0; + in >> tempNum; num += tempNum; m->gobble(in); + in >> tempNum; numFlipped[0] += tempNum; m->gobble(in); + in >> tempNum; numFlipped[1] += tempNum; m->gobble(in); + } in.close(); m->mothurRemove(tempFile); m->appendFiles((alignFileName + toString(processIDS[i]) + ".temp"), alignFileName); @@ -701,7 +714,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s //using the main process as a worker saves time and memory //do my part - do last piece because windows is looking for eof - num = driver(lines[processors-1], (alignFileName + toString(processors-1) + ".temp"), (reportFileName + toString(processors-1) + ".temp"), (accnosFName + toString(processors-1) + ".temp"), filename); + num = driver(lines[processors-1], (alignFileName + toString(processors-1) + ".temp"), (reportFileName + toString(processors-1) + ".temp"), (accnosFName + toString(processors-1) + ".temp"), filename, numFlipped); //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); @@ -712,6 +725,8 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; } num += pDataArray[i]->count; + numFlipped[0] += pDataArray[i]->numFlipped[0]; + numFlipped[1] += pDataArray[i]->numFlipped[1]; CloseHandle(hThreadArray[i]); delete pDataArray[i]; } diff --git a/source/commands/aligncommand.h b/source/commands/aligncommand.h index 01c40cef..5bbaa161 100644 --- a/source/commands/aligncommand.h +++ b/source/commands/aligncommand.h @@ -49,8 +49,8 @@ class AlignCommand : public Command { AlignmentDB* templateDB; - int driver(linePair*, string, string, string, string); - int createProcesses(string, string, string, string); + long long driver(linePair*, string, string, string, string, vector&); + long long createProcesses(string, string, string, string, vector&); void appendReportFiles(string, string); string candidateFileName, templateFileName, distanceFileName, search, align, outputDir; @@ -79,7 +79,7 @@ struct alignData { unsigned long long start; unsigned long long end; MothurOut* m; - //AlignmentDB* templateDB; + vector numFlipped; float match, misMatch, gapOpen, gapExtend, threshold; int count, kmerSize, threadID; @@ -151,6 +151,8 @@ static DWORD WINAPI MyAlignThreadFunction(LPVOID lpParam){ } pDataArray->count = 0; + pDataArray->numFlipped[0] = 0; + pDataArray->numFlipped[1] = 0; for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process if (pDataArray->m->control_pressed) { break; } @@ -184,7 +186,7 @@ static DWORD WINAPI MyAlignThreadFunction(LPVOID lpParam){ //if there is a possibility that this sequence should be reversed if (candidateSeq->getNumBases() < numBasesNeeded) { - + pDataArray->numFlipped[1]++; string wasBetter = ""; //if the user wants you to try the reverse if (pDataArray->flip) { @@ -210,6 +212,7 @@ static DWORD WINAPI MyAlignThreadFunction(LPVOID lpParam){ nast = nast2; needToDeleteCopy = true; wasBetter = "\treverse complement produced a better alignment, so mothur used the reverse complement."; + pDataArray->numFlipped[0]++; }else{ wasBetter = "\treverse complement did NOT produce a better alignment so it was not used, please check sequence."; delete nast2; diff --git a/source/commands/biominfocommand.cpp b/source/commands/biominfocommand.cpp index 55933497..80ad6588 100644 --- a/source/commands/biominfocommand.cpp +++ b/source/commands/biominfocommand.cpp @@ -442,15 +442,15 @@ int BiomInfoCommand::createFilesFromBiom() { m->currentSharedBinLabels = otuNames; //read data - vector lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size()); + SharedRAbundVectors* lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size()); - m->mothurOutEndLine(); m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - lookup[0]->printHeaders(out); - printSharedData(lookup, out); + m->mothurOutEndLine(); m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + lookup->printHeaders(out); + lookup->print(out); if (conTaxonomy.size() != 0) { //sanity check - if ((lookup[0]->getNumBins() == conTaxonomy.size()) && (lookup[0]->getNumBins() == otuNames.size())) { + if ((lookup->getNumBins() == conTaxonomy.size()) && (lookup->getNumBins() == otuNames.size())) { //write taxonomy file map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename)); @@ -464,14 +464,15 @@ int BiomInfoCommand::createFilesFromBiom() { CountTable* ct = NULL; if (basis == "otu") { ct = new CountTable(); - for (int j = 0; j < lookup.size(); j++) { ct->addGroup(lookup[j]->getGroup()); } + vector groupNames = lookup->getNamesGroups(); + for (int j = 0; j < groupNames.size(); j++) { ct->addGroup(groupNames[j]); } - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); for (int i = 0; i < numBins; i++) { vector abunds; - for (int j = 0; j < lookup.size(); j++) { + for (int j = 0; j < lookup->size(); j++) { if (m->control_pressed) { break; } - abunds.push_back(lookup[j]->getAbundance(i)); + abunds.push_back(lookup->get(i, groupNames[j])); } ct->push_back(otuNames[i], abunds); } @@ -479,14 +480,15 @@ int BiomInfoCommand::createFilesFromBiom() { PhyloSummary taxaSum(ct, relabund, printlevel); - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { break; } int total = 0; map containsGroup; - for (int j = 0; j < lookup.size(); j++) { - total += lookup[j]->getAbundance(i); - containsGroup[lookup[j]->getGroup()] = lookup[j]->getAbundance(i); + for (int j = 0; j < lookup->size(); j++) { + int abund = lookup->get(i, groupNames[j]); + total += abund; + containsGroup[groupNames[j]] = abund; } string newTax = m->addUnclassifieds(conTaxonomy[i], maxLevel, false); @@ -516,7 +518,7 @@ int BiomInfoCommand::createFilesFromBiom() { } } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } return 0; @@ -527,17 +529,16 @@ int BiomInfoCommand::createFilesFromBiom() { } } //********************************************************************************************************************** -vector BiomInfoCommand::readData(string matrixFormat, string line, string matrixElementType, vector& groupNames, int numOTUs) { +SharedRAbundVectors* BiomInfoCommand::readData(string matrixFormat, string line, string matrixElementType, vector& groupNames, int numOTUs) { try { - - vector lookup; + SharedRAbundVectors* lookup = new SharedRAbundVectors(); //creates new sharedRAbunds for (int i = 0; i < groupNames.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(numOTUs); //sets all abunds to 0 temp->setLabel(label); temp->setGroup(groupNames[i]); - lookup.push_back(temp); + lookup->push_back(temp); } bool dataStart = false; @@ -568,11 +569,11 @@ vector BiomInfoCommand::readData(string matrixFormat, strin if (matrixFormat == "dense") { //sanity check - if (nums.size() != lookup.size()) { m->mothurOut("[ERROR]: trouble parsing OTU data. OTU " + toString(otuCount) + " causing errors.\n"); m->control_pressed = true; } + if (nums.size() != lookup->size()) { m->mothurOut("[ERROR]: trouble parsing OTU data. OTU " + toString(otuCount) + " causing errors.\n"); m->control_pressed = true; } //set abundances for this otu //nums contains [abundSample0, abundSample1, abundSample2, ...] for current OTU - for (int j = 0; j < lookup.size(); j++) { lookup[j]->set(otuCount, nums[j], groupNames[j]); } + for (int j = 0; j < groupNames.size(); j++) { lookup->set(otuCount, nums[j], groupNames[j]); } otuCount++; }else { @@ -580,7 +581,7 @@ vector BiomInfoCommand::readData(string matrixFormat, strin if (nums.size() != 3) { m->mothurOut("[ERROR]: trouble parsing OTU data.\n"); m->control_pressed = true; } //nums contains [otuNum, sampleNum, abundance] - lookup[nums[1]]->set(nums[0], nums[2], groupNames[nums[1]]); + lookup->set(nums[0], nums[2], groupNames[nums[1]]); } nums.clear(); } @@ -851,8 +852,8 @@ string BiomInfoCommand::getTag(string& line) { exit(1); } } -//********************************************************************************************************************** -void BiomInfoCommand::printSharedData(vector thislookup, ofstream& out) { +/********************************************************************************************************************** +void BiomInfoCommand::printSharedData(SharedRAbundVectors* thislookup, ofstream& out) { try { //sorts alphabetically @@ -877,4 +878,6 @@ void BiomInfoCommand::printSharedData(vector thislookup, of } } -//********************************************************************************************************************** +//**********************************************************************************************************************/ + + diff --git a/source/commands/biominfocommand.h b/source/commands/biominfocommand.h index f624402c..85bb85bb 100644 --- a/source/commands/biominfocommand.h +++ b/source/commands/biominfocommand.h @@ -37,14 +37,14 @@ class BiomInfoCommand : public Command { void help() { m->mothurOut(getHelpString()); } private: - void printSharedData(vector, ofstream&); + void printSharedData(SharedRAbundVectors*, ofstream&); int createFilesFromBiom(); string getTag(string&); string getName(string); string getTaxonomy(string, string); vector< vector > readRows(string, int&, bool&); int getDims(string, int&, int&); - vector readData(string, string, string, vector&, int); + SharedRAbundVectors* readData(string, string, string, vector&, int); vector getNamesAndTaxonomies(string); vector outputNames; diff --git a/source/commands/catchallcommand.cpp b/source/commands/catchallcommand.cpp index 4d65bd69..2c51cd14 100644 --- a/source/commands/catchallcommand.cpp +++ b/source/commands/catchallcommand.cpp @@ -716,29 +716,28 @@ vector CatchAllCommand::parseSharedFile(string filename) { //read first line InputData input(filename, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - + SharedRAbundVectors* shared = input.getSharedRAbundVectors(); + groups = shared->getNamesGroups(); string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename)); //clears file before we start to write to it below - for (int i=0; imothurRemove((sharedFileRoot + lookup[i]->getGroup() + ".sabund")); - filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".sabund")); - groups.push_back(lookup[i]->getGroup()); + for (int i=0; imothurRemove((sharedFileRoot + groups[i] + ".sabund")); + filenames.push_back((sharedFileRoot + groups[i] + ".sabund")); } - - while(lookup[0] != NULL) { - + + while(shared != NULL) { + vector lookup = shared->getSharedRAbundVectors(); for (int i = 0; i < lookup.size(); i++) { SAbundVector sav = lookup[i]->getSAbundVector(); ofstream out; - m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".sabund", out); + m->openOutputFileAppend(sharedFileRoot + groups[i] + ".sabund", out); sav.print(out); out.close(); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input.getSharedRAbundVectors(); + for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } lookup[i] = NULL; } + shared = input.getSharedRAbundVectors(); } return filenames; diff --git a/source/commands/chimerauchimecommand.cpp b/source/commands/chimerauchimecommand.cpp index 952a3aba..81f6ab59 100644 --- a/source/commands/chimerauchimecommand.cpp +++ b/source/commands/chimerauchimecommand.cpp @@ -67,7 +67,7 @@ string ChimeraUchimeCommand::getHelpString(){ helpString += "The count parameter allows you to provide a count file, if you are using template=self. When you use a count file with group info and dereplicate=T, mothur will create a *.pick.count_table file containing seqeunces after chimeras are removed. \n"; helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n"; helpString += "The group parameter allows you to provide a group file. The group file can be used with a namesfile and reference=self. When checking sequences, only sequences from the same group as the query sequence will be used as the reference. \n"; - helpString += "If the dereplicate parameter is false, then if one group finds the seqeunce to be chimeric, then all groups find it to be chimeric, default=f.\n"; + helpString += "If the dereplicate parameter is false, then if one group finds the sequence to be chimeric, then all groups find it to be chimeric, default=f.\n"; helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. You may also set template=self, in this case the abundant sequences will be used as potential parents. \n"; helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; helpString += "The abskew parameter can only be used with template=self. Minimum abundance skew. Default 1.9. Abundance skew is: min [ abund(parent1), abund(parent2) ] / abund(query).\n"; @@ -959,7 +959,7 @@ int ChimeraUchimeCommand::deconvoluteResults(map& uniqueNames, s else { out << itUnique->second << restOfName << '\t'; } }else { out << parent2 << '\t'; } - out << temp2 << '\t' << temp3 << '\t' << temp4 << '\t' << temp5 << '\t' << temp6 << '\t' << temp7 << '\t' << temp8 << '\t' << temp9 << '\t' << temp10 << '\t' << temp11 << '\t' << temp12 << temp13 << '\t' << flag << endl; + out << temp2 << '\t' << temp3 << '\t' << temp4 << '\t' << temp5 << '\t' << temp6 << '\t' << temp7 << '\t' << temp8 << '\t' << temp9 << '\t' << temp10 << '\t' << temp11 << '\t' << temp12 << '\t' << temp13 << '\t' << flag << endl; } } in.close(); diff --git a/source/commands/chimeravsearchcommand.cpp b/source/commands/chimeravsearchcommand.cpp index ae45768a..740b0165 100644 --- a/source/commands/chimeravsearchcommand.cpp +++ b/source/commands/chimeravsearchcommand.cpp @@ -54,7 +54,7 @@ string ChimeraVsearchCommand::getHelpString(){ helpString += "The count parameter allows you to provide a count file, if you are using template=self. When you use a count file with group info and dereplicate=T, mothur will create a *.pick.count_table file containing seqeunces after chimeras are removed. \n"; helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n"; helpString += "The group parameter allows you to provide a group file. The group file can be used with a namesfile and reference=self. When checking sequences, only sequences from the same group as the query sequence will be used as the reference. \n"; - helpString += "If the dereplicate parameter is false, then if one group finds the seqeunce to be chimeric, then all groups find it to be chimeric, default=f.\n"; + helpString += "If the dereplicate parameter is false, then if one group finds the sequence to be chimeric, then all groups find it to be chimeric, default=f.\n"; helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. You may also set template=self, in this case the abundant sequences will be used as potential parents. \n"; helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; helpString += "The abskew parameter can only be used with template=self. Minimum abundance skew. Default 1.9. Abundance skew is: min [ abund(parent1), abund(parent2) ] / abund(query).\n"; @@ -731,7 +731,7 @@ int ChimeraVsearchCommand::execute(){ //remove file made for uchime if (templatefile == "self") { m->mothurRemove(fastaFileNames[s]); } - m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences. " + toString(numChimeras) + " chimeras were found."); m->mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check your sequences. " + toString(numChimeras) + " chimeras were found."); m->mothurOutEndLine(); } outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); @@ -919,7 +919,7 @@ int ChimeraVsearchCommand::deconvoluteResults(map& uniqueNames, else { out << itUnique->second << restOfName << '\t'; } }else { out << parent3 << '\t'; } - out << temp2 << '\t' << temp3 << '\t' << temp4 << '\t' << temp5 << '\t' << temp6 << '\t' << temp7 << '\t' << temp8 << '\t' << temp9 << '\t' << temp10 << '\t' << temp11 << '\t' << temp12 << temp13 << '\t' << flag << endl; + out << temp2 << '\t' << temp3 << '\t' << temp4 << '\t' << temp5 << '\t' << temp6 << '\t' << temp7 << '\t' << temp8 << '\t' << temp9 << '\t' << temp10 << '\t' << temp11 << '\t' << temp12 << '\t' << temp13 << '\t' << flag << endl; } } in.close(); diff --git a/source/commands/classifyrfsharedcommand.cpp b/source/commands/classifyrfsharedcommand.cpp index 2258e3a8..0a05841b 100644 --- a/source/commands/classifyrfsharedcommand.cpp +++ b/source/commands/classifyrfsharedcommand.cpp @@ -269,46 +269,50 @@ int ClassifyRFSharedCommand::execute() { }*/ InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + string lastLabel = lookup->getLabel(); set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - processSharedAndDesignData(lookup); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processSharedAndDesignData(lookup); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -333,14 +337,16 @@ int ClassifyRFSharedCommand::execute() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - processSharedAndDesignData(lookup); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } @@ -359,7 +365,7 @@ int ClassifyRFSharedCommand::execute() { } //********************************************************************************************************************** -void ClassifyRFSharedCommand::processSharedAndDesignData(vector lookup){ +void ClassifyRFSharedCommand::processSharedAndDesignData(vector lookup){ try { // for (int i = 0; i < designMap->getNamesOfGroups().size(); i++) { // string groupName = designMap->getNamesOfGroups()[i]; @@ -398,7 +404,7 @@ void ClassifyRFSharedCommand::processSharedAndDesignData(vectorgetNumBins(); j++) { - int otuCount = lookup[i]->getAbundance(j); + int otuCount = lookup[i]->get(j); dataSet[i][j] = otuCount; } dataSet[i][j] = treatmentToIntMap[treatmentName]; diff --git a/source/commands/classifysvmsharedcommand.cpp b/source/commands/classifysvmsharedcommand.cpp index 21a41657..22abc8de 100644 --- a/source/commands/classifysvmsharedcommand.cpp +++ b/source/commands/classifysvmsharedcommand.cpp @@ -43,15 +43,6 @@ vector ClassifySvmSharedCommand::setParameters() { CommandParameter verbosityParam("verbose", "Number", "", "0", "", "", "", "", false, false); parameters.push_back(verbosityParam); - //CommandParameter potupersplit("otupersplit", "Multiple", "log2-squareroot", "log2", "", "", "","",false,false); parameters.push_back(potupersplit); - //CommandParameter psplitcriteria("splitcriteria", "Multiple", "gainratio-infogain", "gainratio", "", "", "","",false,false); parameters.push_back(psplitcriteria); - //CommandParameter pnumtrees("numtrees", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pnumtrees); - - // parameters related to pruning - //CommandParameter pdopruning("prune", "Boolean", "", "T", "", "", "", "", false, false); parameters.push_back(pdopruning); - //CommandParameter ppruneaggrns("pruneaggressiveness", "Number", "", "0.9", "", "", "", "", false, false); parameters.push_back(ppruneaggrns); - //CommandParameter pdiscardhetrees("discarderrortrees", "Boolean", "", "T", "", "", "", "", false, false); parameters.push_back(pdiscardhetrees); - //CommandParameter phetdiscardthreshold("errorthreshold", "Number", "", "0.4", "", "", "", "", false, false); parameters.push_back(phetdiscardthreshold); // want this parameter to behave like the one in classify.rf CommandParameter pstdthreshold("stdthreshold", "Number", "", "0.0", "", "", "", "", false, false); @@ -132,17 +123,6 @@ ClassifySvmSharedCommand::ClassifySvmSharedCommand() { } } -// here is a little function from StackExchange for splitting a string on a single character -// allows return value optimization -//vector& split(const string &s, char delim, vector& elems) { -// stringstream ss(s); -// string item; -// while (getline(ss, item, delim)) { -// elems.push_back(item); -// } -// return elems; -//} - //********************************************************************************************************************** ClassifySvmSharedCommand::ClassifySvmSharedCommand(string option) { try { @@ -462,48 +442,51 @@ int ClassifySvmSharedCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); //read design file designMap.read(designfile); - string lastLabel = lookup[0]->getLabel(); + string lastLabel = lookup->getLabel(); set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processSharedAndDesignData(lookup); - - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processSharedAndDesignData(lookup); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -528,14 +511,16 @@ int ClassifySvmSharedCommand::execute() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - processSharedAndDesignData(lookup); + vector data = lookup->getSharedRAbundVectors(); + processSharedAndDesignData(data); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } @@ -561,13 +546,16 @@ int ClassifySvmSharedCommand::execute() { // where the vector in the second position of the pair records OTU abundances. void ClassifySvmSharedCommand::readSharedAndDesignFiles(const string& sharedFilePath, const string& designFilePath, LabeledObservationVector& labeledObservationVector, FeatureVector& featureVector) { InputData input(sharedFilePath, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); DesignMap designMap; designMap.read(designFilePath); - while ( lookup[0] != NULL ) { - readSharedRAbundVectors(lookup, designMap, labeledObservationVector, featureVector); + while ( lookup != NULL ) { + vector data = lookup->getSharedRAbundVectors(); + readSharedRAbundVectors(data, designMap, labeledObservationVector, featureVector); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); + delete lookup; lookup = input.getSharedRAbundVectors(); } } @@ -575,17 +563,17 @@ void ClassifySvmSharedCommand::readSharedAndDesignFiles(const string& sharedFile void ClassifySvmSharedCommand::readSharedRAbundVectors(vector& lookup, DesignMap& designMap, LabeledObservationVector& labeledObservationVector, FeatureVector& featureVector) { for ( int j = 0; j < lookup.size(); j++ ) { //i++; - vector data = lookup[j]->getData(); - Observation* observation = new Observation(data.size(), 0.0); + //vector data = lookup[j]->getData(); + Observation* observation = new Observation(lookup[j]->getNumBins(), 0.0); string sharedGroupName = lookup[j]->getGroup(); string treatmentName = designMap.get(sharedGroupName); //cout << "shared group name: " << sharedGroupName << " treatment name: " << treatmentName << endl; //labeledObservationVector.push_back(make_pair(treatmentName, observation)); labeledObservationVector.push_back(LabeledObservation(j, treatmentName, observation)); //cout << " j=" << j << " label : " << lookup[j]->getLabel() << " group: " << lookup[j]->getGroup(); - for (int k = 0; k < data.size(); k++) { + for (int k = 0; k < lookup[j]->size(); k++) { //cout << " abundance " << data[k].abundance; - observation->at(k) = double(data[k].abundance); + observation->at(k) = double(lookup[j]->get(k)); if ( j == 0) { featureVector.push_back(Feature(k, m->currentSharedBinLabels[k])); } diff --git a/source/commands/classifysvmsharedcommand.h b/source/commands/classifysvmsharedcommand.h index a3bc4cfa..7de5e015 100644 --- a/source/commands/classifysvmsharedcommand.h +++ b/source/commands/classifysvmsharedcommand.h @@ -24,11 +24,11 @@ class ClassifySvmSharedCommand : public Command { ~ClassifySvmSharedCommand() {}; vector setParameters(); - string getCommandName() { return "classifysvm.shared"; } + string getCommandName() { return "classify.svm"; } string getCommandCategory() { return "OTU-Based Approaches"; } string getHelpString(); string getOutputPattern(string); - string getCitation() { return "http://www.mothur.org/wiki/ClassifySvm.shared\n"; } + string getCitation() { return "http://www.mothur.org/wiki/Classify.svm\n"; } string getDescription() { return "implements the support vector machine machine learning algorithm to identify OTUs that can be used to differentiate between various groups of samples"; } int execute(); @@ -37,17 +37,9 @@ class ClassifySvmSharedCommand : public Command { void readSharedAndDesignFiles(const string&, const string&, LabeledObservationVector&, FeatureVector&); void readSharedRAbundVectors(vector&, DesignMap&, LabeledObservationVector&, FeatureVector&); - //bool interruptTraining() { return m->control_pressed; } - vector& getSmocList() { return smocList; } const KernelParameterRangeMap& getKernelParameterRangeMap() { return kernelParameterRangeMap; } - //bool interruptTraining() { return m->control_pressed; } - - //std::vector& getSmocList() { return smocList; } - //const KernelParameterRangeMap& getKernelParameterRangeMap() { return kernelParameterRangeMap; } - - private: bool abort; string outputDir; @@ -62,9 +54,6 @@ class ClassifySvmSharedCommand : public Command { DesignMap designMap; - //void readSharedAndDesignFiles(const std::string&, const std::string&, LabeledObservationVector&, FeatureVector&); - //void readSharedRAbundVectors(vector&, GroupMap&, LabeledObservationVector&, FeatureVector&); - // mode is either "rfe" or "classify" string mode; @@ -79,10 +68,6 @@ class ClassifySvmSharedCommand : public Command { double stdthreshold; - //int numDecisionTrees; - //string treeSplitCriterion, optimumFeatureSubsetSelectionCriteria; - //bool doPruning, discardHighErrorTrees; - //double pruneAggressiveness, highErrorTreeDiscardThreshold, featureStandardDeviationThreshold; void processSharedAndDesignData(vector lookup); void trainSharedAndDesignData(vector lookup); diff --git a/source/commands/clustercommand.cpp b/source/commands/clustercommand.cpp index f3322823..6900187a 100644 --- a/source/commands/clustercommand.cpp +++ b/source/commands/clustercommand.cpp @@ -14,6 +14,22 @@ #include "sequence.hpp" #include "systemcommand.h" #include "sensspeccommand.h" +#include "mcc.hpp" +#include "sensitivity.hpp" +#include "specificity.hpp" +#include "fdr.hpp" +#include "npv.hpp" +#include "ppv.hpp" +#include "f1score.hpp" +#include "tp.hpp" +#include "fp.hpp" +#include "fpfn.hpp" +#include "tptn.hpp" +#include "tn.hpp" +#include "fn.hpp" +#include "accuracy.hpp" + + //********************************************************************************************************************** vector ClusterCommand::setParameters(){ @@ -262,6 +278,11 @@ ClusterCommand::ClusterCommand(string option) { } } } + if ((method != "agc") || (method != "dgc")) { + if ((columnfile == "") && (phylipfile == "")) { + m->mothurOut("[ERROR]: You must provide a distance file unless you are using the agc, dgc or unique clustering methods, aborting\n."); abort = true; + } + } }else { if ((countfile == "") && (namefile == "")) { countfile = m->getCountTableFile(); @@ -297,9 +318,9 @@ ClusterCommand::ClusterCommand(string option) { temp = validParameter.validFile(parameters, "delta", false); if (temp == "not found") { temp = "0.0001"; } m->mothurConvert(temp, stableMetric); - metric = validParameter.validFile(parameters, "metric", false); if (metric == "not found") { metric = "mcc"; } + metricName = validParameter.validFile(parameters, "metric", false); if (metricName == "not found") { metricName = "mcc"; } - if ((metric == "mcc") || (metric == "sens") || (metric == "spec") || (metric == "tptn") || (metric == "tp") || (metric == "tn") || (metric == "fp") || (metric == "fn") || (metric == "f1score") || (metric == "accuracy") || (metric == "ppv") || (metric == "npv") || (metric == "fdr") || (metric == "fpfn") ){ } + if ((metricName == "mcc") || (metricName == "sens") || (metricName == "spec") || (metricName == "tptn") || (metricName == "tp") || (metricName == "tn") || (metricName == "fp") || (metricName == "fn") || (metricName == "f1score") || (metricName == "accuracy") || (metricName == "ppv") || (metricName == "npv") || (metricName == "fdr") || (metricName == "fpfn") ){ } else { m->mothurOut("[ERROR]: Not a valid metric. Valid metrics are mcc, sens, spec, tp, tn, fp, fn, tptn, fpfn, f1score, accuracy, ppv, npv, fdr."); m->mothurOutEndLine(); abort = true; } initialize = validParameter.validFile(parameters, "initialize", false); if (initialize == "not found") { initialize = "singleton"; } @@ -861,11 +882,25 @@ int ClusterCommand::runOptiCluster(){ string distfile = columnfile; if (format == "phylip") { distfile = phylipfile; } - //int rstart = time(NULL); OptiMatrix matrix(distfile, thisNamefile, nameOrCount, format, cutoff, false); + + ClusterMetric* metric = NULL; + if (metricName == "mcc") { metric = new MCC(); } + else if (metricName == "sens") { metric = new Sensitivity(); } + else if (metricName == "spec") { metric = new Specificity(); } + else if (metricName == "tptn") { metric = new TPTN(); } + else if (metricName == "tp") { metric = new TP(); } + else if (metricName == "tn") { metric = new TN(); } + else if (metricName == "fp") { metric = new FP(); } + else if (metricName == "fn") { metric = new FN(); } + else if (metricName == "f1score") { metric = new F1Score(); } + else if (metricName == "accuracy") { metric = new Accuracy(); } + else if (metricName == "ppv") { metric = new PPV(); } + else if (metricName == "npv") { metric = new NPV(); } + else if (metricName == "fdr") { metric = new FDR(); } + else if (metricName == "fpfn") { metric = new FPFN(); } - //m->mothurOut("It took " + toString(time(NULL) - rstart) + " seconds to read and process matrix"); m->mothurOutEndLine(); OptiCluster cluster(&matrix, metric, 0); tag = cluster.getTag(); @@ -929,6 +964,8 @@ int ClusterCommand::runOptiCluster(){ } m->mothurOutEndLine(); m->mothurOutEndLine(); + if (m->control_pressed) { delete metric; metric = NULL; return 0; } + ListVector* list = cluster.getList(); list->setLabel(toString(cutoff)); if (!m->printedListHeaders) { m->listBinLabelsInFile.clear(); list->printHeaders(listFile); } diff --git a/source/commands/clustercommand.h b/source/commands/clustercommand.h index f56c62ac..0eafbe19 100644 --- a/source/commands/clustercommand.h +++ b/source/commands/clustercommand.h @@ -19,6 +19,7 @@ #include "clusterdoturcommand.h" #include "opticluster.h" #include "optimatrix.h" +#include "calculator.h" /* The cluster() command: @@ -61,7 +62,7 @@ class ClusterCommand : public Command { string method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, format, distfile, countfile, fastafile, inputDir, vsearchLocation, metric, initialize; double cutoff, stableMetric; float adjust; - string showabund, timing; + string showabund, timing, metricName; int precision, length, maxIters, processors; ofstream sabundFile, rabundFile, listFile; diff --git a/source/commands/clustersplitcommand.cpp b/source/commands/clustersplitcommand.cpp index 5a029135..dc02fecb 100644 --- a/source/commands/clustersplitcommand.cpp +++ b/source/commands/clustersplitcommand.cpp @@ -10,6 +10,20 @@ #include "clustersplitcommand.h" #include "systemcommand.h" #include "sensspeccommand.h" +#include "mcc.hpp" +#include "sensitivity.hpp" +#include "specificity.hpp" +#include "fdr.hpp" +#include "npv.hpp" +#include "ppv.hpp" +#include "f1score.hpp" +#include "tp.hpp" +#include "fp.hpp" +#include "fpfn.hpp" +#include "tptn.hpp" +#include "tn.hpp" +#include "fn.hpp" +#include "accuracy.hpp" //********************************************************************************************************************** vector ClusterSplitCommand::setParameters(){ @@ -86,7 +100,7 @@ string ClusterSplitCommand::getHelpString(){ helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; helpString += "The cluster.split command should be in the following format: \n"; helpString += "cluster.split(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision, splitmethod=yourSplitmethod, taxonomy=yourTaxonomyfile, taxlevel=yourtaxlevel) \n"; - helpString += "Example: cluster.split(column=abrecovery.dist, name=abrecovery.names, method=furthest, cutoff=0.10, precision=1000, splitmethod=classify, taxonomy=abrecovery.silva.slv.taxonomy, taxlevel=5) \n"; + helpString += "Example: cluster.split(column=abrecovery.dist, name=abrecovery.names, method=opti, cutoff=0.10, precision=1000, splitmethod=classify, taxonomy=abrecovery.silva.slv.taxonomy, taxlevel=5) \n"; return helpString; } catch(exception& e) { @@ -375,9 +389,9 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { temp = validParameter.validFile(parameters, "delta", false); if (temp == "not found") { temp = "0.0001"; } m->mothurConvert(temp, stableMetric); - metric = validParameter.validFile(parameters, "metric", false); if (metric == "not found") { metric = "mcc"; } + metricName = validParameter.validFile(parameters, "metric", false); if (metricName == "not found") { metricName = "mcc"; } - if ((metric == "mcc") || (metric == "sens") || (metric == "spec") || (metric == "tptn") || (metric == "tp") || (metric == "tn") || (metric == "fp") || (metric == "fn") || (metric == "f1score") || (metric == "accuracy") || (metric == "ppv") || (metric == "npv") || (metric == "fdr") || (metric == "fpfn") ){ } + if ((metricName == "mcc") || (metricName == "sens") || (metricName == "spec") || (metricName == "tptn") || (metricName == "tp") || (metricName == "tn") || (metricName == "fp") || (metricName == "fn") || (metricName == "f1score") || (metricName == "accuracy") || (metricName == "ppv") || (metricName == "npv") || (metricName == "fdr") || (metricName == "fpfn") ){ } else { m->mothurOut("[ERROR]: Not a valid metric. Valid metrics are mcc, sens, spec, tp, tn, fp, fn, tptn, fpfn, f1score, accuracy, ppv, npv, fdr."); m->mothurOutEndLine(); abort = true; } initialize = validParameter.validFile(parameters, "initialize", false); if (initialize == "not found") { initialize = "singleton"; } @@ -385,7 +399,6 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { if ((initialize == "singleton") || (initialize == "oneotu")){ } else { m->mothurOut("[ERROR]: Not a valid initialization. Valid initializations are singleton and oneotu."); m->mothurOutEndLine(); abort = true; } - method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "opti"; m->mothurOut("[NOTE]: Default clustering method has changed to opti. To use average neighbor, set method=average."); m->mothurOutEndLine(); } if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "weighted") || (method == "agc") || (method == "dgc") || (method == "opti")) { } @@ -1399,6 +1412,22 @@ string ClusterSplitCommand::runOptiCluster(string thisDistFile, string thisNamef OptiMatrix matrix(thisDistFile, thisNamefile, nameOrCount, "column", cutoff, false); + ClusterMetric* metric = NULL; + if (metricName == "mcc") { metric = new MCC(); } + else if (metricName == "sens") { metric = new Sensitivity(); } + else if (metricName == "spec") { metric = new Specificity(); } + else if (metricName == "tptn") { metric = new TPTN(); } + else if (metricName == "tp") { metric = new TP(); } + else if (metricName == "tn") { metric = new TN(); } + else if (metricName == "fp") { metric = new FP(); } + else if (metricName == "fn") { metric = new FN(); } + else if (metricName == "f1score") { metric = new F1Score(); } + else if (metricName == "accuracy") { metric = new Accuracy(); } + else if (metricName == "ppv") { metric = new PPV(); } + else if (metricName == "npv") { metric = new NPV(); } + else if (metricName == "fdr") { metric = new FDR(); } + else if (metricName == "fpfn") { metric = new FPFN(); } + OptiCluster cluster(&matrix, metric, numSingletons); tag = cluster.getTag(); @@ -1425,6 +1454,8 @@ string ClusterSplitCommand::runOptiCluster(string thisDistFile, string thisNamef iters++; } + if (m->control_pressed) { delete metric; metric = NULL; return 0; } + ListVector* list = cluster.getList(); list->setLabel(toString(smallestCutoff)); cutoff = m->ceilDist(cutoff, precision); diff --git a/source/commands/clustersplitcommand.h b/source/commands/clustersplitcommand.h index bf76c442..2fc0eb07 100644 --- a/source/commands/clustersplitcommand.h +++ b/source/commands/clustersplitcommand.h @@ -26,6 +26,7 @@ #include "clusterclassic.h" #include "vsearchfileparser.h" #include "opticluster.h" +#include "calculator.h" class ClusterSplitCommand : public Command { @@ -50,7 +51,7 @@ class ClusterSplitCommand : public Command { vector processIDS; //processid vector outputNames; - string file, method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, countfile, distfile, format, showabund, timing, splitmethod, taxFile, fastafile, inputDir, vsearchLocation, metric, initialize; + string file, method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, countfile, distfile, format, showabund, timing, splitmethod, taxFile, fastafile, inputDir, vsearchLocation, metricName, initialize; double cutoff, splitcutoff, stableMetric; int precision, length, processors, taxLevelCutoff, maxIters; bool print_start, abort, large, classic, runCluster, deleteFiles, isList, cutoffNotSet, makeDist, runsensSpec; diff --git a/source/commands/collectcommand.cpp b/source/commands/collectcommand.cpp index 5fa5e61a..33628e91 100644 --- a/source/commands/collectcommand.cpp +++ b/source/commands/collectcommand.cpp @@ -601,33 +601,34 @@ vector CollectCommand::parseSharedFile(string filename) { map::iterator it3; input = new InputData(filename, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); + SharedRAbundVectors* shared = input->getSharedRAbundVectors(); string sharedFileRoot = m->getRootName(filename); + groups = shared->getNamesGroups(); //clears file before we start to write to it below - for (int i=0; igetGroup(); + string group = groups[i]; m->openOutputFile((sharedFileRoot + group + ".rabund"), temp); + temp.close(); filenames.push_back((sharedFileRoot + group + ".rabund")); files[group] = (sharedFileRoot + group + ".rabund"); - groups.push_back(group); } - while(lookup[0] != NULL) { - + while(shared != NULL) { + + vector lookup = shared->getSharedRAbundVectors(); for (int i = 0; i < lookup.size(); i++) { - RAbundVector rav = lookup[i]->getRAbundVector(); ofstream temp; - string group = lookup[i]->getGroup(); + string group = groups[i]; m->openOutputFileAppend(files[group], temp); - rav.print(temp); + lookup[i]->getRAbundVector().print(temp); temp.close(); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } lookup[i] = NULL; } + shared = input->getSharedRAbundVectors(); } delete input; diff --git a/source/commands/collectcommand.h b/source/commands/collectcommand.h index 8423b7b7..0255db76 100644 --- a/source/commands/collectcommand.h +++ b/source/commands/collectcommand.h @@ -13,7 +13,6 @@ #include "ordervector.hpp" #include "inputdata.h" #include "collect.h" -#include "display.h" #include "validcalculator.h" /*The collect() command: @@ -54,14 +53,14 @@ class CollectCommand : public Command { vector cDisplays; int abund, size, alpha; float freq; - vector outputNames; + vector outputNames, groups; bool abort, allLines; set labels; //holds labels to be used string label, calc, outputDir, sharedfile, listfile, rabundfile, sabundfile, format, inputfile; vector Estimators; vector inputFileNames; - vector groups; + vector parseSharedFile(string); diff --git a/source/commands/cooccurrencecommand.cpp b/source/commands/cooccurrencecommand.cpp index 03153040..bafc8790 100644 --- a/source/commands/cooccurrencecommand.cpp +++ b/source/commands/cooccurrencecommand.cpp @@ -183,9 +183,9 @@ int CooccurrenceCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - InputData* input = new InputData(sharedfile, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + InputData input(sharedfile, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -201,46 +201,45 @@ int CooccurrenceCommand::execute(){ out << "metric\tlabel\tScore\tzScore\tstandardDeviation\tnp_Pvalue\n"; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } delete input; out.close(); m->mothurRemove(outputFileName); return 0; } + if (m->control_pressed) { delete lookup; out.close(); m->mothurRemove(outputFileName); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getCooccurrence(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getCooccurrence(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); - //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + lastLabel = lookup->getLabel(); + delete lookup; - if (m->control_pressed) { outputTypes.clear(); delete input; out.close(); m->mothurRemove(outputFileName); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(outputFileName); return 0; } //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { delete input; out.close(); m->mothurRemove(outputFileName); return 0; } + if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -257,20 +256,19 @@ int CooccurrenceCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getCooccurrence(lookup, out); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } out.close(); - //reset groups parameter - delete input; + //reset groups parameter m->clearGroups(); m->mothurOutEndLine(); @@ -287,25 +285,27 @@ int CooccurrenceCommand::execute(){ } //********************************************************************************************************************** -int CooccurrenceCommand::getCooccurrence(vector& thisLookUp, ofstream& out){ +int CooccurrenceCommand::getCooccurrence(SharedRAbundVectors*& thisLookUp, ofstream& out){ try { - int numOTUS = thisLookUp[0]->getNumBins(); + int numOTUS = thisLookUp->getNumBins(); if(numOTUS < 2) { m->mothurOut("Not enough OTUs for co-occurrence analysis, skipping"); m->mothurOutEndLine(); return 0; } - vector< vector > co_matrix; co_matrix.resize(thisLookUp[0]->getNumBins()); - for (int i = 0; i < thisLookUp[0]->getNumBins(); i++) { co_matrix[i].resize((thisLookUp.size()), 0); } - vector columntotal; columntotal.resize(thisLookUp.size(), 0); + vector< vector > co_matrix; co_matrix.resize(thisLookUp->getNumBins()); + for (int i = 0; i < thisLookUp->getNumBins(); i++) { co_matrix[i].resize((thisLookUp->size()), 0); } + vector columntotal; columntotal.resize(thisLookUp->size(), 0); vector rowtotal; rowtotal.resize(numOTUS, 0); - for (int i = 0; i < thisLookUp.size(); i++) { //nrows in the shared file - for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) { //cols of original shared file + for (int j = 0; j < thisLookUp->getNumBins(); j++) { //cols of original shared file + vector abunds = thisLookUp->getOTU(j); + for (int i = 0; i < abunds.size(); i++) { //nrows in the shared file + if (m->control_pressed) { return 0; } - int abund = thisLookUp[i]->getAbundance(j); - + int abund = abunds[i]; + if(abund > 0) { co_matrix[j][i] = 1; rowtotal[j]++; @@ -314,10 +314,11 @@ int CooccurrenceCommand::getCooccurrence(vector& thisLookUp } } + //nrows is ncols of inital matrix. All the functions need this value. They assume the transposition has already taken place and nrows and ncols refer to that matrix. //comatrix and initmatrix are still vectors of vectors of ints as in the original script. The abundancevector is only what was read in ie not a co-occurrence matrix! int nrows = numOTUS;//rows of inital matrix - int ncols = thisLookUp.size();//groups + int ncols = thisLookUp->size();//groups double initscore = 0.0; vector stats; @@ -568,7 +569,7 @@ int CooccurrenceCommand::getCooccurrence(vector& thisLookUp m->mothurOut("zscore: " + toString(zscore)); m->mothurOutEndLine(); m->mothurOut("standard deviation: " + toString(sd)); m->mothurOutEndLine(); m->mothurOut("non-parametric p-value: " + toString(pvalue)); m->mothurOutEndLine(); - out << metric << '\t' << thisLookUp[0]->getLabel() << '\t' << nullMean << '\t' << zscore << '\t' << sd << '\t' << pvalue << endl; + out << metric << '\t' << thisLookUp->getLabel() << '\t' << nullMean << '\t' << zscore << '\t' << sd << '\t' << pvalue << endl; return 0; } diff --git a/source/commands/cooccurrencecommand.h b/source/commands/cooccurrencecommand.h index 94930ac2..4da8fb78 100644 --- a/source/commands/cooccurrencecommand.h +++ b/source/commands/cooccurrencecommand.h @@ -14,7 +14,7 @@ #include "command.hpp" #include "trialswap2.h" #include "inputdata.h" -#include "sharedrabundvector.h" + class CooccurrenceCommand : public Command { @@ -46,7 +46,7 @@ class CooccurrenceCommand : public Command { vector outputNames, Groups; int runs; - int getCooccurrence(vector&, ofstream&); + int getCooccurrence(SharedRAbundVectors*&, ofstream&); }; diff --git a/source/commands/corraxescommand.cpp b/source/commands/corraxescommand.cpp index 4522b7f1..d4e9ce92 100644 --- a/source/commands/corraxescommand.cpp +++ b/source/commands/corraxescommand.cpp @@ -233,30 +233,28 @@ int CorrAxesCommand::execute(){ getSharedFloat(input); delete input; - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } - if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } + if (m->control_pressed) { delete lookupFloat; return 0; } + if (lookupFloat == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } }else if (relabundfile != "") { InputData* input = new InputData(relabundfile, "relabund"); getSharedFloat(input); delete input; - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } - if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } + if (m->control_pressed) { delete lookupFloat; return 0; } + if (lookupFloat == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } }else if (metadatafile != "") { getMetadata(); //reads metadata file and store in lookupFloat, saves column headings in metadataLabels for later - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } - if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading metadata file."); m->mothurOutEndLine(); return 0; } - - if (pickedGroups) { eliminateZeroOTUS(lookupFloat); } - + if (m->control_pressed) { delete lookupFloat; return 0; } + if (lookupFloat == NULL) { m->mothurOut("[ERROR] reading metadata file."); m->mothurOutEndLine(); return 0; } }else { m->mothurOut("[ERROR]: no file given."); m->mothurOutEndLine(); return 0; } - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + if (m->control_pressed) { delete lookupFloat; return 0; } //this is for a sanity check to make sure the axes file and shared file match - for (int i = 0; i < lookupFloat.size(); i++) { names.insert(lookupFloat[i]->getGroup()); } + vector lookupGroups = lookupFloat->getNamesGroups(); + for (int i = 0; i < lookupGroups.size(); i++) { names.insert(lookupGroups[i]); } /*************************************************************************************/ // read axes file and check for file mismatches with shared or relabund file // @@ -265,19 +263,19 @@ int CorrAxesCommand::execute(){ //read axes file map > axes = readAxes(); - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + if (m->control_pressed) { delete lookupFloat; return 0; } //sanity check, the read only adds groups that are in the shared or relabund file, but we want to make sure the axes file isn't missing anyone - if (axes.size() != lookupFloat.size()) { + if (axes.size() != lookupGroups.size()) { map >::iterator it; - for (int i = 0; i < lookupFloat.size(); i++) { - it = axes.find(lookupFloat[i]->getGroup()); - if (it == axes.end()) { m->mothurOut(lookupFloat[i]->getGroup() + " is in your shared of relabund file but not in your axes file, please correct."); m->mothurOutEndLine(); } + for (int i = 0; i < lookupGroups.size(); i++) { + it = axes.find(lookupGroups[i]); + if (it == axes.end()) { m->mothurOut(lookupGroups[i] + " is in your shared of relabund file but not in your axes file, please correct."); m->mothurOutEndLine(); } } m->control_pressed = true; } - if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } + if (m->control_pressed) { delete lookupFloat; return 0; } /*************************************************************************************/ // calc the r values // @@ -304,7 +302,7 @@ int CorrAxesCommand::execute(){ else { m->mothurOut("[ERROR]: Invalid method."); m->mothurOutEndLine(); } out.close(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; if (m->control_pressed) { return 0; } @@ -325,6 +323,7 @@ int CorrAxesCommand::calcPearson(map >& axes, ofstream& ou try { LinearAlgebra linear; + vector lookupGroups = lookupFloat->getNamesGroups(); //find average of each axis - X vector averageAxes; averageAxes.resize(numaxes, 0.0); @@ -338,17 +337,14 @@ int CorrAxesCommand::calcPearson(map >& axes, ofstream& ou for (int i = 0; i < averageAxes.size(); i++) { averageAxes[i] = averageAxes[i] / (float) axes.size(); } //for each otu - for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) { + for (int i = 0; i < lookupFloat->getNumBins(); i++) { if (metadatafile == "") { out << m->currentSharedBinLabels[i]; } else { out << metadataLabels[i]; } //find the averages this otu - Y - float sumOtu = 0.0; - for (int j = 0; j < lookupFloat.size(); j++) { - sumOtu += lookupFloat[j]->getAbundance(i); - } - float Ybar = sumOtu / (float) lookupFloat.size(); + float sumOtu = lookupFloat->getOTUTotal(i); + float Ybar = sumOtu / (float) lookupFloat->size(); vector rValues(averageAxes.size()); @@ -359,9 +355,9 @@ int CorrAxesCommand::calcPearson(map >& axes, ofstream& ou double numerator = 0.0; double denomTerm1 = 0.0; double denomTerm2 = 0.0; - for (int j = 0; j < lookupFloat.size(); j++) { - float Yi = lookupFloat[j]->getAbundance(i); - float Xi = axes[lookupFloat[j]->getGroup()][k]; + for (int j = 0; j < lookupFloat->size(); j++) { + float Yi = lookupFloat->get(i, lookupGroups[j]); + float Xi = axes[lookupGroups[j]][k]; numerator += ((Xi - averageAxes[k]) * (Yi - Ybar)); denomTerm1 += ((Xi - averageAxes[k]) * (Xi - averageAxes[k])); @@ -377,7 +373,7 @@ int CorrAxesCommand::calcPearson(map >& axes, ofstream& ou rValues[k] = r; out << '\t' << r; - double sig = linear.calcPearsonSig(lookupFloat.size(), r); + double sig = linear.calcPearsonSig(lookupFloat->size(), r); out << '\t' << sig; } @@ -401,6 +397,7 @@ int CorrAxesCommand::calcSpearman(map >& axes, ofstream& o try { LinearAlgebra linear; + vector lookupGroups = lookupFloat->getNamesGroups(); vector sf; //format data @@ -473,7 +470,7 @@ int CorrAxesCommand::calcSpearman(map >& axes, ofstream& o //for each otu - for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) { + for (int i = 0; i < lookupFloat->getNumBins(); i++) { if (metadatafile == "") { out << m->currentSharedBinLabels[i]; } else { out << metadataLabels[i]; } @@ -481,8 +478,8 @@ int CorrAxesCommand::calcSpearman(map >& axes, ofstream& o //find the ranks of this otu - Y vector otuScores; map tableY; - for (int j = 0; j < lookupFloat.size(); j++) { - spearmanRank member(lookupFloat[j]->getGroup(), lookupFloat[j]->getAbundance(i)); + for (int j = 0; j < lookupFloat->size(); j++) { + spearmanRank member(lookupGroups[j], lookupFloat->get(i, lookupGroups[j])); otuScores.push_back(member); itTable = tableY.find(member.score); @@ -537,17 +534,17 @@ int CorrAxesCommand::calcSpearman(map >& axes, ofstream& o for (int j = 0; j < numaxes; j++) { double di = 0.0; - for (int k = 0; k < lookupFloat.size(); k++) { + for (int k = 0; k < lookupFloat->size(); k++) { - float xi = rankAxes[lookupFloat[k]->getGroup()][j]; - float yi = rankOtus[lookupFloat[k]->getGroup()]; + float xi = rankAxes[lookupGroups[k]][j]; + float yi = rankOtus[lookupGroups[k]]; di += ((xi - yi) * (xi - yi)); } double p = 0.0; - double n = (double) lookupFloat.size(); + double n = (double) lookupFloat->size(); double SX2 = ((pow(n, 3.0) - n) / 12.0) - Lx[j]; double SY2 = ((pow(n, 3.0) - n) / 12.0) - Ly; @@ -584,6 +581,7 @@ int CorrAxesCommand::calcKendall(map >& axes, ofstream& ou try { LinearAlgebra linear; + vector lookupGroups = lookupFloat->getNamesGroups(); //format data vector< vector > scores; scores.resize(numaxes); @@ -626,15 +624,15 @@ int CorrAxesCommand::calcKendall(map >& axes, ofstream& ou } //for each otu - for (int i = 0; i < lookupFloat[0]->getNumBins(); i++) { + for (int i = 0; i < lookupFloat->getNumBins(); i++) { if (metadatafile == "") { out << m->currentSharedBinLabels[i]; } else { out << metadataLabels[i]; } //find the ranks of this otu - Y vector otuScores; - for (int j = 0; j < lookupFloat.size(); j++) { - spearmanRank member(lookupFloat[j]->getGroup(), lookupFloat[j]->getAbundance(i)); + for (int j = 0; j < lookupFloat->size(); j++) { + spearmanRank member(lookupGroups[j], lookupFloat->get(i, lookupGroups[j])); otuScores.push_back(member); } @@ -726,7 +724,7 @@ int CorrAxesCommand::calcKendall(map >& axes, ofstream& ou int CorrAxesCommand::getSharedFloat(InputData* input){ try { lookupFloat = input->getSharedRAbundFloatVectors(); - string lastLabel = lookupFloat[0]->getLabel(); + string lastLabel = lookupFloat->getLabel(); if (label == "") { label = lastLabel; return 0; } @@ -736,35 +734,35 @@ int CorrAxesCommand::getSharedFloat(InputData* input){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && (userLabels.size() != 0)) { + while((lookupFloat != NULL) && (userLabels.size() != 0)) { if (m->control_pressed) { return 0; } - if(labels.count(lookupFloat[0]->getLabel()) == 1){ - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + if(labels.count(lookupFloat->getLabel()) == 1){ + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); break; } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); break; } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(); } @@ -786,8 +784,8 @@ int CorrAxesCommand::getSharedFloat(InputData* input){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + delete lookupFloat; + lookupFloat = input->getSharedRAbundFloatVectors(); } return 0; @@ -797,63 +795,6 @@ int CorrAxesCommand::getSharedFloat(InputData* input){ exit(1); } } -//********************************************************************************************************************** -int CorrAxesCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "CorrAxesCommand", "eliminateZeroOTUS"); - exit(1); - } -} /*****************************************************************/ map > CorrAxesCommand::readAxes(){ try { @@ -933,6 +874,7 @@ int CorrAxesCommand::getMetadata(){ int count = metadataLabels.size(); //read rest of file + lookupFloat = new SharedRAbundFloatVectors(); while (!in.eof()) { if (m->control_pressed) { in.close(); return 0; } @@ -942,39 +884,24 @@ int CorrAxesCommand::getMetadata(){ groupNames.push_back(group); SharedRAbundFloatVector* tempLookup = new SharedRAbundFloatVector(); - tempLookup->setGroup(group); tempLookup->setLabel("1"); - + tempLookup->setGroup(group); + for (int i = 0; i < count; i++) { float temp = 0.0; in >> temp; - tempLookup->push_back(temp, group); + tempLookup->push_back(temp); } - - lookupFloat.push_back(tempLookup); + lookupFloat->push_back(tempLookup); m->gobble(in); } in.close(); - //remove any groups the user does not want, and set globaldata->groups with only valid groups - SharedUtil* util; - util = new SharedUtil(); - Groups = m->getGroups(); - util->setGroups(Groups, groupNames); - m->setGroups(Groups); - - for (int i = 0; i < lookupFloat.size(); i++) { - //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookupFloat[i]->getGroup(), m->getGroups()) == false) { - delete lookupFloat[i]; lookupFloat[i] = NULL; - lookupFloat.erase(lookupFloat.begin()+i); - i--; - } - } - - delete util; - + lookupFloat->setLabels("1"); + lookupFloat->eliminateZeroOTUS(); + + return 0; } catch(exception& e) { diff --git a/source/commands/corraxescommand.h b/source/commands/corraxescommand.h index a91a2401..282e67a1 100644 --- a/source/commands/corraxescommand.h +++ b/source/commands/corraxescommand.h @@ -11,7 +11,8 @@ */ #include "command.hpp" -#include "sharedrabundfloatvector.h" +#include "sharedrabundvectors.hpp" +#include "sharedrabundfloatvectors.hpp" #include "inputdata.h" @@ -40,12 +41,11 @@ class CorrAxesCommand : public Command { set names; vector outputNames, Groups; - vector lookupFloat; + SharedRAbundFloatVectors* lookupFloat; vector metadataLabels; int getSharedFloat(InputData*); int getMetadata(); - int eliminateZeroOTUS(vector&); map > readAxes(); int calcPearson(map >&, ofstream&); int calcSpearman(map >&, ofstream&); diff --git a/source/commands/countgroupscommand.cpp b/source/commands/countgroupscommand.cpp index 33598a7b..cd4dbc7a 100644 --- a/source/commands/countgroupscommand.cpp +++ b/source/commands/countgroupscommand.cpp @@ -286,7 +286,7 @@ int CountGroupsCommand::execute(){ if (sharedfile != "") { InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); map variables; string thisOutputDir = outputDir; @@ -298,12 +298,12 @@ int CountGroupsCommand::execute(){ m->openOutputFile(outputFileName, out); int total = 0; - for (int i = 0; i < lookup.size(); i++) { - int num = lookup[i]->getNumSeqs(); + vector groups = lookup->getNamesGroups(); + for (int i = 0; i < groups.size(); i++) { + int num = lookup->getNumSeqs(groups[i]); total += num; - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(num) + "."); m->mothurOutEndLine(); - out << lookup[i]->getGroup() << '\t' << num << endl; - delete lookup[i]; + m->mothurOut(groups[i] + " contains " + toString(num) + "."); m->mothurOutEndLine(); + out << groups[i] << '\t' << num << endl; } out.close(); diff --git a/source/commands/countseqscommand.cpp b/source/commands/countseqscommand.cpp index 12f9374d..5c3583a1 100644 --- a/source/commands/countseqscommand.cpp +++ b/source/commands/countseqscommand.cpp @@ -221,47 +221,50 @@ int CountSeqsCommand::execute(){ variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + processShared(data, variables); + for(int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processShared(lookup, variables); - - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - processShared(lookup, variables); + vector data = lookup->getSharedRAbundVectors(); + processShared(data, variables); + for(int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -286,14 +289,16 @@ int CountSeqsCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - processShared(lookup, variables); + vector data = lookup->getSharedRAbundVectors(); + processShared(data, variables); + for(int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } } @@ -337,8 +342,8 @@ unsigned long long CountSeqsCommand::processShared(vector& int total = 0; string output = ""; for (int i = 0; i < lookup.size(); i++) { - total += lookup[i]->getAbundance(j); - output += '\t' + toString(lookup[i]->getAbundance(j)); + total += lookup[i]->get(j); + output += '\t' + toString(lookup[i]->get(j)); } out << m->currentSharedBinLabels[j] << '\t' << total << output << endl; } @@ -407,20 +412,7 @@ unsigned long long CountSeqsCommand::createProcesses(GroupMap*& groupMap, string positions = m->divideFilePerLine(namefile, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } #else - if(processors == 1){ lines.push_back(linePair(0, 1000)); } - else { - unsigned long long numSeqs = 0; - positions = m->setFilePosEachLine(namefile, numSeqs); - if (positions.size() < processors) { processors = positions.size(); } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor; } - lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); - } - } + lines.push_back(linePair(0, 1000)); #endif @@ -523,41 +515,9 @@ unsigned long long CountSeqsCommand::createProcesses(GroupMap*& groupMap, string numSeqs += num; m->mothurRemove(tempFile); } -#else - vector pDataArray; - DWORD dwThreadIdArray[processors-1]; - HANDLE hThreadArray[processors-1]; - vector copies; - - //Create processor worker threads. - for( int i=0; igetCopy(groupMap); - copies.push_back(copyGroup); - vector cGroups = Groups; - - countData* temp = new countData(filename, copyGroup, m, lines[i].start, lines[i].end, groupfile, namefile, cGroups); - pDataArray.push_back(temp); - processIDS.push_back(i); - - hThreadArray[i] = CreateThread(NULL, 0, MyCountThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]); - } - +#else string filename = toString(processors-1) + ".temp"; numSeqs = driver(lines[processors-1].start, lines[processors-1].end, filename, groupMap); - - //Wait until all threads have terminated. - WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); - - //Close all thread handles and free memory allocations. - for(int i=0; i < pDataArray.size(); i++){ - numSeqs += pDataArray[i]->total; - delete copies[i]; - CloseHandle(hThreadArray[i]); - delete pDataArray[i]; - } #endif //append output files diff --git a/source/commands/countseqscommand.h b/source/commands/countseqscommand.h index d73d4f0a..e9b2ff73 100644 --- a/source/commands/countseqscommand.h +++ b/source/commands/countseqscommand.h @@ -12,7 +12,7 @@ #include "command.hpp" #include "groupmap.h" -#include "sharedrabundvector.h" + class CountSeqsCommand : public Command { @@ -54,114 +54,6 @@ class CountSeqsCommand : public Command { }; -/***********************************************************************/ -struct countData { - unsigned long long start; - unsigned long long end; - MothurOut* m; - string outputFileName, namefile, groupfile; - GroupMap* groupMap; - int total; - vector Groups; - - countData(){} - countData(string fn, GroupMap* g, MothurOut* mout, unsigned long long st, unsigned long long en, string gfn, string nfn, vector gr) { - m = mout; - start = st; - end = en; - groupMap = g; - groupfile = gfn; - namefile = nfn; - outputFileName = fn; - Groups = gr; - total = 0; - } -}; - -/**************************************************************************************************/ -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) -#else -static DWORD WINAPI MyCountThreadFunction(LPVOID lpParam){ - countData* pDataArray; - pDataArray = (countData*)lpParam; - try { - ofstream out; - pDataArray->m->openOutputFile(pDataArray->outputFileName, out); - - ifstream in; - pDataArray->m->openInputFile(pDataArray->namefile, in); - in.seekg(pDataArray->start); - - //print header if you are process 0 - if ((pDataArray->start == 0) || (pDataArray->start == 1)) { - in.seekg(0); - pDataArray->m->zapGremlins(in); - }else { //this accounts for the difference in line endings. - in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); - } - - pDataArray->total = 0; - for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process - - if (pDataArray->m->control_pressed) { break; } - - string firstCol, secondCol; - in >> firstCol; pDataArray->m->gobble(in); in >> secondCol; pDataArray->m->gobble(in); - //cout << firstCol << '\t' << secondCol << endl; - pDataArray->m->checkName(firstCol); - pDataArray->m->checkName(secondCol); - - vector names; - pDataArray->m->splitAtChar(secondCol, names, ','); - - if (pDataArray->groupfile != "") { - //set to 0 - map groupCounts; - int total = 0; - for (int i = 0; i < pDataArray->Groups.size(); i++) { groupCounts[pDataArray->Groups[i]] = 0; } - - //get counts for each of the users groups - for (int i = 0; i < names.size(); i++) { - string group = pDataArray->groupMap->getGroup(names[i]); - - if (group == "not found") { pDataArray->m->mothurOut("[ERROR]: " + names[i] + " is not in your groupfile, please correct."); pDataArray->m->mothurOutEndLine(); } - else { - map::iterator it = groupCounts.find(group); - - //if not found, then this sequence is not from a group we care about - if (it != groupCounts.end()) { - it->second++; - total++; - } - } - } - - if (total != 0) { - out << firstCol << '\t' << total; - for (map::iterator it = groupCounts.begin(); it != groupCounts.end(); it++) { - out << '\t' << it->second; - } - out << endl; - } - }else { - out << firstCol << '\t' << names.size() << endl; - } - - pDataArray->total += names.size(); - } - in.close(); - out.close(); - - - return 0; - } - catch(exception& e) { - pDataArray->m->errorOut(e, "CountSeqsCommand", "MyCountThreadFunction"); - exit(1); - } -} -#endif - #endif diff --git a/source/commands/createdatabasecommand.cpp b/source/commands/createdatabasecommand.cpp index ed66a2e7..1e4ecf8f 100644 --- a/source/commands/createdatabasecommand.cpp +++ b/source/commands/createdatabasecommand.cpp @@ -462,15 +462,16 @@ int CreateDatabaseCommand::execute(){ if (groupfile != "") { delete groupmap; } }else { - vector lookup = getShared(); + SharedRAbundVectors* lookup = getShared(); + vector namesOfGroups = lookup->getNamesGroups(); header = "OTUNumber"; - for (int i = 0; i < lookup.size(); i++) { header += '\t' + lookup[i]->getGroup(); } + for (int i = 0; i < namesOfGroups.size(); i++) { header += '\t' + namesOfGroups[i]; } if (repfastafile != "") { header += "\trepSeqName\trepSeq"; } header += "\tOTUConTaxonomy"; out << header << endl; - for (int h = 0; h < lookup[0]->getNumBins(); h++) { + for (int h = 0; h < lookup->getNumBins(); h++) { if (m->control_pressed) { break; } @@ -482,8 +483,8 @@ int CreateDatabaseCommand::execute(){ out << otuLabels[index]; int totalAbund = 0; - for (int i = 0; i < lookup.size(); i++) { - int abund = lookup[i]->getAbundance(h); + for (int i = 0; i < lookup->size(); i++) { + int abund = lookup->get(h, namesOfGroups[i]); totalAbund += abund; out << '\t' << abund; } @@ -687,11 +688,11 @@ ListVector* CreateDatabaseCommand::getList(){ } } //********************************************************************************************************************** -vector CreateDatabaseCommand::getShared(){ +SharedRAbundVectors* CreateDatabaseCommand::getShared(){ try { InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); if (label == "") { label = lastLabel; return lookup; } @@ -701,34 +702,34 @@ vector CreateDatabaseCommand::getShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { + while((lookup != NULL) && (userLabels.size() != 0)) { if (m->control_pressed) { return lookup; } - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); break; } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); break; } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } @@ -750,7 +751,7 @@ vector CreateDatabaseCommand::getShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); } diff --git a/source/commands/createdatabasecommand.h b/source/commands/createdatabasecommand.h index 79b5646b..717afed2 100644 --- a/source/commands/createdatabasecommand.h +++ b/source/commands/createdatabasecommand.h @@ -42,7 +42,7 @@ class CreateDatabaseCommand : public Command { vector readFasta(vector&); vector readTax(vector&, vector&); ListVector* getList(); - vector getShared(); + SharedRAbundVectors* getShared(); int findIndex(vector&, string); }; diff --git a/source/commands/distancecommand.cpp b/source/commands/distancecommand.cpp index 58a4bae2..2f075105 100644 --- a/source/commands/distancecommand.cpp +++ b/source/commands/distancecommand.cpp @@ -522,7 +522,7 @@ void DistanceCommand::createProcesses(string filename, int numSeqs) { int DistanceCommand::driver(int startLine, int endLine, string dFileName, float cutoff){ try { ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (m->isTrue(countends) == true) { for (int i=0; imothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+"\n"); + m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime) + "\t" + toString(distsBelowCutoff) +"\n"); } } - m->mothurOutJustToScreen(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)+"\n"); + m->mothurOutJustToScreen(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); outFile.close(); delete distCalculator; @@ -599,7 +601,7 @@ int DistanceCommand::driver(int startLine, int endLine, string dFileName, float int DistanceCommand::driver(int startLine, int endLine, string dFileName, string square){ try { ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (m->isTrue(countends) == true) { for (int i=0; icalcDist(alignDB.get(i), alignDB.get(j)); double dist = distCalculator->getDist(); - + + if(dist <= cutoff){ distsBelowCutoff++; } + outFile << dist << '\t'; } outFile << endl; - if(i % 100 == 0){ - m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+"\n"); - } - - } - m->mothurOutJustToScreen(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)+"\n"); + if(i % 100 == 0){ + m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime) + "\t" + toString(distsBelowCutoff) +"\n"); + } + } + m->mothurOutJustToScreen(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); + outFile.close(); delete distCalculator; diff --git a/source/commands/distancecommand.h b/source/commands/distancecommand.h index 8e708d44..0a77bd6b 100644 --- a/source/commands/distancecommand.h +++ b/source/commands/distancecommand.h @@ -13,7 +13,7 @@ #include "mothur.h" #include "command.hpp" #include "validcalculator.h" -#include "dist.h" +#include "calculator.h" #include "sequencedb.h" #include "ignoregaps.h" #include "eachgapdist.h" @@ -61,7 +61,7 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ try { ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (pDataArray->m->isTrue(pDataArray->countends) == true) { for (int i=0; iEstimators.size(); i++) { if (validCalculator.isValidCalculator("distance", pDataArray->Estimators[i]) == true) { @@ -87,7 +87,8 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ outFile.setf(ios::fixed, ios::showpoint); outFile << setprecision(4); pDataArray->count = 0; - + long long distsBelowCutoff = 0; + if (pDataArray->output != "square") { if((pDataArray->output == "lt") && (pDataArray->startLine == 0)){ outFile << pDataArray->alignDB.getNumSeqs() << endl; } @@ -112,6 +113,7 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ if(dist <= pDataArray->cutoff){ if (pDataArray->output == "column") { outFile << pDataArray->alignDB.get(i).getName() << ' ' << pDataArray->alignDB.get(j).getName() << ' ' << dist << endl; } + distsBelowCutoff++; } if (pDataArray->output == "lt") { outFile << '\t' << dist; } } @@ -119,10 +121,10 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ if (pDataArray->output == "lt") { outFile << endl; } if(i % 100 == 0){ - pDataArray->m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+"\n"); } + pDataArray->m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); } pDataArray->count++; } - pDataArray->m->mothurOutJustToScreen(toString(pDataArray->count) + "\t" + toString(time(NULL) - startTime)+"\n"); + pDataArray->m->mothurOutJustToScreen(toString(pDataArray->count) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); }else{ if(pDataArray->startLine == 0){ outFile << pDataArray->alignDB.getNumSeqs() << endl; } @@ -140,6 +142,8 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ distCalculator->calcDist(pDataArray->alignDB.get(i), pDataArray->alignDB.get(j)); double dist = distCalculator->getDist(); + + if(dist <= pDataArray->cutoff){ distsBelowCutoff++; } outFile << '\t' << dist; } @@ -147,11 +151,11 @@ static DWORD WINAPI MyDistThreadFunction(LPVOID lpParam){ outFile << endl; if(i % 100 == 0){ - pDataArray->m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+"\n"); + pDataArray->m->mothurOutJustToScreen(toString(i) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); } pDataArray->count++; } - pDataArray->m->mothurOutJustToScreen(toString(pDataArray->count) + "\t" + toString(time(NULL) - startTime)+"\n"); + pDataArray->m->mothurOutJustToScreen(toString(pDataArray->count) + "\t" + toString(time(NULL) - startTime)+ "\t" + toString(distsBelowCutoff) +"\n"); } outFile.close(); diff --git a/source/commands/filterseqscommand.cpp b/source/commands/filterseqscommand.cpp index c7ae5c90..9e88e126 100644 --- a/source/commands/filterseqscommand.cpp +++ b/source/commands/filterseqscommand.cpp @@ -743,8 +743,8 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair* Sequence seq(in); m->gobble(in); if (seq.getName() != "") { - if (m->debug) { m->mothurOutJustToScreen("[DEBUG]: " + seq.getName() + " length = " + toString(seq.getAligned().length())); m->mothurOutEndLine();} - if (seq.getAligned().length() != alignmentLength) { m->mothurOut("[ERROR]: Sequences are not all the same length, please correct."); m->mothurOutEndLine(); error = true; if (!m->debug) { m->control_pressed = true; }else{ m->mothurOutJustToLog("[DEBUG]: " + seq.getName() + " length = " + toString(seq.getAligned().length())); m->mothurOutEndLine();} } + if (m->debug) { m->mothurOutJustToScreen("[DEBUG]: " + seq.getName() + " length = " + toString(seq.getAligned().length()) + '\n'); } + if (seq.getAligned().length() != alignmentLength) { m->mothurOut("[ERROR]: Sequences are not all the same length, please correct.\n"); error = true; if (!m->debug) { m->control_pressed = true; }else{ m->mothurOutJustToLog("[DEBUG]: " + seq.getName() + " length = " + toString(seq.getAligned().length()) + '\n'); } } if(trump != '*') { F.doTrump(seq); } if(m->isTrue(vertical) || soft != 0) { F.getFreqs(seq); } diff --git a/source/commands/filtersharedcommand.cpp b/source/commands/filtersharedcommand.cpp index 0ee7328c..c9f8f88f 100644 --- a/source/commands/filtersharedcommand.cpp +++ b/source/commands/filtersharedcommand.cpp @@ -227,48 +227,47 @@ int FilterSharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; //get next line to process lookup = input.getSharedRAbundVectors(); @@ -292,14 +291,14 @@ int FilterSharedCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //set shared file as new current sharedfile @@ -322,7 +321,7 @@ int FilterSharedCommand::execute(){ } } //********************************************************************************************************************** -int FilterSharedCommand::processShared(vector& thislookup) { +int FilterSharedCommand::processShared(SharedRAbundVectors*& sharedLookup) { try { //save mothurOut's binLabels to restore for next label @@ -331,33 +330,26 @@ int FilterSharedCommand::processShared(vector& thislookup) map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = thislookup[0]->getLabel(); + variables["[distance]"] = sharedLookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); if (m->control_pressed) { return 0; } map labelsForRare; vector filteredLabels; - vector rareCounts; rareCounts.resize(m->getGroups().size(), 0); - //create new "filtered" lookup - vector filteredLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - filteredLookup.push_back(temp); - } + vector data = sharedLookup->getSharedRAbundVectors(); + vector rareCounts; rareCounts.resize(m->getGroups().size(), 0); //you want to remove a percentage of OTUs set removeLabels; if (rarePercent != -0.01) { vector otus; //rank otus by abundance - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { + for (int i = 0; i < sharedLookup->getNumBins(); i++) { float otuTotal = 0.0; - for (int j = 0; j < thislookup.size(); j++) { - otuTotal += thislookup[j]->getAbundance(i); + for (int j = 0; j < data.size(); j++) { + otuTotal += data[j]->get(i); } spearmanRank temp(saveBinLabels[i], otuTotal); otus.push_back(temp); @@ -367,7 +359,7 @@ int FilterSharedCommand::processShared(vector& thislookup) sort(otus.begin(), otus.end(), compareSpearman); //find index of cutoff - int indexFirstNotRare = ceil(rarePercent * (float)thislookup[0]->getNumBins()); + int indexFirstNotRare = ceil(rarePercent * (float)data[0]->getNumBins()); //handle ties if (keepties) { //adjust indexFirstNotRare if needed @@ -379,7 +371,7 @@ int FilterSharedCommand::processShared(vector& thislookup) indexFirstNotRare = i+1; tie = false; break; } } - if (tie) { if (m->debug) { m->mothurOut("For distance " + thislookup[0]->getLabel() + " all rare OTUs abundance tie with first 'non rare' OTU, not removing any for rarepercent parameter.\n"); }indexFirstNotRare = 0; } + if (tie) { if (m->debug) { m->mothurOut("For distance " + sharedLookup->getLabel() + " all rare OTUs abundance tie with first 'non rare' OTU, not removing any for rarepercent parameter.\n"); }indexFirstNotRare = 0; } } } } @@ -390,21 +382,21 @@ int FilterSharedCommand::processShared(vector& thislookup) bool filteredSomething = false; int numRemoved = 0; - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { + for (int i = 0; i < sharedLookup->getNumBins();) { - if (m->control_pressed) { for (int j = 0; j < filteredLookup.size(); j++) { delete filteredLookup[j]; } return 0; } + if (m->control_pressed) { for (int j = 0; j < data.size(); j++) { delete data[j]; } return 0; } bool okay = true; //innocent until proven guilty if (minAbund != -1) { - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) < minAbund) { okay = false; break; } + for (int j = 0; j < data.size(); j++) { + if (data[j]->get(i) < minAbund) { okay = false; break; } } } if (okay && (minTotal != -1)) { int otuTotal = 0; - for (int j = 0; j < thislookup.size(); j++) { - otuTotal += thislookup[j]->getAbundance(i); + for (int j = 0; j < data.size(); j++) { + otuTotal += data[j]->get(i); } if (otuTotal < minTotal) { okay = false; } } @@ -412,9 +404,9 @@ int FilterSharedCommand::processShared(vector& thislookup) if (okay && (minPercent != -0.01)) { double otuTotal = 0; double total = 0; - for (int j = 0; j < thislookup.size(); j++) { - otuTotal += thislookup[j]->getAbundance(i); - total += thislookup[j]->getNumSeqs(); + for (int j = 0; j < data.size(); j++) { + otuTotal += data[j]->get(i); + total += data[j]->getNumSeqs(); } double percent = otuTotal / total; if (percent < minPercent) { okay = false; } @@ -423,17 +415,17 @@ int FilterSharedCommand::processShared(vector& thislookup) if (okay && (minSamples != -1)) { int samples = 0; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { samples++; } + for (int j = 0; j < data.size(); j++) { + if (data[j]->get(i) != 0) { samples++; } } if (samples < minSamples) { okay = false; } } if (okay && (minPercentSamples != -0.01)) { double samples = 0; - double total = thislookup.size(); - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { samples++; } + double total = data.size(); + for (int j = 0; j < data.size(); j++) { + if (data[j]->get(i) != 0) { samples++; } } double percent = samples / total; if (percent < minPercentSamples) { okay = false; } @@ -449,14 +441,13 @@ int FilterSharedCommand::processShared(vector& thislookup) if (okay) { filteredLabels.push_back(saveBinLabels[i]); labelsForRare[m->getSimpleLabel(saveBinLabels[i])] = i; - for (int j = 0; j < filteredLookup.size(); j++) { //add this OTU to the filtered lookup - filteredLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } + ++i; }else { //if not, do we want to save the counts filteredSomething = true; if (makeRare) { - for (int j = 0; j < rareCounts.size(); j++) { rareCounts[j] += thislookup[j]->getAbundance(i); } + for (int j = 0; j < rareCounts.size(); j++) { rareCounts[j] += data[j]->get(i); } } + sharedLookup->removeOTU(i); numRemoved++; } @@ -465,9 +456,6 @@ int FilterSharedCommand::processShared(vector& thislookup) //if we are saving the counts add a "rare" OTU if anything was filtered if (makeRare) { if (filteredSomething) { - for (int j = 0; j < rareCounts.size(); j++) { //add "rare" OTU to the filtered lookup - filteredLookup[j]->push_back(rareCounts[j], thislookup[j]->getGroup()); - } //create label for rare OTUs map::iterator it; int otuNum = 0; bool notDone = true; @@ -493,6 +481,7 @@ int FilterSharedCommand::processShared(vector& thislookup) } otuNum++; } + sharedLookup->push_back(rareCounts, "rareOTUs" + toString(otuNum)); filteredLabels.push_back("rareOTUs" + toString(otuNum)); } } @@ -503,20 +492,14 @@ int FilterSharedCommand::processShared(vector& thislookup) m->currentSharedBinLabels = filteredLabels; - filteredLookup[0]->printHeaders(out); - - for (int i = 0; i < filteredLookup.size(); i++) { - out << filteredLookup[i]->getLabel() << '\t' << filteredLookup[i]->getGroup() << '\t'; - filteredLookup[i]->print(out); - } + sharedLookup->printHeaders(out); + sharedLookup->print(out); out.close(); //save mothurOut's binLabels to restore for next label m->currentSharedBinLabels = saveBinLabels; - for (int j = 0; j < filteredLookup.size(); j++) { delete filteredLookup[j]; } - m->mothurOut("\nRemoved " + toString(numRemoved) + " OTUs.\n"); return 0; diff --git a/source/commands/filtersharedcommand.h b/source/commands/filtersharedcommand.h index 70465513..d93edd2f 100644 --- a/source/commands/filtersharedcommand.h +++ b/source/commands/filtersharedcommand.h @@ -10,7 +10,7 @@ #define Mothur_filtersharedcommand_h #include "command.hpp" -#include "sharedrabundvector.h" + #include "inputdata.h" @@ -41,7 +41,7 @@ class FilterSharedCommand : public Command { int minAbund, minTotal, minSamples; float minPercent, minPercentSamples, rarePercent; - int processShared(vector&); + int processShared(SharedRAbundVectors*&); }; diff --git a/source/commands/getcoremicrobiomecommand.cpp b/source/commands/getcoremicrobiomecommand.cpp index e889bcf0..77fdd55d 100644 --- a/source/commands/getcoremicrobiomecommand.cpp +++ b/source/commands/getcoremicrobiomecommand.cpp @@ -191,7 +191,6 @@ GetCoreMicroBiomeCommand::GetCoreMicroBiomeCommand(string option) { if (found) { factorString += "0"; } } } - cout << factorString << endl; m->mothurConvert(factorString, factor); }else { factor = 100; @@ -220,11 +219,11 @@ int GetCoreMicroBiomeCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } InputData input(inputFileName, format); - vector lookup = input.getSharedRAbundFloatVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundFloatVectors* lookup = input.getSharedRAbundFloatVectors(); + string lastLabel = lookup->getLabel(); if (samples != -1) { - if ((samples < 1) || (samples > lookup.size())) { m->mothurOut(toString(samples) + " is not a valid number for samples. Must be an integer between 1 and the number of samples in your file. Your file contains " + toString(lookup.size()) + " samples, so I will use that.\n"); samples = lookup.size(); } + if ((samples < 1) || (samples > lookup->size())) { m->mothurOut(toString(samples) + " is not a valid number for samples. Must be an integer between 1 and the number of samples in your file. Your file contains " + toString(lookup->size()) + " samples, so I will use that.\n"); samples = lookup->size(); } } @@ -233,39 +232,39 @@ int GetCoreMicroBiomeCommand::execute(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createTable(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createTable(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -290,14 +289,16 @@ int GetCoreMicroBiomeCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; + lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createTable(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; + } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -317,18 +318,18 @@ int GetCoreMicroBiomeCommand::execute(){ } //********************************************************************************************************************** -int GetCoreMicroBiomeCommand::createTable(vector& lookup){ +int GetCoreMicroBiomeCommand::createTable(SharedRAbundFloatVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[tag]"] = lookup[0]->getLabel(); + variables["[tag]"] = lookup->getLabel(); string outputFileName = getOutputFileName("coremicrobiome", variables); outputNames.push_back(outputFileName); outputTypes["coremicrobiome"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); - int numSamples = lookup.size(); - int numOtus = lookup[0]->getNumBins(); + int numSamples = lookup->size(); + int numOtus = lookup->getNumBins(); //table is 100 by numsamples //question we are answering is: what fraction of OTUs in a study have a relative abundance at or above %X @@ -353,6 +354,7 @@ int GetCoreMicroBiomeCommand::createTable(vector& look otuNames[thisAbund] = temp; } + vector sampleNames = lookup->getNamesGroups(); for (int i = 0; i < numOtus; i++) { if (m->control_pressed) { break; } @@ -360,8 +362,8 @@ int GetCoreMicroBiomeCommand::createTable(vector& look //count number of samples in this otu with a relabund >= spot in count vector counts; counts.resize(factor+1, 0); - for (int j = 0; j < lookup.size(); j++) { - double relabund = lookup[j]->getAbundance(i); + for (int j = 0; j < sampleNames.size(); j++) { + double relabund = lookup->get(i, sampleNames[j]); int wholeRelabund = (int) (floor(relabund*factor)); for (int k = 0; k < wholeRelabund+1; k++) { counts[k]++; } } @@ -409,7 +411,7 @@ int GetCoreMicroBiomeCommand::createTable(vector& look if (m->control_pressed) { return 0; } if ((samples != -1) || (abund != -1)) { - string outputFileName2 = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + ".core.microbiomelist"; + string outputFileName2 = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup->getLabel() + ".core.microbiomelist"; outputNames.push_back(outputFileName2); outputTypes["coremicrobiome"].push_back(outputFileName2); ofstream out2; m->openOutputFile(outputFileName2, out2); diff --git a/source/commands/getcoremicrobiomecommand.h b/source/commands/getcoremicrobiomecommand.h index 68679db8..0ee08516 100644 --- a/source/commands/getcoremicrobiomecommand.h +++ b/source/commands/getcoremicrobiomecommand.h @@ -46,7 +46,7 @@ class GetCoreMicroBiomeCommand : public Command { float abund; int samples, factor; - int createTable(vector&); + int createTable(SharedRAbundFloatVectors*&); }; diff --git a/source/commands/getgroupcommand.cpp b/source/commands/getgroupcommand.cpp index f145cdc0..992afa87 100644 --- a/source/commands/getgroupcommand.cpp +++ b/source/commands/getgroupcommand.cpp @@ -119,13 +119,14 @@ int GetgroupCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - - for (int i = 0; i < lookup.size(); i++) { - m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine(); - delete lookup[i]; + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + vector namesOfGroups = lookup->getNamesGroups(); + delete lookup; + + for (int i = 0; i < namesOfGroups.size(); i++) { + m->mothurOut(namesOfGroups[i]); m->mothurOutEndLine(); } - + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOutEndLine(); diff --git a/source/commands/getgroupscommand.cpp b/source/commands/getgroupscommand.cpp index 600957a0..09bc968a 100644 --- a/source/commands/getgroupscommand.cpp +++ b/source/commands/getgroupscommand.cpp @@ -575,36 +575,31 @@ int GetGroupsCommand::readShared(){ if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); bool wroteSomething = false; - while(lookup[0] != NULL) { + while(lookup != NULL) { - variables["[tag]"] = lookup[0]->getLabel(); + variables["[tag]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); delete lookup; return 0; } - lookup[0]->printHeaders(out); - - for (int i = 0; i < lookup.size(); i++) { - out << lookup[i]->getLabel() << '\t' << lookup[i]->getGroup() << '\t'; - lookup[i]->print(out); - wroteSomething = true; - - } + lookup->printHeaders(out); + lookup->print(out); + wroteSomething = true; //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); out.close(); diff --git a/source/commands/getlineagecommand.cpp b/source/commands/getlineagecommand.cpp index 80ef4b82..79ebc5ec 100644 --- a/source/commands/getlineagecommand.cpp +++ b/source/commands/getlineagecommand.cpp @@ -768,35 +768,24 @@ int GetLineageCommand::getListVector(){ int GetLineageCommand::readShared(){ try { - getShared(); + SharedRAbundVectors* lookup = getShared(); - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; } vector newLabels; - //create new "filtered" lookup - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - bool wroteSomething = false; int numSelected = 0; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins();) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } //is this otu on the list if (names.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) != 0) { numSelected++; wroteSomething = true; newLabels.push_back(m->currentSharedBinLabels[i]); - for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - } + ++i; + }else { lookup->removeOTU(i); } } string thisOutputDir = outputDir; @@ -804,25 +793,18 @@ int GetLineageCommand::readShared(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - m->currentSharedBinLabels = newLabels; - - newLookup[0]->printHeaders(out); - - for (int i = 0; i < newLookup.size(); i++) { - out << newLookup[i]->getLabel() << '\t' << newLookup[i]->getGroup() << '\t'; - newLookup[i]->print(out); - } + lookup->printHeaders(out); + lookup->print(out); out.close(); - for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } + delete lookup; if (wroteSomething == false) { m->mothurOut("Your file does not contain OTUs from " + taxons + "."); m->mothurOutEndLine(); } @@ -836,13 +818,13 @@ int GetLineageCommand::readShared(){ } } //********************************************************************************************************************** -int GetLineageCommand::getShared(){ +SharedRAbundVectors* GetLineageCommand::getShared(){ try { InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (label == "") { label = lastLabel; return 0; } + if (label == "") { label = lastLabel; return lookup; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); @@ -850,34 +832,34 @@ int GetLineageCommand::getShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { + while((lookup != NULL) && (userLabels.size() != 0)) { if (m->control_pressed) { return 0; } - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); break; } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); break; } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } @@ -899,11 +881,11 @@ int GetLineageCommand::getShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); } - return 0; + return lookup; } catch(exception& e) { m->errorOut(e, "GetLineageCommand", "getShared"); diff --git a/source/commands/getlineagecommand.h b/source/commands/getlineagecommand.h index 4cee8b64..0ce6f96b 100644 --- a/source/commands/getlineagecommand.h +++ b/source/commands/getlineagecommand.h @@ -11,7 +11,7 @@ */ #include "command.hpp" -#include "sharedrabundvector.h" +#include "sharedrabundvectors.hpp" #include "listvector.hpp" class GetLineageCommand : public Command { @@ -41,7 +41,6 @@ class GetLineageCommand : public Command { vector outputNames, listOfTaxons; string fastafile, namefile, groupfile, alignfile, countfile, listfile, taxfile, outputDir, taxons, sharedfile, constaxonomy, label; bool abort, dups; - vector lookup; ListVector* list; int readFasta(); @@ -54,7 +53,7 @@ class GetLineageCommand : public Command { int readShared(); int readConsTax(); int readConsList(); - int getShared(); + SharedRAbundVectors* getShared(); int getListVector(); vector< map > getTaxons(string); }; diff --git a/source/commands/getmetacommunitycommand.cpp b/source/commands/getmetacommunitycommand.cpp index a9e3d976..93d60fce 100644 --- a/source/commands/getmetacommunitycommand.cpp +++ b/source/commands/getmetacommunitycommand.cpp @@ -233,8 +233,8 @@ int GetMetaCommunityCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -242,67 +242,50 @@ int GetMetaCommunityCommand::execute(){ if (subsample) { if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } + subsampleSize = lookup->getNumSeqsSmallestGroup(); }else { - m->clearGroups(); - Groups.clear(); - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; - m->setGroups(Groups); + lookup->removeGroups(subsampleSize); + Groups = m->getGroups(); } - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createProcesses(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createProcesses(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -327,14 +310,13 @@ int GetMetaCommunityCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createProcesses(lookup); - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //output files created by command @@ -351,7 +333,7 @@ int GetMetaCommunityCommand::execute(){ } } //********************************************************************************************************************** -int GetMetaCommunityCommand::createProcesses(vector& thislookup){ +int GetMetaCommunityCommand::createProcesses(SharedRAbundVectors*& thislookup){ try { //#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) @@ -370,7 +352,7 @@ int GetMetaCommunityCommand::createProcesses(vector& thislo map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = thislookup[0]->getLabel(); + variables["[distance]"] = thislookup->getLabel(); variables["[method]"] = method; string outputFileName = getOutputFileName("fit", variables); outputNames.push_back(outputFileName); outputTypes["fit"].push_back(outputFileName); @@ -443,7 +425,8 @@ int GetMetaCommunityCommand::createProcesses(vector& thislo if (method == "dmm") { m->mothurOut("K\tNLE\t\tlogDet\tBIC\t\tAIC\t\tLaplace\n"); } else { m->mothurOut("K\tCH"); - for (int i = 0; i < thislookup.size(); i++) { m->mothurOut('\t' + thislookup[i]->getGroup()); } + vector namesOfGroups = thislookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { m->mothurOut('\t' + namesOfGroups[i]); } m->mothurOut("\n"); } minPartition = processDriver(thislookup, dividedPartitions[0], outputFileName, rels[0], matrix[0], doneFlags, 0); @@ -545,12 +528,13 @@ int GetMetaCommunityCommand::createProcesses(vector& thislo } } //********************************************************************************************************************** -int GetMetaCommunityCommand::processDriver(vector& thislookup, vector& parts, string outputFileName, vector relabunds, vector matrix, vector doneFlags, int processID){ +int GetMetaCommunityCommand::processDriver(SharedRAbundVectors*& thislookup, vector& parts, string outputFileName, vector relabunds, vector matrix, vector doneFlags, int processID){ try { double minLaplace = 1e10; int minPartition = 1; - vector minSilhouettes; minSilhouettes.resize(thislookup.size(), 0); + vector minSilhouettes; minSilhouettes.resize(thislookup->size(), 0); + vector namesOfGroups = thislookup->getNamesGroups(); ofstream fitData, silData; if (method == "dmm") { @@ -564,7 +548,8 @@ int GetMetaCommunityCommand::processDriver(vector& thislook silData.setf(ios::fixed, ios::floatfield); silData.setf(ios::showpoint); silData << "K\tCH"; - for (int i = 0; i < thislookup.size(); i++) { silData << '\t' << thislookup[i]->getGroup(); } + + for (int i = 0; i < namesOfGroups.size(); i++) { silData << '\t' << namesOfGroups[i]; } silData << endl; } @@ -572,8 +557,11 @@ int GetMetaCommunityCommand::processDriver(vector& thislook cout.setf(ios::showpoint); vector< vector > sharedMatrix; - vector thisGroups; - for (int i = 0; i < thislookup.size(); i++) { sharedMatrix.push_back(thislookup[i]->getAbundances()); thisGroups.push_back(thislookup[i]->getGroup()); } + vector thisGroups = namesOfGroups; + for (int i = 0; i < thisGroups.size(); i++) { + RAbundVector rav = thislookup->getRAbundVector(thisGroups[i]); + sharedMatrix.push_back(rav.get()); + } vector< vector > dists; //do we want to output this matrix?? if ((method == "pam") || (method == "kmeans")) { dists = generateDistanceMatrix(thislookup); } @@ -880,7 +868,7 @@ int GetMetaCommunityCommand::generateSummaryFile(int numPartitions, map > GetMetaCommunityCommand::generateDistanceMatrix(vector& thisLookup){ +vector > GetMetaCommunityCommand::generateDistanceMatrix(SharedRAbundVectors*& thisLookup){ try { vector > results; @@ -982,52 +970,33 @@ vector > GetMetaCommunityCommand::generateDistanceMatrix(vector thisItersLookup = thisLookup; + SharedRAbundVectors* thisItersLookup = new SharedRAbundVectors(*thisLookup); + vector namesOfGroups = thisItersLookup->getNamesGroups(); if (subsample && (thisIter != 0)) { SubSample sample; vector tempLabels; //dont need since we arent printing the sampled sharedRabunds - //make copy of lookup so we don't get access violations - vector newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return results; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - - tempLabels = sample.getSample(newLookup, subsampleSize); - thisItersLookup = newLookup; + tempLabels = sample.getSample(thisItersLookup, subsampleSize); } - driver(thisItersLookup, calcDists, matrixCalculator); - + if (subsample && (thisIter != 0)) { if((thisIter) % 100 == 0){ m->mothurOutJustToScreen(toString(thisIter)+"\n"); } calcDistsTotals.push_back(calcDists); for (int i = 0; i < calcDists.size(); i++) { for (int j = 0; j < calcDists[i].size(); j++) { - if (m->debug) { m->mothurOut("[DEBUG]: Results: iter = " + toString(thisIter) + ", " + thisLookup[calcDists[i][j].seq1]->getGroup() + " - " + thisLookup[calcDists[i][j].seq2]->getGroup() + " distance = " + toString(calcDists[i][j].dist) + ".\n"); } + if (m->debug) { m->mothurOut("[DEBUG]: Results: iter = " + toString(thisIter) + ", " + namesOfGroups[calcDists[i][j].seq1] + " - " + namesOfGroups[calcDists[i][j].seq2] + " distance = " + toString(calcDists[i][j].dist) + ".\n"); } } } - //clean up memory - for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } - thisItersLookup.clear(); }else { //print results for whole dataset for (int i = 0; i < calcDists.size(); i++) { if (m->control_pressed) { break; } //initialize matrix - results.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { results[k].resize(thisLookup.size(), 0.0); } + results.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { results[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcDists[i].size(); j++) { int row = calcDists[i][j].seq1; @@ -1040,6 +1009,7 @@ vector > GetMetaCommunityCommand::generateDistanceMatrix(vector > GetMetaCommunityCommand::generateDistanceMatrix(vectorsize()); + for (int k = 0; k < thisLookup->size(); k++) { results[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcAverages[i].size(); j++) { int row = calcAverages[i][j].seq1; @@ -1071,32 +1041,33 @@ vector > GetMetaCommunityCommand::generateDistanceMatrix(vector thisLookup, vector< vector >& calcDists, Calculator* matrixCalculator) { +int GetMetaCommunityCommand::driver(SharedRAbundVectors*& thisLookup, vector< vector >& calcDists, Calculator* matrixCalculator) { try { + vector data = thisLookup->getSharedRAbundVectors(); vector subset; - for (int k = 0; k < thisLookup.size(); k++) { // pass cdd each set of groups to compare + for (int k = 0; k < data.size(); k++) { // pass cdd each set of groups to compare for (int l = 0; l < k; l++) { if (k != l) { //we dont need to similiarity of a groups to itself subset.clear(); //clear out old pair of sharedrabunds //add new pair of sharedrabunds - subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); + subset.push_back(data[k]); subset.push_back(data[l]); //if this calc needs all groups to calculate the pair load all groups if (matrixCalculator->getNeedsAll()) { //load subset with rest of lookup for those calcs that need everyone to calc for a pair - for (int w = 0; w < thisLookup.size(); w++) { - if ((w != k) && (w != l)) { subset.push_back(thisLookup[w]); } + for (int w = 0; w < data.size(); w++) { + if ((w != k) && (w != l)) { subset.push_back(data[w]); } } } vector tempdata = matrixCalculator->getValues(subset); //saves the calculator outputs - if (m->control_pressed) { return 1; } + if (m->control_pressed) { for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); return 1; } seqDist temp(l, k, tempdata[0]); //cout << l << '\t' << k << '\t' << tempdata[0] << endl; @@ -1105,6 +1076,8 @@ int GetMetaCommunityCommand::driver(vector thisLookup, vect } } + + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); return 0; } diff --git a/source/commands/getmetacommunitycommand.h b/source/commands/getmetacommunitycommand.h index a12b1be1..1a1332db 100644 --- a/source/commands/getmetacommunitycommand.h +++ b/source/commands/getmetacommunitycommand.h @@ -87,10 +87,10 @@ class GetMetaCommunityCommand : public Command { vector Groups, Estimators; set labels; - vector > generateDistanceMatrix(vector& lookup); - int driver(vector thisLookup, vector< vector >& calcDists, Calculator*); - int processDriver(vector&, vector&, string, vector, vector, vector, int); - int createProcesses(vector&); + vector > generateDistanceMatrix(SharedRAbundVectors*& lookup); + int driver(SharedRAbundVectors*& thisLookup, vector< vector >& calcDists, Calculator*); + int processDriver(SharedRAbundVectors*&, vector&, string, vector, vector, vector, int); + int createProcesses(SharedRAbundVectors*&); vector generateDesignFile(int, map); int generateSummaryFile(int, map, vector); diff --git a/source/commands/getotulabelscommand.cpp b/source/commands/getotulabelscommand.cpp index 3b3112fc..71242153 100644 --- a/source/commands/getotulabelscommand.cpp +++ b/source/commands/getotulabelscommand.cpp @@ -453,61 +453,44 @@ int GetOtuLabelsCommand::readCorrAxes(){ int GetOtuLabelsCommand::readShared(){ try { - getShared(); + SharedRAbundVectors* lookup = getShared(); - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } vector newLabels; - //create new "filtered" lookup - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - bool wroteSomething = false; int numSelected = 0; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins();) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } //is this otu on the list if (labels.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) != 0) { numSelected++; wroteSomething = true; newLabels.push_back(m->currentSharedBinLabels[i]); - for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - } + ++i; + }else { lookup->removeOTU(i); } } - + string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - m->currentSharedBinLabels = newLabels; - newLookup[0]->printHeaders(out); - - for (int i = 0; i < newLookup.size(); i++) { - out << newLookup[i]->getLabel() << '\t' << newLookup[i]->getGroup() << '\t'; - newLookup[i]->print(out); - } + lookup->printHeaders(out); + lookup->print(out); out.close(); - for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } + delete lookup; if (wroteSomething == false) { m->mothurOut("Your file does not contain any OTUs from the .accnos file."); m->mothurOutEndLine(); } @@ -653,13 +636,13 @@ int GetOtuLabelsCommand::getListVector(){ } } //********************************************************************************************************************** -int GetOtuLabelsCommand::getShared(){ +SharedRAbundVectors* GetOtuLabelsCommand::getShared(){ try { InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (label == "") { label = lastLabel; return 0; } + if (label == "") { label = lastLabel; return lookup; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); @@ -667,34 +650,34 @@ int GetOtuLabelsCommand::getShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { return 0; } + while((lookup != NULL) && (userLabels.size() != 0)) { + if (m->control_pressed) { delete lookup; return NULL; } - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); break; } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); break; } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } @@ -716,11 +699,11 @@ int GetOtuLabelsCommand::getShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); } - return 0; + return lookup; } catch(exception& e) { m->errorOut(e, "GetOtuLabelsCommand", "getShared"); diff --git a/source/commands/getotulabelscommand.h b/source/commands/getotulabelscommand.h index 60d13193..772ff53d 100644 --- a/source/commands/getotulabelscommand.h +++ b/source/commands/getotulabelscommand.h @@ -13,7 +13,7 @@ #include "command.hpp" #include "inputdata.h" #include "listvector.hpp" -#include "sharedrabundvector.h" + /**************************************************************************************************/ @@ -41,7 +41,7 @@ class GetOtuLabelsCommand : public Command { vector outputNames; set labels; ListVector* list; - vector lookup; + //vector lookup; int readClassifyOtu(); int readOtuAssociation(); @@ -49,7 +49,7 @@ class GetOtuLabelsCommand : public Command { int readList(); int readShared(); int getListVector(); - int getShared(); + SharedRAbundVectors* getShared(); }; /**************************************************************************************************/ diff --git a/source/commands/getrelabundcommand.cpp b/source/commands/getrelabundcommand.cpp index bb06ea06..21b2340a 100644 --- a/source/commands/getrelabundcommand.cpp +++ b/source/commands/getrelabundcommand.cpp @@ -179,51 +179,51 @@ int GetRelAbundCommand::execute(){ input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); delete input; out.close(); m->mothurRemove(outputFileName); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete lookup; m->clearGroups(); delete input; out.close(); m->mothurRemove(outputFileName); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } getRelAbundance(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } getRelAbundance(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete input; out.close(); m->mothurRemove(outputFileName); return 0; } //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input->getSharedRAbundVectors(); } if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete input; out.close(); m->mothurRemove(outputFileName); return 0; } @@ -243,14 +243,14 @@ int GetRelAbundCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } getRelAbundance(lookup, out); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //reset groups parameter @@ -281,34 +281,32 @@ int GetRelAbundCommand::execute(){ } //********************************************************************************************************************** -int GetRelAbundCommand::getRelAbundance(vector& thisLookUp, ofstream& out){ +int GetRelAbundCommand::getRelAbundance(SharedRAbundVectors*& thisLookUp, ofstream& out){ try { - - for (int i = 0; i < thisLookUp.size(); i++) { - out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t' << thisLookUp[i]->getNumBins(); + vector groups = thisLookUp->getNamesGroups(); + for (int i = 0; i < thisLookUp->size(); i++) { + out << thisLookUp->getLabel() << '\t' << groups[i] << '\t' << thisLookUp->getNumBins(); - for (int j = 0; j < thisLookUp[i]->getNumBins(); j++) { + for (int j = 0; j < thisLookUp->getNumBins(); j++) { if (m->control_pressed) { return 0; } - int abund = thisLookUp[i]->getAbundance(j); + int abund = thisLookUp->get(j, groups[i]); float relabund = 0.0; if (scale == "totalgroup") { - relabund = abund / (float) thisLookUp[i]->getNumSeqs(); + relabund = abund / (float) thisLookUp->getNumSeqs(groups[i]); }else if (scale == "totalotu") { //calc the total in this otu - int totalOtu = 0; - for (int l = 0; l < thisLookUp.size(); l++) { totalOtu += thisLookUp[l]->getAbundance(j); } + int totalOtu = thisLookUp->getOTUTotal(j); relabund = abund / (float) totalOtu; }else if (scale == "averagegroup") { - relabund = abund / (float) (thisLookUp[i]->getNumSeqs() / (float) thisLookUp[i]->getNumBins()); + relabund = abund / (float) (thisLookUp->getNumSeqs(groups[i]) / (float) thisLookUp->getNumBins()); }else if (scale == "averageotu") { //calc the total in this otu - int totalOtu = 0; - for (int l = 0; l < thisLookUp.size(); l++) { totalOtu += thisLookUp[l]->getAbundance(j); } - float averageOtu = totalOtu / (float) thisLookUp.size(); + int totalOtu = thisLookUp->getOTUTotal(j); + float averageOtu = totalOtu / (float) thisLookUp->size(); relabund = abund / (float) averageOtu; }else{ m->mothurOut(scale + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } diff --git a/source/commands/getrelabundcommand.h b/source/commands/getrelabundcommand.h index dcb4cf71..79a34971 100644 --- a/source/commands/getrelabundcommand.h +++ b/source/commands/getrelabundcommand.h @@ -12,8 +12,6 @@ #include "command.hpp" #include "inputdata.h" -#include "sharedrabundvector.h" - class GetRelAbundCommand : public Command { @@ -37,14 +35,14 @@ class GetRelAbundCommand : public Command { private: InputData* input; - vector lookup; + SharedRAbundVectors* lookup; bool abort, allLines, pickedGroups; set labels; //holds labels to be used string groups, label, outputDir, scale, sharedfile; vector Groups, outputNames; - int getRelAbundance(vector&, ofstream&); + int getRelAbundance(SharedRAbundVectors*&, ofstream&); }; diff --git a/source/commands/getsharedotucommand.cpp b/source/commands/getsharedotucommand.cpp index 30963a73..d8487f4d 100644 --- a/source/commands/getsharedotucommand.cpp +++ b/source/commands/getsharedotucommand.cpp @@ -613,8 +613,8 @@ int GetSharedOTUCommand::process(ListVector* shared) { int GetSharedOTUCommand::runShared() { try { InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); if (Groups.size() == 0) { Groups = m->getGroups(); @@ -641,48 +641,48 @@ int GetSharedOTUCommand::runShared() { set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; + delete lookup; m->clearGroups(); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + m->mothurOut(lookup->getLabel()); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; + delete lookup; m->clearGroups(); return 0; } //output error messages about any remaining user labels @@ -700,12 +700,12 @@ int GetSharedOTUCommand::runShared() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); process(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //reset groups parameter @@ -720,14 +720,14 @@ int GetSharedOTUCommand::runShared() { } } /***********************************************************/ -int GetSharedOTUCommand::process(vector& lookup) { +int GetSharedOTUCommand::process(SharedRAbundVectors*& lookup) { try { string outputFileNames; if (outputDir == "") { outputDir += m->hasPath(sharedfile); } map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); variables["[group]"] = userGroups; if (output != "accnos") { outputFileNames = getOutputFileName("sharedseqs", variables); } else { outputFileNames = getOutputFileName("accnos", variables); } @@ -739,7 +739,7 @@ int GetSharedOTUCommand::process(vector& lookup) { int num = 0; //go through each bin, find out if shared - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { outNames.close(); m->mothurRemove(outputFileNames); return 0; } bool uniqueOTU = true; @@ -748,13 +748,15 @@ int GetSharedOTUCommand::process(vector& lookup) { set namesOfGroupsInThisBin; - for(int j = 0; j < lookup.size(); j++) { - string seqGroup = lookup[j]->getGroup(); + vector groupNames = lookup->getNamesGroups(); + for(int j = 0; j < lookup->size(); j++) { + string seqGroup = groupNames[j]; string name = m->currentSharedBinLabels[i]; + int abund = lookup->get(i, seqGroup); - if (lookup[j]->getAbundance(i) != 0) { + if (abund != 0) { if (output != "accnos") { - namesOfGroupsInThisBin.insert(name + "|" + seqGroup + "|" + toString(lookup[j]->getAbundance(i))); + namesOfGroupsInThisBin.insert(name + "|" + seqGroup + "|" + toString(abund)); }else { namesOfGroupsInThisBin.insert(name); } //is this seq in one of the groups we care about diff --git a/source/commands/getsharedotucommand.h b/source/commands/getsharedotucommand.h index cfc933ac..3a5460da 100644 --- a/source/commands/getsharedotucommand.h +++ b/source/commands/getsharedotucommand.h @@ -15,7 +15,7 @@ #include "sequence.hpp" #include "groupmap.h" #include "counttable.h" -#include "sharedrabundvector.h" + #include "inputdata.h" //********************************************************************************************************************** @@ -57,7 +57,7 @@ class GetSharedOTUCommand : public Command { vector outputNames; int process(ListVector*); - int process(vector&); + int process(SharedRAbundVectors*&); int runShared(); }; diff --git a/source/commands/heatmapcommand.cpp b/source/commands/heatmapcommand.cpp index 809b1d6b..5e033e29 100644 --- a/source/commands/heatmapcommand.cpp +++ b/source/commands/heatmapcommand.cpp @@ -281,7 +281,7 @@ int HeatMapCommand::execute(){ if (format == "sharedfile") { //you have groups lookup = input->getSharedRAbundVectors(); - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); }else if ((format == "list") || (format == "rabund") || (format == "sabund")) { //you are using just a list file and have only one group @@ -290,7 +290,7 @@ int HeatMapCommand::execute(){ }else if (format == "relabund") { //you have groups lookupFloat = input->getSharedRAbundFloatVectors(); - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -300,48 +300,51 @@ int HeatMapCommand::execute(){ if (format == "sharedfile") { //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { m->mothurRemove(outputNames[i]); } } outputTypes.clear(); m->clearGroups(); delete input; delete heatmap; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookup); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + string outputFileName = heatmap->getPic(data, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookup); + vector data = lookup->getSharedRAbundVectors(); + string outputFileName = heatmap->getPic(data, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input->getSharedRAbundVectors(); } @@ -366,13 +369,16 @@ int HeatMapCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookup); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + string outputFileName = heatmap->getPic(data, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //reset groups parameter @@ -453,47 +459,51 @@ int HeatMapCommand::execute(){ }else { //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookupFloat != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { m->mothurRemove(outputNames[i]); } } outputTypes.clear(); m->clearGroups(); delete input; delete heatmap; return 0; } - if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookupFloat->getLabel()) == 1){ - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookupFloat); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); + vector data = lookupFloat->getSharedRAbundFloatVectors(); + string outputFileName = heatmap->getPic(data, lookupFloat->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookupFloat); + vector data = lookupFloat->getSharedRAbundFloatVectors(); + string outputFileName = heatmap->getPic(data, lookupFloat->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; } + delete lookupFloat; //get next line to process - lookupFloat = input->getSharedRAbundFloatVectors(); + lookupFloat = input->getSharedRAbundFloatVectors(); } @@ -518,18 +528,20 @@ int HeatMapCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); - - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); - string outputFileName = heatmap->getPic(lookupFloat); + delete lookupFloat; + lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); + + vector data = lookupFloat->getSharedRAbundFloatVectors(); + string outputFileName = heatmap->getPic(data, lookupFloat->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } + outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; } //reset groups parameter m->clearGroups(); - } delete input; diff --git a/source/commands/heatmapcommand.h b/source/commands/heatmapcommand.h index fc5165ed..bd9ccacc 100644 --- a/source/commands/heatmapcommand.h +++ b/source/commands/heatmapcommand.h @@ -42,8 +42,8 @@ class HeatMapCommand : public Command { private: InputData* input; RAbundVector* rabund; - vector lookup; - vector lookupFloat; + SharedRAbundVectors* lookup; + SharedRAbundFloatVectors* lookupFloat; HeatMap* heatmap; bool abort, allLines; diff --git a/source/commands/heatmapsimcommand.cpp b/source/commands/heatmapsimcommand.cpp index 67576807..d9a74ac8 100644 --- a/source/commands/heatmapsimcommand.cpp +++ b/source/commands/heatmapsimcommand.cpp @@ -356,55 +356,59 @@ int HeatMapSimCommand::runCommandShared() { if (heatCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } input = new InputData(sharedfile, "sharedfile"); - lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input->getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; } + if (m->control_pressed) { delete input; delete lookup; m->clearGroups(); return 0; } //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; } + if (m->control_pressed) { delete input; delete lookup; m->clearGroups(); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - vector outfilenames = heatmap->getPic(lookup, heatCalculators); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + vector outfilenames = heatmap->getPic(data, heatCalculators, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - vector outfilenames = heatmap->getPic(lookup, heatCalculators); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + vector outfilenames = heatmap->getPic(data, heatCalculators, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } //prevent memory leak - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(); } @@ -429,14 +433,15 @@ int HeatMapSimCommand::runCommandShared() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); - - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - vector outfilenames = heatmap->getPic(lookup, heatCalculators); + delete lookup; + lookup = input->getSharedRAbundVectors(lastLabel); + + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + vector outfilenames = heatmap->getPic(data, heatCalculators, lookup->getNamesGroups()); + for (int i = 0; i < data.size(); i++) { delete data[i]; } for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } if (m->control_pressed) { delete input; m->clearGroups(); return 0; } diff --git a/source/commands/heatmapsimcommand.h b/source/commands/heatmapsimcommand.h index f421fdc5..c1a382c5 100644 --- a/source/commands/heatmapsimcommand.h +++ b/source/commands/heatmapsimcommand.h @@ -38,7 +38,6 @@ class HeatMapSimCommand : public Command { private: InputData* input; - vector lookup; vector heatCalculators; HeatMapSim* heatmap; OptionParser* parser; diff --git a/source/commands/indicatorcommand.cpp b/source/commands/indicatorcommand.cpp index eb79127c..a9f89ec3 100644 --- a/source/commands/indicatorcommand.cpp +++ b/source/commands/indicatorcommand.cpp @@ -254,7 +254,7 @@ int IndicatorCommand::execute(){ vector nameGroups = designMap->getCategory(); util.setGroups(Groups, nameGroups); - vector namesSeqs = designMap->getNamesGroups(Groups); + namesSeqs = designMap->getNamesGroups(Groups); m->setGroups(namesSeqs); } @@ -263,12 +263,12 @@ int IndicatorCommand::execute(){ /***************************************************/ if (sharedfile != "") { getShared(); - if (m->control_pressed) { if (designfile != "") { delete designMap; } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } - if (lookup[0] == NULL) { m->mothurOut("[ERROR] reading shared file."); m->mothurOutEndLine(); return 0; } + if (m->control_pressed) { if (designfile != "") { delete designMap; } delete lookup; return 0; } + if (lookup == NULL) { m->mothurOut("[ERROR] reading shared file."); m->mothurOutEndLine(); return 0; } }else { getSharedFloat(); - if (m->control_pressed) { if (designfile != "") { delete designMap; } for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } return 0; } - if (lookupFloat[0] == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } + if (m->control_pressed) { if (designfile != "") { delete designMap; } delete lookupFloat; return 0; } + if (lookupFloat == NULL) { m->mothurOut("[ERROR] reading relabund file."); m->mothurOutEndLine(); return 0; } } //reset groups if needed @@ -316,8 +316,8 @@ int IndicatorCommand::execute(){ if (mismatch) { //cleanup and exit if (designfile != "") { delete designMap; } - if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } + if (sharedfile != "") { delete lookup; } + else { delete lookupFloat; } delete ct; return 0; } @@ -333,8 +333,8 @@ int IndicatorCommand::execute(){ if (m->control_pressed) { if (designfile != "") { delete designMap; } - if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } + if (sharedfile != "") { delete lookup; } + else { delete lookupFloat; } for (int i = 0; i < T.size(); i++) { delete T[i]; } delete ct; return 0; } @@ -353,8 +353,8 @@ int IndicatorCommand::execute(){ if (m->control_pressed) { if (designfile != "") { delete designMap; } - if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } + if (sharedfile != "") { delete lookup; } + else { delete lookupFloat; } delete outputTree; delete ct; return 0; } @@ -370,9 +370,9 @@ int IndicatorCommand::execute(){ } if (designfile != "") { delete designMap; } - if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } - + if (sharedfile != "") { delete lookup; } + else { delete lookupFloat; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //set tree file as new current treefile @@ -415,8 +415,8 @@ int IndicatorCommand::GetIndicatorSpecies(){ m->mothurOutEndLine(); m->mothurOut("Species\tIndicator_Groups\tIndicatorValue\tpValue\n"); int numBins = 0; - if (sharedfile != "") { numBins = lookup[0]->getNumBins(); } - else { numBins = lookupFloat[0]->getNumBins(); } + if (sharedfile != "") { numBins = lookup->getNumBins(); } + else { numBins = lookupFloat->getNumBins(); } if (m->control_pressed) { out.close(); return 0; } @@ -431,51 +431,63 @@ int IndicatorCommand::GetIndicatorSpecies(){ if (sharedfile != "") { vector< vector > groupings; + vector< vector > groupingNames; set groupsAlreadyAdded; vector subset; + vector subsetNames; + + vector data = lookup->getSharedRAbundVectors(); + vector dataGroupNames = lookup->getNamesGroups(); //for each grouping for (int i = 0; i < (designMap->getCategory()).size(); i++) { - for (int k = 0; k < lookup.size(); k++) { + for (int k = 0; k < data.size(); k++) { //are you from this grouping? - if (designMap->get(lookup[k]->getGroup()) == (designMap->getCategory())[i]) { - subset.push_back(lookup[k]); - groupsAlreadyAdded.insert(lookup[k]->getGroup()); + if (designMap->get(dataGroupNames[k]) == (designMap->getCategory())[i]) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); } } - if (subset.size() != 0) { groupings.push_back(subset); } + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } subset.clear(); } - if (groupsAlreadyAdded.size() != lookup.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } + if (groupsAlreadyAdded.size() != data.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } - indicatorValues = getValues(groupings, indicatorGroups, randomGroupingsMap); + indicatorValues = getValues(groupings, groupingNames, indicatorGroups, randomGroupingsMap); - pValues = getPValues(groupings, lookup.size(), indicatorValues); + pValues = getPValues(groupings, groupingNames, lookup->size(), indicatorValues); }else { vector< vector > groupings; + vector< vector > groupingNames; set groupsAlreadyAdded; vector subset; + vector subsetNames; + + vector data = lookupFloat->getSharedRAbundFloatVectors(); + vector dataGroupNames = lookupFloat->getNamesGroups(); //for each grouping for (int i = 0; i < (designMap->getCategory()).size(); i++) { - for (int k = 0; k < lookupFloat.size(); k++) { + for (int k = 0; k < data.size(); k++) { //are you from this grouping? - if (designMap->get(lookupFloat[k]->getGroup()) == (designMap->getCategory())[i]) { - subset.push_back(lookupFloat[k]); - groupsAlreadyAdded.insert(lookupFloat[k]->getGroup()); + if (designMap->get(dataGroupNames[k]) == (designMap->getCategory())[i]) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); } } - if (subset.size() != 0) { groupings.push_back(subset); } + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } subset.clear(); } - if (groupsAlreadyAdded.size() != lookupFloat.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } + if (groupsAlreadyAdded.size() != data.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } - indicatorValues = getValues(groupings, indicatorGroups, randomGroupingsMap); + indicatorValues = getValues(groupings, groupingNames, indicatorGroups, randomGroupingsMap); - pValues = getPValues(groupings, lookupFloat.size(), indicatorValues); + pValues = getPValues(groupings, groupingNames, lookupFloat->size(), indicatorValues); } if (m->control_pressed) { out.close(); return 0; } @@ -532,8 +544,8 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); int numBins = 0; - if (sharedfile != "") { numBins = lookup[0]->getNumBins(); } - else { numBins = lookupFloat[0]->getNumBins(); } + if (sharedfile != "") { numBins = lookup->getNumBins(); } + else { numBins = lookupFloat->getNumBins(); } //print headings out << "TreeNode\t"; @@ -551,9 +563,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ //create a map from tree node index to names of descendants, save time later to know which sharedRabund you need map > nodeToDescendants; map > descendantNodes; - for (int i = 0; i < T->getNumNodes(); i++) { - if (m->control_pressed) { return 0; } - + for (int i = 0; i < T->getNumNodes(); i++) { if (m->control_pressed) { return 0; } nodeToDescendants[i] = getDescendantList(T, i, nodeToDescendants, descendantNodes); } @@ -563,7 +573,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ //for each node for (int i = T->getNumLeaves(); i < T->getNumNodes(); i++) { - //cout << endl << i+1 << endl; + if (m->control_pressed) { out.close(); return 0; } /*****************************************************/ @@ -577,6 +587,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ if (sharedfile != "") { vector< vector > groupings; + vector< vector > groupingNames; //get nodes that will be a valid grouping //you are valid if you are not one of my descendants @@ -586,49 +597,55 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ set groupsAlreadyAdded; //create a grouping with my grouping vector subset; + vector subsetNames; int count = 0; int doneCount = nodeToDescendants[i].size(); - for (int k = 0; k < lookup.size(); k++) { + vector data = lookupFloat->getSharedRAbundVectors(); + vector dataGroupNames = lookupFloat->getNamesGroups(); + + for (int k = 0; k < data.size(); k++) { //is this descendant of i - if ((nodeToDescendants[i].count(lookup[k]->getGroup()) != 0)) { - subset.push_back(lookup[k]); - groupsAlreadyAdded.insert(lookup[k]->getGroup()); + if ((nodeToDescendants[i].count(dataGroupNames[k]) != 0)) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); count++; } if (count == doneCount) { break; } //quit once you get the rabunds for this grouping } - if (subset.size() != 0) { groupings.push_back(subset); } - + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } for (int j = (T->getNumNodes()-1); j >= 0; j--) { - if ((descendantNodes[i].count(j) == 0) && (distToRoot[j] >= distToRoot[i])) { vector subset; + vector subsetNames; int count = 0; int doneCount = nodeToDescendants[j].size(); - for (int k = 0; k < lookup.size(); k++) { + for (int k = 0; k < data.size(); k++) { //is this descendant of j, and we didn't already add this as part of a larger grouping - if ((nodeToDescendants[j].count(lookup[k]->getGroup()) != 0) && (groupsAlreadyAdded.count(lookup[k]->getGroup()) == 0)) { - subset.push_back(lookup[k]); - groupsAlreadyAdded.insert(lookup[k]->getGroup()); + if ((nodeToDescendants[j].count(dataGroupNames[k]) != 0) && (groupsAlreadyAdded.count(dataGroupNames[k]) == 0)) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); count++; } if (count == doneCount) { break; } //quit once you get the rabunds for this grouping } //if subset.size == 0 then the node was added as part of a larger grouping - if (subset.size() != 0) { groupings.push_back(subset); } + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } } } - if (groupsAlreadyAdded.size() != lookup.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } + if (groupsAlreadyAdded.size() != data.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } - indicatorValues = getValues(groupings, indicatorGroups, randomGroupingsMap); + indicatorValues = getValues(groupings, groupingNames, indicatorGroups, randomGroupingsMap); - pValues = getPValues(groupings, lookup.size(), indicatorValues); + pValues = getPValues(groupings, groupingNames, data.size(), indicatorValues); }else { vector< vector > groupings; + vector< vector > groupingNames; //get nodes that will be a valid grouping //you are valid if you are not one of my descendants @@ -638,44 +655,52 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ set groupsAlreadyAdded; //create a grouping with my grouping vector subset; + vector subsetNames; int count = 0; int doneCount = nodeToDescendants[i].size(); - for (int k = 0; k < lookupFloat.size(); k++) { + + vector data = lookupFloat->getSharedRAbundFloatVectors(); + vector dataGroupNames = lookupFloat->getNamesGroups(); + + for (int k = 0; k < data.size(); k++) { //is this descendant of i - if ((nodeToDescendants[i].count(lookupFloat[k]->getGroup()) != 0)) { - subset.push_back(lookupFloat[k]); - groupsAlreadyAdded.insert(lookupFloat[k]->getGroup()); + if ((nodeToDescendants[i].count(dataGroupNames[k]) != 0)) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); count++; } if (count == doneCount) { break; } //quit once you get the rabunds for this grouping } - if (subset.size() != 0) { groupings.push_back(subset); } + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } for (int j = (T->getNumNodes()-1); j >= 0; j--) { if ((descendantNodes[i].count(j) == 0) && (distToRoot[j] >= distToRoot[i])) { vector subset; + vector subsetNames; int count = 0; int doneCount = nodeToDescendants[j].size(); - for (int k = 0; k < lookupFloat.size(); k++) { + for (int k = 0; k < data.size(); k++) { //is this descendant of j, and we didn't already add this as part of a larger grouping - if ((nodeToDescendants[j].count(lookupFloat[k]->getGroup()) != 0) && (groupsAlreadyAdded.count(lookupFloat[k]->getGroup()) == 0)) { - subset.push_back(lookupFloat[k]); - groupsAlreadyAdded.insert(lookupFloat[k]->getGroup()); + if ((nodeToDescendants[j].count(dataGroupNames[k]) != 0) && (groupsAlreadyAdded.count(dataGroupNames[k]) == 0)) { + subset.push_back(data[k]); + subsetNames.push_back(dataGroupNames[k]); + groupsAlreadyAdded.insert(dataGroupNames[k]); count++; } if (count == doneCount) { break; } //quit once you get the rabunds for this grouping } //if subset.size == 0 then the node was added as part of a larger grouping - if (subset.size() != 0) { groupings.push_back(subset); } + if (subset.size() != 0) { groupings.push_back(subset); groupingNames.push_back(subsetNames); } } } - if (groupsAlreadyAdded.size() != lookupFloat.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } + if (groupsAlreadyAdded.size() != data.size()) { m->mothurOut("[ERROR]: could not make proper groupings."); m->mothurOutEndLine(); } - indicatorValues = getValues(groupings, indicatorGroups, randomGroupingsMap); + indicatorValues = getValues(groupings, groupingNames, indicatorGroups, randomGroupingsMap); - pValues = getPValues(groupings, lookupFloat.size(), indicatorValues); + pValues = getPValues(groupings, groupingNames, data.size(), indicatorValues); } if (m->control_pressed) { out.close(); return 0; } @@ -725,7 +750,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ } } //********************************************************************************************************************** -vector IndicatorCommand::getValues(vector< vector >& groupings, vector& indicatorGroupings, map< vector, vector > groupingsMap){ +vector IndicatorCommand::getValues(vector< vector >& groupings, vector< vector >& groupingNames, vector& indicatorGroupings, map< vector, vector > groupingsMap){ try { vector values; map< vector, vector >::iterator it; @@ -737,9 +762,9 @@ vector IndicatorCommand::getValues(vector< vectorgetGroup() + "-"; + tempGrouping += groupingNames[j][k] + "-"; } - tempGrouping += groupings[j][groupings[j].size()-1]->getGroup(); + tempGrouping += groupingNames[j][groupingNames[j].size()-1]; groupingsGroups.push_back(tempGrouping); } @@ -763,11 +788,11 @@ vector IndicatorCommand::getValues(vector< vectorgetAbundance(i); - if (groupings[j][k]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += groupings[j][k]->get(i); + if (groupings[j][k]->get(i) != 0.0) { numNotZero++; } }else { - totalAbund += groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i); - if (groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += groupings[(it->second)[0]][(it->second)[1]]->get(i); + if (groupings[(it->second)[0]][(it->second)[1]]->get(i) != 0.0) { numNotZero++; } } } @@ -805,7 +830,7 @@ vector IndicatorCommand::getValues(vector< vector IndicatorCommand::getValues(vector< vector >& groupings, vector& indicatorGroupings, map< vector, vector > groupingsMap){ +vector IndicatorCommand::getValues(vector< vector >& groupings, vector< vector >& groupingNames,vector& indicatorGroupings, map< vector, vector > groupingsMap){ try { vector values; map< vector, vector >::iterator it; @@ -817,9 +842,9 @@ vector IndicatorCommand::getValues(vector< vector >& for (int j = 0; j < groupings.size(); j++) { string tempGrouping = ""; for (int k = 0; k < groupings[j].size()-1; k++) { - tempGrouping += groupings[j][k]->getGroup() + "-"; + tempGrouping += groupingNames[j][k] + "-"; } - tempGrouping += groupings[j][groupings[j].size()-1]->getGroup(); + tempGrouping += groupingNames[j][groupingNames[j].size()-1]; groupingsGroups.push_back(tempGrouping); } @@ -839,11 +864,11 @@ vector IndicatorCommand::getValues(vector< vector >& it = groupingsMap.find(temp); if (it == groupingsMap.end()) { //this one didnt get moved - totalAbund += groupings[j][k]->getAbundance(i); - if (groupings[j][k]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += groupings[j][k]->get(i); + if (groupings[j][k]->get(i) != 0.0) { numNotZero++; } }else { - totalAbund += groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i); - if (groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += groupings[(it->second)[0]][(it->second)[1]]->get(i); + if (groupings[(it->second)[0]][(it->second)[1]]->get(i) != 0.0) { numNotZero++; } } } @@ -990,11 +1015,11 @@ set IndicatorCommand::getDescendantList(Tree*& T, int i, mapgetSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + InputData input(sharedfile, "sharedfile"); + lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (label == "") { label = lastLabel; delete input; return 0; } + if (label == "") { label = lastLabel; return 0; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); @@ -1002,39 +1027,39 @@ int IndicatorCommand::getShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { delete input; return 0; } + while((lookup != NULL) && (userLabels.size() != 0)) { + if (m->control_pressed) { return 0; } - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); break; } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); break; } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + delete lookup; + lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { delete input; return 0; } + if (m->control_pressed) { return 0; } //output error messages about any remaining user labels set::iterator it; @@ -1051,11 +1076,10 @@ int IndicatorCommand::getShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); } - delete input; return 0; } catch(exception& e) { @@ -1066,11 +1090,11 @@ int IndicatorCommand::getShared(){ //********************************************************************************************************************** int IndicatorCommand::getSharedFloat(){ try { - InputData* input = new InputData(relabundfile, "relabund"); - lookupFloat = input->getSharedRAbundFloatVectors(); - string lastLabel = lookupFloat[0]->getLabel(); + InputData input(relabundfile, "relabund"); + lookupFloat = input.getSharedRAbundFloatVectors(); + string lastLabel = lookupFloat->getLabel(); - if (label == "") { label = lastLabel; delete input; return 0; } + if (label == "") { label = lastLabel; return 0; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); @@ -1078,40 +1102,40 @@ int IndicatorCommand::getSharedFloat(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && (userLabels.size() != 0)) { + while((lookupFloat != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { delete input; return 0; } + if (m->control_pressed) { return 0; } - if(labels.count(lookupFloat[0]->getLabel()) == 1){ - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + if(labels.count(lookupFloat->getLabel()) == 1){ + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); break; } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + delete lookupFloat; + lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); break; } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } - lookupFloat = input->getSharedRAbundFloatVectors(); + delete lookupFloat; + lookupFloat = input.getSharedRAbundFloatVectors(); } - if (m->control_pressed) { delete input; return 0; } + if (m->control_pressed) { return 0; } //output error messages about any remaining user labels set::iterator it; @@ -1128,11 +1152,10 @@ int IndicatorCommand::getSharedFloat(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + delete lookupFloat; + lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); } - delete input; return 0; } catch(exception& e) { @@ -1141,7 +1164,7 @@ int IndicatorCommand::getSharedFloat(){ } } //********************************************************************************************************************** -vector IndicatorCommand::driver(vector< vector >& groupings, int num, vector indicatorValues, int numIters){ +vector IndicatorCommand::driver(vector< vector >& groupings, vector< vector >& groupingNames, int num, vector indicatorValues, int numIters){ try { vector pvalues; pvalues.resize(indicatorValues.size(), 0); @@ -1150,7 +1173,7 @@ vector IndicatorCommand::driver(vector< vector for(int i=0;icontrol_pressed) { break; } map< vector, vector > groupingsMap = randomizeGroupings(groupings, num); - vector randomIndicatorValues = getValues(groupings, notUsedGroupings, groupingsMap); + vector randomIndicatorValues = getValues(groupings,groupingNames, notUsedGroupings, groupingsMap); for (int j = 0; j < indicatorValues.size(); j++) { if (randomIndicatorValues[j] >= indicatorValues[j]) { pvalues[j]++; } @@ -1165,13 +1188,13 @@ vector IndicatorCommand::driver(vector< vector } } //********************************************************************************************************************** -vector IndicatorCommand::getPValues(vector< vector >& groupings, int num, vector indicatorValues){ +vector IndicatorCommand::getPValues(vector< vector >& groupings, vector< vector >& groupingNames, int num, vector indicatorValues){ try { vector pvalues; bool recalc = false; if(processors == 1){ - pvalues = driver(groupings, num, indicatorValues, iters); + pvalues = driver(groupings, groupingNames, num, indicatorValues, iters); for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; } }else{ //divide iters between processors @@ -1197,7 +1220,7 @@ vector IndicatorCommand::getPValues(vector< vector IndicatorCommand::getPValues(vector< vector IndicatorCommand::getPValues(vector< vector IndicatorCommand::getPValues(vector< vectorgetNumBins(); k++) { if (m->control_pressed) { for (int j = 0; j < newGroupings.size(); j++) { for (int u = 0; u < newGroupings[j].size(); u++) { delete newGroupings[j][u]; } } return pvalues; } - for (int j = 0; j < groupings[l].size(); j++) { newGroupings[l][j]->push_back(groupings[l][j]->getAbundance(k), groupings[l][j]->getGroup()); } + for (int j = 0; j < groupings[l].size(); j++) { newGroupings[l][j]->push_back(groupings[l][j]->get(k)); } } } @@ -1339,7 +1362,7 @@ vector IndicatorCommand::getPValues(vector< vector IndicatorCommand::getPValues(vector< vector IndicatorCommand::driver(vector< vector >& groupings, int num, vector indicatorValues, int numIters){ +vector IndicatorCommand::driver(vector< vector >& groupings, vector< vector >& groupingNames, int num, vector indicatorValues, int numIters){ try { vector pvalues; pvalues.resize(indicatorValues.size(), 0); @@ -1380,7 +1403,7 @@ vector IndicatorCommand::driver(vector< vector >& gr for(int i=0;icontrol_pressed) { break; } map< vector, vector > groupingsMap = randomizeGroupings(groupings, num); - vector randomIndicatorValues = getValues(groupings, notUsedGroupings, groupingsMap); + vector randomIndicatorValues = getValues(groupings, groupingNames, notUsedGroupings, groupingsMap); for (int j = 0; j < indicatorValues.size(); j++) { if (randomIndicatorValues[j] >= indicatorValues[j]) { pvalues[j]++; } @@ -1396,13 +1419,13 @@ vector IndicatorCommand::driver(vector< vector >& gr } //********************************************************************************************************************** //same as above, just data type difference -vector IndicatorCommand::getPValues(vector< vector >& groupings, int num, vector indicatorValues){ +vector IndicatorCommand::getPValues(vector< vector >& groupings, vector< vector >& groupingNames, int num, vector indicatorValues){ try { vector pvalues; bool recalc = false; if(processors == 1){ - pvalues = driver(groupings, num, indicatorValues, iters); + pvalues = driver(groupings, groupingNames, num, indicatorValues, iters); for (int i = 0; i < pvalues.size(); i++) { pvalues[i] /= (double)iters; } }else{ //divide iters between processors @@ -1428,7 +1451,7 @@ vector IndicatorCommand::getPValues(vector< vector > processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ - pvalues = driver(groupings, num, indicatorValues, procIters[process]); + pvalues = driver(groupings, groupingNames, num, indicatorValues, procIters[process]); //pass pvalues to parent ofstream out; @@ -1485,7 +1508,7 @@ vector IndicatorCommand::getPValues(vector< vector > processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ - pvalues = driver(groupings, num, indicatorValues, procIters[process]); + pvalues = driver(groupings, groupingNames, num, indicatorValues, procIters[process]); //pass pvalues to parent ofstream out; @@ -1507,7 +1530,7 @@ vector IndicatorCommand::getPValues(vector< vector > } //do my part - pvalues = driver(groupings, num, indicatorValues, procIters[0]); + pvalues = driver(groupings, groupingNames, num, indicatorValues, procIters[0]); //force parent to wait until all the processes are done for (int i=0;i IndicatorCommand::getPValues(vector< vector > for (int k = 0; k < groupings[l][0]->getNumBins(); k++) { if (m->control_pressed) { for (int j = 0; j < newGroupings.size(); j++) { for (int u = 0; u < newGroupings[j].size(); u++) { delete newGroupings[j][u]; } } return pvalues; } - for (int j = 0; j < groupings[l].size(); j++) { newGroupings[l][j]->push_back((float)(groupings[l][j]->getAbundance(k)), groupings[l][j]->getGroup()); } + for (int j = 0; j < groupings[l].size(); j++) { newGroupings[l][j]->push_back((float)(groupings[l][j]->get(k))); } } } diff --git a/source/commands/indicatorcommand.h b/source/commands/indicatorcommand.h index db7c39bb..115fb37f 100644 --- a/source/commands/indicatorcommand.h +++ b/source/commands/indicatorcommand.h @@ -13,8 +13,8 @@ #include "command.hpp" #include "readtree.h" #include "counttable.h" -#include "sharedrabundvector.h" -#include "sharedrabundfloatvector.h" + + #include "inputdata.h" #include "designmap.h" @@ -43,27 +43,27 @@ class IndicatorCommand : public Command { string treefile, sharedfile, relabundfile, groups, label, inputFileName, outputDir, designfile; bool abort; int iters, processors; - vector outputNames, Groups; - vector lookup; - vector lookupFloat; + vector outputNames, Groups, namesSeqs; + SharedRAbundVectors* lookup; + SharedRAbundFloatVectors* lookupFloat; int getShared(); int getSharedFloat(); int GetIndicatorSpecies(Tree*&); int GetIndicatorSpecies(); set getDescendantList(Tree*&, int, map >, map >&); - vector getValues(vector< vector >&, vector&, map< vector, vector >); - vector getValues(vector< vector >&, vector&, map< vector, vector >); + vector getValues(vector< vector >&, vector< vector >&, vector&, map< vector, vector >); + vector getValues(vector< vector >&, vector< vector >&, vector&, map< vector, vector >); map getDistToRoot(Tree*&); map< vector, vector > randomizeGroupings(vector< vector >&, int); map< vector, vector > randomizeGroupings(vector< vector >&, int); - vector driver(vector< vector >&, int, vector, int); - vector driver(vector< vector >&, int, vector, int); + vector driver(vector< vector >&, vector< vector >&, int, vector, int); + vector driver(vector< vector >&, vector< vector >&, int, vector, int); - vector getPValues(vector< vector >&, int, vector); - vector getPValues(vector< vector >&, int, vector); + vector getPValues(vector< vector >&, vector< vector >&, int, vector); + vector getPValues(vector< vector >&, vector< vector >&, int, vector); }; @@ -148,11 +148,11 @@ static DWORD WINAPI MyIndicatorThreadFunction(LPVOID lpParam){ it = randomGroupings.find(temp); if (it == randomGroupings.end()) { //this one didnt get moved - totalAbund += pDataArray->groupings[j][k]->getAbundance(i); - if (pDataArray->groupings[j][k]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += pDataArray->groupings[j][k]->get(i); + if (pDataArray->groupings[j][k]->get(i) != 0.0) { numNotZero++; } }else { - totalAbund += pDataArray->groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i); - if (pDataArray->groupings[(it->second)[0]][(it->second)[1]]->getAbundance(i) != 0.0) { numNotZero++; } + totalAbund += pDataArray->groupings[(it->second)[0]][(it->second)[1]]->get(i); + if (pDataArray->groupings[(it->second)[0]][(it->second)[1]]->get(i) != 0.0) { numNotZero++; } } } diff --git a/source/commands/kruskalwalliscommand.cpp b/source/commands/kruskalwalliscommand.cpp index 27ca41cd..e0b36d99 100644 --- a/source/commands/kruskalwalliscommand.cpp +++ b/source/commands/kruskalwalliscommand.cpp @@ -179,8 +179,8 @@ int KruskalWallisCommand::execute(){ if (mclass == "") { mclass = designMap.getDefaultClass(); m->mothurOut("\nYou did not provide a class, using " + mclass +".\n\n"); } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -188,39 +188,43 @@ int KruskalWallisCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - process(lookup, designMap); + vector data = lookup->getSharedRAbundVectors(); + process(data, designMap); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); - process(lookup, designMap); + vector data = lookup->getSharedRAbundVectors(); + process(data, designMap); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -245,13 +249,15 @@ int KruskalWallisCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - process(lookup, designMap); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + process(data, designMap); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } @@ -300,7 +306,7 @@ int KruskalWallisCommand::process(vector& lookup, DesignMap for (int j = 0; j < lookup.size(); j++) { string group = lookup[j]->getGroup(); string treatment = designMap.get(group, mclass); //get value for this group in this category - spearmanRank temp(treatment, lookup[j]->getAbundance(i)); + spearmanRank temp(treatment, lookup[j]->get(i)); values.push_back(temp); } diff --git a/source/commands/lefsecommand.cpp b/source/commands/lefsecommand.cpp index 7caba42d..e700285b 100644 --- a/source/commands/lefsecommand.cpp +++ b/source/commands/lefsecommand.cpp @@ -272,7 +272,7 @@ LefseCommand::LefseCommand(string option) { int LefseCommand::execute(){ try { - srand(1982); + m->setRandomSeed(1982); //for reading lefse formatted file and running in mothur for testing - pass number of rows used for design file if (false) { makeShared(1); exit(1); } @@ -296,47 +296,47 @@ int LefseCommand::execute(){ } InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundFloatVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundFloatVectors* lookup = input.getSharedRAbundFloatVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, designMap); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, designMap); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -361,13 +361,13 @@ int LefseCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, designMap); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } @@ -376,7 +376,7 @@ int LefseCommand::execute(){ m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); - srand((unsigned)time(NULL)); + m->setRandomSeed((unsigned)time(NULL)); return 0; } @@ -387,7 +387,7 @@ int LefseCommand::execute(){ } //********************************************************************************************************************** -int LefseCommand::process(vector& lookup, DesignMap& designMap) { +int LefseCommand::process(SharedRAbundFloatVectors*& lookup, DesignMap& designMap) { try { vector classes; vector subclasses; @@ -396,8 +396,9 @@ int LefseCommand::process(vector& lookup, DesignMap& d map > subClass2GroupIndex; //maps subclass name to vector of indexes in lookup from that subclass. old -> 1,2,3 means groups in location 1,2,3 of lookup are from old. Saves time below. map > class2GroupIndex; //maps subclass name to vector of indexes in lookup from that class. old -> 1,2,3 means groups in location 1,2,3 of lookup are from old. Saves time below. if (normMillion) { normalize(lookup); } - for (int j = 0; j < lookup.size(); j++) { - string group = lookup[j]->getGroup(); + vector namesOfGroups = lookup->getNamesGroups(); + for (int j = 0; j < namesOfGroups.size(); j++) { + string group = namesOfGroups[j]; string treatment = designMap.get(group, mclass); //get value for this group in this category string thisSub = designMap.get(group, subclass); map::iterator it = subclass2Class.find(thisSub); @@ -459,7 +460,7 @@ int LefseCommand::process(vector& lookup, DesignMap& d if (m->debug) { m->mothurOut("[DEBUG]: completed lda\n"); } - printResults(means, significantOtuLabels, sigOTUSLDA, lookup[0]->getLabel(), classes); + printResults(means, significantOtuLabels, sigOTUSLDA, lookup->getLabel(), classes); return 0; } @@ -469,18 +470,18 @@ int LefseCommand::process(vector& lookup, DesignMap& d } } //********************************************************************************************************************** -int LefseCommand::normalize(vector& lookup) { +int LefseCommand::normalize(SharedRAbundFloatVectors*& lookup) { try { vector mul; - for (int i = 0; i < lookup.size(); i++) { - double sum = 0.0; - for (int j = 0; j < lookup[i]->getNumBins(); j++) { sum += lookup[i]->getAbundance(j); } + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < lookup->size(); i++) { + double sum = lookup->getNumSeqs(namesOfGroups[i]); mul.push_back(1000000.0/sum); } - for (int i = 0; i < lookup.size(); i++) { - for (int j = 0; j < lookup[i]->getNumBins(); j++) { - lookup[i]->set(j, lookup[i]->getAbundance(j)*mul[i], lookup[i]->getGroup()); + for (int i = 0; i < lookup->size(); i++) { + for (int j = 0; j < lookup->getNumBins(); j++) { + lookup->set(j, lookup->get(j, namesOfGroups[i])*mul[i], namesOfGroups[i]); } } @@ -492,14 +493,15 @@ int LefseCommand::normalize(vector& lookup) { } } //********************************************************************************************************************** -map LefseCommand::runKruskalWallis(vector& lookup, DesignMap& designMap) { +map LefseCommand::runKruskalWallis(SharedRAbundFloatVectors*& lookup, DesignMap& designMap) { try { map significantOtuLabels; - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); //sanity check to make sure each treatment has a group in the shared file set treatments; - for (int j = 0; j < lookup.size(); j++) { - string group = lookup[j]->getGroup(); + vector namesOfGroups = lookup->getNamesGroups(); + for (int j = 0; j < namesOfGroups.size(); j++) { + string group = namesOfGroups[j]; string treatment = designMap.get(group, mclass); //get value for this group in this category treatments.insert(treatment); } @@ -510,10 +512,11 @@ map LefseCommand::runKruskalWallis(vector if (m->control_pressed) { break; } vector values; - for (int j = 0; j < lookup.size(); j++) { - string group = lookup[j]->getGroup(); + vector abunds = lookup->getOTU(i); + for (int j = 0; j < namesOfGroups.size(); j++) { + string group = namesOfGroups[j]; string treatment = designMap.get(group, mclass); //get value for this group in this category - spearmanRank temp(treatment, lookup[j]->getAbundance(i)); + spearmanRank temp(treatment, abunds[j]); values.push_back(temp); } @@ -532,7 +535,7 @@ map LefseCommand::runKruskalWallis(vector } //********************************************************************************************************************** //assumes not neccessarily paired -map LefseCommand::runWilcoxon(vector& lookup, DesignMap& designMap, map bins, map >& class2SubClasses, map >& subClass2GroupIndex, map subclass2Class) { +map LefseCommand::runWilcoxon(SharedRAbundFloatVectors*& lookup, DesignMap& designMap, map bins, map >& class2SubClasses, map >& subClass2GroupIndex, map subclass2Class) { try { map significantOtuLabels; map::iterator it; @@ -542,14 +545,14 @@ map LefseCommand::runWilcoxon(vector& loo anything else */ - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); for (int i = 0; i < numBins; i++) { if (m->control_pressed) { break; } it = bins.find(i); if (it != bins.end()) { //flagged in Kruskal Wallis - vector abunds; for (int j = 0; j < lookup.size(); j++) { abunds.push_back(lookup[j]->getAbundance(i)); } + vector abunds = lookup->getOTU(i); bool sig = testOTUWilcoxon(class2SubClasses, abunds, subClass2GroupIndex, subclass2Class); if (sig) { significantOtuLabels[i] = it->second; } @@ -721,13 +724,13 @@ bool LefseCommand::testOTUWilcoxon(map >& class2SubClasses, } //********************************************************************************************************************** //modelled after lefse.py test_lda_r function -map LefseCommand::testLDA(vector& lookup, map bins, map >& class2GroupIndex, map >& subClass2GroupIndex) { +map LefseCommand::testLDA(SharedRAbundFloatVectors*& lookup, map bins, map >& class2GroupIndex, map >& subClass2GroupIndex) { try { map sigOTUS; map::iterator it; LinearAlgebra linear; - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); vector< vector > adjustedLookup; for (int i = 0; i < numBins; i++) { @@ -741,8 +744,8 @@ map LefseCommand::testLDA(vector& lookup, if (m->debug) { m->mothurOut("[DEBUG]:flagged bin = " + toString(i) + "\n."); } //fill x with this OTUs abundances - vector x; - for (int j = 0; j < lookup.size(); j++) { x.push_back(lookup[j]->getAbundance(i)); } + vector tempx = lookup->getOTU(i); + vector x; for (int h = 0; h < tempx.size(); h++) { x.push_back((double)tempx[h]); } //go through classes for (map >::iterator it = class2GroupIndex.begin(); it != class2GroupIndex.end(); it++) { @@ -782,7 +785,7 @@ map LefseCommand::testLDA(vector& lookup, classes.push_back(it->first); } - int numGroups = lookup.size(); //lfk + int numGroups = lookup->size(); //lfk int fractionNumGroups = numGroups * fBoots; //rfk minCl = (int)((float)(minCl*fBoots*fBoots*0.05)); minCl = max(minCl, 1); @@ -812,8 +815,8 @@ map LefseCommand::testLDA(vector& lookup, //print data in R input format for testing if (false) { - vector groups; for (int h = 0; h < rand_s.size(); h++) { groups.push_back(lookup[rand_s[h]]->getGroup()); } - for (int h = 0; h < groups.size(); h++) { cout << groups[h]<< endl; } + //vector groups; for (int h = 0; h < rand_s.size(); h++) { groups.push_back(lookup[rand_s[h]]->getGroup()); } + //for (int h = 0; h < groups.size(); h++) { cout << groups[h]<< endl; } //printToCoutForRTesting(adjustedLookup, rand_s, class2GroupIndex, bins, subClass2GroupIndex, groups); } if (save < 1000) { m->mothurOut("[WARNING]: Skipping iter " + toString(j+1) + " in LDA test. This can be caused by too few groups per class or not enough contrast within the classes. \n"); } @@ -856,9 +859,9 @@ map LefseCommand::testLDA(vector& lookup, } } //********************************************************************************************************************** -vector< vector > LefseCommand::getMeans(vector& lookup, map >& class2GroupIndex) { +vector< vector > LefseCommand::getMeans(SharedRAbundFloatVectors*& lookup, map >& class2GroupIndex) { try { - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); int numClasses = class2GroupIndex.size(); vector< vector > means; //[numOTUS][classes] means.resize(numBins); @@ -876,9 +879,10 @@ vector< vector > LefseCommand::getMeans(vector } for (int i = 0; i < numBins; i++) { - for (int j = 0; j < lookup.size(); j++) { + vector abunds = lookup->getOTU(i); + for (int j = 0; j < abunds.size(); j++) { if (m->control_pressed) { return means; } - means[i][quickIndex[indexToClass[j]]] += lookup[j]->getAbundance(i); + means[i][quickIndex[indexToClass[j]]] += abunds[j]; } } @@ -1167,7 +1171,7 @@ bool LefseCommand::printToCoutForRTesting(vector< vector >& adjustedLook exit(1); } } -//********************************************************************************************************************** +/********************************************************************************************************************** int LefseCommand::makeShared(int numDesignLines) { try { ifstream in; @@ -1195,7 +1199,7 @@ int LefseCommand::makeShared(int numDesignLines) { out.close(); DesignMap design(sharedfile+".design"); - vector lookup; + SharedRAbundFloatVectors* lookup; for (int k = 0; k < lines[0].size()-1; k++) { SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); temp->setLabel("0.03"); @@ -1247,6 +1251,7 @@ int LefseCommand::makeShared(int numDesignLines) { } } -//********************************************************************************************************************** +//**********************************************************************************************************************/ + diff --git a/source/commands/lefsecommand.h b/source/commands/lefsecommand.h index 4f9ca72e..42a46ff1 100644 --- a/source/commands/lefsecommand.h +++ b/source/commands/lefsecommand.h @@ -55,15 +55,15 @@ class LefseCommand : public Command { double anovaAlpha, wilcoxonAlpha, fBoots, ldaThreshold; int nlogs, iters, strict, minC; - int process(vector&, DesignMap&); - int normalize(vector&); - map runKruskalWallis(vector&, DesignMap&); - map runWilcoxon(vector&, DesignMap&, map, map >& class2SubClasses, map >& subClass2GroupIndex, map); + int process(SharedRAbundFloatVectors*&, DesignMap&); + int normalize(SharedRAbundFloatVectors*&); + map runKruskalWallis(SharedRAbundFloatVectors*&, DesignMap&); + map runWilcoxon(SharedRAbundFloatVectors*&, DesignMap&, map, map >& class2SubClasses, map >& subClass2GroupIndex, map); bool testOTUWilcoxon(map >& class2SubClasses, vector abunds, map >& subClass2GroupIndex, map); - map testLDA(vector&, map, map >& class2GroupIndex, map >&); + map testLDA(SharedRAbundFloatVectors*&, map, map >& class2GroupIndex, map >&); bool contastWithinClassesOrFewPerClass(vector< vector >&, vector rands, int minCl, map > class2GroupIndex, map indexToClass); vector< vector > lda(vector< vector >& adjustedLookup, vector rand_s, map& indexToClass, vector); - vector< vector > getMeans(vector& lookup, map >& class2GroupIndex); + vector< vector > getMeans(SharedRAbundFloatVectors*& lookup, map >& class2GroupIndex); int printResults(vector< vector >, map, map, string, vector); //for testing diff --git a/source/commands/listotulabelscommand.cpp b/source/commands/listotulabelscommand.cpp index 9e06dfcd..b3b1135f 100644 --- a/source/commands/listotulabelscommand.cpp +++ b/source/commands/listotulabelscommand.cpp @@ -207,47 +207,47 @@ int ListOtuLabelsCommand::execute(){ InputData input(inputFileName, format); if (format == "relabund") { - vector lookup = input.getSharedRAbundFloatVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundFloatVectors* lookup = input.getSharedRAbundFloatVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -272,58 +272,58 @@ int ListOtuLabelsCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } }else if (format == "sharedfile") { - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -348,14 +348,14 @@ int ListOtuLabelsCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); createList(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } }else { ListVector* list = input.getListVector(); @@ -451,12 +451,12 @@ int ListOtuLabelsCommand::execute(){ } //********************************************************************************************************************** -int ListOtuLabelsCommand::createList(vector& lookup){ +int ListOtuLabelsCommand::createList(SharedRAbundVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("otulabels",variables); outputNames.push_back(outputFileName); outputTypes["otulabels"].push_back(outputFileName); ofstream out; @@ -476,11 +476,11 @@ int ListOtuLabelsCommand::createList(vector& lookup){ //********************************************************************************************************************** -int ListOtuLabelsCommand::createList(vector& lookup){ +int ListOtuLabelsCommand::createList(SharedRAbundFloatVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("otulabels",variables); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); ofstream out; diff --git a/source/commands/listotulabelscommand.h b/source/commands/listotulabelscommand.h index d3809146..8df94c79 100644 --- a/source/commands/listotulabelscommand.h +++ b/source/commands/listotulabelscommand.h @@ -11,8 +11,9 @@ #include "command.hpp" -#include "sharedrabundvector.h" #include "listvector.hpp" +#include "sharedrabundvectors.hpp" +#include "sharedrabundfloatvectors.hpp" /**************************************************************************************************/ @@ -42,8 +43,8 @@ class ListOtuLabelsCommand : public Command { vector Groups; set labels; - int createList(vector&); - int createList(vector&); + int createList(SharedRAbundFloatVectors*&); + int createList(SharedRAbundVectors*&); int createList(ListVector*&); }; diff --git a/source/commands/makebiomcommand.cpp b/source/commands/makebiomcommand.cpp index 65d0751d..759ff30f 100644 --- a/source/commands/makebiomcommand.cpp +++ b/source/commands/makebiomcommand.cpp @@ -7,7 +7,7 @@ // #include "makebiomcommand.h" -#include "sharedrabundvector.h" + #include "inputdata.h" #include "sharedutilities.h" #include "phylotree.h" @@ -344,18 +344,18 @@ int MakeBiomCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - vector lookup; - vector lookupRel; + SharedRAbundVectors* lookup = NULL; + SharedRAbundFloatVectors* lookupRel = NULL; string lastLabel; InputData input(inputFileName, fileFormat); if (fileFormat == "sharedfile") { lookup = input.getSharedRAbundVectors(); - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); getSampleMetaData(lookup); }else { lookupRel = input.getSharedRAbundFloatVectors(); - lastLabel = lookupRel[0]->getLabel(); + lastLabel = lookupRel->getLabel(); getSampleMetaData(lookupRel); } @@ -372,77 +372,77 @@ int MakeBiomCommand::execute(){ if (fileFormat == "sharedfile") { //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getBiom(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getBiom(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak and get next set - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; lookup = input.getSharedRAbundVectors(); } }else { //as long as you are not at the end of the file or done wih the lines you want - while((lookupRel[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookupRel != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for (int i = 0; i < lookupRel.size(); i++) { delete lookupRel[i]; } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete lookupRel; return 0; } - if(allLines == 1 || labels.count(lookupRel[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookupRel->getLabel()) == 1){ - m->mothurOut(lookupRel[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupRel->getLabel()); m->mothurOutEndLine(); getBiom(lookupRel); - processedLabels.insert(lookupRel[0]->getLabel()); - userLabels.erase(lookupRel[0]->getLabel()); + processedLabels.insert(lookupRel->getLabel()); + userLabels.erase(lookupRel->getLabel()); } - if ((m->anyLabelsToProcess(lookupRel[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupRel[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupRel->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupRel->getLabel(); - for (int i = 0; i < lookupRel.size(); i++) { delete lookupRel[i]; } + delete lookupRel; lookupRel = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookupRel[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupRel->getLabel()); m->mothurOutEndLine(); getBiom(lookupRel); - processedLabels.insert(lookupRel[0]->getLabel()); - userLabels.erase(lookupRel[0]->getLabel()); + processedLabels.insert(lookupRel->getLabel()); + userLabels.erase(lookupRel->getLabel()); //restore real lastlabel to save below - lookupRel[0]->setLabel(saveLabel); + lookupRel->setLabels(saveLabel); } - lastLabel = lookupRel[0]->getLabel(); + lastLabel = lookupRel->getLabel(); //prevent memory leak and get next set - for (int i = 0; i < lookupRel.size(); i++) { delete lookupRel[i]; lookupRel[i] = NULL; } + delete lookupRel; lookupRel = input.getSharedRAbundFloatVectors(); } } @@ -465,21 +465,21 @@ int MakeBiomCommand::execute(){ //run last label if you need to if (needToRun == true) { if (fileFormat == "sharedfile") { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); getBiom(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; }else { - for (int i = 0; i < lookupRel.size(); i++) { if (lookupRel[i] != NULL) { delete lookupRel[i]; } } + delete lookupRel; lookupRel = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookupRel[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupRel->getLabel()); m->mothurOutEndLine(); getBiom(lookupRel); - for (int i = 0; i < lookupRel.size(); i++) { delete lookupRel[i]; } + delete lookupRel; } } @@ -506,11 +506,11 @@ int MakeBiomCommand::execute(){ } } //********************************************************************************************************************** -int MakeBiomCommand::getBiom(vector& lookup){ +int MakeBiomCommand::getBiom(SharedRAbundVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("biom",variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -527,12 +527,12 @@ int MakeBiomCommand::getBiom(vector& lookup){ string spaces = " "; //standard - out << "{\n" + spaces + "\"id\":\"" + m->getSimpleName(sharedfile) + "-" + lookup[0]->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n"; + out << "{\n" + spaces + "\"id\":\"" + m->getSimpleName(sharedfile) + "-" + lookup->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n"; out << spaces + "\"type\": \"OTU table\",\n" + spaces + "\"generated_by\": \"" << mothurString << "\",\n" + spaces + "\"date\": \"" << dateString << "\",\n"; vector metadata = getMetaData(lookup); - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); if (m->control_pressed) { out.close(); return 0; } @@ -565,14 +565,15 @@ int MakeBiomCommand::getBiom(vector& lookup){ string colBack = "\", \"metadata\":"; out << spaces + "\"columns\":[\n"; - for (int i = 0; i < lookup.size()-1; i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size()-1; i++) { if (m->control_pressed) { out.close(); return 0; } - out << rowFront << lookup[i]->getGroup() << colBack << sampleMetadata[i] << "},\n"; + out << rowFront << namesOfGroups[i] << colBack << sampleMetadata[i] << "},\n"; } - out << rowFront << lookup[(lookup.size()-1)]->getGroup() << colBack << sampleMetadata[lookup.size()-1] << "}\n" + spaces + "],\n"; + out << rowFront << namesOfGroups[(namesOfGroups.size()-1)] << colBack << sampleMetadata[lookup->size()-1] << "}\n" + spaces + "],\n"; out << spaces + "\"matrix_type\": \"" << format << "\",\n" + spaces + "\"matrix_element_type\": \"int\",\n"; - out << spaces + "\"shape\": [" << numBins << "," << lookup.size() << "],\n"; + out << spaces + "\"shape\": [" << numBins << "," << lookup->size() << "],\n"; out << spaces + "\"data\": ["; vector dataRows; @@ -594,14 +595,16 @@ int MakeBiomCommand::getBiom(vector& lookup){ [4,2,1] ]*/ string output = ""; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { out.close(); return 0; } + vector binAbunds = lookup->getOTU(i); - for (int j = 0; j < lookup.size(); j++) { - string binInfo = "[" + toString(i) + "," + toString(j) + "," + toString(lookup[j]->getAbundance(i)) + "]"; + for (int j = 0; j < binAbunds.size(); j++) { + int abund = binAbunds[j]; + string binInfo = "[" + toString(i) + "," + toString(j) + "," + toString(abund) + "]"; //only print non zero values - if (lookup[j]->getAbundance(i) != 0) { dataRows.push_back(binInfo); } + if (abund != 0) { dataRows.push_back(binInfo); } } } }else { @@ -615,15 +618,14 @@ int MakeBiomCommand::getBiom(vector& lookup){ [2,1,1,0,0,1], [0,1,1,0,0,0]]*/ - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { out.close(); return 0; } string binInfo = "["; - for (int j = 0; j < lookup.size()-1; j++) { - binInfo += toString(lookup[j]->getAbundance(i)) + ","; - } - binInfo += toString(lookup[lookup.size()-1]->getAbundance(i)) + "]"; + vector binAbund = lookup->getOTU(i); + for (int j = 0; j < binAbund.size()-1; j++) { binInfo += toString(binAbund[j]) + ","; } + binInfo += toString(binAbund[binAbund.size()-1]) + "]"; dataRows.push_back(binInfo); } } @@ -644,11 +646,11 @@ int MakeBiomCommand::getBiom(vector& lookup){ } } //********************************************************************************************************************** -int MakeBiomCommand::getBiom(vector& lookup){ +int MakeBiomCommand::getBiom(SharedRAbundFloatVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("biom",variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -665,12 +667,12 @@ int MakeBiomCommand::getBiom(vector& lookup){ string spaces = " "; //standard - out << "{\n" + spaces + "\"id\":\"" + sharedfile + "-" + lookup[0]->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n"; + out << "{\n" + spaces + "\"id\":\"" + sharedfile + "-" + lookup->getLabel() + "\",\n" + spaces + "\"format\": \"Biological Observation Matrix 0.9.1\",\n" + spaces + "\"format_url\": \"http://biom-format.org\",\n"; out << spaces + "\"type\": \"OTU table\",\n" + spaces + "\"generated_by\": \"" << mothurString << "\",\n" + spaces + "\"date\": \"" << dateString << "\",\n"; vector metadata = getMetaData(lookup); - int numBins = lookup[0]->getNumBins(); + int numBins = lookup->getNumBins(); if (m->control_pressed) { out.close(); return 0; } @@ -703,14 +705,15 @@ int MakeBiomCommand::getBiom(vector& lookup){ string colBack = "\", \"metadata\":"; out << spaces + "\"columns\":[\n"; - for (int i = 0; i < lookup.size()-1; i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size()-1; i++) { if (m->control_pressed) { out.close(); return 0; } - out << rowFront << lookup[i]->getGroup() << colBack << sampleMetadata[i] << "},\n"; + out << rowFront << namesOfGroups[i] << colBack << sampleMetadata[i] << "},\n"; } - out << rowFront << lookup[(lookup.size()-1)]->getGroup() << colBack << sampleMetadata[lookup.size()-1] << "}\n" + spaces + "],\n"; + out << rowFront << namesOfGroups[(namesOfGroups.size()-1)] << colBack << sampleMetadata[lookup->size()-1] << "}\n" + spaces + "],\n"; out << spaces + "\"matrix_type\": \"" << format << "\",\n" + spaces + "\"matrix_element_type\": \"float\",\n"; - out << spaces + "\"shape\": [" << numBins << "," << lookup.size() << "],\n"; + out << spaces + "\"shape\": [" << numBins << "," << lookup->size() << "],\n"; out << spaces + "\"data\": ["; vector dataRows; @@ -732,14 +735,16 @@ int MakeBiomCommand::getBiom(vector& lookup){ [4,2,1] ]*/ string output = ""; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { out.close(); return 0; } - for (int j = 0; j < lookup.size(); j++) { - string binInfo = "[" + toString(i) + "," + toString(j) + "," + toString(lookup[j]->getAbundance(i)) + "]"; + vector binAbund = lookup->getOTU(i); + for (int j = 0; j < binAbund.size(); j++) { + float abund = binAbund[j]; + string binInfo = "[" + toString(i) + "," + toString(j) + "," + toString(abund) + "]"; //only print non zero values - if (lookup[j]->getAbundance(i) != 0) { dataRows.push_back(binInfo); } + if (abund != 0) { dataRows.push_back(binInfo); } } } }else { @@ -753,17 +758,17 @@ int MakeBiomCommand::getBiom(vector& lookup){ [2,1,1,0,0,1], [0,1,1,0,0,0]]*/ - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { out.close(); return 0; } string binInfo = "["; - for (int j = 0; j < lookup.size()-1; j++) { - binInfo += toString(lookup[j]->getAbundance(i)) + ","; - } - binInfo += toString(lookup[lookup.size()-1]->getAbundance(i)) + "]"; + vector binAbund = lookup->getOTU(i); + for (int j = 0; j < binAbund.size()-1; j++) { binInfo += toString(binAbund[j]) + ","; } + binInfo += toString(binAbund[binAbund.size()-1]) + "]"; dataRows.push_back(binInfo); } + } for (int i = 0; i < dataRows.size()-1; i++) { @@ -782,11 +787,11 @@ int MakeBiomCommand::getBiom(vector& lookup){ } } //********************************************************************************************************************** -vector MakeBiomCommand::getMetaData(vector& lookup){ +vector MakeBiomCommand::getMetaData(SharedRAbundVectors*& lookup){ try { vector metadata; - if (contaxonomyfile == "") { for (int i = 0; i < lookup[0]->getNumBins(); i++) { metadata.push_back("null"); } } + if (contaxonomyfile == "") { for (int i = 0; i < lookup->getNumBins(); i++) { metadata.push_back("null"); } } else { //read constaxonomy file storing in a map, otulabel -> taxonomy @@ -857,7 +862,7 @@ vector MakeBiomCommand::getMetaData(vector& lookup) //traverse the binLabels forming the metadata strings and saving them //make sure to sanity check map::iterator it; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { return metadata; } @@ -899,11 +904,11 @@ vector MakeBiomCommand::getMetaData(vector& lookup) } //********************************************************************************************************************** -vector MakeBiomCommand::getMetaData(vector& lookup){ +vector MakeBiomCommand::getMetaData(SharedRAbundFloatVectors*& lookup){ try { vector metadata; - if (contaxonomyfile == "") { for (int i = 0; i < lookup[0]->getNumBins(); i++) { metadata.push_back("null"); } } + if (contaxonomyfile == "") { for (int i = 0; i < lookup->getNumBins(); i++) { metadata.push_back("null"); } } else { //read constaxonomy file storing in a map, otulabel -> taxonomy @@ -967,7 +972,7 @@ vector MakeBiomCommand::getMetaData(vector& lo //traverse the binLabels forming the metadata strings and saving them //make sure to sanity check map::iterator it; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { return metadata; } @@ -1009,7 +1014,7 @@ vector MakeBiomCommand::getMetaData(vector& lo } //********************************************************************************************************************** -int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, map& labelTaxMap){ +int MakeBiomCommand::getGreenGenesOTUIDs(SharedRAbundVectors*& lookup, map& labelTaxMap){ try { //read reftaxonomy PhyloTree phylo(referenceTax); @@ -1066,12 +1071,12 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma } - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); + temp->setLabel(lookup->getLabel()); + temp->setGroup(namesOfGroups[i]); newLookup.push_back(temp); } @@ -1084,7 +1089,7 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma //ggOTUIDs = 16097 -> for (map >::iterator itMap = ggOTUIDs.begin(); itMap != ggOTUIDs.end(); itMap++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } //set new gg otu id to taxonomy. OTU01 -> k__Bacteria becomes 16097 -> k__Bacteria //find taxonomy of this otu @@ -1092,8 +1097,8 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma vector scores; vector taxonomies = parseTax(it->second, scores); - //merge/set OTU abundances - vector abunds; abunds.resize(lookup.size(), 0); + //merge/set OTU abundances for new merged OTU - abunds[i] = new OTU total for group i + vector abunds; abunds.resize(lookup->size(), 0); string mergeString = ""; vector boots; boots.resize(scores.size(), 0); bool scoresNULL = false; @@ -1114,28 +1119,21 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma //merge abunds mergeString += (itMap->second)[j] + " "; - for (int i = 0; i < lookup.size(); i++) { - abunds[i] += lookup[i]->getAbundance(labelIndex[m->getSimpleLabel((itMap->second)[j])]); - } + for (int i = 0; i < lookup->size(); i++) { abunds[i] += lookup->get(labelIndex[m->getSimpleLabel((itMap->second)[j])], namesOfGroups[i]); } } if (m->debug) { m->mothurOut("[DEBUG]: merging " + mergeString + " for ggOTUid = " + itMap->first + ".\n"); } //average scores //add merged otu to new lookup + //assemble new taxonomy string newTaxString = ""; if (!scoresNULL) { for (int j = 0; j < boots.size(); j++) { boots[j] /= (float) itMap->second.size(); } - //assemble new taxomoy - for (int j = 0; j < boots.size(); j++) { - newTaxString += taxonomies[j] + "(" + toString(boots[j]) + ");"; - } + for (int j = 0; j < boots.size(); j++) { newTaxString += taxonomies[j] + "(" + toString(boots[j]) + ");"; } }else { - //assemble new taxomoy - for (int j = 0; j < taxonomies.size(); j++) { - newTaxString += taxonomies[j] + ";"; - } + for (int j = 0; j < taxonomies.size(); j++) { newTaxString += taxonomies[j] + ";"; } } //set new gg otu id to taxonomy. OTU01 -> k__Bacteria becomes 16097 -> k__Bacteria @@ -1143,33 +1141,30 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma newLabelTaxMap[itMap->first] = newTaxString; //add merged otu to new lookup - for (int j = 0; j < abunds.size(); j++) { newLookup[j]->push_back(abunds[j], newLookup[j]->getGroup()); } + for (int j = 0; j < abunds.size(); j++) { newLookup[j]->push_back(abunds[j]); } //saved otu label newBinLabels.push_back(itMap->first); } - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } + lookup->clear(); + for (int i = 0; i < newLookup.size(); i++) { lookup->push_back(newLookup[i]); } + lookup->eliminateZeroOTUS(); - lookup = newLookup; m->currentSharedBinLabels = newBinLabels; labelTaxMap = newLabelTaxMap; map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared",variables); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); - lookup[0]->printHeaders(out); - - for (int i = 0; i < lookup.size(); i++) { - out << lookup[i]->getLabel() << '\t' << lookup[i]->getGroup() << '\t'; - lookup[i]->print(out); - } - out.close(); + lookup->printHeaders(out); + lookup->print(out); + out.close(); return 0; } @@ -1180,7 +1175,7 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, ma } //********************************************************************************************************************** -int MakeBiomCommand::getGreenGenesOTUIDs(vector& lookup, map& labelTaxMap){ +int MakeBiomCommand::getGreenGenesOTUIDs(SharedRAbundFloatVectors*& lookup, map& labelTaxMap){ try { //read reftaxonomy PhyloTree phylo(referenceTax); @@ -1240,10 +1235,11 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& looku vector newLookup; - for (int i = 0; i < lookup.size(); i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); + temp->setLabel(lookup->getLabel()); + temp->setGroup(namesOfGroups[i]); newLookup.push_back(temp); } @@ -1265,7 +1261,7 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& looku vector taxonomies = parseTax(it->second, scores); //merge/set OTU abundances - vector abunds; abunds.resize(lookup.size(), 0.0); + vector abunds; abunds.resize(lookup->size(), 0.0); string mergeString = ""; vector boots; boots.resize(scores.size(), 0.0); bool scoresNULL = false; @@ -1286,9 +1282,7 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& looku //merge abunds mergeString += (itMap->second)[j] + " "; - for (int i = 0; i < lookup.size(); i++) { - abunds[i] += lookup[i]->getAbundance(labelIndex[m->getSimpleLabel((itMap->second)[j])]); - } + for (int i = 0; i < lookup->size(); i++) { abunds[i] += lookup->get(labelIndex[m->getSimpleLabel((itMap->second)[j])], namesOfGroups[i]); } } if (m->debug) { m->mothurOut("[DEBUG]: merging " + mergeString + " for ggOTUid = " + itMap->first + ".\n"); } @@ -1315,21 +1309,22 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& looku newLabelTaxMap[itMap->first] = newTaxString; //add merged otu to new lookup - for (int j = 0; j < abunds.size(); j++) { newLookup[j]->push_back(abunds[j], newLookup[j]->getGroup()); } + for (int j = 0; j < abunds.size(); j++) { newLookup[j]->push_back(abunds[j]); } //saved otu label newBinLabels.push_back(itMap->first); } - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } + lookup->clear(); + for (int i = 0; i < newLookup.size(); i++) { lookup->push_back(newLookup[i]); } + lookup->eliminateZeroOTUS(); - lookup = newLookup; m->currentSharedBinLabels = newBinLabels; labelTaxMap = newLabelTaxMap; map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("relabund",variables); ofstream out; @@ -1337,12 +1332,8 @@ int MakeBiomCommand::getGreenGenesOTUIDs(vector& looku outputNames.push_back(outputFileName); outputTypes["relabund"].push_back(outputFileName); - lookup[0]->printHeaders(out); - - for (int i = 0; i < lookup.size(); i++) { - out << lookup[i]->getLabel() << '\t' << lookup[i]->getGroup() << '\t'; - lookup[i]->print(out); - } + lookup->printHeaders(out); + lookup->print(out); out.close(); return 0; @@ -1387,10 +1378,10 @@ map MakeBiomCommand::readGGOtuMap(){ } //********************************************************************************************************************** -int MakeBiomCommand::getSampleMetaData(vector& lookup){ +int MakeBiomCommand::getSampleMetaData(SharedRAbundVectors*& lookup){ try { sampleMetadata.clear(); - if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } } + if (metadatafile == "") { for (int i = 0; i < lookup->size(); i++) { sampleMetadata.push_back("null"); } } else { ifstream in; m->openInputFile(metadatafile, in); @@ -1431,13 +1422,14 @@ int MakeBiomCommand::getSampleMetaData(vector& lookup){ in.close(); map >::iterator it; - for (int i = 0; i < lookup.size(); i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { if (m->control_pressed) { return 0; } - it = lines.find(lookup[i]->getGroup()); + it = lines.find(namesOfGroups[i]); - if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + lookup[i]->getGroup() + ", quitting.\n"); m->control_pressed = true; } + if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + namesOfGroups[i] + ", quitting.\n"); m->control_pressed = true; } else { vector values = it->second; @@ -1463,10 +1455,10 @@ int MakeBiomCommand::getSampleMetaData(vector& lookup){ } //********************************************************************************************************************** -int MakeBiomCommand::getSampleMetaData(vector& lookup){ +int MakeBiomCommand::getSampleMetaData(SharedRAbundFloatVectors*& lookup){ try { sampleMetadata.clear(); - if (metadatafile == "") { for (int i = 0; i < lookup.size(); i++) { sampleMetadata.push_back("null"); } } + if (metadatafile == "") { for (int i = 0; i < lookup->size(); i++) { sampleMetadata.push_back("null"); } } else { ifstream in; m->openInputFile(metadatafile, in); @@ -1505,13 +1497,14 @@ int MakeBiomCommand::getSampleMetaData(vector& lookup) in.close(); map >::iterator it; - for (int i = 0; i < lookup.size(); i++) { + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { if (m->control_pressed) { return 0; } - it = lines.find(lookup[i]->getGroup()); + it = lines.find(namesOfGroups[i]); - if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + lookup[i]->getGroup() + ", quitting.\n"); m->control_pressed = true; } + if (it == lines.end()) { m->mothurOut("[ERROR]: can't find metadata information for " + namesOfGroups[i] + ", quitting.\n"); m->control_pressed = true; } else { vector values = it->second; diff --git a/source/commands/makebiomcommand.h b/source/commands/makebiomcommand.h index e411bed0..39690b3a 100644 --- a/source/commands/makebiomcommand.h +++ b/source/commands/makebiomcommand.h @@ -11,7 +11,6 @@ #include "command.hpp" -#include "sharedrabundvector.h" #include "inputdata.h" @@ -42,16 +41,16 @@ class MakeBiomCommand : public Command { bool abort, allLines, picrust; - int getBiom(vector&); - int getBiom(vector& lookup); - vector getMetaData(vector&); - vector getMetaData(vector&); + int getBiom(SharedRAbundVectors*&); + int getBiom(SharedRAbundFloatVectors*&); + vector getMetaData(SharedRAbundVectors*&); + vector getMetaData(SharedRAbundFloatVectors*&); vector parseTax(string tax, vector& scores); - int getSampleMetaData(vector&); - int getSampleMetaData(vector&); + int getSampleMetaData(SharedRAbundVectors*&); + int getSampleMetaData(SharedRAbundFloatVectors*&); //for picrust - int getGreenGenesOTUIDs(vector&, map&); - int getGreenGenesOTUIDs(vector&, map&); + int getGreenGenesOTUIDs(SharedRAbundVectors*&, map&); + int getGreenGenesOTUIDs(SharedRAbundFloatVectors*&, map&); map readGGOtuMap(); }; diff --git a/source/commands/makecontigscommand.cpp b/source/commands/makecontigscommand.cpp index e394ff09..9e148d86 100644 --- a/source/commands/makecontigscommand.cpp +++ b/source/commands/makecontigscommand.cpp @@ -536,8 +536,8 @@ int MakeContigsCommand::execute(){ } } - vector mapFiles = filenames["map"]; cout << mapFiles.size() << endl; - for (int i = 0; i < mapFiles.size(); i++) { outputNames.push_back(mapFiles[i]); cout << mapFiles[i] << endl; } + vector mapFiles = filenames["map"]; + for (int i = 0; i < mapFiles.size(); i++) { outputNames.push_back(mapFiles[i]); } //rename renamed allfiles to original filenames and add to outputNames and outputTypes int countGroups = 0; @@ -618,8 +618,6 @@ unsigned long long MakeContigsCommand::processSingleFileOption(map& string inputFile = ""; vector fileInputs; vector qualOrIndexInputs; - vector lines; - vector qLines; delim = '>'; map variables; string thisOutputDir = outputDir; @@ -703,9 +701,11 @@ unsigned long long MakeContigsCommand::processSingleFileOption(map& allGZ = false; #endif - if (allGZ) { + if (allGZ) { gz = true; - }else { gz = false; } + }else { + gz = false; + } variables["[tag]"] = "trim"; outFastaFile = getOutputFileName("fasta",variables); @@ -714,9 +714,6 @@ unsigned long long MakeContigsCommand::processSingleFileOption(map& variables["[tag]"] = ""; outMisMatchFile = getOutputFileName("report",variables); - //divides the files so that the processors can share the workload. - setLines(fileInputs, qualOrIndexInputs, lines, qLines, delim); - vector > fastaFileNames, qualFileNames; map uniqueFastaNames;// so we don't add the same groupfile multiple times createOligosGroup = false; @@ -730,7 +727,7 @@ unsigned long long MakeContigsCommand::processSingleFileOption(map& if (createFileGroup) { createOligosGroup = false; } m->mothurOut("Making contigs...\n"); - numReads = createProcesses(fileInputs, qualOrIndexInputs, outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, fastaFileNames, qualFileNames, lines, qLines, group); + numReads = createProcesses(fileInputs, qualOrIndexInputs, outFastaFile, outScrapFastaFile, outQualFile, outScrapQualFile, outMisMatchFile, fastaFileNames, qualFileNames, group); if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete oligos; return 0; } @@ -769,7 +766,6 @@ unsigned long long MakeContigsCommand::processSingleFileOption(map& ofstream out; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(it->first)); - //cout << variables["[filename]"] << endl; string thisGroupName = getOutputFileName("group",variables); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); m->openOutputFile(thisGroupName, out); @@ -1442,11 +1438,27 @@ unsigned long long MakeContigsCommand::driverGroups(vector< vector > fil //... //if using index files and only have 1 then the file name = NONE, and entries are duds. Copies of other index file. //if no index files are given, then qualOrIndexFiles.size() == 0. -unsigned long long MakeContigsCommand::createProcesses(vector fileInputs, vector qualOrIndexFiles, string outputFasta, string outputScrapFasta, string outputQual, string outputScrapQual, string outputMisMatches, vector > fastaFileNames, vector > qualFileNames, vector lines, vector qLines, string group) { +unsigned long long MakeContigsCommand::createProcesses(vector fileInputs, vector qualOrIndexFiles, string outputFasta, string outputScrapFasta, string outputQual, string outputScrapQual, string outputMisMatches, vector > fastaFileNames, vector > qualFileNames, string group) { try { int num = 0; vector processIDS; bool recalc = false; + vector lines; + vector qLines; + + if (gz) { + nameType = setNameType(fileInputs[0], fileInputs[1], delim); + for (int i = 0; i < fileInputs.size(); i++) { + //fake out lines - we are just going to check for end of file. Work is divided by number of files per processor. + lines.push_back(linePair(0, 1000)); + qLines.push_back(linePair(0, 1000)); + } + processors = fileInputs.size() / 2; + }else { + //divides the files so that the processors can share the workload. + setLines(fileInputs, qualOrIndexFiles, lines, qLines, delim); + } + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; @@ -1532,7 +1544,18 @@ unsigned long long MakeContigsCommand::createProcesses(vector fileInputs //redo file divide lines.clear(); - setLines(fileInputs, qualOrIndexFiles, lines, qLines, delim); + if (gz) { + for (int i = 0; i < fileInputs.size(); i++) { + //fake out lines - we are just going to check for end of file. Work is divided by number of files per processor. + lines.push_back(linePair(0, 1000)); + qLines.push_back(linePair(0, 1000)); + } + processors = fileInputs.size() / 2; + }else { + //divides the files so that the processors can share the workload. + setLines(fileInputs, qualOrIndexFiles, lines, qLines, delim); + } + num = 0; processIDS.resize(0); @@ -1806,7 +1829,6 @@ unsigned long long MakeContigsCommand::createProcesses(vector fileInputs //********************************************************************************************************************** unsigned long long MakeContigsCommand::driver(vector inputFiles, vector qualOrIndexFiles, string outputFasta, string outputScrapFasta, string outputQual, string outputScrapQual, string outputMisMatches, vector > fastaFileNames, vector > qualFileNames, linePair linesInput, linePair linesInputReverse, linePair qlinesInput, linePair qlinesInputReverse, string group){ try { - vector< vector > qual_match_simple_bayesian; qual_match_simple_bayesian.resize(47); for (int i = 0; i < qual_match_simple_bayesian.size(); i++) { qual_match_simple_bayesian[i].resize(47); } @@ -2215,7 +2237,6 @@ vector MakeContigsCommand::assembleFragments(vector< vector >&qual_ delete fQual; delete rQual; delete savedFQual; delete savedRQual; } - //if (num == 5) { cout << fSeq.getStartPos() << '\t' << fSeq.getEndPos() << '\t' << rSeq.getStartPos() << '\t' << rSeq.getEndPos() << endl; exit(1); } int overlapStart = fSeq.getStartPos()-1; int seq2Start = rSeq.getStartPos()-1; @@ -2233,7 +2254,6 @@ vector MakeContigsCommand::assembleFragments(vector< vector >&qual_ if (seq2End < overlapEnd) { overlapEnd = seq2End; } //smallest end position is where overlapping ends oStart = contig.length(); - //cout << fSeq.getAligned() << endl; cout << rSeq.getAligned() << endl; int firstForward = 0; int seq2FirstForward = 0; int lastReverse = seq1.length(); int seq2lastReverse = seq2.length(); bool firstChooseSeq1 = false; bool lastChooseSeq1 = false; if (hasQuality) { @@ -2245,10 +2265,7 @@ vector MakeContigsCommand::assembleFragments(vector< vector >&qual_ if (lastReverse > seq2lastReverse) { lastReverse = seq2lastReverse; lastChooseSeq1 = true; } } - //cout << firstForward << '\t' << lastReverse << endl; - for (int i = overlapStart; i < overlapEnd; i++) { - //cout << seq1[i] << ' ' << seq2[i] << ' ' << scores1[ABaseMap[i]] << ' ' << scores2[BBaseMap[i]] << endl; if (seq1[i] == seq2[i]) { contig += seq1[i]; if (hasQuality) { @@ -2303,7 +2320,6 @@ vector MakeContigsCommand::assembleFragments(vector< vector >&qual_ for (int i = overlapEnd; i < length; i++) { contig += seq1[i]; if (hasQuality) { if (((seq1[i] != '-') && (seq1[i] != '.'))) { contigScores.push_back(scores1[ABaseMap[i]]); } } } } - //cout << "contig = " << contig << endl; if (trimOverlap) { contig = contig.substr(overlapStart, oend-oStart); @@ -2332,8 +2348,8 @@ bool MakeContigsCommand::read(Sequence& fSeq, Sequence& rSeq, QualityScores*& fQ if (delim == '@') { //fastq files bool tignore; - FastqRead fread(inFF, tignore, format); - FastqRead rread(inRF, ignore, format); + FastqRead fread(inFF, tignore, format); m->gobble(inFF); + FastqRead rread(inRF, ignore, format); m->gobble(inRF); if (!checkName(fread, rread)) { FastqRead f2read(inFF, tignore, format); if (!checkName(f2read, rread)) { @@ -2401,7 +2417,6 @@ bool MakeContigsCommand::read(Sequence& fSeq, Sequence& rSeq, QualityScores*& fQ } if (tfSeq.getName() != trSeq.getName()) { m->mothurOut("[WARNING]: name mismatch in forward and reverse fasta file. Ignoring, " + tfSeq.getName() + ".\n"); ignore = true; } } - return ignore; } @@ -2552,7 +2567,6 @@ int MakeContigsCommand::setNameType(string forward, string reverse) { if (numDiffs == 1) { if ((forwardDiff == '1') && (reverseDiff == '2')) { type = offByOne; offByOneTrimLength = tempForward.length()-spot+1; } } - //cout << tempReverse.substr(0, (tempReverse.length()-offByOneTrimLength)) << endl; } } } @@ -2632,7 +2646,7 @@ int MakeContigsCommand::setLines(vector fasta, vector qual, vect vector temp; nameType = setNameType(fasta[0], fasta[1], delim); - + #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //set file positions for fasta file fastaFilePos = m->divideFile(fasta[0], processors, delim); @@ -3370,7 +3384,6 @@ bool MakeContigsCommand::getOligos(vector >& fastaFileNames, vect fastaFileNames[itBar->first][itPrimer->first] = fastaFileName; m->openOutputFile(fastaFileName, temp); temp.close(); - //cout << fastaFileName << endl; qualFileNames[itBar->first][itPrimer->first] = qualFileName; m->openOutputFile(qualFileName, temp2); temp2.close(); @@ -3463,7 +3476,6 @@ bool MakeContigsCommand::checkName(FastqRead& forward, FastqRead& reverse){ match = false; } } - return match; } catch(exception& e) { diff --git a/source/commands/makecontigscommand.h b/source/commands/makecontigscommand.h index 8e8744ea..9b02bafb 100644 --- a/source/commands/makecontigscommand.h +++ b/source/commands/makecontigscommand.h @@ -95,7 +95,7 @@ class MakeContigsCommand : public Command { vector assembleFragments(vector< vector >&qual_match_simple_bayesian, vector< vector >& qual_mismatch_simple_bayesian, Sequence& fSeq, Sequence& rSeq, QualityScores*&, QualityScores*&, QualityScores*& savedFQual, QualityScores*& savedRQual, bool, Alignment*& alignment, string& contig, string&, int&, int&, int&); //main processing functions - unsigned long long createProcesses(vector, vector, string, string, string, string, string, vector >, vector >, vector, vector, string); + unsigned long long createProcesses(vector, vector, string, string, string, string, string, vector >, vector >, string); unsigned long long createProcessesGroups(vector< vector >, string compositeGroupFile, string compositeFastaFile, string compositeScrapFastaFile, string compositeQualFile, string compositeScrapQualFile, string compositeMisMatchFile, map& totalGroupCounts, map&); unsigned long long driverGroups(vector >, int, int, string, string, string, string, string, string, map&, map&); unsigned long long driver(vector files, vector qualOrIndexFiles, string outputFasta, string outputScrapFasta, string outputQual, string outputScrapQual, string outputMisMatches, vector > fastaFileNames, vector > qualFileNames, linePair, linePair, linePair, linePair, string); diff --git a/source/commands/makefilecommand.cpp b/source/commands/makefilecommand.cpp index 4cdac146..28f8d2b7 100644 --- a/source/commands/makefilecommand.cpp +++ b/source/commands/makefilecommand.cpp @@ -335,13 +335,13 @@ vector< vector > MakeFileCommand::findGroupNames(vector< vector } }else { //separate by the user selected deliminator. default='_' - for (int i = 0; i < paired.size(); i++) { string groupName = "Group_" + toString(i); + string filename = m->getSimpleName(paired[i][0]); + int pos = filename.find(delim); - int pos = paired[i][0].find_first_of(delim); - if (pos != string::npos) { groupName = m->getSimpleName(paired[i][0].substr(0, pos)); } + if (pos != string::npos) { groupName = filename.substr(0, pos); } results[i].push_back(groupName); results[i].push_back(paired[i][0]); results[i].push_back(paired[i][1]); } diff --git a/source/commands/makelefsecommand.cpp b/source/commands/makelefsecommand.cpp index 8ab4c765..de2e222f 100644 --- a/source/commands/makelefsecommand.cpp +++ b/source/commands/makelefsecommand.cpp @@ -224,11 +224,11 @@ int MakeLefseCommand::execute(){ if (sharedfile != "") { inputFile = sharedfile; - vector lookup = getSharedRelabund(); + SharedRAbundFloatVectors* lookup = getSharedRelabund(); runRelabund(consTax, lookup); }else { inputFile = relabundfile; - vector lookup = getRelabund(); + SharedRAbundFloatVectors* lookup = getRelabund(); runRelabund(consTax, lookup); } @@ -248,12 +248,12 @@ int MakeLefseCommand::execute(){ } } //********************************************************************************************************************** -int MakeLefseCommand::runRelabund(map& consTax, vector& lookup){ +int MakeLefseCommand::runRelabund(map& consTax, SharedRAbundFloatVectors*& lookup){ try { if (outputDir == "") { outputDir = m->hasPath(inputFile); } map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFile)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFile = getOutputFileName("lefse",variables); outputNames.push_back(outputFile); outputTypes["lefse"].push_back(outputFile); @@ -261,6 +261,7 @@ int MakeLefseCommand::runRelabund(map& consTax, vectoropenOutputFile(outputFile, out); DesignMap* designMap = NULL; + vector namesOfGroups = lookup->getNamesGroups(); if (designfile != "") { designMap = new DesignMap(designfile); vector categories = designMap->getNamesOfCategories(); @@ -269,26 +270,26 @@ int MakeLefseCommand::runRelabund(map& consTax, vectorcontrol_pressed) { out.close(); delete designMap; return 0; } - string value = designMap->get(lookup[i]->getGroup(), categories[j]); + string value = designMap->get(namesOfGroups[i], categories[j]); if (value == "not found") { - m->mothurOut("[ERROR]: " + lookup[i]->getGroup() + " is not in your design file, please correct.\n"); m->control_pressed = true; + m->mothurOut("[ERROR]: " + namesOfGroups[i] + " is not in your design file, please correct.\n"); m->control_pressed = true; }else { out << '\t' << value; } } - string value = designMap->get(lookup[lookup.size()-1]->getGroup(), categories[j]); + string value = designMap->get(namesOfGroups[namesOfGroups.size()-1], categories[j]); if (value == "not found") { - m->mothurOut("[ERROR]: " + lookup[lookup.size()-1]->getGroup() + " is not in your design file, please correct.\n"); m->control_pressed = true; + m->mothurOut("[ERROR]: " + namesOfGroups[namesOfGroups.size()-1] + " is not in your design file, please correct.\n"); m->control_pressed = true; }else { out << '\t' << value; } out << endl; } } out << "group"; - for (int i = 0; i < lookup.size(); i++) { out << '\t' << lookup[i]->getGroup(); } + for (int i = 0; i < namesOfGroups.size(); i++) { out << '\t' << namesOfGroups[i]; } out << endl; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { //process each otu + for (int i = 0; i < lookup->getNumBins(); i++) { //process each otu if (m->control_pressed) { break; } string nameOfOtu = m->currentSharedBinLabels[i]; @@ -316,7 +317,8 @@ int MakeLefseCommand::runRelabund(map& consTax, vectorgetAbundance(i); } + vector abunds = lookup->getOTU(i); + for (int j = 0; j < abunds.size(); j++) { out << '\t' << abunds[j]; } out << endl; } out.close(); @@ -329,13 +331,12 @@ int MakeLefseCommand::runRelabund(map& consTax, vector MakeLefseCommand::getSharedRelabund(){ +SharedRAbundFloatVectors* MakeLefseCommand::getSharedRelabund(){ try { InputData input(sharedfile, "sharedfile"); - vector templookup = input.getSharedRAbundVectors(); - string lastLabel = templookup[0]->getLabel(); - vector lookup; - + SharedRAbundVectors* templookup = input.getSharedRAbundVectors(); + string lastLabel = templookup->getLabel(); + if (label == "") { label = lastLabel; } else { //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -344,39 +345,39 @@ vector MakeLefseCommand::getSharedRelabund(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((templookup[0] != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { for (int i = 0; i < templookup.size(); i++) { delete templookup[i]; } return lookup; } + while((templookup != NULL) && (userLabels.size() != 0)) { + if (m->control_pressed) { delete templookup; return NULL; } - if(labels.count(templookup[0]->getLabel()) == 1){ - processedLabels.insert(templookup[0]->getLabel()); - userLabels.erase(templookup[0]->getLabel()); + if(labels.count(templookup->getLabel()) == 1){ + processedLabels.insert(templookup->getLabel()); + userLabels.erase(templookup->getLabel()); break; } - if ((m->anyLabelsToProcess(templookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = templookup[0]->getLabel(); + if ((m->anyLabelsToProcess(templookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = templookup->getLabel(); - for (int i = 0; i < templookup.size(); i++) { delete templookup[i]; } + delete templookup; templookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(templookup[0]->getLabel()); - userLabels.erase(templookup[0]->getLabel()); + processedLabels.insert(templookup->getLabel()); + userLabels.erase(templookup->getLabel()); //restore real lastlabel to save below - templookup[0]->setLabel(saveLabel); + templookup->setLabels(saveLabel); break; } - lastLabel = templookup[0]->getLabel(); + lastLabel = templookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < templookup.size(); i++) { delete templookup[i]; } + delete templookup; templookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { for (int i = 0; i < templookup.size(); i++) { delete templookup[i]; } return lookup; } + if (m->control_pressed) { delete templookup; return NULL; } //output error messages about any remaining user labels set::iterator it; @@ -393,50 +394,54 @@ vector MakeLefseCommand::getSharedRelabund(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < templookup.size(); i++) { if (templookup[i] != NULL) { delete templookup[i]; } } + delete templookup; templookup = input.getSharedRAbundVectors(lastLabel); } } - for (int i = 0; i < templookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(templookup[i]->getLabel()); - temp->setGroup(templookup[i]->getGroup()); - lookup.push_back(temp); - } + vector data = templookup->getSharedRAbundVectors(); + delete templookup; + SharedRAbundFloatVectors* lookup = new SharedRAbundFloatVectors(); //convert to relabund - for (int i = 0; i < templookup.size(); i++) { - for (int j = 0; j < templookup[i]->getNumBins(); j++) { + for (int i = 0; i < data.size(); i++) { + SharedRAbundFloatVector* rel = new SharedRAbundFloatVector(); + rel->setGroup(data[i]->getGroup()); + rel->setLabel(data[i]->getLabel()); + + for (int j = 0; j < data[i]->getNumBins(); j++) { - if (m->control_pressed) { for (int k = 0; k < templookup.size(); k++) { delete templookup[k]; } return lookup; } + if (m->control_pressed) { for (int k = 0; k < data.size(); k++) { delete data[k]; } return lookup; } - int abund = templookup[i]->getAbundance(j); + int abund = data[i]->get(j); float relabund = 0.0; if (scale == "totalgroup") { - relabund = abund / (float) templookup[i]->getNumSeqs(); + relabund = abund / (float) data[i]->getNumSeqs(); }else if (scale == "totalotu") { //calc the total in this otu int totalOtu = 0; - for (int l = 0; l < templookup.size(); l++) { totalOtu += templookup[l]->getAbundance(j); } + for (int l = 0; l < data.size(); l++) { totalOtu += data[l]->get(j); } relabund = abund / (float) totalOtu; }else if (scale == "averagegroup") { - relabund = abund / (float) (templookup[i]->getNumSeqs() / (float) templookup[i]->getNumBins()); + relabund = abund / (float) (data[i]->getNumSeqs() / (float) data[i]->getNumBins()); }else if (scale == "averageotu") { //calc the total in this otu int totalOtu = 0; - for (int l = 0; l < templookup.size(); l++) { totalOtu += templookup[l]->getAbundance(j); } - float averageOtu = totalOtu / (float) templookup.size(); + for (int l = 0; l < data.size(); l++) { totalOtu += data[l]->get(j); } + float averageOtu = totalOtu / (float) data.size(); relabund = abund / (float) averageOtu; }else{ m->mothurOut(scale + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; } - lookup[i]->push_back(relabund, lookup[i]->getGroup()); + rel->push_back(relabund); } + + lookup->push_back(rel); + } - - for (int k = 0; k < templookup.size(); k++) { delete templookup[k]; } + for (int k = 0; k < data.size(); k++) { delete data[k]; } data.clear(); + lookup->eliminateZeroOTUS(); return lookup; } @@ -446,11 +451,11 @@ vector MakeLefseCommand::getSharedRelabund(){ } } //********************************************************************************************************************** -vector MakeLefseCommand::getRelabund(){ +SharedRAbundFloatVectors* MakeLefseCommand::getRelabund(){ try { InputData input(relabundfile, "relabund"); - vector lookupFloat = input.getSharedRAbundFloatVectors(); - string lastLabel = lookupFloat[0]->getLabel(); + SharedRAbundFloatVectors* lookupFloat = input.getSharedRAbundFloatVectors(); + string lastLabel = lookupFloat->getLabel(); if (label == "") { label = lastLabel; return lookupFloat; } @@ -460,35 +465,35 @@ vector MakeLefseCommand::getRelabund(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && (userLabels.size() != 0)) { + while((lookupFloat != NULL) && (userLabels.size() != 0)) { if (m->control_pressed) { return lookupFloat; } - if(labels.count(lookupFloat[0]->getLabel()) == 1){ - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + if(labels.count(lookupFloat->getLabel()) == 1){ + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); break; } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); break; } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; lookupFloat = input.getSharedRAbundFloatVectors(); } @@ -510,7 +515,7 @@ vector MakeLefseCommand::getRelabund(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } + delete lookupFloat; lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); } diff --git a/source/commands/makelefsecommand.h b/source/commands/makelefsecommand.h index 02e5f67b..521a8a77 100644 --- a/source/commands/makelefsecommand.h +++ b/source/commands/makelefsecommand.h @@ -41,10 +41,10 @@ class MakeLefseCommand : public Command { vector outputNames, Groups; string sharedfile, designfile, constaxonomyfile, relabundfile, scale, label, inputFile; - int runRelabund(map&, vector&); + int runRelabund(map&, SharedRAbundFloatVectors*&); - vector getRelabund(); - vector getSharedRelabund(); + SharedRAbundFloatVectors* getRelabund(); + SharedRAbundFloatVectors* getSharedRelabund(); }; /**************************************************************************************************/ diff --git a/source/commands/matrixoutputcommand.cpp b/source/commands/matrixoutputcommand.cpp index ba1364f4..c33310eb 100644 --- a/source/commands/matrixoutputcommand.cpp +++ b/source/commands/matrixoutputcommand.cpp @@ -314,90 +314,77 @@ int MatrixOutputCommand::execute(){ //if the users entered no valid calculators don't execute command if (matrixCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } - input = new InputData(sharedfile, "sharedfile"); - lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + InputData input(sharedfile, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + vector lookupGroups = lookup->getNamesGroups(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0;} + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); delete lookup; return 0;} if (subsample) { if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } + subsampleSize = lookup->getNumSeqsSmallestGroup(); }else { m->clearGroups(); Groups.clear(); - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; + lookup->removeGroups(subsampleSize); + Groups = lookup->getNamesGroups(); m->setGroups(Groups); } - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; delete input; return 0; } + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } - numGroups = lookup.size(); + numGroups = lookup->size(); lines.resize(processors); for (int i = 0; i < processors; i++) { lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); lines[i].end = int (sqrt(float(i+1)/float(processors)) * numGroups); } - if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; } + if (m->control_pressed) { delete lookup; m->clearGroups(); return 0; } //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + delete lookup; + lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -412,19 +399,19 @@ int MatrixOutputCommand::execute(){ } } - if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } - if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } m->clearGroups(); return 0; } //reset groups parameter m->clearGroups(); @@ -450,7 +437,7 @@ int MatrixOutputCommand::execute(){ } } /***********************************************************/ -void MatrixOutputCommand::printSims(ostream& out, vector< vector >& simMatrix) { +void MatrixOutputCommand::printSims(ostream& out, vector< vector >& simMatrix, vector groupNames) { try { out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -458,7 +445,7 @@ void MatrixOutputCommand::printSims(ostream& out, vector< vector >& simM if (output == "lt") { out << simMatrix.size() << endl; for (int b = 0; b < simMatrix.size(); b++) { - out << lookup[b]->getGroup(); + out << groupNames[b]; for (int n = 0; n < b; n++) { out << '\t' << simMatrix[b][n]; } @@ -467,13 +454,13 @@ void MatrixOutputCommand::printSims(ostream& out, vector< vector >& simM }else if (output == "column") { for (int b = 0; b < simMatrix.size(); b++) { for (int n = 0; n < b; n++) { - out << lookup[b]->getGroup() << '\t' << lookup[n]->getGroup() << '\t' << simMatrix[b][n] << endl; + out << groupNames[b] << '\t' << groupNames[n] << '\t' << simMatrix[b][n] << endl; } } }else{ out << simMatrix.size() << endl; for (int b = 0; b < simMatrix.size(); b++) { - out << lookup[b]->getGroup(); + out << groupNames[b]; for (int n = 0; n < simMatrix[b].size(); n++) { out << '\t' << simMatrix[b][n]; } @@ -487,7 +474,7 @@ void MatrixOutputCommand::printSims(ostream& out, vector< vector >& simM } } /***********************************************************/ -int MatrixOutputCommand::process(vector thisLookup){ +int MatrixOutputCommand::process(SharedRAbundVectors*& thisLookup){ try { vector< vector< vector > > calcDistsTotals; //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files vector< vector > calcDists; calcDists.resize(matrixCalculators.size()); @@ -495,36 +482,24 @@ int MatrixOutputCommand::process(vector thisLookup){ for (int thisIter = 0; thisIter < iters+1; thisIter++) { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[distance]"] = thisLookup->getLabel(); variables["[tag2]"] = ""; - vector thisItersLookup = thisLookup; + SharedRAbundVectors* thisItersLookup = new SharedRAbundVectors(*thisLookup); + vector namesOfGroups = thisItersLookup->getNamesGroups(); if (subsample && (thisIter != 0)) { SubSample sample; vector tempLabels; //dont need since we arent printing the sampled sharedRabunds - //make copy of lookup so we don't get access violations - vector newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - - tempLabels = sample.getSample(newLookup, subsampleSize); - thisItersLookup = newLookup; + tempLabels = sample.getSample(thisItersLookup, subsampleSize); } - + + vector thisItersRabunds = thisItersLookup->getSharedRAbundVectors(); + vector thisItersGroupNames = thisLookup->getNamesGroups(); + if(processors == 1){ - driver(thisItersLookup, 0, numGroups, calcDists); + driver(thisItersRabunds, 0, numGroups, calcDists); }else{ int process = 1; vector processIDS; @@ -540,7 +515,7 @@ int MatrixOutputCommand::process(vector thisLookup){ process++; }else if (pid == 0){ - driver(thisItersLookup, lines[process].start, lines[process].end, calcDists); + driver(thisItersRabunds, lines[process].start, lines[process].end, calcDists); string tempdistFileName = m->getRootName(m->getSimpleName(sharedfile)) + m->mothurGetpid(process) + ".dist"; ofstream outtemp; @@ -597,7 +572,7 @@ int MatrixOutputCommand::process(vector thisLookup){ process++; }else if (pid == 0){ - driver(thisItersLookup, lines[process].start, lines[process].end, calcDists); + driver(thisItersRabunds, lines[process].start, lines[process].end, calcDists); string tempdistFileName = m->getRootName(m->getSimpleName(sharedfile)) + m->mothurGetpid(process) + ".dist"; ofstream outtemp; @@ -623,7 +598,7 @@ int MatrixOutputCommand::process(vector thisLookup){ //parent do your part - driver(thisItersLookup, lines[0].start, lines[0].end, calcDists); + driver(thisItersRabunds, lines[0].start, lines[0].end, calcDists); //force parent to wait until all the processes are done for (int i = 0; i < processIDS.size(); i++) { @@ -669,22 +644,10 @@ int MatrixOutputCommand::process(vector thisLookup){ for( int i=1; i newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } + vector thisItersRabunds = thisItersLookup->getSharedRAbundVectors(); // Allocate memory for thread data. - distSharedData* tempSum = new distSharedData(m, lines[i].start, lines[i].end, Estimators, newLookup); + distSharedData* tempSum = new distSharedData(m, lines[i].start, lines[i].end, Estimators, thisItersRabunds); pDataArray.push_back(tempSum); processIDS.push_back(i); @@ -692,7 +655,7 @@ int MatrixOutputCommand::process(vector thisLookup){ } //parent do your part - driver(thisItersLookup, lines[0].start, lines[0].end, calcDists); + driver(thisItersRabunds, lines[0].start, lines[0].end, calcDists); //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); @@ -716,25 +679,24 @@ int MatrixOutputCommand::process(vector thisLookup){ #endif } + for (int i = 0; i < thisItersRabunds.size(); i++) { delete thisItersRabunds[i]; } + if (subsample && (thisIter != 0)) { if((thisIter) % 100 == 0){ m->mothurOutJustToScreen(toString(thisIter)+"\n"); } calcDistsTotals.push_back(calcDists); for (int i = 0; i < calcDists.size(); i++) { for (int j = 0; j < calcDists[i].size(); j++) { - if (m->debug) { m->mothurOut("[DEBUG]: Results: iter = " + toString(thisIter) + ", " + thisLookup[calcDists[i][j].seq1]->getGroup() + " - " + thisLookup[calcDists[i][j].seq2]->getGroup() + " distance = " + toString(calcDists[i][j].dist) + ".\n"); } + if (m->debug) { m->mothurOut("[DEBUG]: Results: iter = " + toString(thisIter) + ", " + thisItersGroupNames[calcDists[i][j].seq1] + " - " + thisItersGroupNames[calcDists[i][j].seq2] + " distance = " + toString(calcDists[i][j].dist) + ".\n"); } } } - //clean up memory - for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } - thisItersLookup.clear(); }else { //print results for whole dataset for (int i = 0; i < calcDists.size(); i++) { if (m->control_pressed) { break; } //initialize matrix vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + matrix.resize(thisItersLookup->size()); + for (int k = 0; k < thisItersLookup->size(); k++) { matrix[k].resize(thisItersLookup->size(), 0.0); } for (int j = 0; j < calcDists[i].size(); j++) { int row = calcDists[i][j].seq1; @@ -754,12 +716,13 @@ int MatrixOutputCommand::process(vector thisLookup){ m->openOutputFile(distFileName, outDist); outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); - printSims(outDist, matrix); + printSims(outDist, matrix, thisItersGroupNames); outDist.close(); } } for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } + delete thisItersLookup; } if (iters != 0) { @@ -772,12 +735,12 @@ int MatrixOutputCommand::process(vector thisLookup){ //print results for (int i = 0; i < calcDists.size(); i++) { vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + matrix.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { matrix[k].resize(thisLookup->size(), 0.0); } vector< vector > stdmatrix; //square matrix to represent the stdDev - stdmatrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { stdmatrix[k].resize(thisLookup.size(), 0.0); } + stdmatrix.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { stdmatrix[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcAverages[i].size(); j++) { @@ -794,7 +757,7 @@ int MatrixOutputCommand::process(vector thisLookup){ map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[distance]"] = thisLookup->getLabel(); variables["[outputtag]"] = output; variables["[tag2]"] = "ave"; variables["[calc]"] = matrixCalculators[i]->getName(); @@ -806,7 +769,7 @@ int MatrixOutputCommand::process(vector thisLookup){ m->openOutputFile(distFileName, outAve); outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint); - printSims(outAve, matrix); + printSims(outAve, matrix, thisLookup->getNamesGroups()); outAve.close(); @@ -817,7 +780,7 @@ int MatrixOutputCommand::process(vector thisLookup){ m->openOutputFile(distFileName, outSTD); outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint); - printSims(outSTD, stdmatrix); + printSims(outSTD, stdmatrix, thisLookup->getNamesGroups()); outSTD.close(); @@ -832,7 +795,7 @@ int MatrixOutputCommand::process(vector thisLookup){ } } /**************************************************************************************************/ -int MatrixOutputCommand::driver(vector thisLookup, int start, int end, vector< vector >& calcDists) { +int MatrixOutputCommand::driver(vector& thisLookup, int start, int end, vector< vector >& calcDists) { try { vector subset; diff --git a/source/commands/matrixoutputcommand.h b/source/commands/matrixoutputcommand.h index fa1fe574..977728bb 100644 --- a/source/commands/matrixoutputcommand.h +++ b/source/commands/matrixoutputcommand.h @@ -88,13 +88,11 @@ class MatrixOutputCommand : public Command { private: vector lines; - void printSims(ostream&, vector< vector >&); - int process(vector); + void printSims(ostream&, vector< vector >&, vector); + int process(SharedRAbundVectors*&); vector matrixCalculators; - //vector< vector > simMatrix; - InputData* input; - vector lookup; + //SharedRAbundVectors* lookup; string exportFileName, output, sharedfile; int numGroups, processors, iters, subsampleSize; ofstream out; @@ -103,8 +101,8 @@ class MatrixOutputCommand : public Command { set labels; //holds labels to be used string outputFile, calc, groups, label, outputDir, mode; vector Estimators, Groups, outputNames; //holds estimators to be used - int process(vector, string, string); - int driver(vector, int, int, vector< vector >&); + int process(SharedRAbundVectors*&, string, string); + int driver(vector&, int, int, vector< vector >&); }; @@ -122,7 +120,7 @@ struct distSharedData { int count; distSharedData(){} - distSharedData(MothurOut* mout, unsigned long long st, unsigned long long en, vector est, vector lu) { + distSharedData(MothurOut* mout, unsigned long long st, unsigned long long en, vector est, vector& lu) { m = mout; start = st; end = en; @@ -265,6 +263,7 @@ static DWORD WINAPI MyDistSharedThreadFunction(LPVOID lpParam){ } for(int i=0;ithisLookup.size();i++){ delete pDataArray->thisLookup[i]; } return 0; diff --git a/source/commands/mergegroupscommand.cpp b/source/commands/mergegroupscommand.cpp index 7c40ce86..de90edf7 100644 --- a/source/commands/mergegroupscommand.cpp +++ b/source/commands/mergegroupscommand.cpp @@ -328,137 +328,66 @@ int MergeGroupsCommand::execute(){ } //********************************************************************************************************************** -int MergeGroupsCommand::process(vector& thisLookUp, ofstream& out){ +int MergeGroupsCommand::process(SharedRAbundVectors*& thisLookUp, ofstream& out){ try { vector setNames = designMap->getCategory(); - if (method == "average") { - //create sharedRabundFloatVectors - vector temp = thisLookUp[0]->getSharedRAbundFloatVectors(thisLookUp); - - //follow code below - map merged; - map::iterator it; - for (int i = 0; i < setNames.size(); i++) { - SharedRAbundFloatVector myLookup(thisLookUp[0]->getNumBins()); - myLookup.setLabel(thisLookUp[0]->getLabel()); - merged[setNames[i]] = myLookup; - } + //create sharedRabundVectors + vector data = thisLookUp->getSharedRAbundVectors(); + + //create SharedRAbundVectors for the merged groups. Fill with blank rabundFloatVectors + SharedRAbundVectors* merged; merged = new SharedRAbundVectors(); + for (int i = 0; i < setNames.size(); i++) { + SharedRAbundVector* myLookup = new SharedRAbundVector(thisLookUp->getNumBins()); + myLookup->setLabel(thisLookUp->getLabel()); + myLookup->setGroup(setNames[i]); + merged->push_back(myLookup); + } + + //for each OTU + for (int j = 0; j < data[0]->getNumBins(); j++) { + if (m->control_pressed) { break; } - map > clearGroupAbunds; + map > otusGroupAbunds; map >::iterator itAbunds; - for (int i = 0; i < temp.size(); i++) { - if (m->control_pressed) { return 0; } - //what grouping does this group belong to - string grouping = designMap->get(temp[i]->getGroup()); - if (grouping == "not found") { m->mothurOut("[ERROR]: " + temp[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; } - else { - //do we already have a member of this grouping? - it = merged.find(grouping); - - if (it == merged.end()) { //nope, so create it - merged[grouping] = *temp[i]; - merged[grouping].setGroup(grouping); - vector temp; - clearGroupAbunds[grouping] = temp; - } - } - } - - for (int j = 0; j < temp[0]->getNumBins(); j++) { - if (m->control_pressed) { return 0; } + //for each sample + for (int i = 0; i < data.size(); i++) { - map > otusGroupAbunds = clearGroupAbunds; - for (int i = 0; i < temp.size(); i++) { - - string grouping = designMap->get(temp[i]->getGroup()); - if (grouping == "not found") { m->mothurOut("[ERROR]: " + temp[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; } - else { - otusGroupAbunds[grouping].push_back(temp[i]->getAbundance(j)); - } - } - - for (itAbunds = otusGroupAbunds.begin(); itAbunds != otusGroupAbunds.end(); itAbunds++) { - int abund = mergeAbund(itAbunds->second); - merged[itAbunds->first].set(j, abund, itAbunds->first); - } - } - - if (method == "median") { - vector temp2; - for (it = merged.begin(); it != merged.end(); it++) { temp2.push_back(&(it->second)); } - eliminateZeroOTUS(temp2); - } - - //print new file - for (it = merged.begin(); it != merged.end(); it++) { - if (!m->printedSharedHeaders) { (it->second).printHeaders(out); } - out << (it->second).getLabel() << '\t' << it->first << '\t'; - (it->second).print(out); - } - }else { - map merged; - map::iterator it; - for (int i = 0; i < setNames.size(); i++) { - SharedRAbundVector myLookup(thisLookUp[0]->getNumBins()); - myLookup.setLabel(thisLookUp[0]->getLabel()); - merged[setNames[i]] = myLookup; - } - - map > clearGroupAbunds; - map >::iterator itAbunds; - - for (int i = 0; i < thisLookUp.size(); i++) { - if (m->control_pressed) { return 0; } - //what grouping does this group belong to - string grouping = designMap->get(thisLookUp[i]->getGroup()); - if (grouping == "not found") { m->mothurOut("[ERROR]: " + thisLookUp[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; } + string grouping = designMap->get(data[i]->getGroup()); //what set to your belong to + if (grouping == "not found") { m->mothurOut("[ERROR]: " + data[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; } else { - //do we already have a member of this grouping? - it = merged.find(grouping); - - if (it == merged.end()) { //nope, so create it - merged[grouping] = *thisLookUp[i]; - merged[grouping].setGroup(grouping); + //Add this OTUs values to sets abunds + itAbunds = otusGroupAbunds.find(grouping); + if (itAbunds == otusGroupAbunds.end()) { //new group vector temp; - clearGroupAbunds[grouping] = temp; + temp.push_back(data[i]->get(j)); + otusGroupAbunds[grouping] = temp; + }else { + (itAbunds->second).push_back(data[i]->get(j)); } } } - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { - if (m->control_pressed) { return 0; } - - map > otusGroupAbunds = clearGroupAbunds; - for (int i = 0; i < thisLookUp.size(); i++) { - - string grouping = designMap->get(thisLookUp[i]->getGroup()); - if (grouping == "not found") { m->mothurOut("[ERROR]: " + thisLookUp[i]->getGroup() + " is not in your design file. Ignoring!"); m->mothurOutEndLine(); grouping = "NOTFOUND"; } - else { - otusGroupAbunds[grouping].push_back(thisLookUp[i]->getAbundance(j)); - } - } - - for (itAbunds = otusGroupAbunds.begin(); itAbunds != otusGroupAbunds.end(); itAbunds++) { - int abund = mergeAbund(itAbunds->second); - merged[itAbunds->first].set(j, abund, itAbunds->first); - } - } - - if (method == "median") { - vector temp; - for (it = merged.begin(); it != merged.end(); it++) { temp.push_back(&(it->second)); } - eliminateZeroOTUS(temp); - } - - //print new file - for (it = merged.begin(); it != merged.end(); it++) { - if (!m->printedSharedHeaders) { (it->second).printHeaders(out); } - out << (it->second).getLabel() << '\t' << it->first << '\t'; - (it->second).print(out); + //find results for this bin. Set merged value for this bin in the results + for (itAbunds = otusGroupAbunds.begin(); itAbunds != otusGroupAbunds.end(); itAbunds++) { + int abund = mergeAbund(itAbunds->second); + merged->set(j, abund, itAbunds->first); } } + + //free memory + for (int i = 0; i < data.size(); i++) { delete data[i]; } + + if (m->control_pressed) { delete merged; return 0; } + + merged->eliminateZeroOTUS(); // remove any zero OTUs created by median option. + + //print new file + if (!m->printedSharedHeaders) { merged->printHeaders(out); } + merged->print(out); + delete merged; + return 0; } @@ -484,46 +413,46 @@ int MergeGroupsCommand::processSharedFile(DesignMap*& designMap){ m->openOutputFile(outputFileName, out); InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { out.close(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { out.close(); delete lookup; m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, out); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { out.close(); m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -548,13 +477,13 @@ int MergeGroupsCommand::processSharedFile(DesignMap*& designMap){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup, out); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } out.close(); @@ -780,119 +709,6 @@ int MergeGroupsCommand::mergeAbund(vector values){ } } //********************************************************************************************************************** -int MergeGroupsCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - thislookup.clear(); - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "eliminateZeroOTUS"); - exit(1); - } -} -//********************************************************************************************************************** -int MergeGroupsCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "eliminateZeroOTUS"); - exit(1); - } -} -//********************************************************************************************************************** diff --git a/source/commands/mergegroupscommand.h b/source/commands/mergegroupscommand.h index 8973546d..47496e1c 100644 --- a/source/commands/mergegroupscommand.h +++ b/source/commands/mergegroupscommand.h @@ -12,7 +12,7 @@ #include "command.hpp" #include "inputdata.h" -#include "sharedrabundvector.h" + #include "designmap.h" class MergeGroupsCommand : public Command { @@ -41,20 +41,17 @@ class MergeGroupsCommand : public Command { private: DesignMap* designMap; - vector lookup; bool abort, allLines, pickedGroups; set labels; //holds labels to be used string groups, label, outputDir, inputDir, designfile, sharedfile, groupfile, countfile, method, fastafile; vector Groups, outputNames; - int process(vector&, ofstream&); + int process(SharedRAbundVectors*&, ofstream&); int processSharedFile(DesignMap*&); int processGroupFile(DesignMap*&); int processCountFile(DesignMap*&); int mergeAbund(vector); - int eliminateZeroOTUS(vector&); - int eliminateZeroOTUS(vector&); }; #endif diff --git a/source/commands/metastatscommand.cpp b/source/commands/metastatscommand.cpp index 307c1173..1762f8da 100644 --- a/source/commands/metastatscommand.cpp +++ b/source/commands/metastatscommand.cpp @@ -9,7 +9,7 @@ #include "metastatscommand.h" #include "sharedutilities.h" -#include "sharedrabundfloatvector.h" + //********************************************************************************************************************** @@ -226,9 +226,9 @@ int MetaStatsCommand::execute(){ designMap = new DesignMap(designfile); - input = new InputData(sharedfile, "sharedfile"); - lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + InputData input(sharedfile, "sharedfile"); + lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -268,46 +268,46 @@ int MetaStatsCommand::execute(){ } //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { outputTypes.clear(); delete lookup; m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; - if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->clearGroups(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -324,19 +324,18 @@ int MetaStatsCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } //reset groups parameter - m->clearGroups(); - delete input; + m->clearGroups(); delete designMap; if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0;} @@ -355,7 +354,7 @@ int MetaStatsCommand::execute(){ } //********************************************************************************************************************** -int MetaStatsCommand::process(vector& thisLookUp){ +int MetaStatsCommand::process(SharedRAbundVectors*& thisLookUp){ try { @@ -452,21 +451,8 @@ int MetaStatsCommand::process(vector& thisLookUp){ for( int i=1; i newLookup; - vector designMapGroups; - for (int k = 0; k < thisLookUp.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisLookUp[k]->getLabel()); - temp->setGroup(thisLookUp[k]->getGroup()); - newLookup.push_back(temp); - designMapGroups.push_back(designMap->get(thisLookUp[k]->getGroup())); - } - - //for each bin - for (int k = 0; k < thisLookUp[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisLookUp.size(); j++) { newLookup[j]->push_back(thisLookUp[j]->getAbundance(k), thisLookUp[j]->getGroup()); } - } + SharedRAbundVectors* newLookup = new SharedRAbundVectors(*lookup); + vector designMapGroups = lookup->getNamesGroups(); // Allocate memory for thread data. metastatsData* tempSum = new metastatsData(sharedfile, outputDir, m, lines[i].start, lines[i].end, namesOfGroupCombos, newLookup, designMapGroups, iters, threshold); @@ -487,7 +473,7 @@ int MetaStatsCommand::process(vector& thisLookUp){ if (pDataArray[i]->count != (pDataArray[i]->num)) { m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->num) + " groups assigned to it, quitting. \n"); m->control_pressed = true; } - for (int j = 0; j < pDataArray[i]->thisLookUp.size(); j++) { delete pDataArray[i]->thisLookUp[j]; } + delete pDataArray[i]->thisLookUp; for (int j = 0; j < pDataArray[i]->outputNames.size(); j++) { outputNames.push_back(pDataArray[i]->outputNames[j]); outputTypes["metastats"].push_back(pDataArray[i]->outputNames[j]); @@ -509,9 +495,12 @@ int MetaStatsCommand::process(vector& thisLookUp){ } } //********************************************************************************************************************** -int MetaStatsCommand::driver(unsigned long long start, unsigned long long num, vector& thisLookUp) { +int MetaStatsCommand::driver(unsigned long long start, unsigned long long num, SharedRAbundVectors*& thisLookUp) { try { + vector thisLookupNames = thisLookUp->getNamesGroups(); + vector thisLookupRabunds = thisLookUp->getSharedRAbundVectors(); + //for each combo for (int c = start; c < (start+num); c++) { @@ -522,33 +511,29 @@ int MetaStatsCommand::driver(unsigned long long start, unsigned long long num, v //get filename map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = thisLookUp[0]->getLabel(); + variables["[distance]"] = thisLookUp->getLabel(); variables["[group]"] = setA + "-" + setB; string outputFileName = getOutputFileName("metastats",variables); outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName); - //int nameLength = outputFileName.length(); - //char * output = new char[nameLength]; - //strcpy(output, outputFileName.c_str()); - - //build matrix from shared rabunds - //double** data; - //data = new double*[thisLookUp[0]->getNumBins()]; - vector< vector > data2; data2.resize(thisLookUp[0]->getNumBins()); + vector< vector > data2; data2.resize(thisLookUp->getNumBins()); vector subset; + vector subsetGroups; int setACount = 0; int setBCount = 0; - for (int i = 0; i < thisLookUp.size(); i++) { - string thisGroup = thisLookUp[i]->getGroup(); + for (int i = 0; i < thisLookUp->size(); i++) { + string thisGroup = thisLookupNames[i]; //is this group for a set we want to compare?? //sorting the sets by putting setB at the back and setA in the front if ((designMap->get(thisGroup) == setB)) { - subset.push_back(thisLookUp[i]); + subset.push_back(thisLookupRabunds[i]); + subsetGroups.push_back(thisGroup); setBCount++; }else if ((designMap->get(thisGroup) == setA)) { - subset.insert(subset.begin()+setACount, thisLookUp[i]); + subset.insert(subset.begin()+setACount, thisLookupRabunds[i]); + subsetGroups.insert(subsetGroups.begin()+setACount, thisGroup); setACount++; } } @@ -558,18 +543,17 @@ int MetaStatsCommand::driver(unsigned long long start, unsigned long long num, v }else { //fill data - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { - //data[j] = new double[subset.size()]; + for (int j = 0; j < thisLookUp->getNumBins(); j++) { data2[j].resize(subset.size(), 0.0); for (int i = 0; i < subset.size(); i++) { - data2[j][i] = (subset[i]->getAbundance(j)); + data2[j][i] = (subset[i]->get(j)); } } m->mothurOut("Comparing " + setA + " and " + setB + "..."); m->mothurOutEndLine(); //metastat_main(output, thisLookUp[0]->getNumBins(), subset.size(), threshold, iters, data, setACount); - if (convertSharedToInput) { convertToInput(subset, outputFileName); } + if (convertSharedToInput) { convertToInput(subset, subsetGroups, outputFileName); } m->mothurOutEndLine(); MothurMetastats mothurMeta(threshold, iters); @@ -577,13 +561,10 @@ int MetaStatsCommand::driver(unsigned long long start, unsigned long long num, v m->mothurOutEndLine(); m->mothurOutEndLine(); } - - //free memory - //delete output; - //for(int i = 0; i < thisLookUp[0]->getNumBins(); i++) { delete[] data[i]; } - //delete[] data; } + for(int i = 0; i < thisLookupRabunds.size(); i++) { delete thisLookupRabunds[i]; } + return 0; } @@ -618,13 +599,12 @@ int MetaStatsCommand::convertToShared(string filename) { string header = m->getline(in); m->gobble(in); vector groups = m->splitWhiteSpace(header); - vector newLookup; + vector newLookup; cout << groups.size() << endl; for (int i = 0; i < groups.size(); i++) { cout << "creating group " << groups[i] << endl; - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); + RAbundFloatVector* temp = new RAbundFloatVector(); temp->setLabel("0.03"); - temp->setGroup(groups[i]); newLookup.push_back(temp); } @@ -639,7 +619,7 @@ int MetaStatsCommand::convertToShared(string filename) { for (int i = 0; i < groups.size(); i++) { double temp; in >> temp; m->gobble(in); - newLookup[i]->push_back(temp, groups[i]); + newLookup[i]->push_back(temp); } m->gobble(in); } @@ -680,20 +660,20 @@ int MetaStatsCommand::convertToShared(string filename) { } //********************************************************************************************************************** -int MetaStatsCommand::convertToInput(vector& subset, string thisfilename) { +int MetaStatsCommand::convertToInput(vector& subset, vector subsetGroups, string thisfilename) { try { ofstream out; m->openOutputFile(thisfilename+".matrix", out); for (int i = 0; i < subset.size(); i++) { - out << '\t' << subset[i]->getGroup(); + out << '\t' << subsetGroups[i]; } out << endl; for (int i = 0; i < subset[0]->getNumBins(); i++) { out << m->currentSharedBinLabels[i]; for (int j = 0; j < subset.size(); j++) { - out << '\t' << subset[j]->getAbundance(i); + out << '\t' << subset[j]->get(i); } out << endl; } diff --git a/source/commands/metastatscommand.h b/source/commands/metastatscommand.h index b54aec1f..242ba9f9 100644 --- a/source/commands/metastatscommand.h +++ b/source/commands/metastatscommand.h @@ -12,7 +12,7 @@ #include "command.hpp" #include "inputdata.h" -#include "sharedrabundvector.h" +#include "sharedrabundvectors.hpp" #include "mothurmetastats.h" #include "designmap.h" @@ -39,8 +39,7 @@ class MetaStatsCommand : public Command { vector lines; DesignMap* designMap; - InputData* input; - vector lookup; + SharedRAbundVectors* lookup; bool abort, allLines, pickedGroups; set labels; //holds labels to be used @@ -50,10 +49,10 @@ class MetaStatsCommand : public Command { int iters, processors; float threshold; - int process(vector&); - int driver(unsigned long long, unsigned long long, vector&); + int process(SharedRAbundVectors*&); + int driver(unsigned long long, unsigned long long, SharedRAbundVectors*&); int convertToShared(string filename); - int convertToInput(vector&, string); + int convertToInput(vector&, vector, string); bool convertSharedToInput; }; @@ -62,7 +61,7 @@ class MetaStatsCommand : public Command { // This is passed by void pointer so it can be any data type // that can be passed using a single void pointer (LPVOID). struct metastatsData { - vector thisLookUp; + SharedRAbundVectors* thisLookUp; vector< vector > namesOfGroupCombos; vector designMapGroups; vector outputNames; @@ -74,7 +73,7 @@ struct metastatsData { string outputDir; metastatsData(){} - metastatsData(string sf, string oDir, MothurOut* mout, int st, int en, vector< vector > ns, vector lu, vector dg, int i, float thr) { + metastatsData(string sf, string oDir, MothurOut* mout, int st, int en, vector< vector > ns, SharedRAbundVectors*& lu, vector dg, int i, float thr) { sharedfile = sf; outputDir = oDir; m = mout; @@ -97,6 +96,9 @@ static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){ try { + vector thisLookupNames = pDataArray->thisLookUp->getNamesGroups(); + vector thisLookupRabunds = pDataArray->thisLookUp->getSharedRAbundVectors(); + //for each combo for (int c = pDataArray->start; c < (pDataArray->start+pDataArray->num); c++) { pDataArray->count++; @@ -105,10 +107,10 @@ static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){ string setB = pDataArray->namesOfGroupCombos[c][1]; //get filename - string outputFileName = pDataArray->outputDir + pDataArray->m->getRootName(pDataArray->m->getSimpleName(pDataArray->sharedfile)) + pDataArray->thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats"; + string outputFileName = pDataArray->outputDir + pDataArray->m->getRootName(pDataArray->m->getSimpleName(pDataArray->sharedfile)) + pDataArray->thisLookUp->getLabel() + "." + setA + "-" + setB + ".metastats"; pDataArray->outputNames.push_back(outputFileName); - vector< vector > data2; data2.resize(pDataArray->thisLookUp[0]->getNumBins()); + vector< vector > data2; data2.resize(pDataArray->thisLookUp->getNumBins()); vector subset; int setACount = 0; @@ -117,10 +119,10 @@ static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){ //is this group for a set we want to compare?? //sorting the sets by putting setB at the back and setA in the front if (pDataArray->designMapGroups[i] == setB) { - subset.push_back(pDataArray->thisLookUp[i]); + subset.push_back(thisLookupRabunds[i]); setBCount++; }else if (pDataArray->designMapGroups[i] == setA) { - subset.insert(subset.begin()+setACount, pDataArray->thisLookUp[i]); + subset.insert(subset.begin()+setACount, thisLookupRabunds[i]); setACount++; } } @@ -133,7 +135,7 @@ static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){ for (int j = 0; j < pDataArray->thisLookUp[0]->getNumBins(); j++) { data2[j].resize(subset.size(), 0.0); for (int i = 0; i < subset.size(); i++) { - data2[j][i] = (subset[i]->getAbundance(j)); + data2[j][i] = (subset[i]->get(j)); } } @@ -147,6 +149,7 @@ static DWORD WINAPI MyMetastatsThreadFunction(LPVOID lpParam){ } } + for(int i = 0; i < thisLookupRabunds.size(); i++) { delete thisLookupRabunds[i]; } return 0; } diff --git a/source/commands/mgclustercommand.cpp b/source/commands/mgclustercommand.cpp index 7ad4dcb5..423cf6b6 100644 --- a/source/commands/mgclustercommand.cpp +++ b/source/commands/mgclustercommand.cpp @@ -19,7 +19,11 @@ vector MGClusterCommand::setParameters(){ CommandParameter ppenalty("penalty", "Number", "", "0.10", "", "", "","",false,false); parameters.push_back(ppenalty); CommandParameter pcutoff("cutoff", "Number", "", "0.70", "", "", "","",false,false,true); parameters.push_back(pcutoff); CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average", "average", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-opti", "opti", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter pinitialize("initialize", "Multiple", "oneotu-singleton", "singleton", "", "", "","",false,false,true); parameters.push_back(pinitialize); + CommandParameter pmetric("metric", "Multiple", "mcc-sens-spec-tptn-fpfn-tp-tn-fp-fn-f1score-accuracy-ppv-npv-fdr", "mcc", "", "", "","",false,false,true); parameters.push_back(pmetric); + CommandParameter pmetriccutoff("delta", "Number", "", "0.0001", "", "", "","",false,false,true); parameters.push_back(pmetriccutoff); + CommandParameter piters("iters", "Number", "", "100", "", "", "","",false,false,true); parameters.push_back(piters); CommandParameter pmin("min", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmin); CommandParameter pmerge("merge", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmerge); CommandParameter padjust("adjust", "String", "", "F", "", "", "","",false,false); parameters.push_back(padjust); @@ -41,13 +45,17 @@ vector MGClusterCommand::setParameters(){ string MGClusterCommand::getHelpString(){ try { string helpString = ""; - helpString += "The mgcluster command parameter options are blast, name, cutoff, precision, method, merge, min, length, penalty and adjust. The blast parameter is required.\n"; + helpString += "The mgcluster command parameter options are blast, name, cutoff, precision, method, metric, initialize, iters, merge, min, length, penalty and adjust. The blast parameter is required.\n"; helpString += "The mgcluster command reads a blast and name file and clusters the sequences into OPF units similar to the OTUs.\n"; helpString += "This command outputs a .list, .rabund and .sabund file that can be used with mothur other commands to estimate richness.\n"; helpString += "The cutoff parameter is used to specify the maximum distance you would like to cluster to. The default is 0.70.\n"; helpString += "The precision parameter's default value is 100. \n"; - helpString += "The acceptable mgcluster methods are furthest, nearest and average. If no method is provided then average is assumed.\n"; + helpString += "The acceptable mgcluster methods are furthest, nearest, average and opti. If no method is provided then opti is assumed.\n"; helpString += "The min parameter allows you to specify is you want the minimum or maximum blast score ratio used in calculating the distance. The default is true, meaning you want the minimum.\n"; + helpString += "The iters parameter allow you to set the maxiters for the opticluster method. \n"; + helpString += "The metric parameter allows to select the metric in the opticluster method. Options are Matthews correlation coefficient (mcc), sensitivity (sens), specificity (spec), true positives + true negatives (tptn), false positives + false negatives (fpfn), true positives (tp), true negative (tn), false positive (fp), false negative (fn), f1score (f1score), accuracy (accuracy), positive predictive value (ppv), negative predictive value (npv), false discovery rate (fdr). Default=mcc.\n"; + helpString += "The initialize parameter allows to select the initial randomization for the opticluster method. Options are singleton, meaning each sequence is randomly assigned to its own OTU, or oneotu meaning all sequences are assigned to one otu. Default=singleton.\n"; + helpString += "The delta parameter allows to set the stable value for the metric in the opticluster method (delta=0.0001). \n"; helpString += "The length parameter is used to specify the minimum overlap required. The default is 5.\n"; helpString += "The adjust parameter is used to handle missing distances. If you set a cutoff, adjust=f by default. If not, adjust=t by default. Adjust=f, means ignore missing distances and adjust cutoff as needed with the average neighbor method. Adjust=t, will treat missing distances as 1.0. You can also set the value the missing distances should be set to, adjust=0.5 would give missing distances a value of 0.5.\n"; helpString += "The penalty parameter is used to adjust the error rate. The default is 0.10.\n"; @@ -70,6 +78,8 @@ string MGClusterCommand::getOutputPattern(string type) { if (type == "list") { pattern = "[filename],[clustertag],list-[filename],[clustertag],[tag2],list"; } else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else if (type == "steps") { pattern = "[filename],[clustertag],steps"; } + else if (type == "sensspec") { pattern = "[filename],[clustertag],sensspec"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } return pattern; @@ -88,6 +98,8 @@ MGClusterCommand::MGClusterCommand(){ outputTypes["list"] = tempOutNames; outputTypes["rabund"] = tempOutNames; outputTypes["sabund"] = tempOutNames; + outputTypes["steps"] = tempOutNames; + outputTypes["sensspec"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "MGClusterCommand", "MGClusterCommand"); @@ -122,6 +134,8 @@ MGClusterCommand::MGClusterCommand(string option) { outputTypes["list"] = tempOutNames; outputTypes["rabund"] = tempOutNames; outputTypes["sabund"] = tempOutNames; + outputTypes["steps"] = tempOutNames; + outputTypes["sensspec"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -192,10 +206,26 @@ MGClusterCommand::MGClusterCommand(string option) { m->mothurConvert(temp, cutoff); method = validParameter.validFile(parameters, "method", false); - if (method == "not found") { method = "average"; } + if (method == "not found") { method = "opti"; } - if ((method == "furthest") || (method == "nearest") || (method == "average")) { } - else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; } + if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "opti")) { } + else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest, average or opti."); m->mothurOutEndLine(); abort = true; } + + metric = validParameter.validFile(parameters, "metric", false); if (metric == "not found") { metric = "mcc"; } + + if ((metric == "mcc") || (metric == "sens") || (metric == "spec") || (metric == "tptn") || (metric == "tp") || (metric == "tn") || (metric == "fp") || (metric == "fn") || (metric == "f1score") || (metric == "accuracy") || (metric == "ppv") || (metric == "npv") || (metric == "fdr") || (metric == "fpfn") ){ } + else { m->mothurOut("[ERROR]: Not a valid metric. Valid metrics are mcc, sens, spec, tp, tn, fp, fn, tptn, fpfn, f1score, accuracy, ppv, npv, fdr."); m->mothurOutEndLine(); abort = true; } + + initialize = validParameter.validFile(parameters, "initialize", false); if (initialize == "not found") { initialize = "singleton"; } + + if ((initialize == "singleton") || (initialize == "oneotu")){ } + else { m->mothurOut("[ERROR]: Not a valid initialization. Valid initializations are singleton and oneotu."); m->mothurOutEndLine(); abort = true; } + + temp = validParameter.validFile(parameters, "delta", false); if (temp == "not found") { temp = "0.0001"; } + m->mothurConvert(temp, stableMetric); + + temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "100"; } + m->mothurConvert(temp, maxIters); temp = validParameter.validFile(parameters, "length", false); if (temp == "not found") { temp = "5"; } m->mothurConvert(temp, length); @@ -226,12 +256,274 @@ int MGClusterCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - //read names file + fileroot = outputDir + m->getRootName(m->getSimpleName(blastfile)); + tag = ""; + if (method == "furthest") { tag = "fn"; } + else if (method == "nearest") { tag = "nn"; } + else if (method == "average") { tag = "an"; } + else if (method == "opti") { tag = "opti"; } + + if (method == "opti") { runOptiCluster(); } + else { runMothurCluster(); } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(listFileName); m->mothurOutEndLine(); outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); + if (countfile == "") { + m->mothurOut(rabundFileName); m->mothurOutEndLine(); outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + m->mothurOut(sabundFileName); m->mothurOutEndLine(); outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + } + m->mothurOutEndLine(); + + //set list file as new current listfile + string current = ""; + itTypes = outputTypes.find("list"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); } + } + + //set rabund file as new current rabundfile + itTypes = outputTypes.find("rabund"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } + } + + //set sabund file as new current sabundfile + itTypes = outputTypes.find("sabund"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); } + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "execute"); + exit(1); + } +} +//********************************************************************************************************************** +void MGClusterCommand::printData(ListVector* mergedList, map& counts){ + try { + if (countfile != "") { + mergedList->print(listFile, counts); + }else { mergedList->print(listFile, true); } + + SAbundVector sabund = mergedList->getSAbundVector(); + + if (countfile == "") { + mergedList->getRAbundVector().print(rabundFile); + sabund.print(sabundFile); + } + + sabund.print(cout); + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "printData"); + exit(1); + } +} +//********************************************************************************************************************** +int MGClusterCommand::runOptiCluster(){ + try { + if (!cutoffSet) { m->mothurOut("\nYou did not set a cutoff, using 0.03.\n"); cutoff = 0.03; } + + string nameOrCount = ""; + string thisNamefile = ""; map counts; - if (namefile != "") { - nameMap = new NameAssignment(namefile); - nameMap->readMap(); - }else if (countfile != "") { + if (countfile != "") { nameOrCount = "count"; thisNamefile = countfile; CountTable ct; ct.readTable(countfile, false, false); counts = ct.getNameMap(); } + else if (namefile != "") { nameOrCount = "name"; thisNamefile = namefile; } + + string distfile = blastfile; + + time_t start = time(NULL); + + OptiMatrix matrix; + matrix.setBlastVariables(length, penalty, minWanted); + matrix.readFile(distfile, thisNamefile, nameOrCount, "blast", cutoff, false); + + ClusterMetric* metricCalc = NULL; + if (metric == "mcc") { metricCalc = new MCC(); } + else if (metric == "sens") { metricCalc = new Sensitivity(); } + else if (metric == "spec") { metricCalc = new Specificity(); } + else if (metric == "tptn") { metricCalc = new TPTN(); } + else if (metric == "tp") { metricCalc = new TP(); } + else if (metric == "tn") { metricCalc = new TN(); } + else if (metric == "fp") { metricCalc = new FP(); } + else if (metric == "fn") { metricCalc = new FN(); } + else if (metric == "f1score") { metricCalc = new F1Score(); } + else if (metric == "accuracy") { metricCalc = new Accuracy(); } + else if (metric == "ppv") { metricCalc = new PPV(); } + else if (metric == "npv") { metricCalc = new NPV(); } + else if (metric == "fdr") { metricCalc = new FDR(); } + else if (metric == "fpfn") { metricCalc = new FPFN(); } + + OptiCluster cluster(&matrix, metricCalc, 0); + string tag = cluster.getTag(); + + map variables; + variables["[filename]"] = fileroot; + variables["[clustertag]"] = tag; + sabundFileName = getOutputFileName("sabund", variables); + rabundFileName = getOutputFileName("rabund", variables); + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + listFileName = getOutputFileName("list", variables); + string outputName = getOutputFileName("steps", variables); + outputNames.push_back(outputName); outputTypes["steps"].push_back(outputName); + + m->mothurOutEndLine(); m->mothurOut("Clustering " + distfile); m->mothurOutEndLine(); + + if (outputDir == "") { outputDir += m->hasPath(distfile); } + + ofstream listFile; + m->openOutputFile(listFileName, listFile); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); + + ofstream outStep; + m->openOutputFile(outputName, outStep); + + int iters = 0; + double listVectorMetric = 0; //worst state + double delta = 1; + + cluster.initialize(listVectorMetric, true, initialize); + + long long numBins = cluster.getNumBins(); + m->mothurOut("\n\niter\ttime\tlabel\tnum_otus\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n"); + outStep << "iter\ttime\tlabel\tnum_otus\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n"; + long long tp, tn, fp, fn; + vector results = cluster.getStats(tp, tn, fp, fn); + m->mothurOut("0\t0\t" + toString(cutoff) + "\t" + toString(numBins) + "\t"+ toString(cutoff) + "\t" + toString(tp) + "\t" + toString(tn) + "\t" + toString(fp) + "\t" + toString(fn) + "\t"); + outStep << "0\t0\t" + toString(cutoff) + "\t" + toString(numBins) + "\t" + toString(cutoff) + "\t" << tp << '\t' << tn << '\t' << fp << '\t' << fn << '\t'; + for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); outStep << results[i] << "\t"; } + m->mothurOutEndLine(); + outStep << endl; + + while ((delta > stableMetric) && (iters < maxIters)) { + + int start = time(NULL); + + if (m->control_pressed) { break; } + double oldMetric = listVectorMetric; + + cluster.update(listVectorMetric); + + delta = abs(oldMetric - listVectorMetric); + iters++; + + results = cluster.getStats(tp, tn, fp, fn); + numBins = cluster.getNumBins(); + + m->mothurOut(toString(iters) + "\t" + toString(time(NULL) - start) + "\t" + toString(cutoff) + "\t" + toString(numBins) + "\t" + toString(cutoff) + "\t"+ toString(tp) + "\t" + toString(tn) + "\t" + toString(fp) + "\t" + toString(fn) + "\t"); + outStep << (toString(iters) + "\t" + toString(time(NULL) - start) + "\t" + toString(cutoff) + "\t" + toString(numBins) + "\t" + toString(cutoff) + "\t") << tp << '\t' << tn << '\t' << fp << '\t' << fn << '\t'; + for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); outStep << results[i] << "\t"; } + m->mothurOutEndLine(); + outStep << endl; + } + m->mothurOutEndLine(); m->mothurOutEndLine(); + + list = cluster.getList(); + list->setLabel(toString(cutoff)); + + if (merge) { + vector< set > overlap = matrix.getBlastOverlap(); + + //assign each sequence to bins + map seqToBin; + for (int i = 0; i < list->getNumBins(); i++) { + if (m->control_pressed) { break; } + string bin = list->get(i); + vector names; m->splitAtComma(bin, names); + for (int j = 0; j < names.size(); j++) { seqToBin[names[j]] = i; } + } + + //merge overlapping bins + int mergedBinCount = 0; + for (int i = 0; i < overlap.size(); i++) { + set temp = overlap[i]; overlap[i].clear(); + for (set::iterator itOverlap = temp.begin(); itOverlap != temp.end(); itOverlap++) { + string firstName = matrix.getOverlapName(i); + string secondName = matrix.getOverlapName(*itOverlap); + int binKeep = seqToBin[firstName]; + int binRemove = seqToBin[secondName]; + + if(binKeep != binRemove) { + //save names in old bin + string bin = list->get(binRemove); + + //merge bins into name1s bin + list->set(binKeep, bin+','+list->get(binKeep)); + list->set(binRemove, ""); + + vector binNames; m->splitAtComma(bin, binNames); + //update binInfo //save name and new bin number + for (int k = 0; k < binNames.size(); k++) { seqToBin[binNames[k]] = binKeep; } + mergedBinCount++; + } + } + } + + if (mergedBinCount != 0) { m->mothurOut("Merged " + toString(mergedBinCount) + " OTUs based on blast overlap.\n\n"); } + } + + if (!m->printedListHeaders) { m->listBinLabelsInFile.clear(); list->printHeaders(listFile); } + if(countfile != "") { list->print(listFile, counts); } + else { list->print(listFile); } + listFile.close(); + + variables["[filename]"] = fileroot; + variables["[clustertag]"] = tag; + string sabundFileName = getOutputFileName("sabund", variables); + string rabundFileName = getOutputFileName("rabund", variables); + + if (countfile == "") { + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + + SAbundVector sabund = list->getSAbundVector(); + sabund.print(sabundFile); + sabundFile.close(); + + RAbundVector rabund = list->getRAbundVector(); + rabund.print(rabundFile); + rabundFile.close(); + } + delete list; + + string sensspecFilename = fileroot+ tag + ".sensspec"; + ofstream sensFile; + m->openOutputFile(sensspecFilename, sensFile); + outputNames.push_back(sensspecFilename); outputTypes["sensspec"].push_back(sensspecFilename); + + + sensFile << "label\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n"; + + results = cluster.getStats(tp, tn, fp, fn); + + sensFile << cutoff << '\t' << cutoff << '\t' << tp << '\t' << tn << '\t' << fp << '\t' << fn << '\t'; + for (int i = 0; i < results.size(); i++) { sensFile << results[i] << '\t'; } + sensFile << '\n'; + sensFile.close(); + + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); m->mothurOutEndLine(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "runOptiCluster"); + exit(1); + } +} +//********************************************************************************************************************** +int MGClusterCommand::runMothurCluster(){ + try { + //read names file + map counts; + if (namefile != "") { + nameMap = new NameAssignment(namefile); + nameMap->readMap(); + }else if (countfile != "") { ct = new CountTable(); ct->readTable(countfile, false, false); nameMap= new NameAssignment(); @@ -239,17 +531,24 @@ int MGClusterCommand::execute(){ for (int i = 0; i < tempNames.size(); i++) { nameMap->push_back(tempNames[i]); } counts = ct->getNameMap(); }else{ nameMap= new NameAssignment(); } - - string fileroot = outputDir + m->getRootName(m->getSimpleName(blastfile)); - string tag = ""; - time_t start; - float previousDist = 0.00000; - float rndPreviousDist = 0.00000; - //read blastfile - creates sparsematrices for the distances and overlaps as well as a listvector - //must remember to delete those objects here since readBlast does not - read = new ReadBlast(blastfile, cutoff, penalty, length, minWanted); - read->read(nameMap); + map variables; + variables["[filename]"] = fileroot; + variables["[clustertag]"] = tag; + sabundFileName = getOutputFileName("sabund", variables); + rabundFileName = getOutputFileName("rabund", variables); + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + listFileName = getOutputFileName("list", variables); + + float previousDist = 0.00000; + float rndPreviousDist = 0.00000; + + time_t start = time(NULL); + + //read blastfile - creates sparsematrices for the distances and overlaps as well as a listvector + //must remember to delete those objects here since readBlast does not + read = new ReadBlast(blastfile, cutoff, penalty, length, minWanted); + read->read(nameMap); list = new ListVector(nameMap->getListVector()); RAbundVector* rabund = NULL; @@ -261,46 +560,29 @@ int MGClusterCommand::execute(){ rabund = new RAbundVector(list->getRAbundVector()); } - - //list = new ListVector(nameMap->getListVector()); - //rabund = new RAbundVector(list->getRAbundVector()); - - if (m->control_pressed) { outputTypes.clear(); delete nameMap; delete read; delete list; delete rabund; return 0; } - - start = time(NULL); - oldList = *list; - map Seq2Bin; - map oldSeq2Bin; - - if (method == "furthest") { tag = "fn"; } - else if (method == "nearest") { tag = "nn"; } - else { tag = "an"; } - - map variables; - variables["[filename]"] = fileroot; - variables["[clustertag]"] = tag; - string sabundFileName = getOutputFileName("sabund", variables); - string rabundFileName = getOutputFileName("rabund", variables); - if (countfile != "") { variables["[tag2]"] = "unique_list"; } - string listFileName = getOutputFileName("list", variables); + if (m->control_pressed) { outputTypes.clear(); delete nameMap; delete read; delete list; delete rabund; return 0; } + + + oldList = *list; + map Seq2Bin; + map oldSeq2Bin; if (countfile == "") { m->openOutputFile(sabundFileName, sabundFile); m->openOutputFile(rabundFileName, rabundFile); } - m->openOutputFile(listFileName, listFile); + m->openOutputFile(listFileName, listFile); list->printHeaders(listFile); - - if (m->control_pressed) { - delete nameMap; delete read; delete list; delete rabund; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); - outputTypes.clear(); - return 0; - } - - double saveCutoff = cutoff; - - + + if (m->control_pressed) { + delete nameMap; delete read; delete list; delete rabund; + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); + outputTypes.clear(); + return 0; + } + + double saveCutoff = cutoff; + //get distmatrix and overlap SparseDistanceMatrix* distMatrix = read->getDistMatrix(); overlapMatrix = read->getOverlapMatrix(); //already sorted by read @@ -316,7 +598,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); outputTypes.clear(); return 0; } @@ -331,7 +613,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); outputTypes.clear(); return 0; } @@ -349,7 +631,7 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); outputTypes.clear(); return 0; } @@ -380,9 +662,9 @@ int MGClusterCommand::execute(){ if (m->control_pressed) { delete nameMap; delete distMatrix; delete list; delete rabund; delete cluster; delete temp; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); outputTypes.clear(); - return 0; + return 0; } temp->setLabel(toString(rndPreviousDist, precisionLength-1)); @@ -398,84 +680,35 @@ int MGClusterCommand::execute(){ overlapMatrix.clear(); delete distMatrix; delete cluster; - delete list; - delete rabund; - listFile.close(); + delete list; + delete rabund; + listFile.close(); if (countfile == "") { sabundFile.close(); rabundFile.close(); } - if (m->control_pressed) { - delete nameMap; - listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); } m->mothurRemove((fileroot+ tag + ".list")); - outputTypes.clear(); - return 0; - } - - m->mothurOutEndLine(); - m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(listFileName); m->mothurOutEndLine(); outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); - if (countfile == "") { - m->mothurOut(rabundFileName); m->mothurOutEndLine(); outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); - m->mothurOut(sabundFileName); m->mothurOutEndLine(); outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + if (m->control_pressed) { + delete nameMap; + listFile.close(); if (countfile == "") { rabundFile.close(); sabundFile.close(); m->mothurRemove(rabundFileName); m->mothurRemove(sabundFileName); } m->mothurRemove(listFileName); + outputTypes.clear(); + return 0; } - m->mothurOutEndLine(); - - if (saveCutoff != cutoff) { - saveCutoff = m->ceilDist(saveCutoff, precision); - m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); - } - - //set list file as new current listfile - string current = ""; - itTypes = outputTypes.find("list"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); } - } - - //set rabund file as new current rabundfile - itTypes = outputTypes.find("rabund"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } - } - - //set sabund file as new current sabundfile - itTypes = outputTypes.find("sabund"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); } - } - - - m->mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); m->mothurOutEndLine(); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "execute"); - exit(1); - } -} -//********************************************************************************************************************** -void MGClusterCommand::printData(ListVector* mergedList, map& counts){ - try { - if (countfile != "") { - mergedList->print(listFile, counts); - }else { mergedList->print(listFile, true); } - - SAbundVector sabund = mergedList->getSAbundVector(); - if (countfile == "") { - mergedList->getRAbundVector().print(rabundFile); - sabund.print(sabundFile); + if (saveCutoff != cutoff) { + saveCutoff = m->ceilDist(saveCutoff, precision); + m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); } + + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); m->mothurOutEndLine(); + + return 0; - sabund.print(cout); - } - catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "printData"); - exit(1); - } + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "runMothurCluster"); + exit(1); + } } //********************************************************************************************************************** //this merging is just at the reporting level, after this info is printed to the file it is gone and does not effect the datastructures @@ -489,44 +722,19 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ ifstream inOverlap; int count = 0; - if (hclusterWanted) { - m->openInputFile(overlapFile, inOverlap); - if (inOverlap.eof()) { done = true; } - }else { if (overlapMatrix.size() == 0) { done = true; } } + if (overlapMatrix.size() == 0) { done = true; } while (!done) { - if (m->control_pressed) { - if (hclusterWanted) { inOverlap.close(); } - return newList; - } + if (m->control_pressed) { return newList; } //get next overlap seqDist overlapNode; - if (!hclusterWanted) { - if (count < overlapMatrix.size()) { //do we have another node in the matrix - overlapNode = overlapMatrix[count]; - count++; - }else { break; } - }else { - if (!inOverlap.eof()) { - string firstName, secondName; - float overlapDistance; - inOverlap >> firstName >> secondName >> overlapDistance; m->gobble(inOverlap); - - //commented out because we check this in readblast already - //map::iterator itA = nameMap->find(firstName); - //map::iterator itB = nameMap->find(secondName); - //if(itA == nameMap->end()){ cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; exit(1); } - //if(itB == nameMap->end()){ cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1); } - - //overlapNode.seq1 = itA->second; - //overlapNode.seq2 = itB->second; - overlapNode.seq1 = nameMap->get(firstName); - overlapNode.seq2 = nameMap->get(secondName); - overlapNode.dist = overlapDistance; - }else { inOverlap.close(); break; } - } - + + if (count < overlapMatrix.size()) { //do we have another node in the matrix + overlapNode = overlapMatrix[count]; + count++; + }else { break; } + if (overlapNode.dist < dist) { //get names of seqs that overlap string name1 = nameMap->get(overlapNode.seq1); @@ -555,17 +763,9 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ newList->set(binKeep, newList->get(binRemove)+','+newList->get(binKeep)); newList->set(binRemove, ""); - //update binInfo - while (names.find_first_of(',') != -1) { - //get name from bin - string name = names.substr(0,names.find_first_of(',')); - //save name and bin number - binInfo[name] = binKeep; - names = names.substr(names.find_first_of(',')+1, names.length()); - } - - //get last name - binInfo[names] = binKeep; + vector binNames; m->splitAtComma(names, binNames); + //update binInfo //save name and new bin number + for (int i = 0; i < binNames.size(); i++) { binInfo[binNames[i]] = binKeep; } } }else { done = true; } @@ -581,25 +781,6 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ } } //********************************************************************************************************************** -void MGClusterCommand::sortHclusterFiles(string unsortedDist, string unsortedOverlap) { - try { - //sort distFile - string sortedDistFile = m->sortFile(unsortedDist, outputDir); - m->mothurRemove(unsortedDist); //delete unsorted file - distFile = sortedDistFile; - - //sort overlap file - string sortedOverlapFile = m->sortFile(unsortedOverlap, outputDir); - m->mothurRemove(unsortedOverlap); //delete unsorted file - overlapFile = sortedOverlapFile; - } - catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "sortHclusterFiles"); - exit(1); - } -} - -//********************************************************************************************************************** void MGClusterCommand::createRabund(CountTable*& ct, ListVector*& list, RAbundVector*& rabund){ try { diff --git a/source/commands/mgclustercommand.h b/source/commands/mgclustercommand.h index 55ad90a9..8435ddea 100644 --- a/source/commands/mgclustercommand.h +++ b/source/commands/mgclustercommand.h @@ -17,6 +17,8 @@ #include "rabundvector.hpp" #include "sabundvector.hpp" #include "counttable.h" +#include "opticluster.h" +#include "optimatrix.h" /**********************************************************************/ @@ -45,25 +47,25 @@ class MGClusterCommand : public Command { NameAssignment* nameMap; Cluster* cluster; ListVector* list; + ListVector oldList; CountTable* ct; - ListVector oldList; RAbundVector rav; vector overlapMatrix; vector outputNames; - string blastfile, method, namefile, countfile, overlapFile, distFile, outputDir; + string blastfile, method, namefile, countfile, overlapFile, distFile, outputDir, sabundFileName, rabundFileName, listFileName, metric, initialize, tag, fileroot; ofstream sabundFile, rabundFile, listFile; double cutoff; - float penalty, adjust; - int precision, length, precisionLength; + float penalty, adjust, stableMetric; + int precision, length, precisionLength, maxIters; bool abort, minWanted, hclusterWanted, merge, cutoffSet; void printData(ListVector*, map&); ListVector* mergeOPFs(map, float); - void sortHclusterFiles(string, string); - vector getSeqs(ifstream&); + vector getSeqs(ifstream&); void createRabund(CountTable*&, ListVector*&, RAbundVector*&); - + int runOptiCluster(); + int runMothurCluster(); }; /**********************************************************************/ diff --git a/source/commands/normalizesharedcommand.cpp b/source/commands/normalizesharedcommand.cpp index 0ef4aead..a7032ba7 100644 --- a/source/commands/normalizesharedcommand.cpp +++ b/source/commands/normalizesharedcommand.cpp @@ -211,28 +211,18 @@ int NormalizeSharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - input = new InputData(inputfile, format); - + InputData input(inputfile, format); + //you are reading a sharedfile and you do not want to make relabund if ((format == "sharedfile") && (!makeRelabund)) { - lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); //look for groups whose numseqs is below norm and remove them, warning the user if (norm != 0) { m->clearGroups(); - vector mGroups; - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < norm) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - mGroups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; + lookup->removeGroups(norm); + vector mGroups = lookup->getNamesGroups(); m->setGroups(mGroups); } @@ -242,55 +232,50 @@ int NormalizeSharedCommand::execute(){ if (method == "totalgroup") { //set norm to smallest group number - if (norm == 0) { - norm = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < norm) { norm = lookup[i]->getNumSeqs(); } - } - } + if (norm == 0) { norm = lookup->getNumSeqsSmallestGroup(); } m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine(); } //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); delete lookup; m->clearGroups(); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); normalize(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); normalize(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; } //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input.getSharedRAbundVectors(); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; } @@ -310,19 +295,16 @@ int NormalizeSharedCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); - - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); normalize(lookup); - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } }else{ //relabund values - lookupFloat = input->getSharedRAbundFloatVectors(); - string lastLabel = lookupFloat[0]->getLabel(); + SharedRAbundFloatVectors* lookupFloat = input.getSharedRAbundFloatVectors(); + string lastLabel = lookupFloat->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -330,74 +312,73 @@ int NormalizeSharedCommand::execute(){ //look for groups whose numseqs is below norm and remove them, warning the user if (norm != 0) { - m->clearGroups(); - vector mGroups; - vector temp; - for (int i = 0; i < lookupFloat.size(); i++) { - if (lookupFloat[i]->getNumSeqs() < norm) { - m->mothurOut(lookupFloat[i]->getGroup() + " contains " + toString(lookupFloat[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookupFloat[i]; - }else { - mGroups.push_back(lookupFloat[i]->getGroup()); - temp.push_back(lookupFloat[i]); - } - } - lookupFloat = temp; - m->setGroups(mGroups); + m->clearGroups(); + vector mGroups; + vector temp; + vector lookupGroups = lookupFloat->getNamesGroups(); + for (int i = 0; i < lookupGroups.size(); i++) { + if (lookupFloat->getNumSeqs(lookupGroups[i]) < norm) { + m->mothurOut(lookupGroups[i] + " contains " + toString(lookupFloat->getNumSeqs(lookupGroups[i])) + ". Eliminating."); m->mothurOutEndLine(); + temp.push_back(lookupGroups[i]); + }else { Groups.push_back(lookupGroups[i]); } + } + lookupFloat->removeGroups(temp); + m->setGroups(mGroups); } //set norm to smallest group number if (method == "totalgroup") { - if (norm == 0) { - norm = lookupFloat[0]->getNumSeqs(); - for (int i = 1; i < lookupFloat.size(); i++) { - if (lookupFloat[i]->getNumSeqs() < norm) { norm = lookupFloat[i]->getNumSeqs(); } - } - } + if (norm == 0) { + vector lookupGroups = lookupFloat->getNamesGroups(); + norm = lookupFloat->getNumSeqs(lookupGroups[0]); + for (int i = 1; i < lookupGroups.size(); i++) { + if (lookupFloat->getNumSeqs(lookupGroups[i]) < norm) { norm = lookupFloat->getNumSeqs(lookupGroups[i]); } + } + } m->mothurOut("Normalizing to " + toString(norm) + "."); m->mothurOutEndLine(); } //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookupFloat != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->clearGroups(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); delete lookupFloat; m->clearGroups(); return 0; } - if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookupFloat->getLabel()) == 1){ - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); normalize(lookupFloat); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + delete lookupFloat; + lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); normalize(lookupFloat); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; } + delete lookupFloat; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; } //get next line to process - lookupFloat = input->getSharedRAbundFloatVectors(); + lookupFloat = input.getSharedRAbundFloatVectors(); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; } @@ -417,20 +398,19 @@ int NormalizeSharedCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } - lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); + delete lookupFloat; + lookupFloat = input.getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookupFloat->getLabel()); m->mothurOutEndLine(); normalize(lookupFloat); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } + delete lookupFloat; } } //reset groups parameter - m->clearGroups(); - delete input; + m->clearGroups(); if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;} @@ -456,16 +436,15 @@ int NormalizeSharedCommand::execute(){ } //********************************************************************************************************************** -int NormalizeSharedCommand::normalize(vector& thisLookUp){ +int NormalizeSharedCommand::normalize(SharedRAbundVectors*& thisLookUp){ try { //save mothurOut's binLabels to restore for next label vector saveBinLabels = m->currentSharedBinLabels; - - if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } + vector lookupGroups = thisLookUp->getNamesGroups(); map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); - variables["[distance]"] = thisLookUp[0]->getLabel(); + variables["[distance]"] = thisLookUp->getLabel(); string outputFileName = getOutputFileName("shared",variables); ofstream out; @@ -476,69 +455,61 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ //save numSeqs since they will change as the data is normalized vector sizes; - for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); } + for (int i = 0; i < lookupGroups.size(); i++) { sizes.push_back(thisLookUp->getNumSeqs(lookupGroups[i])); } - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { - - for (int i = 0; i < thisLookUp.size(); i++) { - - if (m->control_pressed) { out.close(); return 0; } - - int abund = thisLookUp[i]->getAbundance(j); - - float relabund = abund / (float) sizes[i]; - float newNorm = relabund * norm; - - //round to nearest int - int finalNorm = (int) floor((newNorm + 0.5)); - - thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup()); - } - } + for (int j = 0; j < thisLookUp->getNumBins(); j++) { + + for (int i = 0; i < lookupGroups.size(); i++) { + + if (m->control_pressed) { out.close(); return 0; } + + int abund = thisLookUp->get(j, lookupGroups[i]); + + float relabund = abund / (float) sizes[i]; + float newNorm = relabund * norm; + + //round to nearest int + int finalNorm = (int) floor((newNorm + 0.5)); + + thisLookUp->set(j, finalNorm, lookupGroups[i]); + } + } }else if (method == "zscore") { - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { + for (int j = 0; j < thisLookUp->getNumBins(); j++) { if (m->control_pressed) { out.close(); return 0; } //calc mean float mean = 0.0; - for (int i = 0; i < thisLookUp.size(); i++) { mean += thisLookUp[i]->getAbundance(j); } - mean /= (float) thisLookUp.size(); + for (int i = 0; i < lookupGroups.size(); i++) { mean += thisLookUp->get(j, lookupGroups[i]); } + mean /= (float) lookupGroups.size(); //calc standard deviation float sumSquared = 0.0; - for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += (((float)thisLookUp[i]->getAbundance(j) - mean) * ((float)thisLookUp[i]->getAbundance(j) - mean)); } - sumSquared /= (float) thisLookUp.size(); + for (int i = 0; i < lookupGroups.size(); i++) { sumSquared += (((float)thisLookUp->get(j, lookupGroups[i]) - mean) * ((float)thisLookUp->get(j, lookupGroups[i]) - mean)); } + sumSquared /= (float) lookupGroups.size(); float standardDev = sqrt(sumSquared); - for (int i = 0; i < thisLookUp.size(); i++) { + for (int i = 0; i < lookupGroups.size(); i++) { int finalNorm = 0; if (standardDev != 0) { // stop divide by zero - float newNorm = ((float)thisLookUp[i]->getAbundance(j) - mean) / standardDev; + float newNorm = ((float)thisLookUp->get(j, lookupGroups[i]) - mean) / standardDev; //round to nearest int finalNorm = (int) floor((newNorm + 0.5)); } - thisLookUp[i]->set(j, finalNorm, thisLookUp[i]->getGroup()); + thisLookUp->set(j, finalNorm, lookupGroups[i]); } } }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } - - - eliminateZeroOTUS(thisLookUp); - - thisLookUp[0]->printHeaders(out); - - for (int i = 0; i < thisLookUp.size(); i++) { - out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t'; - thisLookUp[i]->print(out); - } - + thisLookUp->eliminateZeroOTUS(); + thisLookUp->printHeaders(out); + thisLookUp->print(out); out.close(); m->currentSharedBinLabels = saveBinLabels; @@ -552,83 +523,75 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ } //********************************************************************************************************************** -int NormalizeSharedCommand::normalize(vector& thisLookUp){ +int NormalizeSharedCommand::normalize(SharedRAbundFloatVectors*& thisLookUp){ try { //save mothurOut's binLabels to restore for next label vector saveBinLabels = m->currentSharedBinLabels; + vector lookupGroups = thisLookUp->getNamesGroups(); map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); - variables["[distance]"] = thisLookUp[0]->getLabel(); + variables["[distance]"] = thisLookUp->getLabel(); string outputFileName = getOutputFileName("shared",variables); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); - - if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } - if (method == "totalgroup") { //save numSeqs since they will change as the data is normalized vector sizes; - for (int i = 0; i < thisLookUp.size(); i++) { sizes.push_back(thisLookUp[i]->getNumSeqs()); } + for (int i = 0; i < lookupGroups.size(); i++) { sizes.push_back(thisLookUp->getNumSeqs(lookupGroups[i])); } - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { + for (int j = 0; j < thisLookUp->getNumBins(); j++) { - for (int i = 0; i < thisLookUp.size(); i++) { + for (int i = 0; i < lookupGroups.size(); i++) { if (m->control_pressed) { out.close(); return 0; } - float abund = thisLookUp[i]->getAbundance(j); + float abund = thisLookUp->get(j, lookupGroups[i]); float relabund = abund / (float) sizes[i]; float newNorm = relabund * norm; - thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup()); + thisLookUp->set(j, newNorm, lookupGroups[i]); } } }else if (method == "zscore") { - for (int j = 0; j < thisLookUp[0]->getNumBins(); j++) { + for (int j = 0; j < thisLookUp->getNumBins(); j++) { if (m->control_pressed) { out.close(); return 0; } //calc mean float mean = 0.0; - for (int i = 0; i < thisLookUp.size(); i++) { mean += thisLookUp[i]->getAbundance(j); } - mean /= (float) thisLookUp.size(); + for (int i = 0; i < lookupGroups.size(); i++) { mean += thisLookUp->get(j, lookupGroups[i]); } + mean /= (float) lookupGroups.size(); //calc standard deviation float sumSquared = 0.0; - for (int i = 0; i < thisLookUp.size(); i++) { sumSquared += ((thisLookUp[i]->getAbundance(j) - mean) * (thisLookUp[i]->getAbundance(j) - mean)); } - sumSquared /= (float) thisLookUp.size(); + for (int i = 0; i < lookupGroups.size(); i++) { sumSquared += ((thisLookUp->get(j, lookupGroups[i]) - mean) * (thisLookUp->get(j, lookupGroups[i]) - mean)); } + sumSquared /= (float) lookupGroups.size(); float standardDev = sqrt(sumSquared); - for (int i = 0; i < thisLookUp.size(); i++) { + for (int i = 0; i < lookupGroups.size(); i++) { float newNorm = 0.0; - if (standardDev != 0) { // stop divide by zero - newNorm = (thisLookUp[i]->getAbundance(j) - mean) / standardDev; - } - thisLookUp[i]->set(j, newNorm, thisLookUp[i]->getGroup()); - } + if (standardDev != 0) { // stop divide by zero + newNorm = ((float)thisLookUp->get(j, lookupGroups[i]) - mean) / standardDev; + } + thisLookUp->set(j, newNorm, lookupGroups[i]); + } } }else{ m->mothurOut(method + " is not a valid scaling option."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } - eliminateZeroOTUS(thisLookUp); - - thisLookUp[0]->printHeaders(out); - - for (int i = 0; i < thisLookUp.size(); i++) { - out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t'; - thisLookUp[i]->print(out); - } - - out.close(); + thisLookUp->eliminateZeroOTUS(); + thisLookUp->printHeaders(out); + thisLookUp->print(out); + out.close(); m->currentSharedBinLabels = saveBinLabels; @@ -640,116 +603,3 @@ int NormalizeSharedCommand::normalize(vector& thisLook } } //********************************************************************************************************************** -int NormalizeSharedCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS"); - exit(1); - } -} -//********************************************************************************************************************** -int NormalizeSharedCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "eliminateZeroOTUS"); - exit(1); - } -} - -//********************************************************************************************************************** diff --git a/source/commands/normalizesharedcommand.h b/source/commands/normalizesharedcommand.h index 53bcd6b5..1f7c9ffe 100644 --- a/source/commands/normalizesharedcommand.h +++ b/source/commands/normalizesharedcommand.h @@ -12,7 +12,7 @@ #include "command.hpp" #include "inputdata.h" -#include "sharedrabundvector.h" + class NormalizeSharedCommand : public Command { @@ -36,21 +36,14 @@ class NormalizeSharedCommand : public Command { private: - InputData* input; - vector lookup; - vector lookupFloat; - bool abort, allLines, pickedGroups, makeRelabund; set labels; //holds labels to be used string groups, label, outputDir, method, sharedfile, relabundfile, format, inputfile; int norm; vector Groups, outputNames; - int normalize(vector&); - int normalize(vector&); - int eliminateZeroOTUS(vector&); - int eliminateZeroOTUS(vector&); - + int normalize(SharedRAbundVectors*&); + int normalize(SharedRAbundFloatVectors*&); }; #endif diff --git a/source/commands/otuassociationcommand.cpp b/source/commands/otuassociationcommand.cpp index af4e1b01..4a580a50 100644 --- a/source/commands/otuassociationcommand.cpp +++ b/source/commands/otuassociationcommand.cpp @@ -237,13 +237,12 @@ int OTUAssociationCommand::execute(){ int OTUAssociationCommand::processShared(){ try { InputData* input = new InputData(sharedfile, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input->getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (metadatafile != "") { - getMetadata(); + if (metadatafile != "") { bool error = false; - if (metadata[0].size() != lookup.size()) { m->mothurOut("[ERROR]: You have selected to use " + toString(metadata[0].size()) + " data rows from the metadata file, but " + toString(lookup.size()) + " from the shared file.\n"); m->control_pressed = true; error=true;} + if (metadata[0].size() != lookup->size()) { m->mothurOut("[ERROR]: You have selected to use " + toString(metadata[0].size()) + " data rows from the metadata file, but " + toString(lookup->size()) + " from the shared file.\n"); m->control_pressed = true; error=true;} if (error) { //maybe add extra info here?? compare groups in each file?? } @@ -254,39 +253,39 @@ int OTUAssociationCommand::processShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete input; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(); } @@ -308,10 +307,10 @@ int OTUAssociationCommand::processShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); } @@ -325,11 +324,11 @@ int OTUAssociationCommand::processShared(){ } } //********************************************************************************************************************** -int OTUAssociationCommand::process(vector& lookup){ +int OTUAssociationCommand::process(SharedRAbundVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); variables["[tag]"] = method; string outputFileName = getOutputFileName("otucorr",variables); outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); @@ -343,8 +342,12 @@ int OTUAssociationCommand::process(vector& lookup){ else { out << "OTUA\tMetadata\t" << method << "Coef\tSignificance\n"; } - vector< vector > xy; xy.resize(lookup[0]->getNumBins()); - for (int i = 0; i < lookup[0]->getNumBins(); i++) { for (int j = 0; j < lookup.size(); j++) { xy[i].push_back(lookup[j]->getAbundance(i)); } } + vector< vector > xy; xy.resize(lookup->getNumBins()); + vector sampleNames = lookup->getNamesGroups(); + for (int i = 0; i < lookup->getNumBins(); i++) { + vector abunds = lookup->getOTU(i); + for (int j = 0; j < abunds.size(); j++) { xy[i].push_back(abunds[j]); } + } LinearAlgebra linear; if (metadatafile == "") {//compare otus @@ -398,58 +401,55 @@ int OTUAssociationCommand::process(vector& lookup){ int OTUAssociationCommand::processRelabund(){ try { InputData* input = new InputData(relabundfile, "relabund"); - vector lookup = input->getSharedRAbundFloatVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundFloatVectors* lookup = input->getSharedRAbundFloatVectors(); + string lastLabel = lookup->getLabel(); - if (metadatafile != "") { - getMetadata(); + if (metadatafile != "") { bool error = false; - if (metadata[0].size() != lookup.size()) { m->mothurOut("[ERROR]: You have selected to use " + toString(metadata[0].size()) + " data rows from the metadata file, but " + toString(lookup.size()) + " from the relabund file.\n"); m->control_pressed = true; error=true;} + if (metadata[0].size() != lookup->size()) { m->mothurOut("[ERROR]: You have selected to use " + toString(metadata[0].size()) + " data rows from the metadata file, but " + toString(lookup->size()) + " from the relabund file.\n"); m->control_pressed = true; error=true;} if (error) { //maybe add extra info here?? compare groups in each file?? } } - - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { delete input; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundFloatVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundFloatVectors(); } @@ -471,11 +471,12 @@ int OTUAssociationCommand::processRelabund(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input->getSharedRAbundFloatVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); + delete lookup; } delete input; @@ -488,12 +489,12 @@ int OTUAssociationCommand::processRelabund(){ } } //********************************************************************************************************************** -int OTUAssociationCommand::process(vector& lookup){ +int OTUAssociationCommand::process(SharedRAbundFloatVectors*& lookup){ try { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); variables["[tag]"] = method; string outputFileName = getOutputFileName("otucorr",variables); outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); @@ -506,8 +507,11 @@ int OTUAssociationCommand::process(vector& lookup){ if (metadatafile == "") { out << "OTUA\tOTUB\t" << method << "Coef\tSignificance\n"; } else { out << "OTUA\tMetadata\t" << method << "Coef\tSignificance\n"; } - vector< vector > xy; xy.resize(lookup[0]->getNumBins()); - for (int i = 0; i < lookup[0]->getNumBins(); i++) { for (int j = 0; j < lookup.size(); j++) { xy[i].push_back(lookup[j]->getAbundance(i)); } } + vector< vector > xy; xy.resize(lookup->getNumBins()); + vector sampleNames = lookup->getNamesGroups(); + for (int i = 0; i < lookup->getNumBins(); i++) { + for (int j = 0; j < sampleNames.size(); j++) { xy[i].push_back(lookup->get(i, sampleNames[j])); } + } LinearAlgebra linear; if (metadatafile == "") {//compare otus @@ -576,7 +580,12 @@ int OTUAssociationCommand::readMetadata(){ if (m->debug) { m->mothurOut("[DEBUG]: metadata column Label = " + columnLabel + "\n"); } metadataLabels.push_back(columnLabel); } + vector savedLabels = m->currentSharedBinLabels; int count = metadataLabels.size(); + SharedRAbundFloatVectors* metadataLookup = new SharedRAbundFloatVectors(); + metadataLookup->setLabels("1"); + + vector mGroups = m->getGroups(); //read rest of file while (!in.eof()) { @@ -587,22 +596,34 @@ int OTUAssociationCommand::readMetadata(){ in >> group; m->gobble(in); if (m->debug) { m->mothurOut("[DEBUG]: metadata group = " + group + "\n"); } - SharedRAbundFloatVector* tempLookup = new SharedRAbundFloatVector(); - tempLookup->setGroup(group); - tempLookup->setLabel("1"); + SharedRAbundFloatVector* tempLookup = new SharedRAbundFloatVector(); + tempLookup->setLabel("1"); + tempLookup->setGroup(group); for (int i = 0; i < count; i++) { float temp = 0.0; in >> temp; if (m->debug) { m->mothurOut("[DEBUG]: metadata value = " + toString(temp) + "\n"); } - tempLookup->push_back(temp, group); + tempLookup->push_back(temp); } - metadataLookup.push_back(tempLookup); + if (m->inUsersGroups(group, mGroups)) { metadataLookup->push_back(tempLookup); } m->gobble(in); } in.close(); + + //elimnatezeros remove zero otus, we want to remove the extra labels from metaLabels + m->currentSharedBinLabels = metadataLabels; + metadataLookup->eliminateZeroOTUS(); + metadataLabels = m->currentSharedBinLabels; + m->currentSharedBinLabels = savedLabels; + + metadata.resize(metadataLookup->getNumBins()); + vector sampleNames = metadataLookup->getNamesGroups(); + for (int i = 0; i < metadataLookup->getNumBins(); i++) { + for (int j = 0; j < sampleNames.size(); j++) { metadata[i].push_back(metadataLookup->get(i, sampleNames[j])); } + } return 0; } @@ -612,69 +633,7 @@ int OTUAssociationCommand::readMetadata(){ } } /*****************************************************************/ -//eliminate groups user did not pick, remove zeroed out otus, fill metadata vector. -int OTUAssociationCommand::getMetadata(){ - try { - - vector mGroups = m->getGroups(); - - bool remove = false; - for (int i = 0; i < metadataLookup.size(); i++) { - //if this sharedrabund is not from a group the user wants then delete it. - if (!(m->inUsersGroups(metadataLookup[i]->getGroup(), mGroups))) { - delete metadataLookup[i]; metadataLookup[i] = NULL; - metadataLookup.erase(metadataLookup.begin()+i); - i--; - remove = true; - } - } - - vector newLookup; - for (int i = 0; i < metadataLookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(metadataLookup[i]->getLabel()); - temp->setGroup(metadataLookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - for (int i = 0; i < metadataLookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < metadataLookup.size(); j++) { - if (metadataLookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < metadataLookup.size(); j++) { - newLookup[j]->push_back(metadataLookup[j]->getAbundance(i), metadataLookup[j]->getGroup()); - } - newBinLabels.push_back(metadataLabels[i]); - } - } - - metadataLabels = newBinLabels; - - for (int j = 0; j < metadataLookup.size(); j++) { delete metadataLookup[j]; } - metadataLookup.clear(); - - metadata.resize(newLookup[0]->getNumBins()); - for (int i = 0; i < newLookup[0]->getNumBins(); i++) { for (int j = 0; j < newLookup.size(); j++) { metadata[i].push_back(newLookup[j]->getAbundance(i)); } } - - for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } - - return 0; - } - catch(exception& e) { - m->errorOut(e, "OTUAssociationCommand", "getMetadata"); - exit(1); - } -} -/*****************************************************************/ + diff --git a/source/commands/otuassociationcommand.h b/source/commands/otuassociationcommand.h index e9cdb2a2..9e68adc1 100644 --- a/source/commands/otuassociationcommand.h +++ b/source/commands/otuassociationcommand.h @@ -12,7 +12,6 @@ #include "command.hpp" -#include "sharedrabundfloatvector.h" #include "inputdata.h" @@ -39,16 +38,15 @@ class OTUAssociationCommand : public Command { bool abort, pickedGroups, allLines; double cutoff; set labels; - vector metadataLookup; vector< vector< double> > metadata; vector outputNames, Groups, metadataLabels; int processShared(); - int process(vector&); + int process(SharedRAbundVectors*&); int processRelabund(); - int process(vector&); + int process(SharedRAbundFloatVectors*&); int readMetadata(); - int getMetadata(); + //int getMetadata(); }; diff --git a/source/commands/pairwiseseqscommand.cpp b/source/commands/pairwiseseqscommand.cpp index bf85337d..c2def70b 100644 --- a/source/commands/pairwiseseqscommand.cpp +++ b/source/commands/pairwiseseqscommand.cpp @@ -537,7 +537,7 @@ int PairwiseSeqsCommand::driver(int startLine, int endLine, string dFileName, fl } ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (countends) { if (validCalculator.isValidCalculator("distance", Estimators[0]) == true) { if (Estimators[0] == "nogaps") { distCalculator = new ignoreGaps(); } @@ -637,7 +637,7 @@ int PairwiseSeqsCommand::driver(int startLine, int endLine, string dFileName, st } ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (countends) { if (validCalculator.isValidCalculator("distance", Estimators[0]) == true) { if (Estimators[0] == "nogaps") { distCalculator = new ignoreGaps(); } diff --git a/source/commands/pairwiseseqscommand.h b/source/commands/pairwiseseqscommand.h index f64285bc..55067dc2 100644 --- a/source/commands/pairwiseseqscommand.h +++ b/source/commands/pairwiseseqscommand.h @@ -15,7 +15,7 @@ #include "database.hpp" #include "alignment.hpp" #include "validcalculator.h" -#include "dist.h" +#include "calculator.h" #include "sequencedb.h" #include "sequence.hpp" @@ -139,7 +139,7 @@ static DWORD WINAPI MyPairwiseSquareThreadFunction(LPVOID lpParam){ } ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (pDataArray->countends) { if (validCalculator.isValidCalculator("distance", pDataArray->distcalcType) == true) { if (pDataArray->distcalcType == "nogaps") { distCalculator = new ignoreGaps(); } @@ -237,7 +237,7 @@ static DWORD WINAPI MyPairwiseThreadFunction(LPVOID lpParam){ } ValidCalculators validCalculator; - Dist* distCalculator; + DistCalc* distCalculator; if (pDataArray->countends) { if (validCalculator.isValidCalculator("distance", pDataArray->distcalcType) == true) { if (pDataArray->distcalcType == "nogaps") { distCalculator = new ignoreGaps(); } diff --git a/source/commands/parsefastaqcommand.cpp b/source/commands/parsefastaqcommand.cpp index 6a9612a9..a5c09675 100644 --- a/source/commands/parsefastaqcommand.cpp +++ b/source/commands/parsefastaqcommand.cpp @@ -341,6 +341,7 @@ int ParseFastaQCommand::execute(){ } //remove names for outputFileNames, just cleans up the output + outputTypes.clear(); for(int i = 0; i < outputNames.size(); i++) { if (namesToRemove.count(outputNames[i]) != 0) { outputNames.erase(outputNames.begin()+i); diff --git a/source/commands/pcacommand.cpp b/source/commands/pcacommand.cpp index bb38c014..23a55a97 100644 --- a/source/commands/pcacommand.cpp +++ b/source/commands/pcacommand.cpp @@ -205,8 +205,8 @@ int PCACommand::execute(){ input = new InputData(inputFile, "relabund"); }else { m->mothurOut("[ERROR]: filetype not recognized."); m->mothurOutEndLine(); return 0; } - vector lookupFloat = input->getSharedRAbundFloatVectors(); - string lastLabel = lookupFloat[0]->getLabel(); + SharedRAbundFloatVectors* lookupFloat = input->getSharedRAbundFloatVectors(); + string lastLabel = lookupFloat->getLabel(); set processedLabels; set userLabels = labels; @@ -219,42 +219,42 @@ int PCACommand::execute(){ } //as long as you are not at the end of the file or done wih the lines you want - while((lookupFloat[0] != NULL) && (userLabels.size() != 0)) { + while((lookupFloat != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } lookupFloat.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; delete lookupFloat; return 0; } - if(labels.count(lookupFloat[0]->getLabel()) == 1){ - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + if(labels.count(lookupFloat->getLabel()) == 1){ + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); process(lookupFloat); } - if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookupFloat[0]->getLabel(); + if ((m->anyLabelsToProcess(lookupFloat->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookupFloat->getLabel(); - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } lookupFloat.clear(); + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); process(lookupFloat); - processedLabels.insert(lookupFloat[0]->getLabel()); - userLabels.erase(lookupFloat[0]->getLabel()); + processedLabels.insert(lookupFloat->getLabel()); + userLabels.erase(lookupFloat->getLabel()); //restore real lastlabel to save below - lookupFloat[0]->setLabel(saveLabel); + lookupFloat->setLabels(saveLabel); } - lastLabel = lookupFloat[0]->getLabel(); + lastLabel = lookupFloat->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } lookupFloat.clear(); + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(); } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } lookupFloat.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete input; delete lookupFloat; return 0; } //output error messages about any remaining user labels set::iterator it; @@ -271,15 +271,15 @@ int PCACommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } lookupFloat.clear(); + delete lookupFloat; lookupFloat = input->getSharedRAbundFloatVectors(lastLabel); process(lookupFloat); - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } lookupFloat.clear(); + delete lookupFloat; } - for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } } lookupFloat.clear(); + delete lookupFloat; delete input; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -327,26 +327,28 @@ vector< vector > PCACommand::createMatrix(vector& lookupFloat){ +int PCACommand::process(SharedRAbundFloatVectors*& lookupFloat){ try { - m->mothurOut("\nProcessing " + lookupFloat[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut("\nProcessing " + lookupFloat->getLabel()); m->mothurOutEndLine(); - int numOTUs = lookupFloat[0]->getNumBins(); - int numSamples = lookupFloat.size(); + int numOTUs = lookupFloat->getNumBins(); + int numSamples = lookupFloat->getNumGroups(); vector< vector > matrix(numSamples); vector colMeans(numOTUs); //fill matrix with shared relative abundances, re-center - for (int i = 0; i < lookupFloat.size(); i++) { + vector data = lookupFloat->getSharedRAbundFloatVectors(); + for (int i = 0; i < numSamples; i++) { matrix[i].resize(numOTUs, 0); for (int j = 0; j < numOTUs; j++) { - matrix[i][j] = lookupFloat[i]->getAbundance(j); + matrix[i][j] = data[i]->get(j); colMeans[j] += matrix[i][j]; } + delete data[i]; } - + data.clear(); for(int j=0;j& lookupFloat){ string fbase = outputDir + m->getRootName(m->getSimpleName(inputFile)); //string outputFileName = fbase + lookupFloat[0]->getLabel(); - output(fbase, lookupFloat[0]->getLabel(), m->getGroups(), X, d); + output(fbase, lookupFloat->getLabel(), m->getGroups(), X, d); if (metric) { diff --git a/source/commands/pcacommand.h b/source/commands/pcacommand.h index 482ecc3f..85feed42 100644 --- a/source/commands/pcacommand.h +++ b/source/commands/pcacommand.h @@ -12,7 +12,8 @@ #include "command.hpp" #include "linearalgebra.h" -#include "sharedrabundfloatvector.h" +#include "sharedrabundfloatvectors.hpp" + /*****************************************************************/ class PCACommand : public Command { @@ -44,7 +45,7 @@ class PCACommand : public Command { LinearAlgebra linearCalc; //vector< vector > createMatrix(vector); - int process(vector&); + int process(SharedRAbundFloatVectors*&); void output(string, string, vector, vector >&, vector); }; diff --git a/source/commands/pcrseqscommand.cpp b/source/commands/pcrseqscommand.cpp index d6eba86d..94657192 100644 --- a/source/commands/pcrseqscommand.cpp +++ b/source/commands/pcrseqscommand.cpp @@ -662,9 +662,7 @@ int PcrSeqsCommand::createProcesses(string filename, string goodFileName, string int myEnd = thisEnd + myDiff; //cout << name << '\t' << thisStart << '\t' << thisEnd << " diff = " << myDiff << '\t' << myEnd << endl; - if (thisEnd != -1) { - if (myEnd > pend) { pend = myEnd; } - } + if (thisEnd != -1) { if (myEnd > pend) { pend = myEnd; } } } inLocations.close(); @@ -712,10 +710,12 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta for (map::iterator it = primerPairs.begin(); it != primerPairs.end(); it++) { primers[(it->second).forward] = it->first; revPrimer.push_back((it->second).reverse); + //cout << (it->second).forward << '\t' << (it->second).reverse << endl; } }else{ primers = oligos.getPrimers(); revPrimer = oligos.getReversePrimers(); + //cout << (primers.begin())->first << '\t' << revPrimer[0] << endl; } TrimOligos trim(pdiffs, rdiffs, 0, primers, barcodes, revPrimer); @@ -837,9 +837,9 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta else if (currSeq.getAligned().length() != length) { m->mothurOut("[ERROR]: seqs are not the same length as ecoli seq. When using ecoli option your sequences must be aligned and the same length as the ecoli sequence.\n"); m->control_pressed = true; break; }else { - if (keepdots) { - currSeq.filterToPos(start); + if (keepdots) { currSeq.filterFromPos(end); + currSeq.filterToPos(start-1); }else { string seqString = currSeq.getAligned().substr(0, end); seqString = seqString.substr(start); @@ -850,25 +850,22 @@ int PcrSeqsCommand::driverPcr(string filename, string goodFasta, string badFasta //make sure the seqs are aligned if (!fileAligned) { m->mothurOut("[ERROR]: seqs are not aligned. When using start and end your sequences must be aligned.\n"); m->control_pressed = true; break; } else { - if (end != -1) { if (end > currSeq.getAligned().length()) { m->mothurOut("[ERROR]: end is longer than your sequence length, aborting.\n"); m->control_pressed = true; break; } else { if (keepdots) { currSeq.filterFromPos(end); } else { - string seqString = currSeq.getAligned().substr(0, end); currSeq.setAligned(seqString); - } } } + if (start != -1) { - if (keepdots) { currSeq.filterToPos(start); } + if (keepdots) { currSeq.filterToPos(start-1); } else { string seqString = currSeq.getAligned().substr(start); currSeq.setAligned(seqString); - } } } @@ -976,8 +973,8 @@ int PcrSeqsCommand::adjustDots(string goodFasta, string locations, int pstart, i if (numRPrimers != 0) { inLocations >> name >> thisEnd; m->gobble(inLocations); } - //cout << seq.getName() << '\t' << thisStart << '\t' << thisEnd << '\t' << seq.getAligned().length() << endl; - //cout << seq.getName() << '\t' << pstart << '\t' << pend << endl; + //cout << "'" << seq.getName() << "'" << '\t' << thisStart << '\t' << thisEnd << '\t' << seq.getAligned().length() << endl; + //cout << "'" << name << "'" << '\t' << pstart << '\t' << pend << endl; if (name != seq.getName()) { m->mothurOut("[ERROR]: name mismatch in pcr.seqs.\n"); } else { @@ -1307,11 +1304,12 @@ int PcrSeqsCommand::readOligos(){ if (oligos.hasPairedPrimers()) { pairedOligos = true; numFPrimers = oligos.getPairedPrimers().size(); + numRPrimers = numFPrimers; }else { pairedOligos = false; numFPrimers = oligos.getPrimers().size(); + numRPrimers = oligos.getReversePrimers().size(); } - numRPrimers = oligos.getReversePrimers().size(); if (oligos.getLinkers().size() != 0) { m->mothurOut("[WARNING]: pcr.seqs is not setup to remove linkers, ignoring.\n"); } if (oligos.getSpacers().size() != 0) { m->mothurOut("[WARNING]: pcr.seqs is not setup to remove spacers, ignoring.\n"); } diff --git a/source/commands/rarefactcommand.cpp b/source/commands/rarefactcommand.cpp index 594957d6..70f25386 100644 --- a/source/commands/rarefactcommand.cpp +++ b/source/commands/rarefactcommand.cpp @@ -404,20 +404,20 @@ int RareFactCommand::execute(){ //if the users entered no valid calculators don't execute command if (rDisplays.size() == 0) { for(int i=0;igetOrderVector(); + InputData input(inputFileNames[p], format); + OrderVector* order = input.getOrderVector(); string lastLabel = order->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } //as long as you are not at the end of the file or done wih the lines you want while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } if(allLines == 1 || labels.count(order->getLabel()) == 1){ @@ -438,7 +438,7 @@ int RareFactCommand::execute(){ string saveLabel = order->getLabel(); delete order; - order = (input->getOrderVector(lastLabel)); + order = (input.getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); map >::iterator itEndings = labelToEnds.find(order->getLabel()); @@ -459,10 +459,10 @@ int RareFactCommand::execute(){ lastLabel = order->getLabel(); delete order; - order = (input->getOrderVector()); + order = (input.getOrderVector()); } - if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -477,12 +477,12 @@ int RareFactCommand::execute(){ } } - if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } return 0; } //run last label if you need to if (needToRun == true) { if (order != NULL) { delete order; } - order = (input->getOrderVector(lastLabel)); + order = (input.getOrderVector(lastLabel)); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); map >::iterator itEndings = labelToEnds.find(order->getLabel()); @@ -499,7 +499,6 @@ int RareFactCommand::execute(){ for(int i=0;i RareFactCommand::parseSharedFile(string filename, map files; map::iterator it3; - input = new InputData(filename, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); + InputData input(filename, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + vector lookupGroups = lookup->getNamesGroups(); string sharedFileRoot = m->getRootName(filename); //clears file before we start to write to it below - for (int i=0; igetGroup(); + string group = lookupGroups[i]; m->openOutputFile((sharedFileRoot + group + ".rabund"), temp); filenames.push_back((sharedFileRoot + group + ".rabund")); files[group] = (sharedFileRoot + group + ".rabund"); groups.push_back(group); } - while(lookup[0] != NULL) { - - for (int i = 0; i < lookup.size(); i++) { - RAbundVector rav = lookup[i]->getRAbundVector(); + while(lookup != NULL) { + vector data = lookup->getSharedRAbundVectors(); + for (int i = 0; i < data.size(); i++) { ofstream temp; - string group = lookup[i]->getGroup(); + string group = lookupGroups[i]; m->openOutputFileAppend(files[group], temp); - rav.print(temp); + data[i]->getRAbundVector().print(temp); temp.close(); - label2Ends[lookup[i]->getLabel()].insert(rav.getNumSeqs()); + label2Ends[lookup->getLabel()].insert(data[i]->getNumSeqs()); } - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + for (int i = 0; i < data.size(); i++) { delete data[i]; } + delete lookup; + lookup = input.getSharedRAbundVectors(); } - - delete input; m->clearGroups(); return filenames; diff --git a/source/commands/rarefactcommand.h b/source/commands/rarefactcommand.h index 09de39fd..62d606c0 100644 --- a/source/commands/rarefactcommand.h +++ b/source/commands/rarefactcommand.h @@ -38,8 +38,6 @@ class RareFactCommand : public Command { private: vector rDisplays; - OrderVector* order; - InputData* input; Rarefact* rCurve; int nIters, abund, processors, alpha; float freq; diff --git a/source/commands/rarefactsharedcommand.cpp b/source/commands/rarefactsharedcommand.cpp index 8a22c5cb..586b1c0b 100644 --- a/source/commands/rarefactsharedcommand.cpp +++ b/source/commands/rarefactsharedcommand.cpp @@ -289,10 +289,10 @@ int RareFactSharedCommand::process(DesignMap& designMap, string thisSet){ vector rDisplays; InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - if (lookup.size() < 2) { + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + if (lookup->size() < 2) { m->mothurOut("I cannot run the command without at least 2 valid groups."); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; return 0; } @@ -305,42 +305,32 @@ int RareFactSharedCommand::process(DesignMap& designMap, string thisSet){ fileNameRoot += thisSet + "."; } - vector subset; - if (thisSet == "") { subset.clear(); subset = lookup; } - else {//fill subset with this sets groups - subset.clear(); - for (int i = 0; i < lookup.size(); i++) { - if (m->inUsersGroups(lookup[i]->getGroup(), newGroups)) { - subset.push_back(lookup[i]); - } - } - } + SharedRAbundVectors* subset = new SharedRAbundVectors(); + vector data = lookup->getSharedRAbundVectors(); + if (thisSet != "") {//remove unwanted groups + for (int i = 0; i < data.size(); i++) { if (m->inUsersGroups(data[i]->getGroup(), newGroups)) { subset->push_back(data[i]); } } + subset->eliminateZeroOTUS(); + }else { for (int i = 0; i < data.size(); i++) { subset->push_back(data[i]); } } + /******************************************************/ - if (subsample) { - if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = subset[0]->getNumSeqs(); - for (int i = 1; i < subset.size(); i++) { - int thisSize = subset[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } - }else { + if (subsample) { + //user has not set size, set size = smallest samples size + if (subsampleSize == -1) { subsampleSize = subset->getNumSeqsSmallestGroup(); } + else { + vector lookupGroups = subset->getNamesGroups(); newGroups.clear(); - vector temp; - for (int i = 0; i < subset.size(); i++) { - if (subset[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(subset[i]->getGroup() + " contains " + toString(subset[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete subset[i]; - }else { - newGroups.push_back(subset[i]->getGroup()); - temp.push_back(subset[i]); - } - } - subset = temp; + vector temp; + for (int i = 0; i < lookupGroups.size(); i++) { + if (lookup->getNumSeqs(lookupGroups[i]) < subsampleSize) { + m->mothurOut(lookupGroups[i] + " contains " + toString(subset->getNumSeqs(lookupGroups[i])) + ". Eliminating."); m->mothurOutEndLine(); + temp.push_back(lookupGroups[i]); + }else { newGroups.push_back(lookupGroups[i]); } + } + subset->removeGroups(temp); } - if (subset.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } + if (subset->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } /******************************************************/ @@ -361,90 +351,86 @@ int RareFactSharedCommand::process(DesignMap& designMap, string thisSet){ } //if the users entered no valid calculators don't execute command - if (rDisplays.size() == 0) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (rDisplays.size() == 0) { delete lookup; delete subset; return 0; } if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; delete subset; return 0; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. - string lastLabel = subset[0]->getLabel(); + string lastLabel = subset->getLabel(); set processedLabels; set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((subset[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((subset != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for(int i=0;imothurRemove(outputNames[i]); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; delete subset; return 0; } - if(allLines == 1 || labels.count(subset[0]->getLabel()) == 1){ - m->mothurOut(subset[0]->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); - rCurve = new Rarefact(subset, rDisplays); + if(allLines == 1 || labels.count(subset->getLabel()) == 1){ + m->mothurOut(subset->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); + vector rabunds = subset->getSharedRAbundVectors(); + rCurve = new Rarefact(rabunds, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; + for (int i = 0; i < rabunds.size(); i++) { delete rabunds[i]; } if (subsample) { subsampleLookup(subset, fileNameRoot); } - processedLabels.insert(subset[0]->getLabel()); - userLabels.erase(subset[0]->getLabel()); + processedLabels.insert(subset->getLabel()); + userLabels.erase(subset->getLabel()); } - if ((m->anyLabelsToProcess(subset[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = subset[0]->getLabel(); + if ((m->anyLabelsToProcess(subset->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = subset->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete subset; lookup = input.getSharedRAbundVectors(lastLabel); - if (thisSet == "") { subset.clear(); subset = lookup; } - else {//fill subset with this sets groups - subset.clear(); - for (int i = 0; i < lookup.size(); i++) { - if (m->inUsersGroups(lookup[i]->getGroup(), newGroups)) { - subset.push_back(lookup[i]); - } - } - } - - m->mothurOut(subset[0]->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); - rCurve = new Rarefact(subset, rDisplays); + subset = new SharedRAbundVectors(); + vector data = lookup->getSharedRAbundVectors(); + if (thisSet != "") {//remove unwanted groups + for (int i = 0; i < data.size(); i++) { if (m->inUsersGroups(data[i]->getGroup(), newGroups)) { subset->push_back(data[i]); } } + subset->eliminateZeroOTUS(); + }else { for (int i = 0; i < data.size(); i++) { subset->push_back(data[i]); } } + + m->mothurOut(subset->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); + vector rabunds = subset->getSharedRAbundVectors(); + rCurve = new Rarefact(rabunds, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; + for (int i = 0; i < rabunds.size(); i++) { delete rabunds[i]; } if (subsample) { subsampleLookup(subset, fileNameRoot); } - processedLabels.insert(subset[0]->getLabel()); - userLabels.erase(subset[0]->getLabel()); + processedLabels.insert(subset->getLabel()); + userLabels.erase(subset->getLabel()); //restore real lastlabel to save below - subset[0]->setLabel(saveLabel); + subset->setLabels(saveLabel); } - lastLabel = subset[0]->getLabel(); + lastLabel = subset->getLabel(); //get next line to process - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; delete subset; lookup = input.getSharedRAbundVectors(); - if (lookup[0] != NULL) { - if (thisSet == "") { subset.clear(); subset = lookup; } - else {//fill subset with this sets groups - subset.clear(); - for (int i = 0; i < lookup.size(); i++) { - if (m->inUsersGroups(lookup[i]->getGroup(), newGroups)) { - subset.push_back(lookup[i]); - } - } - } - }else { subset.clear(); subset.push_back(NULL); } + if (lookup != NULL) { + if (thisSet != "") {//remove unwanted groups + for (int i = 0; i < data.size(); i++) { if (m->inUsersGroups(data[i]->getGroup(), newGroups)) { subset->push_back(data[i]); } } + subset->eliminateZeroOTUS(); + }else { for (int i = 0; i < data.size(); i++) { subset->push_back(data[i]); } } + }else { subset = NULL; } } @@ -475,27 +461,26 @@ int RareFactSharedCommand::process(DesignMap& designMap, string thisSet){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input.getSharedRAbundVectors(lastLabel); - - if (thisSet == "") { subset.clear(); subset = lookup; } - else {//fill subset with this sets groups - subset.clear(); - for (int i = 0; i < lookup.size(); i++) { - if (m->inUsersGroups(lookup[i]->getGroup(), newGroups)) { - subset.push_back(lookup[i]); - } - } - } - - m->mothurOut(subset[0]->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); - rCurve = new Rarefact(subset, rDisplays); + delete lookup; delete subset; + lookup = input.getSharedRAbundVectors(); + + if (lookup != NULL) { + if (thisSet != "") {//remove unwanted groups + for (int i = 0; i < data.size(); i++) { if (m->inUsersGroups(data[i]->getGroup(), newGroups)) { subset->push_back(data[i]); } } + subset->eliminateZeroOTUS(); + }else { for (int i = 0; i < data.size(); i++) { subset->push_back(data[i]); } } + }else { subset = NULL; } + + m->mothurOut(subset->getLabel() + '\t' + thisSet); m->mothurOutEndLine(); + vector rabunds = subset->getSharedRAbundVectors(); + rCurve = new Rarefact(rabunds, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; + for (int i = 0; i < rabunds.size(); i++) { delete rabunds[i]; } if (subsample) { subsampleLookup(subset, fileNameRoot); } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; delete subset; } for(int i=0;i& thisLookup, string fileNameRoot) { +int RareFactSharedCommand::subsampleLookup(SharedRAbundVectors*& thisLookup, string fileNameRoot) { try { map > filenames; for (int thisIter = 0; thisIter < iters; thisIter++) { - vector thisItersLookup = thisLookup; + SharedRAbundVectors* thisItersLookup = new SharedRAbundVectors(*thisLookup); //we want the summary results for the whole dataset, then the subsampling SubSample sample; vector tempLabels; //dont need since we arent printing the sampled sharedRabunds - - //make copy of lookup so we don't get access violations - vector newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - - tempLabels = sample.getSample(newLookup, subsampleSize); - thisItersLookup = newLookup; - + tempLabels = sample.getSample(thisItersLookup, subsampleSize); Rarefact* rCurve; vector rDisplays; @@ -561,14 +528,15 @@ int RareFactSharedCommand::subsampleLookup(vector& thisLook } } - rCurve = new Rarefact(thisItersLookup, rDisplays); + vector rabunds = thisItersLookup->getSharedRAbundVectors(); + rCurve = new Rarefact(rabunds, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; + for (int i = 0; i < rabunds.size(); i++) { delete rabunds[i]; } //clean up memory - for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } - thisItersLookup.clear(); for(int i=0;i& thisLook if (!m->control_pressed) { //process results - map variables; variables["[filename]"] = fileNameRoot + "ave-std." + thisLookup[0]->getLabel() + "."; + map variables; variables["[filename]"] = fileNameRoot + "ave-std." + thisLookup->getLabel() + "."; string outputFile = getOutputFileName(it->first,variables); ofstream out; diff --git a/source/commands/rarefactsharedcommand.h b/source/commands/rarefactsharedcommand.h index 545c1bdf..057eb047 100644 --- a/source/commands/rarefactsharedcommand.h +++ b/source/commands/rarefactsharedcommand.h @@ -37,8 +37,6 @@ class RareFactSharedCommand : public Command { private: - - vector lookup; int nIters, subsampleSize, iters; string format; float freq; @@ -51,7 +49,7 @@ class RareFactSharedCommand : public Command { int process(DesignMap&, string); vector createGroupFile(vector&); - int subsampleLookup(vector&, string); + int subsampleLookup(SharedRAbundVectors*&, string); }; diff --git a/source/commands/removegroupscommand.cpp b/source/commands/removegroupscommand.cpp index 8788ef5d..a787f8f6 100644 --- a/source/commands/removegroupscommand.cpp +++ b/source/commands/removegroupscommand.cpp @@ -582,8 +582,8 @@ int RemoveGroupsCommand::readShared(){ //get group names from sharedfile so we can set Groups to the groupNames we want to keep //that way we can take advantage of the reads in inputdata and sharedRabundVector - InputData* tempInput = new InputData(sharedfile, "sharedfile"); - vector lookup = tempInput->getSharedRAbundVectors(); + InputData input(sharedfile, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); @@ -600,11 +600,10 @@ int RemoveGroupsCommand::readShared(){ } } - if (allGroupsNames.size() == groupsToKeep.size()) { m->mothurOut("Your file does not contain any groups you wish to remove."); m->mothurOutEndLine(); m->setGroups(mothurOutGroups); delete tempInput; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (allGroupsNames.size() == groupsToKeep.size()) { m->mothurOut("Your file does not contain any groups you wish to remove."); m->mothurOutEndLine(); m->setGroups(mothurOutGroups); delete lookup; return 0; } //reset read - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - delete tempInput; + delete lookup; m->setGroups(groupsToKeep); m->clearAllGroups(); m->saveNextLabel = ""; @@ -612,33 +611,28 @@ int RemoveGroupsCommand::readShared(){ m->currentSharedBinLabels.clear(); m->sharedBinLabelsInFile.clear(); - InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); + InputData input2(sharedfile, "sharedfile"); + lookup = input2.getSharedRAbundVectors(); bool wroteSomething = false; - while(lookup[0] != NULL) { + while(lookup != NULL) { - variables["[tag]"] = lookup[0]->getLabel(); + variables["[tag]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } - - lookup[0]->printHeaders(out); + if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); delete lookup; return 0; } - for (int i = 0; i < lookup.size(); i++) { - out << lookup[i]->getLabel() << '\t' << lookup[i]->getGroup() << '\t'; - lookup[i]->print(out); - wroteSomething = true; - - } + if (lookup->size() != 0) { wroteSomething = true; } + lookup->printHeaders(out); + lookup->print(out); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); out.close(); diff --git a/source/commands/removelineagecommand.cpp b/source/commands/removelineagecommand.cpp index 9bcafc96..c6161913 100644 --- a/source/commands/removelineagecommand.cpp +++ b/source/commands/removelineagecommand.cpp @@ -848,35 +848,23 @@ int RemoveLineageCommand::getListVector(){ int RemoveLineageCommand::readShared(){ try { - getShared(); + SharedRAbundVectors* lookup = getShared(); - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } vector newLabels; - - //create new "filtered" lookup - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - bool wroteSomething = false; int numRemoved = 0; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins();) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } //is this otu on the list if (names.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) == 0) { wroteSomething = true; newLabels.push_back(m->currentSharedBinLabels[i]); - for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - }else { numRemoved++; } + ++i; + }else { lookup->removeOTU(i); numRemoved++; } } string thisOutputDir = outputDir; @@ -884,26 +872,18 @@ int RemoveLineageCommand::readShared(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - + m->currentSharedBinLabels = newLabels; - newLookup[0]->printHeaders(out); - - for (int i = 0; i < newLookup.size(); i++) { - out << newLookup[i]->getLabel() << '\t' << newLookup[i]->getGroup() << '\t'; - newLookup[i]->print(out); - } + lookup->printHeaders(out); + lookup->print(out); out.close(); - for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } - if (wroteSomething == false) { m->mothurOut("Your file only contains OTUs from " + taxons + "."); m->mothurOutEndLine(); } m->mothurOut("Removed " + toString(numRemoved) + " OTUs from your shared file."); m->mothurOutEndLine(); @@ -916,13 +896,13 @@ int RemoveLineageCommand::readShared(){ } } //********************************************************************************************************************** -int RemoveLineageCommand::getShared(){ +SharedRAbundVectors* RemoveLineageCommand::getShared(){ try { InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - if (label == "") { label = lastLabel; return 0; } + if (label == "") { label = lastLabel; return lookup; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); @@ -930,34 +910,34 @@ int RemoveLineageCommand::getShared(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { + while((lookup != NULL) && (userLabels.size() != 0)) { if (m->control_pressed) { return 0; } - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); break; } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); break; } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } @@ -979,11 +959,11 @@ int RemoveLineageCommand::getShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); } - return 0; + return lookup; } catch(exception& e) { m->errorOut(e, "RemoveLineageCommand", "getShared"); diff --git a/source/commands/removelineagecommand.h b/source/commands/removelineagecommand.h index 8bfa5f15..6668bf3e 100644 --- a/source/commands/removelineagecommand.h +++ b/source/commands/removelineagecommand.h @@ -11,7 +11,7 @@ */ #include "command.hpp" -#include "sharedrabundvector.h" +#include "sharedrabundvectors.hpp" #include "listvector.hpp" @@ -40,7 +40,6 @@ class RemoveLineageCommand : public Command { vector outputNames, listOfTaxons; string fastafile, namefile, groupfile, alignfile, listfile, countfile, taxfile, outputDir, taxons, sharedfile, constaxonomy, label; bool abort, dups; - vector lookup; ListVector* list; int readFasta(); @@ -53,7 +52,7 @@ class RemoveLineageCommand : public Command { int readShared(); int readConsTax(); int readConsList(); - int getShared(); + SharedRAbundVectors* getShared(); int getListVector(); vector< map > getTaxons(string); }; diff --git a/source/commands/removeotulabelscommand.cpp b/source/commands/removeotulabelscommand.cpp index af1b610f..8f2b8042 100644 --- a/source/commands/removeotulabelscommand.cpp +++ b/source/commands/removeotulabelscommand.cpp @@ -448,61 +448,44 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ int RemoveOtuLabelsCommand::readShared(){ try { - getShared(); + SharedRAbundVectors* lookup = getShared(); - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } vector newLabels; - - //create new "filtered" lookup - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - + bool wroteSomething = false; int numRemoved = 0; - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins();) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } //is this otu on the list if (otulabels.count(m->getSimpleLabel(m->currentSharedBinLabels[i])) == 0) { wroteSomething = true; newLabels.push_back(m->currentSharedBinLabels[i]); - for (int j = 0; j < newLookup.size(); j++) { //add this OTU to the new lookup - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - }else { numRemoved++; } + ++i; + }else { numRemoved++; lookup->removeOTU(i); } } - + string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - m->currentSharedBinLabels = newLabels; - newLookup[0]->printHeaders(out); - - for (int i = 0; i < newLookup.size(); i++) { - out << newLookup[i]->getLabel() << '\t' << newLookup[i]->getGroup() << '\t'; - newLookup[i]->print(out); - } - out.close(); + lookup->printHeaders(out); + lookup->print(out); + out.close(); - for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } + delete lookup; if (wroteSomething == false) { m->mothurOut("Your file contains only OTUs from the .accnos file."); m->mothurOutEndLine(); } @@ -647,74 +630,76 @@ int RemoveOtuLabelsCommand::getListVector(){ } } //********************************************************************************************************************** -int RemoveOtuLabelsCommand::getShared(){ +SharedRAbundVectors* RemoveOtuLabelsCommand::getShared(){ try { InputData input(sharedfile, "sharedfile"); - lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); - - if (label == "") { label = lastLabel; return 0; } - - //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. - set labels; labels.insert(label); - set processedLabels; - set userLabels = labels; - - //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && (userLabels.size() != 0)) { - if (m->control_pressed) { return 0; } - - if(labels.count(lookup[0]->getLabel()) == 1){ - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); - break; - } - - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input.getSharedRAbundVectors(lastLabel); - - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); - - //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); - break; - } - - lastLabel = lookup[0]->getLabel(); - - //get next line to process - //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input.getSharedRAbundVectors(); - } - - - if (m->control_pressed) { return 0; } - - //output error messages about any remaining user labels - set::iterator it; - bool needToRun = false; - for (it = userLabels.begin(); it != userLabels.end(); it++) { - m->mothurOut("Your file does not include the label " + *it); - if (processedLabels.count(lastLabel) != 1) { - m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); - needToRun = true; - }else { - m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); - } - } + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); + + if (label == "") { label = lastLabel; return lookup; } - //run last label if you need to - if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input.getSharedRAbundVectors(lastLabel); - } + if (label == "") { label = lastLabel; return lookup; } + + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. + set labels; labels.insert(label); + set processedLabels; + set userLabels = labels; + + //as long as you are not at the end of the file or done wih the lines you want + while((lookup != NULL) && (userLabels.size() != 0)) { + if (m->control_pressed) { delete lookup; return NULL; } + + if(labels.count(lookup->getLabel()) == 1){ + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); + break; + } + + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); + + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); + + //restore real lastlabel to save below + lookup->setLabels(saveLabel); + break; + } + + lastLabel = lookup->getLabel(); + + //get next line to process + //prevent memory leak + delete lookup; + lookup = input.getSharedRAbundVectors(); + } + + + if (m->control_pressed) { return 0; } + + //output error messages about any remaining user labels + set::iterator it; + bool needToRun = false; + for (it = userLabels.begin(); it != userLabels.end(); it++) { + m->mothurOut("Your file does not include the label " + *it); + if (processedLabels.count(lastLabel) != 1) { + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); + needToRun = true; + }else { + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); + } + } + + //run last label if you need to + if (needToRun == true) { + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); + } - return 0; + return lookup; } catch(exception& e) { m->errorOut(e, "RemoveOtuLabelsCommand", "getShared"); diff --git a/source/commands/removeotulabelscommand.h b/source/commands/removeotulabelscommand.h index 2da2690e..e16863ba 100644 --- a/source/commands/removeotulabelscommand.h +++ b/source/commands/removeotulabelscommand.h @@ -13,7 +13,7 @@ #include "command.hpp" #include "inputdata.h" #include "listvector.hpp" -#include "sharedrabundvector.h" + /**************************************************************************************************/ @@ -41,7 +41,6 @@ class RemoveOtuLabelsCommand : public Command { vector outputNames; set otulabels; ListVector* list; - vector lookup; int readClassifyOtu(); int readOtuAssociation(); @@ -49,7 +48,7 @@ class RemoveOtuLabelsCommand : public Command { int readList(); int readShared(); int getListVector(); - int getShared(); + SharedRAbundVectors* getShared(); }; /**************************************************************************************************/ diff --git a/source/commands/removerarecommand.cpp b/source/commands/removerarecommand.cpp index eca3f7cb..f7052f05 100644 --- a/source/commands/removerarecommand.cpp +++ b/source/commands/removerarecommand.cpp @@ -743,43 +743,43 @@ int RemoveRareCommand::processShared(){ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); set processedLabels; set userLabels = labels; - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (m->control_pressed) { delete lookup; return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); processLookup(lookup); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); processLookup(lookup); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(); } @@ -800,13 +800,13 @@ int RemoveRareCommand::processShared(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processLookup(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } return 0; @@ -817,7 +817,7 @@ int RemoveRareCommand::processShared(){ } } //********************************************************************************************************************** -int RemoveRareCommand::processLookup(vector& lookup){ +int RemoveRareCommand::processLookup(SharedRAbundVectors*& lookup){ try { string thisOutputDir = outputDir; @@ -825,60 +825,60 @@ int RemoveRareCommand::processLookup(vector& lookup){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[tag]"] = lookup[0]->getLabel(); + variables["[tag]"] = lookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); - vector newRabunds; newRabunds.resize(lookup.size()); + vector newRabunds; newRabunds.resize(lookup->size()); vector headers; - for (int i = 0; i < lookup.size(); i++) { - newRabunds[i].setGroup(lookup[i]->getGroup()); - newRabunds[i].setLabel(lookup[i]->getLabel()); + vector namesOfGroups = lookup->getNamesGroups(); + for (int i = 0; i < namesOfGroups.size(); i++) { + newRabunds[i].setGroup(namesOfGroups[i]); + newRabunds[i].setLabel(lookup->getLabel()); } + vector data = lookup->getSharedRAbundVectors(); if (byGroup) { //for each otu - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { bool allZero = true; if (m->control_pressed) { out.close(); return 0; } //for each group - for (int j = 0; j < lookup.size(); j++) { + vector abunds = lookup->getOTU(i); + for (int j = 0; j < abunds.size(); j++) { //are you rare? - if (lookup[j]->getAbundance(i) > nseqs) { - newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup()); - allZero = false; - }else { - newRabunds[j].push_back(0, newRabunds[j].getGroup()); - } + if (abunds[j] > nseqs) { allZero = false; } + else { abunds[j] = 0; } } //eliminates zero otus - if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } } - else { headers.push_back(m->currentSharedBinLabels[i]); } + if (allZero) { } + else { + for (int j = 0; j < abunds.size(); j++) { newRabunds[j].push_back(abunds[j]); } + headers.push_back(m->currentSharedBinLabels[i]); + } } }else { //for each otu - for (int i = 0; i < lookup[0]->getNumBins(); i++) { + for (int i = 0; i < lookup->getNumBins(); i++) { if (m->control_pressed) { out.close(); return 0; } - int totalAbund = 0; - //get total otu abundance - for (int j = 0; j < lookup.size(); j++) { - newRabunds[j].push_back(lookup[j]->getAbundance(i), newRabunds[j].getGroup()); - totalAbund += lookup[j]->getAbundance(i); - } + int totalAbund = lookup->getOTUTotal(i); //eliminates otus below rare cutoff - if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } } - else { headers.push_back(m->currentSharedBinLabels[i]); } + if (totalAbund <= nseqs) { } //ignore + else { + headers.push_back(m->currentSharedBinLabels[i]); + for (int j = 0; j < data.size(); j++) { newRabunds[j].push_back(data[j]->get(i)); } + } } } @@ -887,10 +887,7 @@ int RemoveRareCommand::processLookup(vector& lookup){ out << "label\tGroup\tnumOtus"; for (int j = 0; j < headers.size(); j++) { out << '\t' << headers[j]; } out << endl; - for (int j = 0; j < newRabunds.size(); j++) { - out << newRabunds[j].getLabel() << '\t' << newRabunds[j].getGroup() << '\t'; - newRabunds[j].print(out); - } + for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].print(out); } } out.close(); diff --git a/source/commands/removerarecommand.h b/source/commands/removerarecommand.h index 6a9f2699..fe45827a 100644 --- a/source/commands/removerarecommand.h +++ b/source/commands/removerarecommand.h @@ -13,6 +13,7 @@ #include "command.hpp" #include "listvector.hpp" +#include "sharedrabundvectors.hpp" class RemoveRareCommand : public Command { @@ -47,7 +48,7 @@ class RemoveRareCommand : public Command { int processRabund(); int processList(); int processShared(); - int processLookup(vector&); + int processLookup(SharedRAbundVectors*&); }; diff --git a/source/commands/screenseqscommand.cpp b/source/commands/screenseqscommand.cpp index ce86e744..4782db7f 100644 --- a/source/commands/screenseqscommand.cpp +++ b/source/commands/screenseqscommand.cpp @@ -9,6 +9,8 @@ #include "screenseqscommand.h" #include "counttable.h" +#include "summary.hpp" +#include "removeseqscommand.h" //********************************************************************************************************************** vector ScreenSeqsCommand::setParameters(){ @@ -444,27 +446,101 @@ int ScreenSeqsCommand::execute(){ map badSeqNames; int start = time(NULL); - int numFastaSeqs = 0; + long long numFastaSeqs = 0; + + //use the namefile to optimize correctly + if (namefile != "") { nameMap = m->readNames(namefile); } + else if (countfile != "") { + CountTable ct; + ct.readTable(countfile, true, false); + nameMap = ct.getNameMap(); + } + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + badAccnosFile = getOutputFileName("accnos",variables); + outputNames.push_back(badAccnosFile); outputTypes["accnos"].push_back(badAccnosFile); + if ((contigsreport == "") && (summaryfile == "") && (alignreport == "")) { numFastaSeqs = screenFasta(badSeqNames); } else { numFastaSeqs = screenReports(badSeqNames); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - - if(namefile != "" && groupfile != "") { - screenNameGroupFile(badSeqNames); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - }else if(namefile != "") { - screenNameGroupFile(badSeqNames); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - }else if(groupfile != "") { screenGroupFile(badSeqNames); } // this screens just the group - else if (countfile != "") { screenCountFile(badSeqNames); } + + //use remove.seqs to create new name, group and count file + if ((countfile != "") || (namefile != "") || (groupfile != "") || (qualfile != "") || (taxonomy != "")) { + string inputString = "accnos=" + badAccnosFile; - - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - - if(qualfile != "") { screenQual(badSeqNames); } - if(taxonomy != "") { screenTaxonomy(badSeqNames); } + if (countfile != "") { inputString += ", count=" + countfile; } + else{ + if (namefile != "") { inputString += ", name=" + namefile; } + if (groupfile != "") { inputString += ", group=" + groupfile; } + } + if(qualfile != "") { inputString += ", qfile=" + qualfile; } + if(taxonomy != "") { inputString += ", taxonomy=" + taxonomy; } + + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + m->mothurOut("Running command: remove.seqs(" + inputString + ")"); m->mothurOutEndLine(); + m->mothurCalling = true; + + Command* removeCommand = new RemoveSeqsCommand(inputString); + removeCommand->execute(); + + map > filenames = removeCommand->getOutputFiles(); + + delete removeCommand; + m->mothurCalling = false; + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + + if (groupfile != "") { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outGroup = getOutputFileName("group", variables); + m->renameFile(filenames["group"][0], outGroup); + outputNames.push_back(outGroup); outputTypes["group"].push_back(outGroup); + } + + if (namefile != "") { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outName = getOutputFileName("name", variables); + m->renameFile(filenames["name"][0], outName); + outputNames.push_back(outName); outputTypes["name"].push_back(outName); + } + + if (countfile != "") { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outCount = getOutputFileName("count", variables); + m->renameFile(filenames["count"][0], outCount); + outputNames.push_back(outCount); outputTypes["count"].push_back(outCount); + } + + if (qualfile != "") { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)); + variables["[extension]"] = m->getExtension(qualfile); + string outQual = getOutputFileName("qfile", variables); + m->renameFile(filenames["qfile"][0], outQual); + outputNames.push_back(outQual); outputTypes["name"].push_back(outQual); + } + + if (taxonomy != "") { + string thisOutputDir = outputDir; + if (outputDir == "") { thisOutputDir += m->hasPath(taxonomy); } + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxonomy)); + variables["[extension]"] = m->getExtension(taxonomy); + string outTax = getOutputFileName("taxonomy", variables); + m->renameFile(filenames["taxonomy"][0], outTax); + outputNames.push_back(outTax); outputTypes["count"].push_back(outTax); + } + } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -505,6 +581,11 @@ int ScreenSeqsCommand::execute(){ if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); } } + + itTypes = outputTypes.find("accnos"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } + } m->mothurOut("It took " + toString(time(NULL) - start) + " secs to screen " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); @@ -522,11 +603,30 @@ int ScreenSeqsCommand::runFastaScreening(map& badSeqNames){ int numFastaSeqs = 0; map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string badAccnosFile = getOutputFileName("accnos",variables); variables["[extension]"] = m->getExtension(fastafile); string goodSeqFile = getOutputFileName("fasta", variables); outputNames.push_back(goodSeqFile); outputTypes["fasta"].push_back(goodSeqFile); - outputNames.push_back(badAccnosFile); outputTypes["accnos"].push_back(badAccnosFile); + + vector positions; +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + positions = m->divideFile(fastafile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } +#else + if(processors == 1){ lines.push_back(linePair(0, 1000)); } + else { + int numFastaSeqs = 0; + positions = m->setFilePosFasta(fastafile, numFastaSeqs); + if (numFastaSeqs < processors) { processors = numFastaSeqs; } + + //figure out how many sequences you have to process + int numSeqsPerProcessor = numFastaSeqs / processors; + for (int i = 0; i < processors; i++) { + int startIndex = i * numSeqsPerProcessor; + if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; } + lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); + } + } +#endif if(processors == 1){ numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames); } else{ numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames); } @@ -545,22 +645,12 @@ int ScreenSeqsCommand::runFastaScreening(map& badSeqNames){ int ScreenSeqsCommand::screenReports(map& badSeqNames){ try{ int numFastaSeqs = 0; - bool summarizedFasta = false; - //use the namefile to optimize correctly - if (namefile != "") { nameMap = m->readNames(namefile); } - else if (countfile != "") { - CountTable ct; - ct.readTable(countfile, true, false); - nameMap = ct.getNameMap(); - } - //did not provide a summary file, but set a parameter that requires summarizing the fasta file //or did provide a summary file, but set maxn parameter so we must summarize the fasta file vector positions; if (((summaryfile == "") && ((m->inUsersGroups("maxambig", optimize)) ||(m->inUsersGroups("maxhomop", optimize)) ||(m->inUsersGroups("maxlength", optimize)) || (m->inUsersGroups("minlength", optimize)) || (m->inUsersGroups("start", optimize)) || (m->inUsersGroups("end", optimize)))) || ((summaryfile != "") && m->inUsersGroups("maxn", optimize))) { - getSummary(positions); - summarizedFasta = true; + getSummary(); }else { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(fastafile, processors); @@ -583,7 +673,7 @@ int ScreenSeqsCommand::screenReports(map& badSeqNames){ #endif } - if ((summaryfile != "") && ((m->inUsersGroups("maxambig", optimize)) ||(m->inUsersGroups("maxhomop", optimize)) ||(m->inUsersGroups("maxlength", optimize)) || (m->inUsersGroups("minlength", optimize)) || (m->inUsersGroups("start", optimize)) || (m->inUsersGroups("end", optimize))) && !summarizedFasta) { //summarize based on summaryfile + if ((summaryfile != "") && ((m->inUsersGroups("maxambig", optimize)) ||(m->inUsersGroups("maxhomop", optimize)) ||(m->inUsersGroups("maxlength", optimize)) || (m->inUsersGroups("minlength", optimize)) || (m->inUsersGroups("start", optimize)) || (m->inUsersGroups("end", optimize)))) { //summarize based on summaryfile getSummaryReport(); }else if ((contigsreport != "") && ((m->inUsersGroups("minoverlap", optimize)) || (m->inUsersGroups("ostart", optimize)) || (m->inUsersGroups("oend", optimize)) || (m->inUsersGroups("mismatches", optimize)))) { //optimize settings based on contigs file optimizeContigs(); @@ -591,7 +681,6 @@ int ScreenSeqsCommand::screenReports(map& badSeqNames){ optimizeAlign(); } - //provided summary file, and did not set maxn so no need to summarize fasta if (summaryfile != "") { numFastaSeqs = screenSummary(badSeqNames); } //add in any seqs that fail due to contigs report results @@ -608,12 +697,12 @@ int ScreenSeqsCommand::screenReports(map& badSeqNames){ } //*************************************************************************************************************** int ScreenSeqsCommand::screenAlignReport(map& badSeqNames){ - try { + try { - map variables; + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(alignreport)); string outSummary = getOutputFileName("alignreport",variables); - outputNames.push_back(outSummary); outputTypes["alignreport"].push_back(outSummary); + outputNames.push_back(outSummary); outputTypes["alignreport"].push_back(outSummary); string name, TemplateName, SearchMethod, AlignmentMethod; //QueryName QueryLength TemplateName TemplateLength SearchMethod SearchScore AlignmentMethod QueryStart QueryEnd TemplateStart TemplateEnd PairwiseAlignmentLength GapsInQuery GapsInTemplate LongestInsert SimBtwnQuery&Template @@ -629,15 +718,15 @@ int ScreenSeqsCommand::screenAlignReport(map& badSeqNames){ m->openInputFile(alignreport, in); out << (m->getline(in)) << endl; //skip headers - int count = 0; + int count = 0; - while (!in.eof()) { + while (!in.eof()) { if (m->control_pressed) { in.close(); out.close(); return 0; } //seqname start end nbases ambigs polymer numSeqs in >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; m->gobble(in); - + bool goodSeq = 1; // innocent until proven guilty string trashCode = ""; if(maxInsert != -1 && maxInsert < LongestInsert) { goodSeq = 0; trashCode += "insert|"; } @@ -676,7 +765,7 @@ int ScreenSeqsCommand::screenAlignReport(map& badSeqNames){ in2 >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; m->gobble(in2); if (badSeqNames.count(name) == 0) { //are you good? - out2 << name << '\t' << length << '\t' << TemplateName << '\t' << TemplateLength << '\t' << SearchMethod << '\t' << SearchScore << '\t' << AlignmentMethod << '\t' << QueryStart << '\t' << QueryEnd << '\t' << TemplateStart << '\t' << TemplateEnd << '\t' << PairwiseAlignmentLength << '\t' << GapsInQuery << '\t' << GapsInTemplate << '\t' << LongestInsert << '\t' << SimBtwnQueryTemplate << endl; + out2 << name << '\t' << length << '\t' << TemplateName << '\t' << TemplateLength << '\t' << SearchMethod << '\t' << SearchScore << '\t' << AlignmentMethod << '\t' << QueryStart << '\t' << QueryEnd << '\t' << TemplateStart << '\t' << TemplateEnd << '\t' << PairwiseAlignmentLength << '\t' << GapsInQuery << '\t' << GapsInTemplate << '\t' << LongestInsert << '\t' << SimBtwnQueryTemplate << endl; } } in2.close(); @@ -689,22 +778,22 @@ int ScreenSeqsCommand::screenAlignReport(map& badSeqNames){ return count; - return 0; + return 0; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenAlignReport"); - exit(1); - } - + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "screenAlignReport"); + exit(1); + } + } //***************************************************************************************************************/ int ScreenSeqsCommand::screenContigs(map& badSeqNames){ - try{ - map variables; + try{ + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(contigsreport)); string outSummary = getOutputFileName("contigsreport",variables); - outputNames.push_back(outSummary); outputTypes["contigsreport"].push_back(outSummary); + outputNames.push_back(outSummary); outputTypes["contigsreport"].push_back(outSummary); string name; //Name Length Overlap_Length Overlap_Start Overlap_End MisMatches Num_Ns @@ -718,9 +807,9 @@ int ScreenSeqsCommand::screenContigs(map& badSeqNames){ m->openInputFile(contigsreport, in); out << (m->getline(in)) << endl; //skip headers - int count = 0; + int count = 0; - while (!in.eof()) { + while (!in.eof()) { if (m->control_pressed) { in.close(); out.close(); return 0; } @@ -736,7 +825,7 @@ int ScreenSeqsCommand::screenContigs(map& badSeqNames){ if(mismatches != -1 && mismatches < numMisMatches) { goodSeq = 0; trashCode += "mismatches|"; } if(goodSeq == 1){ - out << name << '\t' << length << '\t' << OLength << '\t' << thisOStart << '\t' << thisOEnd << '\t' << numMisMatches << '\t' << numNs << endl; + out << name << '\t' << length << '\t' << OLength << '\t' << thisOStart << '\t' << thisOEnd << '\t' << numMisMatches << '\t' << numNs << endl; } else{ badSeqNames[name] = trashCode; } count++; @@ -767,7 +856,7 @@ int ScreenSeqsCommand::screenContigs(map& badSeqNames){ in2 >> name >> length >> OLength >> thisOStart >> thisOEnd >> numMisMatches >> numNs; m->gobble(in2); if (badSeqNames.count(name) == 0) { //are you good? - out2 << name << '\t' << length << '\t' << OLength << '\t' << thisOStart << '\t' << thisOEnd << '\t' << numMisMatches << '\t' << numNs << endl; + out2 << name << '\t' << length << '\t' << OLength << '\t' << thisOStart << '\t' << thisOEnd << '\t' << numMisMatches << '\t' << numNs << endl; } } in2.close(); @@ -781,10 +870,10 @@ int ScreenSeqsCommand::screenContigs(map& badSeqNames){ return count; } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenContigs"); - exit(1); - } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "screenContigs"); + exit(1); + } } //***************************************************************************************************************/ int ScreenSeqsCommand::screenSummary(map& badSeqNames){ @@ -877,47 +966,13 @@ int ScreenSeqsCommand::screenSummary(map& badSeqNames){ //***************************************************************************************************************/ int ScreenSeqsCommand::screenFasta(map& badSeqNames){ try{ - - - //if the user want to optimize we need to know the 90% mark - vector positions; - if (optimize.size() != 0) { //get summary is paralellized so we need to divideFile, no need to do this step twice so I moved it here - //use the namefile to optimize correctly - if (namefile != "") { nameMap = m->readNames(namefile); } - else if (countfile != "") { - CountTable ct; - ct.readTable(countfile, true, false); - nameMap = ct.getNameMap(); - } - getSummary(positions); - }else { -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } -#else - if(processors == 1){ lines.push_back(linePair(0, 1000)); } - else { - int numFastaSeqs = 0; - positions = m->setFilePosFasta(fastafile, numFastaSeqs); - if (numFastaSeqs < processors) { processors = numFastaSeqs; } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numFastaSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; } - lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); - } - } -#endif - } - + if (optimize.size() != 0) { getSummary(); } + if (m->control_pressed) { return 0; } int numFastaSeqs = runFastaScreening(badSeqNames); return numFastaSeqs; - } catch(exception& e) { m->errorOut(e, "ScreenSeqsCommand", "screenFasta"); @@ -925,170 +980,22 @@ int ScreenSeqsCommand::screenFasta(map& badSeqNames){ } } //*************************************************************************************************************** - -int ScreenSeqsCommand::screenNameGroupFile(map badSeqNames){ - try { - ifstream inputNames; - m->openInputFile(namefile, inputNames); - map badSeqGroups; - string seqName, seqList, group; - map::iterator it; - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(namefile)); - variables["[extension]"] = m->getExtension(namefile); - string goodNameFile = getOutputFileName("name", variables); - outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile); - - ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); - - while(!inputNames.eof()){ - if (m->control_pressed) { goodNameOut.close(); inputNames.close(); m->mothurRemove(goodNameFile); return 0; } - - inputNames >> seqName; m->gobble(inputNames); inputNames >> seqList; - it = badSeqNames.find(seqName); - - if(it != badSeqNames.end()){ - if(namefile != ""){ - int start = 0; - for(int i=0;isecond; - start = i+1; - } - } - badSeqGroups[seqList.substr(start,seqList.length()-start)] = it->second; - } - badSeqNames.erase(it); - } - else{ - goodNameOut << seqName << '\t' << seqList << endl; - } - m->gobble(inputNames); - } - inputNames.close(); - goodNameOut.close(); - - //we were unable to remove some of the bad sequences - if (badSeqNames.size() != 0) { - for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your namefile does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - - if(groupfile != ""){ - - ifstream inputGroups; - m->openInputFile(groupfile, inputGroups); - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); - variables["[extension]"] = m->getExtension(groupfile); - string goodGroupFile = getOutputFileName("group", variables); - - outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); - - ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); - - while(!inputGroups.eof()){ - if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodNameFile); m->mothurRemove(goodGroupFile); return 0; } - - inputGroups >> seqName; m->gobble(inputGroups); inputGroups >> group; - - it = badSeqGroups.find(seqName); - - if(it != badSeqGroups.end()){ - badSeqGroups.erase(it); - } - else{ - goodGroupOut << seqName << '\t' << group << endl; - } - m->gobble(inputGroups); - } - inputGroups.close(); - goodGroupOut.close(); - - //we were unable to remove some of the bad sequences - if (badSeqGroups.size() != 0) { - for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) { - m->mothurOut("Your groupfile does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - } - - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenNameGroupFile"); - exit(1); - } -} -//*************************************************************************************************************** int ScreenSeqsCommand::getSummaryReport(){ try { - - vector startPosition; - vector endPosition; - vector seqLength; - vector ambigBases; - vector longHomoPolymer; - - //read summary file - ifstream in; - m->openInputFile(summaryfile, in); - m->getline(in); + Summary sum; + sum.summarizeFastaSummary(summaryfile); - string name; - int start, end, length, ambigs, polymer, numReps; + double criteriaPercentile = criteria; + double mincriteriaPercentile = (100 - criteria); - while (!in.eof()) { - - if (m->control_pressed) { in.close(); return 0; } - - //seqname start end nbases ambigs polymer numSeqs - in >> name >> start >> end >> length >> ambigs >> polymer >> numReps; m->gobble(in); - - if (m->debug) { m->mothurOut("[DEBUG]: " + name + "\t" + toString(start) + "\t" + toString(end) + "\t" + toString(length) + "\n"); } - - int num = 1; - if ((namefile != "") || (countfile !="")) { - //make sure this sequence is in the namefile, else error - map::iterator it = nameMap.find(name); - - if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + name + " is not in your " + fileType + " please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - for (int i = 0; i < num; i++) { - startPosition.push_back(start); - endPosition.push_back(end); - seqLength.push_back(length); - ambigBases.push_back(ambigs); - longHomoPolymer.push_back(polymer); - } - + for (int i = 0; i < optimize.size(); i++) { + if (optimize[i] == "start") { startPos = sum.getStart(criteriaPercentile); m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "end") { endPos = sum.getEnd(mincriteriaPercentile); m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();} + else if (optimize[i] == "maxambig") { maxAmbig = sum.getAmbig(criteriaPercentile); m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxhomop") { maxHomoP = sum.getAmbig(criteriaPercentile); m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "minlength") { minLength = sum.getLength(mincriteriaPercentile); m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); if (minLength < 0) { m->control_pressed = true; } } + else if (optimize[i] == "maxlength") { maxLength = sum.getLength(criteriaPercentile); m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); } } - in.close(); - - sort(startPosition.begin(), startPosition.end()); - sort(endPosition.begin(), endPosition.end()); - sort(seqLength.begin(), seqLength.end()); - sort(ambigBases.begin(), ambigBases.end()); - sort(longHomoPolymer.begin(), longHomoPolymer.end()); - - //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs - int criteriaPercentile = int(startPosition.size() * (criteria / (float) 100)); - - for (int i = 0; i < optimize.size(); i++) { - if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "end") { int endcriteriaPercentile = int(endPosition.size() * ((100 - criteria) / (float) 100)); endPos = endPosition[endcriteriaPercentile]; m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();} - else if (optimize[i] == "maxambig") { maxAmbig = ambigBases[criteriaPercentile]; m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "maxhomop") { maxHomoP = longHomoPolymer[criteriaPercentile]; m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "minlength") { int mincriteriaPercentile = int(seqLength.size() * ((100 - criteria) / (float) 100)); minLength = seqLength[mincriteriaPercentile]; m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); if (minLength < 0) { m->control_pressed = true; } } - else if (optimize[i] == "maxlength") { maxLength = seqLength[criteriaPercentile]; m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); } - } return 0; @@ -1100,58 +1007,21 @@ int ScreenSeqsCommand::getSummaryReport(){ } //*************************************************************************************************************** int ScreenSeqsCommand::optimizeContigs(){ - try { - vector olengths; - vector oStarts; - vector oEnds; - vector numMismatches; - vector numNs; - - vector positions; - vector contigsLines; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - positions = m->divideFilePerLine(contigsreport, processors); - for (int i = 0; i < (positions.size()-1); i++) { contigsLines.push_back(linePair(positions[i], positions[(i+1)])); } -#else - if(processors == 1){ contigsLines.push_back(linePair(0, 1000)); } - else { - int numContigsSeqs = 0; - positions = m->setFilePosEachLine(contigsreport, numContigsSeqs); - if (positions.size() < processors) { processors = positions.size(); } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numContigsSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numContigsSeqs - i * numSeqsPerProcessor; } - contigsLines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); - } - } -#endif - - - createProcessesContigsSummary(olengths, oStarts, oEnds, numMismatches, numNs, contigsLines); - - if (m->control_pressed) { return 0; } - - sort(olengths.begin(), olengths.end()); - sort(oStarts.begin(), oStarts.end()); - sort(oEnds.begin(), oEnds.end()); - sort(numMismatches.begin(), numMismatches.end()); - sort(numNs.begin(), numNs.end()); - - //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs - int criteriaPercentile = int(oStarts.size() * (criteria / (float) 100)); - - for (int i = 0; i < optimize.size(); i++) { - if (optimize[i] == "ostart") { oStart = oStarts[criteriaPercentile]; m->mothurOut("Optimizing ostart to " + toString(oStart) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "oend") { int endcriteriaPercentile = int(oEnds.size() * ((100 - criteria) / (float) 100)); oEnd = oEnds[endcriteriaPercentile]; m->mothurOut("Optimizing oend to " + toString(oEnd) + "."); m->mothurOutEndLine();} - else if (optimize[i] == "mismatches") { mismatches = numMismatches[criteriaPercentile]; m->mothurOut("Optimizing mismatches to " + toString(mismatches) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "maxn") { maxN = numNs[criteriaPercentile]; m->mothurOut("Optimizing maxn to " + toString(maxN) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "minoverlap") { int mincriteriaPercentile = int(olengths.size() * ((100 - criteria) / (float) 100)); minOverlap = olengths[mincriteriaPercentile]; m->mothurOut("Optimizing minoverlap to " + toString(minOverlap) + "."); m->mothurOutEndLine(); } + try{ + Summary sum; + sum.summarizeContigsSummary(contigsreport); + + double criteriaPercentile = criteria; + double mincriteriaPercentile = (100 - criteria); - } - + for (int i = 0; i < optimize.size(); i++) { + if (optimize[i] == "ostart") { oStart = sum.getOStart(criteriaPercentile); m->mothurOut("Optimizing ostart to " + toString(oStart) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "oend") { endPos = sum.getOEnd(mincriteriaPercentile); m->mothurOut("Optimizing oend to " + toString(oEnd) + "."); m->mothurOutEndLine();} + else if (optimize[i] == "mismatches") { mismatches = sum.getMisMatches(criteriaPercentile); m->mothurOut("Optimizing mismatches to " + toString(mismatches) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxn") { maxN = sum.getNumNs(criteriaPercentile); m->mothurOut("Optimizing maxn to " + toString(maxN) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "minoverlap") { minOverlap = sum.getOLength(mincriteriaPercentile); m->mothurOut("Optimizing minoverlap to " + toString(minOverlap) + "."); m->mothurOutEndLine(); } + } + return 0; } catch(exception& e) { @@ -1159,1145 +1029,54 @@ int ScreenSeqsCommand::optimizeContigs(){ exit(1); } } -/**************************************************************************************/ -int ScreenSeqsCommand::driverContigsSummary(vector& oLength, vector& ostartPosition, vector& oendPosition, vector& omismatches, vector& numNs, linePair filePos) { +//*************************************************************************************************************** +int ScreenSeqsCommand::optimizeAlign(){ try { - - string name; - //Name Length Overlap_Length Overlap_Start Overlap_End MisMatches Num_Ns - int length, OLength, thisOStart, thisOEnd, numMisMatches, numns; - ifstream in; - m->openInputFile(contigsreport, in); + Summary sum; + sum.summarizeAlignSummary(alignreport); + + double mincriteriaPercentile = (100 - criteria); - in.seekg(filePos.start); - if (filePos.start == 0) { //read headers - m->zapGremlins(in); m->gobble(in); m->getline(in); m->gobble(in); + for (int i = 0; i < optimize.size(); i++) { + if (optimize[i] == "minsim") { minSim = sum.getSims(mincriteriaPercentile); m->mothurOut("Optimizing minsim to " + toString(minSim) + "."); m->mothurOutEndLine();} + else if (optimize[i] == "minscore") { minScore = sum.getScores(mincriteriaPercentile); m->mothurOut("Optimizing minscore to " + toString(minScore) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxinsert") { maxInsert = sum.getNumInserts(mincriteriaPercentile); m->mothurOut("Optimizing maxinsert to " + toString(maxInsert) + "."); m->mothurOutEndLine(); } } - bool done = false; - int count = 0; - - while (!done) { - - if (m->control_pressed) { in.close(); return 1; } - - //seqname start end nbases ambigs polymer numSeqs - in >> name >> length >> OLength >> thisOStart >> thisOEnd >> numMisMatches >> numns; m->gobble(in); - - int num = 1; - if ((namefile != "") || (countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = nameMap.find(name); - - if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + name + " is not in your " + fileType + " please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - for (int i = 0; i < num; i++) { - ostartPosition.push_back(thisOStart); - oendPosition.push_back(thisOEnd); - oLength.push_back(OLength); - omismatches.push_back(numMisMatches); - numNs.push_back(numns); - } - - count++; - - //if((count) % 100 == 0){ m->mothurOut("Optimizing sequence: " + toString(count)); m->mothurOutEndLine(); } -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - unsigned long long pos = in.tellg(); - if ((pos == -1) || (pos >= filePos.end)) { break; } -#else - if (in.eof()) { break; } -#endif - } - - in.close(); - - return count; + return 0; } catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "driverContigsSummary"); + m->errorOut(e, "ScreenSeqsCommand", "optimizeAlign"); exit(1); } } - -/**************************************************************************************************/ -int ScreenSeqsCommand::createProcessesContigsSummary(vector& oLength, vector& ostartPosition, vector& oendPosition, vector& omismatches, vector& numNs, vector contigsLines) { +//*************************************************************************************************************** +int ScreenSeqsCommand::getSummary(){ try { + Summary sum; + sum.summarizeFasta(fastafile, ""); - int process = 1; - int num = 0; - vector processIDS; - bool recalc = false; - - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs + double criteriaPercentile = criteria; + double mincriteriaPercentile = (100 - criteria); - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverContigsSummary(oLength, ostartPosition, oendPosition, omismatches, numNs, contigsLines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = contigsreport + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << ostartPosition.size() << endl; - for (int k = 0; k < ostartPosition.size(); k++) { out << ostartPosition[k] << '\t'; } out << endl; - for (int k = 0; k < oendPosition.size(); k++) { out << oendPosition[k] << '\t'; } out << endl; - for (int k = 0; k < oLength.size(); k++) { out << oLength[k] << '\t'; } out << endl; - for (int k = 0; k < omismatches.size(); k++) { out << omismatches[k] << '\t'; } out << endl; - for (int k = 0; k < numNs.size(); k++) { out << numNs[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - //wait to die - for (int i=0;icontrol_pressed = false; - for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp")); - } - recalc = true; - break; - } - } - - if (recalc) { - //test line, also set recalc to true. - //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); - - vector positions; - contigsLines.clear(); - positions = m->divideFilePerLine(contigsreport, processors); - for (int i = 0; i < (positions.size()-1); i++) { contigsLines.push_back(linePair(positions[i], positions[(i+1)])); } - - //redo file divide - lines.clear(); positions.clear(); - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } - - ostartPosition.clear(); - oendPosition.clear(); - oLength.clear(); - omismatches.clear(); - numNs.clear(); - - num = 0; - processIDS.resize(0); - process = 1; - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverContigsSummary(oLength, ostartPosition, oendPosition, omismatches, numNs, contigsLines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = contigsreport + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << ostartPosition.size() << endl; - for (int k = 0; k < ostartPosition.size(); k++) { out << ostartPosition[k] << '\t'; } out << endl; - for (int k = 0; k < oendPosition.size(); k++) { out << oendPosition[k] << '\t'; } out << endl; - for (int k = 0; k < oLength.size(); k++) { out << oLength[k] << '\t'; } out << endl; - for (int k = 0; k < omismatches.size(); k++) { out << omismatches[k] << '\t'; } out << endl; - for (int k = 0; k < numNs.size(); k++) { out << numNs[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - exit(0); - } - } - } - - num = driverContigsSummary(oLength, ostartPosition, oendPosition, omismatches, numNs, contigsLines[0]); - - //force parent to wait until all the processes are done - for (int i=0;iopenInputFile(tempFilename, in); - - int temp, tempNum; - in >> tempNum; m->gobble(in); num += tempNum; - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; ostartPosition.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; oendPosition.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; oLength.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; omismatches.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; numNs.push_back(temp); } m->gobble(in); - - in.close(); - m->mothurRemove(tempFilename); - } - - -#else - ////////////////////////////////////////////////////////////////////////////////////////////////////// - //Windows version shared memory, so be careful when passing variables through the seqSumData struct. - //Above fork() will clone, so memory is separate, but that's not the case with windows, - //Taking advantage of shared memory to allow both threads to add info to vectors. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /* - vector pDataArray; - DWORD dwThreadIdArray[processors-1]; - HANDLE hThreadArray[processors-1]; - - //Create processor worker threads. - for( int i=0; icount; - if (pDataArray[i]->count != pDataArray[i]->end) { - m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; - } - for (int k = 0; k < pDataArray[i]->ostartPosition.size(); k++) { ostartPosition.push_back(pDataArray[i]->ostartPosition[k]); } - for (int k = 0; k < pDataArray[i]->oendPosition.size(); k++) { oendPosition.push_back(pDataArray[i]->oendPosition[k]); } - for (int k = 0; k < pDataArray[i]->oLength.size(); k++) { oLength.push_back(pDataArray[i]->oLength[k]); } - for (int k = 0; k < pDataArray[i]->omismatches.size(); k++) { omismatches.push_back(pDataArray[i]->omismatches[k]); } - for (int k = 0; k < pDataArray[i]->numNs.size(); k++) { numNs.push_back(pDataArray[i]->numNs[k]); } - CloseHandle(hThreadArray[i]); - delete pDataArray[i]; - } - */ -#endif - return num; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "createProcessesContigsSummary"); - exit(1); - } -} -//*************************************************************************************************************** -int ScreenSeqsCommand::optimizeAlign(){ - try { - - vector sims; - vector scores; - vector inserts; - - vector positions; - vector alignLines; -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - positions = m->divideFilePerLine(alignreport, processors); - for (int i = 0; i < (positions.size()-1); i++) { alignLines.push_back(linePair(positions[i], positions[(i+1)])); } -#else - if(processors == 1){ alignLines.push_back(linePair(0, 1000)); } - else { - int numAlignSeqs = 0; - positions = m->setFilePosEachLine(alignreport, numAlignSeqs); - if (positions.size() < processors) { processors = positions.size(); } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numAlignSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numAlignSeqs - i * numSeqsPerProcessor; } - alignLines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); - } - } -#endif - - - createProcessesAlignSummary(sims, scores, inserts, alignLines); - - if (m->control_pressed) { return 0; } - - sort(sims.begin(), sims.end()); - sort(scores.begin(), scores.end()); - sort(inserts.begin(), inserts.end()); - - //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs - //int criteriaPercentile = int(sims.size() * (criteria / (float) 100)); - - for (int i = 0; i < optimize.size(); i++) { - if (optimize[i] == "minsim") { int mincriteriaPercentile = int(sims.size() * ((100 - criteria) / (float) 100)); minSim = sims[mincriteriaPercentile]; m->mothurOut("Optimizing minsim to " + toString(minSim) + "."); m->mothurOutEndLine();} - else if (optimize[i] == "minscore") { int mincriteriaPercentile = int(scores.size() * ((100 - criteria) / (float) 100)); minScore = scores[mincriteriaPercentile]; m->mothurOut("Optimizing minscore to " + toString(minScore) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "maxinsert") { int criteriaPercentile = int(inserts.size() * ((100 - criteria) / (float) 100)); maxInsert = inserts[criteriaPercentile]; m->mothurOut("Optimizing maxinsert to " + toString(maxInsert) + "."); m->mothurOutEndLine(); } - } - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "optimizeContigs"); - exit(1); - } -} -/**************************************************************************************/ -int ScreenSeqsCommand::driverAlignSummary(vector& sims, vector& scores, vector& inserts, linePair filePos) { - try { - - string name, TemplateName, SearchMethod, AlignmentMethod; - //QueryName QueryLength TemplateName TemplateLength SearchMethod SearchScore AlignmentMethod QueryStart QueryEnd TemplateStart TemplateEnd PairwiseAlignmentLength GapsInQuery GapsInTemplate LongestInsert SimBtwnQuery&Template - //checking for minScore, maxInsert, minSim - int length, TemplateLength, QueryStart, QueryEnd, TemplateStart, TemplateEnd, PairwiseAlignmentLength, GapsInQuery, GapsInTemplate, LongestInsert; - float SearchScore, SimBtwnQueryTemplate; - - ifstream in; - m->openInputFile(alignreport, in); - - in.seekg(filePos.start); - if (filePos.start == 0) { //read headers - m->zapGremlins(in); m->gobble(in); m->getline(in); m->gobble(in); - } - - bool done = false; - int count = 0; - - while (!done) { - - if (m->control_pressed) { in.close(); return 1; } - - in >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; m->gobble(in); - - int num = 1; - if ((namefile != "") || (countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = nameMap.find(name); - - if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + name + " is not in your " + fileType + " please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - for (int i = 0; i < num; i++) { - sims.push_back(SimBtwnQueryTemplate); - scores.push_back(SearchScore); - inserts.push_back(LongestInsert); - } - - count++; - - //if((count) % 100 == 0){ m->mothurOut("Optimizing sequence: " + toString(count)); m->mothurOutEndLine(); } -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - unsigned long long pos = in.tellg(); - if ((pos == -1) || (pos >= filePos.end)) { break; } -#else - if (in.eof()) { break; } -#endif - } - - in.close(); - - return count; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "driverAlignSummary"); - exit(1); - } -} - -/**************************************************************************************************/ -int ScreenSeqsCommand::createProcessesAlignSummary(vector& sims, vector& scores, vector& inserts, vector alignLines) { - try { - - int process = 1; - int num = 0; - vector processIDS; - bool recalc = false; - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverAlignSummary(sims, scores, inserts, alignLines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = alignreport + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << sims.size() << endl; - for (int k = 0; k < sims.size(); k++) { out << sims[k] << '\t'; } out << endl; - for (int k = 0; k < scores.size(); k++) { out << scores[k] << '\t'; } out << endl; - for (int k = 0; k < inserts.size(); k++) { out << inserts[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - //wait to die - for (int i=0;icontrol_pressed = false; - for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp")); - } - recalc = true; - break; - } - } - - if (recalc) { - //test line, also set recalc to true. - //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); - - vector positions; - alignLines.clear(); - positions = m->divideFilePerLine(contigsreport, processors); - for (int i = 0; i < (positions.size()-1); i++) { alignLines.push_back(linePair(positions[i], positions[(i+1)])); } - - //redo file divide - lines.clear(); positions.clear(); - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } - - sims.clear(); - scores.clear(); - inserts.clear(); - - num = 0; - processIDS.resize(0); - process = 1; - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverAlignSummary(sims, scores, inserts, alignLines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = alignreport + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << sims.size() << endl; - for (int k = 0; k < sims.size(); k++) { out << sims[k] << '\t'; } out << endl; - for (int k = 0; k < scores.size(); k++) { out << scores[k] << '\t'; } out << endl; - for (int k = 0; k < inserts.size(); k++) { out << inserts[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - exit(0); - } - } - } - - num = driverAlignSummary(sims, scores, inserts, alignLines[0]); - - //force parent to wait until all the processes are done - for (int i=0;iopenInputFile(tempFilename, in); - - int temp, tempNum; - float temp2; - in >> tempNum; m->gobble(in); num += tempNum; - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp2; sims.push_back(temp2); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp2; scores.push_back(temp2); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; inserts.push_back(temp); } m->gobble(in); - - in.close(); - m->mothurRemove(tempFilename); - } - - -#else - ////////////////////////////////////////////////////////////////////////////////////////////////////// - //Windows version shared memory, so be careful when passing variables through the seqSumData struct. - //Above fork() will clone, so memory is separate, but that's not the case with windows, - //Taking advantage of shared memory to allow both threads to add info to vectors. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /* - vector pDataArray; - DWORD dwThreadIdArray[processors-1]; - HANDLE hThreadArray[processors-1]; - - //Create processor worker threads. - for( int i=0; icount; - if (pDataArray[i]->count != pDataArray[i]->end) { - m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; - } - for (int k = 0; k < pDataArray[i]->sims.size(); k++) { sims.push_back(pDataArray[i]->sims[k]); } - for (int k = 0; k < pDataArray[i]->scores.size(); k++) { scores.push_back(pDataArray[i]->scores[k]); } - for (int k = 0; k < pDataArray[i]->inserts.size(); k++) { inserts.push_back(pDataArray[i]->inserts[k]); } - CloseHandle(hThreadArray[i]); - delete pDataArray[i]; - } - */ -#endif - return num; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "createProcessesAlignSummary"); - exit(1); - } -} -//*************************************************************************************************************** -int ScreenSeqsCommand::getSummary(vector& positions){ - try { - - vector startPosition; - vector endPosition; - vector seqLength; - vector ambigBases; - vector longHomoPolymer; - vector numNs; - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } -#else - if(processors == 1){ lines.push_back(linePair(0, 1000)); } - else { - int numFastaSeqs = 0; - positions = m->setFilePosFasta(fastafile, numFastaSeqs); - if (numFastaSeqs < processors) { processors = numFastaSeqs; } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numFastaSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; } - lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); - } - } -#endif - - - int numSeqs = 0; - - if(processors == 1){ - numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, numNs, fastafile, lines[0]); - }else{ - numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, numNs, fastafile); - } - - if (m->control_pressed) { return 0; } - - sort(startPosition.begin(), startPosition.end()); - sort(endPosition.begin(), endPosition.end()); - sort(seqLength.begin(), seqLength.end()); - sort(ambigBases.begin(), ambigBases.end()); - sort(longHomoPolymer.begin(), longHomoPolymer.end()); - sort(numNs.begin(), numNs.end()); - - //numSeqs is the number of unique seqs, startPosition.size() is the total number of seqs, we want to optimize using all seqs - int criteriaPercentile = int(startPosition.size() * (criteria / (float) 100)); - - for (int i = 0; i < optimize.size(); i++) { - if (optimize[i] == "start") { startPos = startPosition[criteriaPercentile]; m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "end") { int endcriteriaPercentile = int(endPosition.size() * ((100 - criteria) / (float) 100)); endPos = endPosition[endcriteriaPercentile]; m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();} - else if (optimize[i] == "maxambig") { maxAmbig = ambigBases[criteriaPercentile]; m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "maxhomop") { maxHomoP = longHomoPolymer[criteriaPercentile]; m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "minlength") { int mincriteriaPercentile = int(seqLength.size() * ((100 - criteria) / (float) 100)); minLength = seqLength[mincriteriaPercentile]; m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); if (minLength < 0) { m->control_pressed = true; } } - else if (optimize[i] == "maxlength") { maxLength = seqLength[criteriaPercentile]; m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); } - else if (optimize[i] == "maxn") { maxN = numNs[criteriaPercentile]; m->mothurOut("Optimizing maxn to " + toString(maxN) + "."); m->mothurOutEndLine(); } - } - - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "getSummary"); - exit(1); - } -} -/**************************************************************************************/ -int ScreenSeqsCommand::driverCreateSummary(vector& startPosition, vector& endPosition, vector& seqLength, vector& ambigBases, vector& longHomoPolymer, vector& numNs, string filename, linePair filePos) { - try { - - ifstream in; - m->openInputFile(filename, in); - - in.seekg(filePos.start); - - //adjust start if null strings - if (filePos.start == 0) { m->zapGremlins(in); m->gobble(in); } - - m->gobble(in); - - bool done = false; - int count = 0; - - while (!done) { - - if (m->control_pressed) { in.close(); return 1; } - - Sequence current(in); m->gobble(in); - - if (current.getName() != "") { - int num = 1; - if ((namefile != "") || (countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = nameMap.find(current.getName()); - - if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + current.getName() + " is not in your " + fileType + " please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - else { num = it->second; } - } - - if (m->debug) { m->mothurOut("[DEBUG]: " + current.getName() + "\t" + toString(current.getStartPos()) + "\t" + toString(current.getEndPos()) + "\t" + toString(current.getNumBases()) + "\n"); } - - //for each sequence this sequence represents - int numns = current.getNumNs(); - for (int i = 0; i < num; i++) { - startPosition.push_back(current.getStartPos()); - endPosition.push_back(current.getEndPos()); - seqLength.push_back(current.getNumBases()); - ambigBases.push_back(current.getAmbigBases()); - longHomoPolymer.push_back(current.getLongHomoPolymer()); - numNs.push_back(numns); - } - - count++; - } - //if((count) % 100 == 0){ m->mothurOut("Optimizing sequence: " + toString(count)); m->mothurOutEndLine(); } - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - unsigned long long pos = in.tellg(); - if ((pos == -1) || (pos >= filePos.end)) { break; } - #else - if (in.eof()) { break; } - #endif - - } - - in.close(); - - return count; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "driverCreateSummary"); - exit(1); - } -} -/**************************************************************************************************/ -int ScreenSeqsCommand::createProcessesCreateSummary(vector& startPosition, vector& endPosition, vector& seqLength, vector& ambigBases, vector& longHomoPolymer, vector& numNs, string filename) { - try { - - int process = 1; - int num = 0; - vector processIDS; - bool recalc = false; - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, numNs, fastafile, lines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = fastafile + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << startPosition.size() << endl; - for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl; - for (int k = 0; k < endPosition.size(); k++) { out << endPosition[k] << '\t'; } out << endl; - for (int k = 0; k < seqLength.size(); k++) { out << seqLength[k] << '\t'; } out << endl; - for (int k = 0; k < ambigBases.size(); k++) { out << ambigBases[k] << '\t'; } out << endl; - for (int k = 0; k < longHomoPolymer.size(); k++) { out << longHomoPolymer[k] << '\t'; } out << endl; - for (int k = 0; k < numNs.size(); k++) { out << numNs[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - //wait to die - for (int i=0;icontrol_pressed = false; - for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp")); - } - recalc = true; - break; - } - } - - if (recalc) { - //test line, also set recalc to true. - //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(contigsreport + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); - - vector positions; - lines.clear(); - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } - - startPosition.clear(); - endPosition.clear(); - seqLength.clear(); - ambigBases.clear(); - longHomoPolymer.clear(); - numNs.clear(); - - num = 0; - processIDS.resize(0); - process = 1; - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, numNs, fastafile, lines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = fastafile + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << startPosition.size() << endl; - for (int k = 0; k < startPosition.size(); k++) { out << startPosition[k] << '\t'; } out << endl; - for (int k = 0; k < endPosition.size(); k++) { out << endPosition[k] << '\t'; } out << endl; - for (int k = 0; k < seqLength.size(); k++) { out << seqLength[k] << '\t'; } out << endl; - for (int k = 0; k < ambigBases.size(); k++) { out << ambigBases[k] << '\t'; } out << endl; - for (int k = 0; k < longHomoPolymer.size(); k++) { out << longHomoPolymer[k] << '\t'; } out << endl; - for (int k = 0; k < numNs.size(); k++) { out << numNs[k] << '\t'; } out << endl; - - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - exit(0); - } - } - } - - - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, numNs, fastafile, lines[0]); - - //force parent to wait until all the processes are done - for (int i=0;iopenInputFile(tempFilename, in); - - int temp, tempNum; - in >> tempNum; m->gobble(in); num += tempNum; - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; startPosition.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; endPosition.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; seqLength.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; ambigBases.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; longHomoPolymer.push_back(temp); } m->gobble(in); - for (int k = 0; k < tempNum; k++) { in >> temp; numNs.push_back(temp); } m->gobble(in); - - in.close(); - m->mothurRemove(tempFilename); - } - - -#else - ////////////////////////////////////////////////////////////////////////////////////////////////////// - //Windows version shared memory, so be careful when passing variables through the seqSumData struct. - //Above fork() will clone, so memory is separate, but that's not the case with windows, - //Taking advantage of shared memory to allow both threads to add info to vectors. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - vector pDataArray; - DWORD dwThreadIdArray[processors-1]; - HANDLE hThreadArray[processors-1]; - - //Create processor worker threads. - for( int i=0; icount; - if (pDataArray[i]->count != pDataArray[i]->end) { - m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; - } - for (int k = 0; k < pDataArray[i]->startPosition.size(); k++) { startPosition.push_back(pDataArray[i]->startPosition[k]); } - for (int k = 0; k < pDataArray[i]->endPosition.size(); k++) { endPosition.push_back(pDataArray[i]->endPosition[k]); } - for (int k = 0; k < pDataArray[i]->seqLength.size(); k++) { seqLength.push_back(pDataArray[i]->seqLength[k]); } - for (int k = 0; k < pDataArray[i]->ambigBases.size(); k++) { ambigBases.push_back(pDataArray[i]->ambigBases[k]); } - for (int k = 0; k < pDataArray[i]->longHomoPolymer.size(); k++) { longHomoPolymer.push_back(pDataArray[i]->longHomoPolymer[k]); } - for (int k = 0; k < pDataArray[i]->numNs.size(); k++) { numNs.push_back(pDataArray[i]->numNs[k]); } - CloseHandle(hThreadArray[i]); - delete pDataArray[i]; - } - -#endif - return num; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "createProcessesCreateSummary"); - exit(1); - } -} - -//*************************************************************************************************************** - -int ScreenSeqsCommand::screenGroupFile(map badSeqNames){ - try { - ifstream inputGroups; - m->openInputFile(groupfile, inputGroups); - string seqName, group; - map::iterator it; - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); - variables["[extension]"] = m->getExtension(groupfile); - string goodGroupFile = getOutputFileName("group", variables); - outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); - ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); - - while(!inputGroups.eof()){ - if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodGroupFile); return 0; } - - inputGroups >> seqName; m->gobble(inputGroups); inputGroups >> group; m->gobble(inputGroups); - it = badSeqNames.find(seqName); - - if(it != badSeqNames.end()){ - badSeqNames.erase(it); - } - else{ - goodGroupOut << seqName << '\t' << group << endl; - } - } - - if (m->control_pressed) { goodGroupOut.close(); inputGroups.close(); m->mothurRemove(goodGroupFile); return 0; } - - //we were unable to remove some of the bad sequences - if (badSeqNames.size() != 0) { - for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your groupfile does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - - inputGroups.close(); - goodGroupOut.close(); - - if (m->control_pressed) { m->mothurRemove(goodGroupFile); } - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenGroupFile"); - exit(1); - } -} -//*************************************************************************************************************** -int ScreenSeqsCommand::screenCountFile(map badSeqNames){ - try { - ifstream in; - m->openInputFile(countfile, in); - map::iterator it; - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); - variables["[extension]"] = m->getExtension(countfile); - string goodCountFile = getOutputFileName("count", variables); - - outputNames.push_back(goodCountFile); outputTypes["count"].push_back(goodCountFile); - ofstream goodCountOut; m->openOutputFile(goodCountFile, goodCountOut); - - string headers = m->getline(in); m->gobble(in); - goodCountOut << headers << endl; - string test = headers; vector pieces = m->splitWhiteSpace(test); - - string name, rest; int thisTotal; rest = ""; - while (!in.eof()) { - - if (m->control_pressed) { goodCountOut.close(); in.close(); m->mothurRemove(goodCountFile); return 0; } - - in >> name; m->gobble(in); - in >> thisTotal; m->gobble(in); - if (pieces.size() > 2) { rest = m->getline(in); m->gobble(in); } - - it = badSeqNames.find(name); - - if(it != badSeqNames.end()){ - badSeqNames.erase(it); - } - else{ - goodCountOut << name << '\t' << thisTotal << '\t' << rest << endl; - } - } - if (m->control_pressed) { goodCountOut.close(); in.close(); m->mothurRemove(goodCountFile); return 0; } - - //we were unable to remove some of the bad sequences - if (badSeqNames.size() != 0) { - for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your count file does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - - in.close(); - goodCountOut.close(); - - //check for groups that have been eliminated - CountTable ct; - if (ct.testGroups(goodCountFile)) { - ct.readTable(goodCountFile, true, false); - ct.printTable(goodCountFile); + for (int i = 0; i < optimize.size(); i++) { + if (optimize[i] == "start") { startPos = sum.getStart(criteriaPercentile); m->mothurOut("Optimizing start to " + toString(startPos) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "end") { endPos = sum.getEnd(mincriteriaPercentile); m->mothurOut("Optimizing end to " + toString(endPos) + "."); m->mothurOutEndLine();} + else if (optimize[i] == "maxambig") { maxAmbig = sum.getAmbig(criteriaPercentile); m->mothurOut("Optimizing maxambig to " + toString(maxAmbig) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxhomop") { maxHomoP = sum.getAmbig(criteriaPercentile); m->mothurOut("Optimizing maxhomop to " + toString(maxHomoP) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "minlength") { minLength = sum.getLength(mincriteriaPercentile); m->mothurOut("Optimizing minlength to " + toString(minLength) + "."); m->mothurOutEndLine(); if (minLength < 0) { m->control_pressed = true; } } + else if (optimize[i] == "maxlength") { maxLength = sum.getLength(criteriaPercentile); m->mothurOut("Optimizing maxlength to " + toString(maxLength) + "."); m->mothurOutEndLine(); } + else if (optimize[i] == "maxn") { maxN = sum.getNumNs(criteriaPercentile); m->mothurOut("Optimizing maxn to " + toString(maxN) + "."); m->mothurOutEndLine(); } } - - if (m->control_pressed) { m->mothurRemove(goodCountFile); } - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenCountFile"); - exit(1); - } -} -//*************************************************************************************************************** - -int ScreenSeqsCommand::screenTaxonomy(map badSeqNames){ - try { - ifstream input; - m->openInputFile(taxonomy, input); - string seqName, tax; - map::iterator it; - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(taxonomy)); - variables["[extension]"] = m->getExtension(taxonomy); - string goodTaxFile = getOutputFileName("taxonomy", variables); - - outputNames.push_back(goodTaxFile); outputTypes["taxonomy"].push_back(goodTaxFile); - ofstream goodTaxOut; m->openOutputFile(goodTaxFile, goodTaxOut); - - while(!input.eof()){ - if (m->control_pressed) { goodTaxOut.close(); input.close(); m->mothurRemove(goodTaxFile); return 0; } - - input >> seqName; m->gobble(input); - tax = m->getline(input); m->gobble(input); - - it = badSeqNames.find(seqName); - - if(it != badSeqNames.end()){ badSeqNames.erase(it); } - else{ - goodTaxOut << seqName << '\t' << tax << endl; - } - } - - if (m->control_pressed) { goodTaxOut.close(); input.close(); m->mothurRemove(goodTaxFile); return 0; } - - //we were unable to remove some of the bad sequences - if (badSeqNames.size() != 0) { - for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your taxonomy file does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - - input.close(); - goodTaxOut.close(); - - if (m->control_pressed) { m->mothurRemove(goodTaxFile); return 0; } - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenTaxonomy"); - exit(1); - } - -} -//*************************************************************************************************************** - -int ScreenSeqsCommand::screenQual(map badSeqNames){ - try { - ifstream in; - m->openInputFile(qualfile, in); - map::iterator it; - map variables; - variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(qualfile)); - variables["[extension]"] = m->getExtension(qualfile); - string goodQualFile = getOutputFileName("qfile", variables); - - outputNames.push_back(goodQualFile); outputTypes["qfile"].push_back(goodQualFile); - ofstream goodQual; m->openOutputFile(goodQualFile, goodQual); - - while(!in.eof()){ - - if (m->control_pressed) { goodQual.close(); in.close(); m->mothurRemove(goodQualFile); return 0; } - string saveName = ""; - string name = ""; - string scores = ""; - - in >> name; - - if (name.length() != 0) { - saveName = name.substr(1); - while (!in.eof()) { - char c = in.get(); - if (c == 10 || c == 13 || c == -1){ break; } - else { name += c; } - } - m->gobble(in); - } - - while(in){ - char letter= in.get(); - if(letter == '>'){ in.putback(letter); break; } - else{ scores += letter; } - } - - m->gobble(in); - - it = badSeqNames.find(saveName); - - if(it != badSeqNames.end()){ - badSeqNames.erase(it); - }else{ - goodQual << name << endl << scores; - } - - m->gobble(in); - } - - in.close(); - goodQual.close(); - - //we were unable to remove some of the bad sequences - if (badSeqNames.size() != 0) { - for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - m->mothurOut("Your qual file does not include the sequence " + it->first + " please correct."); - m->mothurOutEndLine(); - } - } - - if (m->control_pressed) { m->mothurRemove(goodQualFile); return 0; } - return 0; - } catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "screenQual"); + m->errorOut(e, "ScreenSeqsCommand", "getSummary"); exit(1); } - } //********************************************************************************************************************** @@ -2312,7 +1091,10 @@ int ScreenSeqsCommand::driver(linePair filePos, string goodFName, string badAccn ifstream inFASTA; m->openInputFile(filename, inFASTA); - inFASTA.seekg(filePos.start); + inFASTA.seekg(filePos.start); + + //print header if you are process 0 + if (filePos.start == 0) { m->zapGremlins(inFASTA); m->gobble(inFASTA); } bool done = false; int count = 0; diff --git a/source/commands/screenseqscommand.h b/source/commands/screenseqscommand.h index 20a88445..9e758a7a 100644 --- a/source/commands/screenseqscommand.h +++ b/source/commands/screenseqscommand.h @@ -36,33 +36,21 @@ class ScreenSeqsCommand : public Command { private: vector lines; - int screenNameGroupFile(map); - int screenGroupFile(map); - int screenCountFile(map); - int screenAlignReport(map&); - int screenQual(map); - int screenTaxonomy(map); - int optimizeContigs(); int optimizeAlign(); int driver(linePair, string, string, string, map&); int createProcesses(string, string, string, map&); int screenSummary(map&); int screenContigs(map&); + int screenAlignReport(map&); int runFastaScreening(map&); int screenFasta(map&); int screenReports(map&); - int getSummary(vector&); - int createProcessesCreateSummary(vector&, vector&, vector&, vector&, vector&, vector&, string); - int driverCreateSummary(vector&, vector&, vector&, vector&, vector&, vector&, string, linePair); - int getSummaryReport(); - int driverContigsSummary(vector&, vector&, vector&, vector&, vector&, linePair); - int createProcessesContigsSummary(vector&, vector&, vector&, vector&, vector&, vector); - int driverAlignSummary(vector&, vector&, vector&, linePair); - int createProcessesAlignSummary(vector&, vector&, vector&, vector); + int getSummary(); + int getSummaryReport(); bool abort; - string fastafile, namefile, groupfile, alignreport, outputDir, qualfile, taxonomy, countfile, contigsreport, summaryfile, fileType; + string fastafile, namefile, groupfile, alignreport, outputDir, qualfile, taxonomy, countfile, contigsreport, summaryfile, fileType, badAccnosFile; int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, processors, minOverlap, oStart, oEnd, mismatches, maxN, maxInsert; float minSim, minScore, criteria; vector outputNames; @@ -107,62 +95,6 @@ struct sumData { //custom data structure for threads to use. // This is passed by void pointer so it can be any data type // that can be passed using a single void pointer (LPVOID). -struct contigsSumData { - vector ostartPosition; - vector oendPosition; - vector oLength; - vector omismatches; - vector numNs; - string filename, namefile, countfile; - unsigned long long start; - unsigned long long end; - int count; - MothurOut* m; - map nameMap; - - - contigsSumData(){} - contigsSumData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, string nf, string cf, map nam) { - filename = f; - namefile = nf; - countfile = cf; - m = mout; - start = st; - end = en; - nameMap = nam; - count = 0; - } -}; -/**************************************************************************************************/ -struct alignsData { - vector sims; - vector scores; - vector inserts; - string filename, namefile, countfile; - unsigned long long start; - unsigned long long end; - int count; - MothurOut* m; - map nameMap; - - - alignsData(){} - alignsData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, string nf, string cf, map nam) { - filename = f; - namefile = nf; - countfile = cf; - m = mout; - start = st; - end = en; - nameMap = nam; - count = 0; - } -}; - -/**************************************************************************************************/ -//custom data structure for threads to use. -// This is passed by void pointer so it can be any data type -// that can be passed using a single void pointer (LPVOID). struct sumScreenData { int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, maxN; unsigned long long start; @@ -195,189 +127,8 @@ struct sumScreenData { count = 0; } }; - - -/**************************************************************************************************/ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) #else -static DWORD WINAPI MySumThreadFunction(LPVOID lpParam){ - sumData* pDataArray; - pDataArray = (sumData*)lpParam; - - try { - ifstream in; - pDataArray->m->openInputFile(pDataArray->filename, in); - - //print header if you are process 0 - if ((pDataArray->start == 0) || (pDataArray->start == 1)) { - in.seekg(0); - pDataArray->m->zapGremlins(in); - }else { //this accounts for the difference in line endings. - in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); - } - - - for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process - - pDataArray->count++; - - if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } - - Sequence current(in); pDataArray->m->gobble(in); - - if (current.getName() != "") { - - int num = 1; - if ((pDataArray->namefile != "") || (pDataArray->countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = pDataArray->nameMap.find(current.getName()); - - if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " is not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - int numns = current.getNumNs(); - for (int i = 0; i < num; i++) { - pDataArray->startPosition.push_back(current.getStartPos()); - pDataArray->endPosition.push_back(current.getEndPos()); - pDataArray->seqLength.push_back(current.getNumBases()); - pDataArray->ambigBases.push_back(current.getAmbigBases()); - pDataArray->longHomoPolymer.push_back(current.getLongHomoPolymer()); - pDataArray->numNs.push_back(numns); - } - } - } - - in.close(); - - return 0; - - } - catch(exception& e) { - pDataArray->m->errorOut(e, "ScreenSeqsCommand", "MySumThreadFunction"); - exit(1); - } -} - -/**************************************************************************************************/ -static DWORD WINAPI MyContigsSumThreadFunction(LPVOID lpParam){ - contigsSumData* pDataArray; - pDataArray = (contigsSumData*)lpParam; - - try { - string name; - //Name Length Overlap_Length Overlap_Start Overlap_End MisMatches Num_Ns - int length, OLength, thisOStart, thisOEnd, numMisMatches, numns; - - ifstream in; - pDataArray->m->openInputFile(pDataArray->filename, in); - - //print header if you are process 0 - if ((pDataArray->start == 0) || (pDataArray->start == 1)) { - in.seekg(0); pDataArray->m->getline(in); pDataArray->m->gobble(in); - }else { //this accounts for the difference in line endings. - in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); - } - - - for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process - - pDataArray->count++; - - if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } - - //seqname start end nbases ambigs polymer numSeqs - in >> name >> length >> OLength >> thisOStart >> thisOEnd >> numMisMatches >> numns; pDataArray->m->gobble(in); - - int num = 1; - if ((pDataArray->namefile != "") || (pDataArray->countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = pDataArray->nameMap.find(name); - - if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + name + " is not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - for (int i = 0; i < num; i++) { - pDataArray->ostartPosition.push_back(thisOStart); - pDataArray->oendPosition.push_back(thisOEnd); - pDataArray->oLength.push_back(OLength); - pDataArray->omismatches.push_back(numMisMatches); - pDataArray->numNs.push_back(numns); - } - } - - in.close(); - - return 0; - - } - catch(exception& e) { - pDataArray->m->errorOut(e, "ScreenSeqsCommand", "MyContigsThreadFunction"); - exit(1); - } -} -/**************************************************************************************************/ -static DWORD WINAPI MyAlignsThreadFunction(LPVOID lpParam){ - alignsData* pDataArray; - pDataArray = (alignsData*)lpParam; - - try { - - string name, TemplateName, SearchMethod, AlignmentMethod; - //QueryName QueryLength TemplateName TemplateLength SearchMethod SearchScore AlignmentMethod QueryStart QueryEnd TemplateStart TemplateEnd PairwiseAlignmentLength GapsInQuery GapsInTemplate LongestInsert SimBtwnQuery&Template - //checking for minScore, maxInsert, minSim - int length, TemplateLength, QueryStart, QueryEnd, TemplateStart, TemplateEnd, PairwiseAlignmentLength, GapsInQuery, GapsInTemplate, LongestInsert; - float SearchScore, SimBtwnQueryTemplate; - - ifstream in; - pDataArray->m->openInputFile(pDataArray->filename, in); - - //print header if you are process 0 - if ((pDataArray->start == 0) || (pDataArray->start == 1)) { - in.seekg(0); pDataArray->m->zapGremlins(in); pDataArray->m->getline(in); pDataArray->m->gobble(in); - }else { //this accounts for the difference in line endings. - in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); - } - - for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process - - pDataArray->count++; - - if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } - - in >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; pDataArray->m->gobble(in); - //cout << i << '\t' << name << endl; - int num = 1; - if ((pDataArray->namefile != "") || (pDataArray->countfile !="")){ - //make sure this sequence is in the namefile, else error - map::iterator it = pDataArray->nameMap.find(name); - - if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + name + " is not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } - else { num = it->second; } - } - - //for each sequence this sequence represents - for (int i = 0; i < num; i++) { - pDataArray->sims.push_back(SimBtwnQueryTemplate); - pDataArray->scores.push_back(SearchScore); - pDataArray->inserts.push_back(LongestInsert); - } - } - - in.close(); - - return 0; - - } - catch(exception& e) { - pDataArray->m->errorOut(e, "ScreenSeqsCommand", "MyAlignsThreadFunction"); - exit(1); - } -} - /**************************************************************************************************/ static DWORD WINAPI MySumScreenThreadFunction(LPVOID lpParam){ sumScreenData* pDataArray; diff --git a/source/commands/seqsummarycommand.cpp b/source/commands/seqsummarycommand.cpp index 1705a7d8..c809ec1b 100644 --- a/source/commands/seqsummarycommand.cpp +++ b/source/commands/seqsummarycommand.cpp @@ -9,11 +9,15 @@ #include "seqsummarycommand.h" #include "counttable.h" +#include "summary.hpp" //********************************************************************************************************************** vector SeqSummaryCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pfasta); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaReport", "none", "none","summary",false,true,true); parameters.push_back(pfasta); + CommandParameter psummary("summary", "InputTypes", "", "", "FastaReport", "none", "none","",false,false,true); parameters.push_back(psummary); + CommandParameter pcontigsreport("contigsreport", "InputTypes", "", "", "FastaReport", "none", "none","",false,false,true); parameters.push_back(pcontigsreport); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "FastaReport", "none", "none","",false,false,true); parameters.push_back(palignreport); CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pname); CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pcount); CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); @@ -34,8 +38,8 @@ vector SeqSummaryCommand::setParameters(){ string SeqSummaryCommand::getHelpString(){ try { string helpString = ""; - helpString += "The summary.seqs command reads a fastafile and summarizes the sequences.\n"; - helpString += "The summary.seqs command parameters are fasta, name, count and processors, fasta is required, unless you have a valid current fasta file.\n"; + helpString += "The summary.seqs command reads a fastafile, summary, contigsreport or alignreport file and summarizes it.\n"; + helpString += "The summary.seqs command parameters are fasta, name, count, summary, contigsreport, alignreport and processors, fasta, contigsreport , alignreport or summary is required, unless you have a valid current files.\n"; helpString += "The name parameter allows you to enter a name file associated with your fasta file. \n"; helpString += "The count parameter allows you to enter a count file associated with your fasta file. \n"; helpString += "The summary.seqs command should be in the following format: \n"; @@ -113,7 +117,31 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } + + it = parameters.find("summary"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["summary"] = inputDir + it->second; } + } + + it = parameters.find("contigsreport"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["contigsreport"] = inputDir + it->second; } + } + it = parameters.find("alignreport"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["alignreport"] = inputDir + it->second; } + } + it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ @@ -138,12 +166,44 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { - fastafile = m->getFastaFile(); - if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } - else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } - }else { m->setFastaFile(fastafile); } + else if (fastafile == "not found") { fastafile = ""; } + else { m->setFastaFile(fastafile); } + summaryfile = validParameter.validFile(parameters, "summary", true); + if (summaryfile == "not open") { abort = true; } + else if (summaryfile == "not found") { summaryfile = ""; } + else { m->setSummaryFile(summaryfile); } + + contigsfile = validParameter.validFile(parameters, "contigsreport", true); + if (contigsfile == "not open") { abort = true; } + else if (contigsfile == "not found") { contigsfile = ""; } + else { m->setContigsReportFile(contigsfile); } + + alignfile = validParameter.validFile(parameters, "alignreport", true); + if (alignfile == "not open") { abort = true; } + else if (alignfile == "not found") { alignfile = ""; } + + if ((summaryfile == "") && (fastafile == "") && (contigsfile == "") && (alignfile == "")) { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { + summaryfile = m->getSummaryFile(); + if (summaryfile != "") { m->mothurOut("Using " + summaryfile + " as input file for the summary parameter."); m->mothurOutEndLine(); } + else { + contigsfile = m->getContigsReportFile(); + if (contigsfile != "") { m->mothurOut("Using " + contigsfile + " as input file for the contigsreport parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fasta, summary, contigsreport or alignreport file, one is required."); m->mothurOutEndLine(); abort = true; } + } + } + } + + if (((fastafile != "") && ((summaryfile != "") || (contigsfile != "") || (alignfile != ""))) || + ((summaryfile != "") && ((fastafile != "") || (contigsfile != "") || (alignfile != ""))) || + ((contigsfile != "") && ((summaryfile != "") || (fastafile != "") || (alignfile != ""))) || + ((alignfile != "") && ((summaryfile != "") || (contigsfile != "") || (fastafile != "")))) { + m->mothurOut("[ERROR]: you may only use one of the following: fasta, summary, contigsreport or alignreport."); m->mothurOutEndLine(); abort = true; + } + namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } @@ -188,604 +248,106 @@ int SeqSummaryCommand::execute(){ int start = time(NULL); - //set current fasta to fastafile - m->setFastaFile(fastafile); - map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string summaryFile = getOutputFileName("summary",variables); - - long long numSeqs = 0; - long long size = 0; - long long numUniques = 0; - map startPosition; - map endPosition; - map seqLength; - map ambigBases; - map longHomoPolymer; - - if (namefile != "") { nameMap = m->readNames(namefile); numUniques = nameMap.size(); } - else if (countfile != "") { - CountTable ct; - ct.readTable(countfile, false, false); - nameMap = ct.getNameMap(); - size = ct.getNumSeqs(); - numUniques = ct.getNumUniqueSeqs(); - } - - if (m->control_pressed) { return 0; } - - - vector positions; - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - positions = m->divideFile(fastafile, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } - #else - positions = m->setFilePosFasta(fastafile, numSeqs); - if (numSeqs < processors) { processors = numSeqs; } - - //figure out how many sequences you have to process - int numSeqsPerProcessor = numSeqs / processors; - for (int i = 0; i < processors; i++) { - int startIndex = i * numSeqsPerProcessor; - if(i == (processors - 1)){ numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor; } - lines.push_back(new linePair(positions[startIndex], numSeqsPerProcessor)); - } - #endif - - - if(processors == 1){ - numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, summaryFile, lines[0]); - }else{ - numSeqs = createProcessesCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, summaryFile); - } - - if (m->control_pressed) { return 0; } - - - - //set size - if (countfile != "") {}//already set - else if (namefile == "") { size = numSeqs; } - else { for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { size += it->second; } } + string outputFile = getOutputFileName("summary",variables); - if ((namefile != "") || (countfile != "")) { - string type = "count"; - if (namefile != "") { type = "name"; } - if (numSeqs != numUniques) { // do fasta and name/count files match - m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(numUniques) + " unique sequences, but your fasta file contains " + toString(numSeqs) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true; - } - } - - if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; } - - long long ptile0_25 = 1+(long long)(size * 0.025); //number of sequences at 2.5% - long long ptile25 = 1+(long long)(size * 0.250); //number of sequences at 25% - long long ptile50 = 1+(long long)(size * 0.500); - long long ptile75 = 1+(long long)(size * 0.750); - long long ptile97_5 = 1+(long long)(size * 0.975); - long long ptile100 = (long long)(size); - vector starts; starts.resize(7,0); vector ends; ends.resize(7,0); vector ambigs; ambigs.resize(7,0); vector lengths; lengths.resize(7,0); vector homops; homops.resize(7,0); - - //find means - long long meanStartPosition, meanEndPosition, meanSeqLength, meanAmbigBases, meanLongHomoPolymer; - meanStartPosition = 0; meanEndPosition = 0; meanSeqLength = 0; meanAmbigBases = 0; meanLongHomoPolymer = 0; - //minimum - if ((startPosition.begin())->first == -1) { starts[0] = 0; } - else {starts[0] = (startPosition.begin())->first; } - long long totalSoFar = 0; - //set all values to min - starts[1] = starts[0]; starts[2] = starts[0]; starts[3] = starts[0]; starts[4] = starts[0]; starts[5] = starts[0]; - int lastValue = 0; - for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { - int value = it->first; if (value == -1) { value = 0; } - meanStartPosition += (value*it->second); - totalSoFar += it->second; - if (((totalSoFar <= ptile0_25) && (totalSoFar > 1)) || ((lastValue < ptile0_25) && (totalSoFar > ptile0_25))){ starts[1] = value; } //save value - if (((totalSoFar <= ptile25) && (totalSoFar > ptile0_25)) || ((lastValue < ptile25) && (totalSoFar > ptile25))) { starts[2] = value; } //save value - if (((totalSoFar <= ptile50) && (totalSoFar > ptile25)) || ((lastValue < ptile50) && (totalSoFar > ptile50))) { starts[3] = value; } //save value - if (((totalSoFar <= ptile75) && (totalSoFar > ptile50)) || ((lastValue < ptile75) && (totalSoFar > ptile75))) { starts[4] = value; } //save value - if (((totalSoFar <= ptile97_5) && (totalSoFar > ptile75)) || ((lastValue < ptile97_5) && (totalSoFar > ptile97_5))) { starts[5] = value; } //save value - if ((totalSoFar <= ptile100) && (totalSoFar > ptile97_5)) { starts[6] = value; } //save value - lastValue = totalSoFar; - } - starts[6] = (startPosition.rbegin())->first; + string nameOrCount = countfile; + if (namefile != "") { nameOrCount = namefile; } - if ((endPosition.begin())->first == -1) { ends[0] = 0; } - else {ends[0] = (endPosition.begin())->first; } - totalSoFar = 0; - //set all values to min - ends[1] = ends[0]; ends[2] = ends[0]; ends[3] = ends[0]; ends[4] = ends[0]; ends[5] = ends[0]; - lastValue = 0; - for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { - int value = it->first; if (value == -1) { value = 0; } - meanEndPosition += (value*it->second); - totalSoFar += it->second; - - if (((totalSoFar <= ptile0_25) && (totalSoFar > 1)) || ((lastValue < ptile0_25) && (totalSoFar > ptile0_25))){ ends[1] = value; } //save value - if (((totalSoFar <= ptile25) && (totalSoFar > ptile0_25)) || ((lastValue < ptile25) && (totalSoFar > ptile25))) { ends[2] = value; } //save value - if (((totalSoFar <= ptile50) && (totalSoFar > ptile25)) || ((lastValue < ptile50) && (totalSoFar > ptile50))) { ends[3] = value; } //save value - if (((totalSoFar <= ptile75) && (totalSoFar > ptile50)) || ((lastValue < ptile75) && (totalSoFar > ptile75))) { ends[4] = value; } //save value - if (((totalSoFar <= ptile97_5) && (totalSoFar > ptile75)) || ((lastValue < ptile97_5) && (totalSoFar > ptile97_5))) { ends[5] = value; } //save value - if ((totalSoFar <= ptile100) && (totalSoFar > ptile97_5)) { ends[6] = value; } //save value - lastValue = totalSoFar; - } - ends[6] = (endPosition.rbegin())->first; + Summary sum; + if (fastafile != "") { sum.summarizeFasta(fastafile, nameOrCount, outputFile); } + else if (summaryfile != "") { sum.summarizeFastaSummary(summaryfile, nameOrCount); } + else if (contigsfile != "") { sum.summarizeContigsSummary(contigsfile, nameOrCount); } + else if (alignfile != "") { sum.summarizeAlignSummary(alignfile, nameOrCount); } + else { m->mothurOut("[ERROR]: Unknown type: you may only use one of the following: fasta, summary, contigsreport or alignreport."); m->mothurOutEndLine(); m->control_pressed = true; } + + if (m->control_pressed) { m->mothurRemove(outputFile); return 0; } - if ((seqLength.begin())->first == -1) { lengths[0] = 0; } - else {lengths[0] = (seqLength.begin())->first; } - //set all values to min - lengths[1] = lengths[0]; lengths[2] = lengths[0]; lengths[3] = lengths[0]; lengths[4] = lengths[0]; lengths[5] = lengths[0]; - totalSoFar = 0; - lastValue = 0; - for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { - int value = it->first; - meanSeqLength += (value*it->second); - totalSoFar += it->second; + long long size = sum.getTotalSeqs(); + long long numUniques = sum.getUniqueSeqs(); + + vector ptiles = sum.getDefaults(); + + if ((fastafile != "") || (summaryfile != "")) { + vector starts = sum.getStart(); + vector ends = sum.getEnd(); + vector ambigs = sum.getAmbig(); + vector lengths = sum.getLength(); + vector homops = sum.getHomop(); - if (((totalSoFar <= ptile0_25) && (totalSoFar > 1)) || ((lastValue < ptile0_25) && (totalSoFar > ptile0_25))){ lengths[1] = value; } //save value - if (((totalSoFar <= ptile25) && (totalSoFar > ptile0_25)) || ((lastValue < ptile25) && (totalSoFar > ptile25))) { lengths[2] = value; } //save value - if (((totalSoFar <= ptile50) && (totalSoFar > ptile25)) || ((lastValue < ptile50) && (totalSoFar > ptile50))) { lengths[3] = value; } //save value - if (((totalSoFar <= ptile75) && (totalSoFar > ptile50)) || ((lastValue < ptile75) && (totalSoFar > ptile75))) { lengths[4] = value; } //save value - if (((totalSoFar <= ptile97_5) && (totalSoFar > ptile75)) || ((lastValue < ptile97_5) && (totalSoFar > ptile97_5))) { lengths[5] = value; } //save value - if ((totalSoFar <= ptile100) && (totalSoFar > ptile97_5)) { lengths[6] = value; } //save value - lastValue = totalSoFar; - } - lengths[6] = (seqLength.rbegin())->first; - - if ((ambigBases.begin())->first == -1) { ambigs[0] = 0; } - else {ambigs[0] = (ambigBases.begin())->first; } - //set all values to min - ambigs[1] = ambigs[0]; ambigs[2] = ambigs[0]; ambigs[3] = ambigs[0]; ambigs[4] = ambigs[0]; ambigs[5] = ambigs[0]; - totalSoFar = 0; - lastValue = 0; - for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { - int value = it->first; - meanAmbigBases += (value*it->second); - totalSoFar += it->second; + m->mothurOutEndLine(); + m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer\tNumSeqs"); m->mothurOutEndLine(); + m->mothurOut("Minimum:\t" + toString(starts[0]) + "\t" + toString(ends[0]) + "\t" + toString(lengths[0]) + "\t" + toString(ambigs[0]) + "\t" + toString(homops[0]) + "\t" + toString(ptiles[0])); m->mothurOutEndLine(); + m->mothurOut("2.5%-tile:\t" + toString(starts[1]) + "\t" + toString(ends[1]) + "\t" + toString(lengths[1]) + "\t" + toString(ambigs[1]) + "\t" + toString(homops[1]) + "\t" + toString(ptiles[1])); m->mothurOutEndLine(); + m->mothurOut("25%-tile:\t" + toString(starts[2]) + "\t" + toString(ends[2]) + "\t" + toString(lengths[2]) + "\t" + toString(ambigs[2]) + "\t" + toString(homops[2]) + "\t" + toString(ptiles[2])); m->mothurOutEndLine(); + m->mothurOut("Median: \t" + toString(starts[3]) + "\t" + toString(ends[3]) + "\t" + toString(lengths[3]) + "\t" + toString(ambigs[3]) + "\t" + toString(homops[3]) + "\t" + toString(ptiles[3])); m->mothurOutEndLine(); + m->mothurOut("75%-tile:\t" + toString(starts[4]) + "\t" + toString(ends[4]) + "\t" + toString(lengths[4]) + "\t" + toString(ambigs[4]) + "\t" + toString(homops[4]) + "\t" + toString(ptiles[4])); m->mothurOutEndLine(); + m->mothurOut("97.5%-tile:\t" + toString(starts[5]) + "\t" + toString(ends[5]) + "\t" + toString(lengths[5]) + "\t" + toString(ambigs[5]) + "\t" + toString(homops[5]) + "\t" + toString(ptiles[5])); m->mothurOutEndLine(); + m->mothurOut("Maximum:\t" + toString(starts[6]) + "\t" + toString(ends[6]) + "\t" + toString(lengths[6]) + "\t" + toString(ambigs[6]) + "\t" + toString(homops[6]) + "\t" + toString(ptiles[6])); m->mothurOutEndLine(); + m->mothurOut("Mean:\t" + toString(starts[7]) + "\t" + toString(ends[7]) + "\t" + toString(lengths[7]) + "\t" + toString(ambigs[7]) + "\t" + toString(homops[7])); m->mothurOutEndLine(); + }else if (contigsfile != "") { + vector ostarts = sum.getOStart(); + vector oends = sum.getOEnd(); + vector length = sum.getLength(); + vector olengths = sum.getOLength(); + vector numns = sum.getNumNs(); + vector mismatches = sum.getMisMatches(); - if (((totalSoFar <= ptile0_25) && (totalSoFar > 1)) || ((lastValue < ptile0_25) && (totalSoFar > ptile0_25))){ ambigs[1] = value; } //save value - if (((totalSoFar <= ptile25) && (totalSoFar > ptile0_25)) || ((lastValue < ptile25) && (totalSoFar > ptile25))) { ambigs[2] = value; } //save value - if (((totalSoFar <= ptile50) && (totalSoFar > ptile25)) || ((lastValue < ptile50) && (totalSoFar > ptile50))) { ambigs[3] = value; } //save value - if (((totalSoFar <= ptile75) && (totalSoFar > ptile50)) || ((lastValue < ptile75) && (totalSoFar > ptile75))) { ambigs[4] = value; } //save value - if (((totalSoFar <= ptile97_5) && (totalSoFar > ptile75)) || ((lastValue < ptile97_5) && (totalSoFar > ptile97_5))) { ambigs[5] = value; } //save value - if ((totalSoFar <= ptile100) && (totalSoFar > ptile97_5)) { ambigs[6] = value; } //save value - lastValue = totalSoFar; - } - ambigs[6] = (ambigBases.rbegin())->first; - - - if ((longHomoPolymer.begin())->first == -1) { homops[0] = 0; } - else {homops[0] = (longHomoPolymer.begin())->first; } - //set all values to min - homops[1] = homops[0]; homops[2] = homops[0]; homops[3] = homops[0]; homops[4] = homops[0]; homops[5] = homops[0]; - totalSoFar = 0; - lastValue = 0; - for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { - int value = it->first; - meanLongHomoPolymer += (it->first*it->second); - totalSoFar += it->second; + m->mothurOutEndLine(); + m->mothurOut("\t\tLength\tOverlap_Length\tOverlap_Start\tOverlap_End\tMisMatches\tNum_Ns\tNumSeqs"); m->mothurOutEndLine(); + m->mothurOut("Minimum:\t" + toString(length[0]) + "\t" + toString(olengths[0]) + "\t" + toString(ostarts[0]) + "\t" + toString(oends[0]) + "\t" + toString(mismatches[0]) + "\t" + toString(numns[0]) + "\t" + toString(ptiles[0])); m->mothurOutEndLine(); + m->mothurOut("2.5%-tile:\t" + toString(length[1]) + "\t" + toString(olengths[1]) + "\t" + toString(ostarts[1]) + "\t" + toString(oends[1]) + "\t" + toString(mismatches[1]) + "\t" + toString(numns[1]) + "\t" + toString(ptiles[1])); m->mothurOutEndLine(); + m->mothurOut("25%-tile:\t" + toString(length[2]) + "\t" + toString(olengths[2]) + "\t" + toString(ostarts[2]) + "\t" + toString(oends[2]) + "\t" + toString(mismatches[2]) + "\t" + toString(numns[2]) + "\t" + toString(ptiles[2])); m->mothurOutEndLine(); + m->mothurOut("Median: \t" + toString(length[3]) + "\t" + toString(olengths[3]) + "\t" + toString(ostarts[3]) + "\t" + toString(oends[3]) + "\t" + toString(mismatches[3]) + "\t" + toString(numns[3]) + "\t" + toString(ptiles[3])); m->mothurOutEndLine(); + m->mothurOut("75%-tile:\t" + toString(length[4]) + "\t" + toString(olengths[4]) + "\t" + toString(ostarts[4]) + "\t" + toString(oends[4]) + "\t" + toString(mismatches[4]) + "\t" + toString(numns[4]) + "\t" + toString(ptiles[4])); m->mothurOutEndLine(); + m->mothurOut("97.5%-tile:\t" + toString(length[5]) + "\t" + toString(olengths[5]) + "\t" + toString(ostarts[5]) + "\t" + toString(oends[5]) + "\t" + toString(mismatches[5]) + "\t" + toString(numns[5]) + "\t" + toString(ptiles[5])); m->mothurOutEndLine(); + m->mothurOut("Maximum:\t" + toString(length[6]) + "\t" + toString(olengths[6]) + "\t" + toString(ostarts[6]) + "\t" + toString(oends[6]) + "\t" + toString(mismatches[6]) + "\t" + toString(numns[6]) + "\t" + toString(ptiles[6])); m->mothurOutEndLine(); + m->mothurOut("Mean:\t" + toString(length[7]) + "\t" + toString(olengths[7]) + "\t" + toString(ostarts[7]) + "\t" + toString(oends[7]) + "\t" + toString(mismatches[7]) + "\t" + toString(numns[7]) ); m->mothurOutEndLine(); + }else if (alignfile != "") { + vector sims = sum.getSims(); + vector scores = sum.getScores(); + vector inserts = sum.getNumInserts(); + vector length = sum.getLength(); - if (((totalSoFar <= ptile0_25) && (totalSoFar > 1)) || ((lastValue < ptile0_25) && (totalSoFar > ptile0_25))){ homops[1] = value; } //save value - if (((totalSoFar <= ptile25) && (totalSoFar > ptile0_25)) || ((lastValue < ptile25) && (totalSoFar > ptile25))) { homops[2] = value; } //save value - if (((totalSoFar <= ptile50) && (totalSoFar > ptile25)) || ((lastValue < ptile50) && (totalSoFar > ptile50))) { homops[3] = value; } //save value - if (((totalSoFar <= ptile75) && (totalSoFar > ptile50)) || ((lastValue < ptile75) && (totalSoFar > ptile75))) { homops[4] = value; } //save value - if (((totalSoFar <= ptile97_5) && (totalSoFar > ptile75)) || ((lastValue < ptile97_5) && (totalSoFar > ptile97_5))) { homops[5] = value; } //save value - if ((totalSoFar <= ptile100) && (totalSoFar > ptile97_5)) { homops[6] = value; } //save value - lastValue = totalSoFar; + m->mothurOutEndLine(); + m->mothurOut("\t\tLength\tSimBtwnQueryTemplate\tLongestInsert\tSearchScore\tNumSeqs"); m->mothurOutEndLine(); + m->mothurOut("Minimum:\t" + toString(length[0]) + "\t" + toString(sims[0]) + "\t" + toString(inserts[0]) + "\t" + toString(scores[0]) + "\t" + toString(ptiles[0])); m->mothurOutEndLine(); + m->mothurOut("2.5%-tile:\t" + toString(length[1]) + "\t" + toString(sims[1]) + "\t" + toString(inserts[1]) + "\t" + toString(scores[1]) + "\t" + toString(ptiles[1])); m->mothurOutEndLine(); + m->mothurOut("25%-tile:\t" + toString(length[2]) + "\t" + toString(sims[2]) + "\t" + toString(inserts[2]) + "\t" + toString(scores[2]) + "\t" + toString(ptiles[2])); m->mothurOutEndLine(); + m->mothurOut("Median: \t" + toString(length[3]) + "\t" + toString(sims[3]) + "\t" + toString(inserts[3]) + "\t" + toString(scores[3]) + "\t" + toString(ptiles[3])); m->mothurOutEndLine(); + m->mothurOut("75%-tile:\t" + toString(length[4]) + "\t" + toString(sims[4]) + "\t" + toString(inserts[4]) + "\t" + toString(scores[4]) + "\t" + toString(ptiles[4])); m->mothurOutEndLine(); + m->mothurOut("97.5%-tile:\t" + toString(length[5]) + "\t" + toString(sims[5]) + "\t" + toString(inserts[5]) + "\t" + toString(scores[5]) + "\t" + toString(ptiles[5])); m->mothurOutEndLine(); + m->mothurOut("Maximum:\t" + toString(length[6]) + "\t" + toString(sims[6]) + "\t" + toString(inserts[6]) + "\t" + toString(scores[6]) + "\t" + toString(ptiles[6])); m->mothurOutEndLine(); + m->mothurOut("Mean:\t" + toString(length[7]) + "\t" + toString(sims[7]) + "\t" + toString(inserts[7]) + "\t" + toString(scores[7])); m->mothurOutEndLine(); } - homops[6] = (longHomoPolymer.rbegin())->first; - - double meanstartPosition, meanendPosition, meanseqLength, meanambigBases, meanlongHomoPolymer; - - meanstartPosition = meanStartPosition / (double) size; meanendPosition = meanEndPosition /(double) size; meanlongHomoPolymer = meanLongHomoPolymer / (double) size; meanseqLength = meanSeqLength / (double) size; meanambigBases = meanAmbigBases /(double) size; - - if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; } - - m->mothurOutEndLine(); - m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer\tNumSeqs"); m->mothurOutEndLine(); - m->mothurOut("Minimum:\t" + toString(starts[0]) + "\t" + toString(ends[0]) + "\t" + toString(lengths[0]) + "\t" + toString(ambigs[0]) + "\t" + toString(homops[0]) + "\t" + toString(1)); m->mothurOutEndLine(); - m->mothurOut("2.5%-tile:\t" + toString(starts[1]) + "\t" + toString(ends[1]) + "\t" + toString(lengths[1]) + "\t" + toString(ambigs[1]) + "\t" + toString(homops[1]) + "\t" + toString(ptile0_25)); m->mothurOutEndLine(); - m->mothurOut("25%-tile:\t" + toString(starts[2]) + "\t" + toString(ends[2]) + "\t" + toString(lengths[2]) + "\t" + toString(ambigs[2]) + "\t" + toString(homops[2]) + "\t" + toString(ptile25)); m->mothurOutEndLine(); - m->mothurOut("Median: \t" + toString(starts[3]) + "\t" + toString(ends[3]) + "\t" + toString(lengths[3]) + "\t" + toString(ambigs[3]) + "\t" + toString(homops[3]) + "\t" + toString(ptile50)); m->mothurOutEndLine(); - m->mothurOut("75%-tile:\t" + toString(starts[4]) + "\t" + toString(ends[4]) + "\t" + toString(lengths[4]) + "\t" + toString(ambigs[4]) + "\t" + toString(homops[4]) + "\t" + toString(ptile75)); m->mothurOutEndLine(); - m->mothurOut("97.5%-tile:\t" + toString(starts[5]) + "\t" + toString(ends[5]) + "\t" + toString(lengths[5]) + "\t" + toString(ambigs[5]) + "\t" + toString(homops[5]) + "\t" + toString(ptile97_5)); m->mothurOutEndLine(); - m->mothurOut("Maximum:\t" + toString(starts[6]) + "\t" + toString(ends[6]) + "\t" + toString(lengths[6]) + "\t" + toString(ambigs[6]) + "\t" + toString(homops[6]) + "\t" + toString(ptile100)); m->mothurOutEndLine(); - m->mothurOut("Mean:\t" + toString(meanstartPosition) + "\t" + toString(meanendPosition) + "\t" + toString(meanseqLength) + "\t" + toString(meanambigBases) + "\t" + toString(meanlongHomoPolymer)); m->mothurOutEndLine(); - if ((namefile == "") && (countfile == "")) { m->mothurOut("# of Seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); } - else { m->mothurOut("# of unique seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); m->mothurOut("total # of seqs:\t" + toString(size)); m->mothurOutEndLine(); } - - if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; } - - m->mothurOutEndLine(); - m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(summaryFile); m->mothurOutEndLine(); outputNames.push_back(summaryFile); outputTypes["summary"].push_back(summaryFile); - m->mothurOutEndLine(); - - if ((namefile == "") && (countfile == "")) { m->mothurOut("It took " + toString(time(NULL) - start) + " secs to summarize " + toString(numSeqs) + " sequences.\n"); } - else{ m->mothurOut("It took " + toString(time(NULL) - start) + " secs to summarize " + toString(size) + " sequences.\n"); } - - //set fasta file as new current fastafile - string current = ""; - itTypes = outputTypes.find("summary"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSummaryFile(current); } - } - return 0; - } - catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "execute"); - exit(1); - } -} -/**************************************************************************************/ - long long SeqSummaryCommand::driverCreateSummary(map& startPosition, map& endPosition, map& seqLength, map& ambigBases, map& longHomoPolymer, string filename, string sumFile, linePair* filePos) { - try { - - ofstream outSummary; - m->openOutputFile(sumFile, outSummary); + if (m->control_pressed) { m->mothurRemove(outputFile); return 0; } - ifstream in; - m->openInputFile(filename, in); + if ((namefile == "") && (countfile == "") && (summaryfile == "")) { m->mothurOut("# of Seqs:\t" + toString(numUniques)); m->mothurOutEndLine(); } + else { m->mothurOut("# of unique seqs:\t" + toString(numUniques)); m->mothurOutEndLine(); m->mothurOut("total # of seqs:\t" + toString(size)); m->mothurOutEndLine(); } - in.seekg(filePos->start); - - //print header if you are process 0 - if (filePos->start == 0) { - outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs" << endl; - m->zapGremlins(in); m->gobble(in); - } - - bool done = false; - int count = 0; + if (((namefile == "") && (countfile == "")) && (summaryfile == "")) { m->mothurOut("\nIt took " + toString(time(NULL) - start) + " secs to summarize " + toString(numUniques) + " sequences.\n"); } + else{ m->mothurOut("\nIt took " + toString(time(NULL) - start) + " secs to summarize " + toString(size) + " sequences.\n"); } - - while (!done) { - - if (m->control_pressed) { in.close(); outSummary.close(); return 1; } - - if (m->debug) { m->mothurOut("[DEBUG]: count = " + toString(count) + "\n"); } - - Sequence current(in); m->gobble(in); - - if (current.getName() != "") { - - if (m->debug) { m->mothurOut("[DEBUG]: " + current.getName() + '\t' + toString(current.getNumBases()) + "\n"); } - - int num = 1; - if ((namefile != "") || (countfile != "")) { - //make sure this sequence is in the namefile, else error - map::iterator it = nameMap.find(current.getName()); - - if (it == nameMap.end()) { m->mothurOut("[ERROR]: '" + current.getName() + "' is not in your name or count file, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } - else { num = it->second; } - } - - int thisStartPosition = current.getStartPos(); - map::iterator it = startPosition.find(thisStartPosition); - if (it == startPosition.end()) { startPosition[thisStartPosition] = num; } //first finding of this start position, set count. - else { it->second += num; } //add counts - - int thisEndPosition = current.getEndPos(); - it = endPosition.find(thisEndPosition); - if (it == endPosition.end()) { endPosition[thisEndPosition] = num; } //first finding of this end position, set count. - else { it->second += num; } //add counts - - int thisSeqLength = current.getNumBases(); - it = seqLength.find(thisSeqLength); - if (it == seqLength.end()) { seqLength[thisSeqLength] = num; } //first finding of this length, set count. - else { it->second += num; } //add counts - - int thisAmbig = current.getAmbigBases(); - it = ambigBases.find(thisAmbig); - if (it == ambigBases.end()) { ambigBases[thisAmbig] = num; } //first finding of this ambig, set count. - else { it->second += num; } //add counts - - int thisHomoP = current.getLongHomoPolymer(); - it = longHomoPolymer.find(thisHomoP); - if (it == longHomoPolymer.end()) { longHomoPolymer[thisHomoP] = num; } //first finding of this homop, set count. - else { it->second += num; } //add counts - - count++; - outSummary << current.getName() << '\t'; - outSummary << thisStartPosition << '\t' << thisEndPosition << '\t'; - outSummary << thisSeqLength << '\t' << thisAmbig << '\t'; - outSummary << thisHomoP << '\t' << num << endl; - - if (m->debug) { m->mothurOut("[DEBUG]: " + current.getName() + '\t' + toString(num) + "\n"); } - } - - #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - unsigned long long pos = in.tellg(); - if ((pos == -1) || (pos >= filePos->end)) { break; } - #else - if (in.eof()) { break; } - #endif - } - - in.close(); - - return count; - } - catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "driverCreateSummary"); - exit(1); - } -} -/**************************************************************************************************/ - long long SeqSummaryCommand::createProcessesCreateSummary(map& startPosition, map& endPosition, map& seqLength, map& ambigBases, map& longHomoPolymer, string filename, string sumFile) { - try { - int process = 1; - int num = 0; - processIDS.clear(); - bool recalc = false; - -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, sumFile + m->mothurGetpid(process) + ".temp", lines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = fastafile + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << startPosition.size() << endl; - for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << endPosition.size() << endl; - for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << seqLength.size() << endl; - for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << ambigBases.size() << endl; - for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << longHomoPolymer.size() << endl; - for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - //wait to die - for (int i=0;icontrol_pressed = false; - for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp")); - m->mothurRemove(sumFile + (toString(processIDS[i]) + ".temp")); - } - recalc = true; - break; - } - } - - if (recalc) { - //test line, also set recalc to true. - //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); - - //redo file divide - for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - vector positions = m->divideFile(filename, processors); - for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } - - startPosition.clear(); - endPosition.clear(); - seqLength.clear(); - ambigBases.clear(); - longHomoPolymer.clear(); - - num = 0; - processIDS.resize(0); - process = 1; - - //loop through and create all the processes you want - while (process != processors) { - pid_t pid = fork(); - - if (pid > 0) { - processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later - process++; - }else if (pid == 0){ - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, sumFile + m->mothurGetpid(process) + ".temp", lines[process]); - - //pass numSeqs to parent - ofstream out; - string tempFile = fastafile + m->mothurGetpid(process) + ".num.temp"; - m->openOutputFile(tempFile, out); - - out << num << endl; - out << startPosition.size() << endl; - for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << endPosition.size() << endl; - for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << seqLength.size() << endl; - for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << ambigBases.size() << endl; - for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } - out << longHomoPolymer.size() << endl; - for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } - out.close(); - - exit(0); - }else { - m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); - for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } - exit(0); - } + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + if ((summaryfile == "") && (contigsfile == "") && (alignfile == "")) { m->mothurOut(outputFile); m->mothurOutEndLine(); outputNames.push_back(outputFile); outputTypes["summary"].push_back(outputFile); + //set fasta file as new current fastafile + string current = ""; + itTypes = outputTypes.find("summary"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSummaryFile(current); } } } + m->mothurOutEndLine(); - - //do your part - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, sumFile, lines[0]); - - //force parent to wait until all the processes are done - for (int i=0;iopenInputFile(tempFilename, in); - - long long tempNum; - in >> tempNum; m->gobble(in); num += tempNum; - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { - long long first, second; - in >> first; m->gobble(in); in >> second; m->gobble(in); - map::iterator it = startPosition.find(first); - if (it == startPosition.end()) { startPosition[first] = second; } //first finding of this start position, set count. - else { it->second += second; } //add counts - } - m->gobble(in); - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { - long long first, second; - in >> first; m->gobble(in); in >> second; m->gobble(in); - map::iterator it = endPosition.find(first); - if (it == endPosition.end()) { endPosition[first] = second; } //first finding of this end position, set count. - else { it->second += second; } //add counts - } - m->gobble(in); - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { - long long first, second; - in >> first; m->gobble(in); in >> second; m->gobble(in); - map::iterator it = seqLength.find(first); - if (it == seqLength.end()) { seqLength[first] = second; } //first finding of this end position, set count. - else { it->second += second; } //add counts - } - m->gobble(in); - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { - long long first, second; - in >> first; m->gobble(in); in >> second; m->gobble(in); - map::iterator it = ambigBases.find(first); - if (it == ambigBases.end()) { ambigBases[first] = second; } //first finding of this end position, set count. - else { it->second += second; } //add counts - } - m->gobble(in); - in >> tempNum; m->gobble(in); - for (int k = 0; k < tempNum; k++) { - long long first, second; - in >> first; m->gobble(in); in >> second; m->gobble(in); - map::iterator it = longHomoPolymer.find(first); - if (it == longHomoPolymer.end()) { longHomoPolymer[first] = second; } //first finding of this end position, set count. - else { it->second += second; } //add counts - } - m->gobble(in); - - in.close(); - m->mothurRemove(tempFilename); - - m->appendFiles((sumFile + toString(processIDS[i]) + ".temp"), sumFile); - m->mothurRemove((sumFile + toString(processIDS[i]) + ".temp")); - } - -#else - ////////////////////////////////////////////////////////////////////////////////////////////////////// - //Windows version shared memory, so be careful when passing variables through the seqSumData struct. - //Above fork() will clone, so memory is separate, but that's not the case with windows, - //Taking advantage of shared memory to allow both threads to add info to vectors. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - vector pDataArray; - DWORD dwThreadIdArray[processors-1]; - HANDLE hThreadArray[processors-1]; - - bool hasNameMap = false; - if ((namefile !="") || (countfile != "")) { hasNameMap = true; } - - //Create processor worker threads. - for( int i=0; istart, lines[i]->end, hasNameMap, nameMap); - pDataArray.push_back(tempSum); - - //MySeqSumThreadFunction is in header. It must be global or static to work with the threads. - //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier - hThreadArray[i] = CreateThread(NULL, 0, MySeqSumThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]); - } - - //do your part - num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, (sumFile+toString(processors-1)+".temp"), lines[processors-1]); - processIDS.push_back(processors-1); - - //Wait until all threads have terminated. - WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); - - //Close all thread handles and free memory allocations. - for(int i=0; i < pDataArray.size(); i++){ - num += pDataArray[i]->count; - if (pDataArray[i]->count != pDataArray[i]->end) { - m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; - } - for (map::iterator it = pDataArray[i]->startPosition.begin(); it != pDataArray[i]->startPosition.end(); it++) { - map::iterator itMain = startPosition.find(it->first); - if (itMain == startPosition.end()) { //newValue - startPosition[it->first] = it->second; - }else { itMain->second += it->second; } //merge counts - } - for (map::iterator it = pDataArray[i]->endPosition.begin(); it != pDataArray[i]->endPosition.end(); it++) { - map::iterator itMain = endPosition.find(it->first); - if (itMain == endPosition.end()) { //newValue - endPosition[it->first] = it->second; - }else { itMain->second += it->second; } //merge counts - } - for (map::iterator it = pDataArray[i]->seqLength.begin(); it != pDataArray[i]->seqLength.end(); it++) { - map::iterator itMain = seqLength.find(it->first); - if (itMain == seqLength.end()) { //newValue - seqLength[it->first] = it->second; - }else { itMain->second += it->second; } //merge counts - } - for (map::iterator it = pDataArray[i]->ambigBases.begin(); it != pDataArray[i]->ambigBases.end(); it++) { - map::iterator itMain = ambigBases.find(it->first); - if (itMain == ambigBases.end()) { //newValue - ambigBases[it->first] = it->second; - }else { itMain->second += it->second; } //merge counts - } - for (map::iterator it = pDataArray[i]->longHomoPolymer.begin(); it != pDataArray[i]->longHomoPolymer.end(); it++) { - map::iterator itMain = longHomoPolymer.find(it->first); - if (itMain == longHomoPolymer.end()) { //newValue - longHomoPolymer[it->first] = it->second; - }else { itMain->second += it->second; } //merge counts - } - CloseHandle(hThreadArray[i]); - delete pDataArray[i]; - } - - //append files - for(int i=0;iappendFiles((sumFile + toString(processIDS[i]) + ".temp"), sumFile); - m->mothurRemove((sumFile + toString(processIDS[i]) + ".temp")); - } -#endif - return num; + return 0; } catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "createProcessesCreateSummary"); + m->errorOut(e, "SeqSummaryCommand", "execute"); exit(1); } } -/**********************************************************************************************************************/ - - +//*************************************************************************************************************** diff --git a/source/commands/seqsummarycommand.h b/source/commands/seqsummarycommand.h index a54bd06a..024eec55 100644 --- a/source/commands/seqsummarycommand.h +++ b/source/commands/seqsummarycommand.h @@ -35,142 +35,11 @@ class SeqSummaryCommand : public Command { void help() { m->mothurOut(getHelpString()); } private: bool abort; - string fastafile, outputDir, namefile, countfile; + string fastafile, outputDir, namefile, countfile, summaryfile, contigsfile, alignfile; int processors; vector outputNames; - map nameMap; - - vector lines; - vector processIDS; - - long long createProcessesCreateSummary(map&, map&, map&, map&, map&, string, string); - long long driverCreateSummary(map&, map&, map&, map&, map&, string, string, linePair*); - - -}; - -/**************************************************************************************************/ -//custom data structure for threads to use. -// This is passed by void pointer so it can be any data type -// that can be passed using a single void pointer (LPVOID). -struct seqSumData { - map startPosition; - map endPosition; - map seqLength; - map ambigBases; - map longHomoPolymer; - string filename; - string sumFile; - unsigned long long start; - unsigned long long end; - int count; - MothurOut* m; - bool hasNameMap; - map nameMap; - - - seqSumData(){} - seqSumData(string f, string sf, MothurOut* mout, unsigned long long st, unsigned long long en, bool na, map nam) { - filename = f; - sumFile = sf; - m = mout; - start = st; - end = en; - hasNameMap = na; - nameMap = nam; - count = 0; - } }; -/**************************************************************************************************/ -#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) -#else -static DWORD WINAPI MySeqSumThreadFunction(LPVOID lpParam){ - seqSumData* pDataArray; - pDataArray = (seqSumData*)lpParam; - - try { - ofstream outSummary; - pDataArray->m->openOutputFile(pDataArray->sumFile, outSummary); - - ifstream in; - pDataArray->m->openInputFile(pDataArray->filename, in); - - //print header if you are process 0 - if ((pDataArray->start == 0) || (pDataArray->start == 1)) { - outSummary << "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs" << endl; - in.seekg(0); - pDataArray->m->zapGremlins(in); - }else { //this accounts for the difference in line endings. - in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); - } - - for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process - - if (pDataArray->m->control_pressed) { in.close(); outSummary.close(); pDataArray->count = 1; return 1; } - - Sequence current(in); pDataArray->m->gobble(in); - - if (current.getName() != "") { - - int num = 1; - if (pDataArray->hasNameMap){ - //make sure this sequence is in the namefile, else error - map::iterator it = pDataArray->nameMap.find(current.getName()); - - if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " is not in your name or count file, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } - else { num = it->second; } - } - - int thisStartPosition = current.getStartPos(); - map::iterator it = pDataArray->startPosition.find(thisStartPosition); - if (it == pDataArray->startPosition.end()) { pDataArray->startPosition[thisStartPosition] = num; } //first finding of this start position, set count. - else { it->second += num; } //add counts - - int thisEndPosition = current.getEndPos(); - it = pDataArray->endPosition.find(thisEndPosition); - if (it == pDataArray->endPosition.end()) { pDataArray->endPosition[thisEndPosition] = num; } //first finding of this end position, set count. - else { it->second += num; } //add counts - - int thisSeqLength = current.getNumBases(); - it = pDataArray->seqLength.find(thisSeqLength); - if (it == pDataArray->seqLength.end()) { pDataArray->seqLength[thisSeqLength] = num; } //first finding of this length, set count. - else { it->second += num; } //add counts - - int thisAmbig = current.getAmbigBases(); - it = pDataArray->ambigBases.find(thisAmbig); - if (it == pDataArray->ambigBases.end()) { pDataArray->ambigBases[thisAmbig] = num; } //first finding of this ambig, set count. - else { it->second += num; } //add counts - - int thisHomoP = current.getLongHomoPolymer(); - it = pDataArray->longHomoPolymer.find(thisHomoP); - if (it == pDataArray->longHomoPolymer.end()) { pDataArray->longHomoPolymer[thisHomoP] = num; } //first finding of this homop, set count. - else { it->second += num; } //add counts - - pDataArray->count++; - outSummary << current.getName() << '\t'; - outSummary << thisStartPosition << '\t' << thisEndPosition << '\t'; - outSummary << thisSeqLength << '\t' << thisAmbig << '\t'; - outSummary << thisHomoP << '\t' << num << endl; - } - } - - in.close(); - outSummary.close(); - - return 0; - - } - catch(exception& e) { - pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqSumThreadFunction"); - exit(1); - } -} -#endif - - - - #endif /**************************************************************************************************/ diff --git a/source/commands/setdircommand.cpp b/source/commands/setdircommand.cpp index 6e79a082..640cc0f6 100644 --- a/source/commands/setdircommand.cpp +++ b/source/commands/setdircommand.cpp @@ -120,7 +120,7 @@ SetDirectoryCommand::SetDirectoryCommand(string option) { if (debug) { m->mothurOut("Setting [DEBUG] flag.\n"); } if (seed) { - srand(random); + m->setRandomSeed(random); m->mothurOut("Setting random seed to " + toString(random) + ".\n\n"); } diff --git a/source/commands/setseedcommand.cpp b/source/commands/setseedcommand.cpp index 1bbcd335..626c523b 100644 --- a/source/commands/setseedcommand.cpp +++ b/source/commands/setseedcommand.cpp @@ -86,7 +86,7 @@ int SetSeedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - srand(random); + m->setRandomSeed(random); m->mothurOut("Setting random seed to " + toString(random) + ".\n\n"); return 0; diff --git a/source/commands/sharedcommand.cpp b/source/commands/sharedcommand.cpp index f3e643c6..3a00d737 100644 --- a/source/commands/sharedcommand.cpp +++ b/source/commands/sharedcommand.cpp @@ -475,18 +475,14 @@ int SharedCommand::createSharedFromBiom() { m->currentSharedBinLabels = otuNames; //read data - vector lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size()); - - eliminateZeroOTUS(lookup); + SharedRAbundVectors* lookup = readData(matrixFormat, thisLine, matrixElementType, groupNames, otuNames.size()); + lookup->eliminateZeroOTUS(); - m->mothurOutEndLine(); m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - lookup[0]->printHeaders(out); + m->mothurOutEndLine(); m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + lookup->printHeaders(out); printSharedData(lookup, out); } - //for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - //out.close(); - if (m->control_pressed) { m->mothurRemove(filename); return 0; } return 0; @@ -497,18 +493,18 @@ int SharedCommand::createSharedFromBiom() { } } //********************************************************************************************************************** -vector SharedCommand::readData(string matrixFormat, string line, string matrixElementType, vector& groupNames, int numOTUs) { +SharedRAbundVectors* SharedCommand::readData(string matrixFormat, string line, string matrixElementType, vector& groupNames, int numOTUs) { try { - vector lookup; - + SharedRAbundVectors* lookup = new SharedRAbundVectors(); + //creates new sharedRAbunds for (int i = 0; i < groupNames.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(numOTUs); //sets all abunds to 0 - temp->setLabel("userLabel"); temp->setGroup(groupNames[i]); - lookup.push_back(temp); + lookup->push_back(temp); } + lookup->setLabels("userLabel"); bool dataStart = false; bool inBrackets = false; @@ -538,11 +534,11 @@ vector SharedCommand::readData(string matrixFormat, string if (matrixFormat == "dense") { //sanity check - if (nums.size() != lookup.size()) { m->mothurOut("[ERROR]: trouble parsing OTU data. OTU " + toString(otuCount) + " causing errors.\n"); m->control_pressed = true; } + if (nums.size() != lookup->getNumGroups()) { m->mothurOut("[ERROR]: trouble parsing OTU data. OTU " + toString(otuCount) + " causing errors.\n"); m->control_pressed = true; } //set abundances for this otu //nums contains [abundSample0, abundSample1, abundSample2, ...] for current OTU - for (int j = 0; j < lookup.size(); j++) { lookup[j]->set(otuCount, nums[j], groupNames[j]); } + for (int j = 0; j < groupNames.size(); j++) { lookup->set(otuCount, nums[j], groupNames[j]); } otuCount++; }else { @@ -550,7 +546,7 @@ vector SharedCommand::readData(string matrixFormat, string if (nums.size() != 3) { m->mothurOut("[ERROR]: trouble parsing OTU data.\n"); m->control_pressed = true; } //nums contains [otuNum, sampleNum, abundance] - lookup[nums[1]]->set(nums[0], nums[2], groupNames[nums[1]]); + lookup->set(nums[0], nums[2], groupNames[nums[1]]); } nums.clear(); } @@ -568,23 +564,7 @@ vector SharedCommand::readData(string matrixFormat, string } } - - SharedUtil util; - bool remove = false; - if (pickedGroups) { - for (int i = 0; i < lookup.size(); i++) { - //if this sharedrabund is not from a group the user wants then delete it. - if (util.isValidGroup(lookup[i]->getGroup(), m->getGroups()) == false) { - remove = true; - delete lookup[i]; lookup[i] = NULL; - lookup.erase(lookup.begin()+i); - i--; - } - } - } - - if (remove) { eliminateZeroOTUS(lookup); } - + if (pickedGroups) { lookup->eliminateZeroOTUS(); } return lookup; } @@ -594,63 +574,6 @@ vector SharedCommand::readData(string matrixFormat, string } } //********************************************************************************************************************** -int SharedCommand::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "SharedCommand", "eliminateZeroOTUS"); - exit(1); - } -} -//********************************************************************************************************************** int SharedCommand::getDims(string line, int& shapeNumRows, int& shapeNumCols) { try { //get shape @@ -832,7 +755,7 @@ int SharedCommand::createSharedFromListGroup() { InputData input(listfile, "shared"); SharedListVector* SharedList = input.getSharedListVector(); string lastLabel = SharedList->getLabel(); - vector lookup; + SharedRAbundVectors* lookup; if (m->control_pressed) { delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } @@ -903,11 +826,11 @@ int SharedCommand::createSharedFromListGroup() { lookup = SharedList->getSharedRAbundVector(); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; if (!pickedGroups) { out.close(); m->mothurRemove(filename); } return 0; } @@ -919,24 +842,24 @@ int SharedCommand::createSharedFromListGroup() { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); filename = getOutputFileName("shared",variables); outputNames.push_back(filename); outputTypes["shared"].push_back(filename); ofstream out2; m->openOutputFile(filename, out2); vector savedLabels = m->currentSharedBinLabels; - eliminateZeroOTUS(lookup); - lookup[0]->printHeaders(out2); + lookup->eliminateZeroOTUS(); + lookup->printHeaders(out2); printSharedData(lookup, out2); out2.close(); m->currentSharedBinLabels = savedLabels; //restore old labels }else { - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } printSharedData(lookup, out); //prints info to the .shared file } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; processedLabels.insert(SharedList->getLabel()); userLabels.erase(SharedList->getLabel()); @@ -949,11 +872,11 @@ int SharedCommand::createSharedFromListGroup() { SharedList = input.getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; if (!pickedGroups) { out.close(); m->mothurRemove(filename); } return 0; } @@ -965,25 +888,24 @@ int SharedCommand::createSharedFromListGroup() { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); filename = getOutputFileName("shared",variables); outputNames.push_back(filename); outputTypes["shared"].push_back(filename); ofstream out2; m->openOutputFile(filename, out2); vector savedLabels = m->currentSharedBinLabels; - eliminateZeroOTUS(lookup); - lookup[0]->printHeaders(out2); + lookup->eliminateZeroOTUS(); + lookup->printHeaders(out2); printSharedData(lookup, out2); out2.close(); m->currentSharedBinLabels = savedLabels; //restore old labels }else { - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } printSharedData(lookup, out); //prints info to the .shared file } - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; processedLabels.insert(SharedList->getLabel()); userLabels.erase(SharedList->getLabel()); @@ -1014,7 +936,7 @@ int SharedCommand::createSharedFromListGroup() { SharedList = input.getSharedListVector(lastLabel); //get new list vector to process lookup = SharedList->getSharedRAbundVector(); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); if (m->control_pressed) { if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } @@ -1029,24 +951,24 @@ int SharedCommand::createSharedFromListGroup() { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = lookup->getLabel(); filename = getOutputFileName("shared",variables); outputNames.push_back(filename); outputTypes["shared"].push_back(filename); ofstream out2; m->openOutputFile(filename, out2); vector savedLabels = m->currentSharedBinLabels; - eliminateZeroOTUS(lookup); - lookup[0]->printHeaders(out2); + lookup->eliminateZeroOTUS(); + lookup->printHeaders(out2); printSharedData(lookup, out2); out2.close(); m->currentSharedBinLabels = savedLabels; //restore old labels }else { - if (!m->printedSharedHeaders) { lookup[0]->printHeaders(out); } + if (!m->printedSharedHeaders) { lookup->printHeaders(out); } printSharedData(lookup, out); //prints info to the .shared file } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; delete SharedList; } @@ -1067,31 +989,21 @@ int SharedCommand::createSharedFromListGroup() { } } //********************************************************************************************************************** -void SharedCommand::printSharedData(vector thislookup, ofstream& out) { +void SharedCommand::printSharedData(SharedRAbundVectors*& thislookup, ofstream& out) { try { if (order.size() == 0) { //user has not specified an order so do aplabetically - sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); - m->clearGroups(); - vector Groups; - - //initialize bin values - for (int i = 0; i < thislookup.size(); i++) { - out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; - thislookup[i]->print(out); - - Groups.push_back(thislookup[i]->getGroup()); - } - m->setGroups(Groups); + vector Groups = thislookup->getNamesGroups(); + thislookup->print(out); + m->setGroups(Groups); }else{ //create a map from groupName to each sharedrabund map myMap; map::iterator myIt; + vector data = thislookup->getSharedRAbundVectors(); - for (int i = 0; i < thislookup.size(); i++) { - myMap[thislookup[i]->getGroup()] = thislookup[i]; - } + for (int i = 0; i < data.size(); i++) { myMap[data[i]->getGroup()] = data[i]; } m->clearGroups(); vector Groups; @@ -1111,7 +1023,7 @@ void SharedCommand::printSharedData(vector thislookup, ofst } m->setGroups(Groups); - + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); } } diff --git a/source/commands/sharedcommand.h b/source/commands/sharedcommand.h index 9b5ab4ea..5320101c 100644 --- a/source/commands/sharedcommand.h +++ b/source/commands/sharedcommand.h @@ -40,17 +40,16 @@ class SharedCommand : public Command { void help() { m->mothurOut(getHelpString()); } private: - void printSharedData(vector, ofstream&); + void printSharedData(SharedRAbundVectors*&, ofstream&); int readOrderFile(); bool isValidGroup(string, vector); - int eliminateZeroOTUS(vector&); int ListGroupSameSeqs(vector&, SharedListVector*); int createSharedFromListGroup(); int createSharedFromBiom(); string getTag(string&); vector readRows(string, int&); int getDims(string, int&, int&); - vector readData(string, string, string, vector&, int); + SharedRAbundVectors* readData(string, string, string, vector&, int); vector Groups, outputNames, order; set labels; diff --git a/source/commands/shhhseqscommand.cpp b/source/commands/shhhseqscommand.cpp index 206cf249..31e446ae 100644 --- a/source/commands/shhhseqscommand.cpp +++ b/source/commands/shhhseqscommand.cpp @@ -581,41 +581,48 @@ vector ShhhSeqsCommand::driverGroups(SequenceParser& parser, string newF start = time(NULL); if (m->control_pressed) { return mapFileNames; } - - m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[i] + ":"); m->mothurOutEndLine(); - - map thisNameMap; - thisNameMap = parser.getNameMap(groups[i]); - vector thisSeqs = parser.getSeqs(groups[i]); - - vector sequences; - vector uniqueNames; - vector redundantNames; - vector seqFreq; - - seqNoise noise; - correctDist* correct = new correctDist(1); //we use one processor since we already split up the work load. - - //load this groups info in order - loadData(correct, noise, sequences, uniqueNames, redundantNames, seqFreq, thisNameMap, thisSeqs); - if (m->control_pressed) { return mapFileNames; } - - //calc distances for cluster - string distFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + groups[i] + ".shhh.dist"; - correct->execute(distFileName); - delete correct; - - if (m->control_pressed) { m->mothurRemove(distFileName); return mapFileNames; } - - driver(noise, sequences, uniqueNames, redundantNames, seqFreq, distFileName, newFFile+groups[i], newNFile+groups[i], newMFile+groups[i]+".map"); - - if (m->control_pressed) { return mapFileNames; } - - m->appendFiles(newFFile+groups[i], newFFile); m->mothurRemove(newFFile+groups[i]); - m->appendFiles(newNFile+groups[i], newNFile); m->mothurRemove(newNFile+groups[i]); - mapFileNames.push_back(newMFile+groups[i]+".map"); - - m->mothurOut("It took " + toString(time(NULL) - start) + " secs to process group " + groups[i] + "."); m->mothurOutEndLine(); + + string lowerCaseName = groups[i]; + for (int j = 0; j < lowerCaseName.length(); j++) { lowerCaseName[j] = tolower(lowerCaseName[j]); } + + if (lowerCaseName == "ignore") { } + else { + + m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[i] + ":"); m->mothurOutEndLine(); + + map thisNameMap; + thisNameMap = parser.getNameMap(groups[i]); + vector thisSeqs = parser.getSeqs(groups[i]); + + vector sequences; + vector uniqueNames; + vector redundantNames; + vector seqFreq; + + seqNoise noise; + correctDist* correct = new correctDist(1); //we use one processor since we already split up the work load. + + //load this groups info in order + loadData(correct, noise, sequences, uniqueNames, redundantNames, seqFreq, thisNameMap, thisSeqs); + if (m->control_pressed) { return mapFileNames; } + + //calc distances for cluster + string distFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + groups[i] + ".shhh.dist"; + correct->execute(distFileName); + delete correct; + + if (m->control_pressed) { m->mothurRemove(distFileName); return mapFileNames; } + + driver(noise, sequences, uniqueNames, redundantNames, seqFreq, distFileName, newFFile+groups[i], newNFile+groups[i], newMFile+groups[i]+".map"); + + if (m->control_pressed) { return mapFileNames; } + + m->appendFiles(newFFile+groups[i], newFFile); m->mothurRemove(newFFile+groups[i]); + m->appendFiles(newNFile+groups[i], newNFile); m->mothurRemove(newNFile+groups[i]); + mapFileNames.push_back(newMFile+groups[i]+".map"); + + m->mothurOut("It took " + toString(time(NULL) - start) + " secs to process group " + groups[i] + "."); m->mothurOutEndLine(); + } } return mapFileNames; diff --git a/source/commands/shhhseqscommand.h b/source/commands/shhhseqscommand.h index 4c11638a..a78d7e89 100644 --- a/source/commands/shhhseqscommand.h +++ b/source/commands/shhhseqscommand.h @@ -115,206 +115,212 @@ static DWORD WINAPI MyShhhSeqsThreadFunction(LPVOID lpParam){ if (pDataArray->m->control_pressed) { return 0; } - pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("Processing group " + pDataArray->groups[k] + ":"); pDataArray->m->mothurOutEndLine(); - - map thisNameMap; - thisNameMap = parser.getNameMap(pDataArray->groups[k]); - vector thisSeqs = parser.getSeqs(pDataArray->groups[k]); - - if (pDataArray->m->control_pressed) { return 0; } - - vector sequences; - vector uniqueNames; - vector redundantNames; - vector seqFreq; - - seqNoise noise; - correctDist* correct = new correctDist(1); //we use one processor since we already split up the work load. - - //load this groups info in order - //loadData(correct, noise, sequences, uniqueNames, redundantNames, seqFreq, thisNameMap, thisSeqs); - ////////////////////////////////////////////////////////////////////////////////////////////////// - bool error = false; - map::iterator it; - - for (int i = 0; i < thisSeqs.size(); i++) { - - if (pDataArray->m->control_pressed) { return 0; } - - if (thisSeqs[i].getName() != "") { - correct->addSeq(thisSeqs[i].getName(), thisSeqs[i].getAligned()); - - it = thisNameMap.find(thisSeqs[i].getName()); - if (it != thisNameMap.end()) { - noise.addSeq(thisSeqs[i].getAligned(), sequences); - noise.addRedundantName(it->first, it->second, uniqueNames, redundantNames, seqFreq); - }else { - pDataArray->m->mothurOut("[ERROR]: " + thisSeqs[i].getName() + " is in your fasta file and not in your namefile, please correct."); - error = true; - } - } - } - - if (error) { return 0; } - ////////////////////////////////////////////////////////////////////////////////////////////////// - - if (pDataArray->m->control_pressed) { return 0; } - - //calc distances for cluster - string distFileName = pDataArray->m->getRootName(pDataArray->m->getSimpleName(pDataArray->fastafile)) + pDataArray->groups[k] + ".shhh.dist"; - correct->execute(distFileName); - delete correct; - - if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(distFileName); return 0; } - - //driver(noise, sequences, uniqueNames, redundantNames, seqFreq, distFileName, newFFile+groups[i], newNFile+groups[i], newMFile+groups[i]+".map"); - /////////////////////////////////////////////////////////////////////////////////////////////////// - double cutOff = 0.08; - int minIter = 10; - int maxIter = 1000; - double minDelta = 1e-6; - int numIters = 0; - double maxDelta = 1e6; - int numSeqs = sequences.size(); - - //run cluster command - string inputString = "phylip=" + distFileName + ", method=furthest, cutoff=0.08"; - pDataArray->m->mothurOut("/******************************************/"); pDataArray->m->mothurOutEndLine(); - pDataArray->m->mothurOut("Running command: cluster(" + inputString + ")"); pDataArray->m->mothurOutEndLine(); - - Command* clusterCommand = new ClusterCommand(inputString); - clusterCommand->execute(); - - map > filenames = clusterCommand->getOutputFiles(); - string listFileName = filenames["list"][0]; - string rabundFileName = filenames["rabund"][0]; pDataArray->m->mothurRemove(rabundFileName); - string sabundFileName = filenames["sabund"][0]; pDataArray->m->mothurRemove(sabundFileName); - - delete clusterCommand; - pDataArray->m->mothurOut("/******************************************/"); pDataArray->m->mothurOutEndLine(); - - if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(distFileName); pDataArray->m->mothurRemove(listFileName); return 0; } - - vector distances(numSeqs * numSeqs); - noise.getDistanceData(distFileName, distances); - pDataArray->m->mothurRemove(distFileName); - if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(listFileName); return 0; } - - vector otuData(numSeqs); - vector otuFreq; - vector > otuBySeqLookUp; - noise.getListData(listFileName, cutOff, otuData, otuFreq, otuBySeqLookUp); - pDataArray->m->mothurRemove(listFileName); - if (pDataArray->m->control_pressed) { return 0; } - - int numOTUs = otuFreq.size(); - - vector weights(numOTUs, 0); - vector change(numOTUs, 1); - vector centroids(numOTUs, -1); - vector cumCount(numOTUs, 0); - - vector tau(numSeqs, 1); - vector anP(numSeqs, 0); - vector anI(numSeqs, 0); - vector anN(numSeqs, 0); - vector > aanI = otuBySeqLookUp; - - while(numIters < minIter || ((maxDelta > minDelta) && (numIters < maxIter))){ - - if (pDataArray->m->control_pressed) { return 0; } - - noise.updateOTUCountData(otuFreq, otuBySeqLookUp, aanI, anP, anI, cumCount); if (pDataArray->m->control_pressed) { return 0; } - maxDelta = noise.calcNewWeights(weights, seqFreq, anI, cumCount, anP, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } - - noise.calcCentroids(anI, anP, change, centroids, cumCount, distances, seqFreq, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } - noise.checkCentroids(weights, centroids); if (pDataArray->m->control_pressed) { return 0; } - - otuFreq.assign(numOTUs, 0); - - int total = 0; - - for(int i=0;im->control_pressed) { return 0; } - - double offset = 1e6; - double norm = 0.0000; - double minWeight = 0.1; - vector currentTau(numOTUs); - - for(int j=0;jm->control_pressed) { return 0; } - if(weights[j] > minWeight && distances[i * numSeqs+centroids[j]] < offset){ - offset = distances[i * numSeqs+centroids[j]]; - } - } - - for(int j=0;jm->control_pressed) { return 0; } - if(weights[j] > minWeight){ - currentTau[j] = exp(pDataArray->sigma * (-distances[(i * numSeqs + centroids[j])] + offset)) * weights[j]; - norm += currentTau[j]; - } - else{ - currentTau[j] = 0.0000; - } - } - - for(int j=0;jm->control_pressed) { return 0; } - currentTau[j] /= norm; - } - - for(int j=0;jm->control_pressed) { return 0; } - - if(currentTau[j] > 1.0e-4){ - int oldTotal = total; - total++; - - tau.resize(oldTotal+1); - tau[oldTotal] = currentTau[j]; - otuBySeqLookUp[j][otuFreq[j]] = oldTotal; - aanI[j][otuFreq[j]] = i; - otuFreq[j]++; - - } - } - - anP.resize(total); - anI.resize(total); - } - - numIters++; - } - - noise.updateOTUCountData(otuFreq, otuBySeqLookUp, aanI, anP, anI, cumCount); if (pDataArray->m->control_pressed) { return 0; } - - vector percentage(numSeqs); - noise.setUpOTUData(otuData, percentage, cumCount, tau, otuFreq, anP, anI); if (pDataArray->m->control_pressed) { return 0; } - noise.finishOTUData(otuData, otuFreq, anP, anI, cumCount, otuBySeqLookUp, aanI, tau); if (pDataArray->m->control_pressed) { return 0; } - - change.assign(numOTUs, 1); - noise.calcCentroids(anI, anP, change, centroids, cumCount, distances, seqFreq, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } - - - vector finalTau(numOTUs, 0); - for(int i=0;im->control_pressed) { return 0; } - finalTau[otuData[i]] += int(seqFreq[i]); - } - - noise.writeOutput(pDataArray->newFName+pDataArray->groups[k], pDataArray->newNName+pDataArray->groups[k], pDataArray->newMName+pDataArray->groups[k]+".map", finalTau, centroids, otuData, sequences, uniqueNames, redundantNames, seqFreq, distances); - - /////////////////////////////////////////////////////////////////////////////////////////////////// - - if (pDataArray->m->control_pressed) { return 0; } - - pDataArray->m->appendFiles(pDataArray->newFName+pDataArray->groups[k], pDataArray->newFName); pDataArray->m->mothurRemove(pDataArray->newFName+pDataArray->groups[k]); - pDataArray->m->appendFiles(pDataArray->newNName+pDataArray->groups[k], pDataArray->newNName); pDataArray->m->mothurRemove(pDataArray->newNName+pDataArray->groups[k]); - pDataArray->mapfileNames.push_back(pDataArray->newMName+pDataArray->groups[k]+".map"); - - pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to process group " + pDataArray->groups[k] + "."); pDataArray->m->mothurOutEndLine(); + string lowerCaseName = pDataArray->groups[k]; + for (int j = 0; j < lowerCaseName.length(); j++) { lowerCaseName[j] = tolower(lowerCaseName[j]); } + + if (lowerCaseName == "ignore") { } + else { + pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("Processing group " + pDataArray->groups[k] + ":"); pDataArray->m->mothurOutEndLine(); + + map thisNameMap; + thisNameMap = parser.getNameMap(pDataArray->groups[k]); + vector thisSeqs = parser.getSeqs(pDataArray->groups[k]); + + if (pDataArray->m->control_pressed) { return 0; } + + vector sequences; + vector uniqueNames; + vector redundantNames; + vector seqFreq; + + seqNoise noise; + correctDist* correct = new correctDist(1); //we use one processor since we already split up the work load. + + //load this groups info in order + //loadData(correct, noise, sequences, uniqueNames, redundantNames, seqFreq, thisNameMap, thisSeqs); + ////////////////////////////////////////////////////////////////////////////////////////////////// + bool error = false; + map::iterator it; + + for (int i = 0; i < thisSeqs.size(); i++) { + + if (pDataArray->m->control_pressed) { return 0; } + + if (thisSeqs[i].getName() != "") { + correct->addSeq(thisSeqs[i].getName(), thisSeqs[i].getAligned()); + + it = thisNameMap.find(thisSeqs[i].getName()); + if (it != thisNameMap.end()) { + noise.addSeq(thisSeqs[i].getAligned(), sequences); + noise.addRedundantName(it->first, it->second, uniqueNames, redundantNames, seqFreq); + }else { + pDataArray->m->mothurOut("[ERROR]: " + thisSeqs[i].getName() + " is in your fasta file and not in your namefile, please correct."); + error = true; + } + } + } + + if (error) { return 0; } + ////////////////////////////////////////////////////////////////////////////////////////////////// + + if (pDataArray->m->control_pressed) { return 0; } + + //calc distances for cluster + string distFileName = pDataArray->m->getRootName(pDataArray->m->getSimpleName(pDataArray->fastafile)) + pDataArray->groups[k] + ".shhh.dist"; + correct->execute(distFileName); + delete correct; + + if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(distFileName); return 0; } + + //driver(noise, sequences, uniqueNames, redundantNames, seqFreq, distFileName, newFFile+groups[i], newNFile+groups[i], newMFile+groups[i]+".map"); + /////////////////////////////////////////////////////////////////////////////////////////////////// + double cutOff = 0.08; + int minIter = 10; + int maxIter = 1000; + double minDelta = 1e-6; + int numIters = 0; + double maxDelta = 1e6; + int numSeqs = sequences.size(); + + //run cluster command + string inputString = "phylip=" + distFileName + ", method=furthest, cutoff=0.08"; + pDataArray->m->mothurOut("/******************************************/"); pDataArray->m->mothurOutEndLine(); + pDataArray->m->mothurOut("Running command: cluster(" + inputString + ")"); pDataArray->m->mothurOutEndLine(); + + Command* clusterCommand = new ClusterCommand(inputString); + clusterCommand->execute(); + + map > filenames = clusterCommand->getOutputFiles(); + string listFileName = filenames["list"][0]; + string rabundFileName = filenames["rabund"][0]; pDataArray->m->mothurRemove(rabundFileName); + string sabundFileName = filenames["sabund"][0]; pDataArray->m->mothurRemove(sabundFileName); + + delete clusterCommand; + pDataArray->m->mothurOut("/******************************************/"); pDataArray->m->mothurOutEndLine(); + + if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(distFileName); pDataArray->m->mothurRemove(listFileName); return 0; } + + vector distances(numSeqs * numSeqs); + noise.getDistanceData(distFileName, distances); + pDataArray->m->mothurRemove(distFileName); + if (pDataArray->m->control_pressed) { pDataArray->m->mothurRemove(listFileName); return 0; } + + vector otuData(numSeqs); + vector otuFreq; + vector > otuBySeqLookUp; + noise.getListData(listFileName, cutOff, otuData, otuFreq, otuBySeqLookUp); + pDataArray->m->mothurRemove(listFileName); + if (pDataArray->m->control_pressed) { return 0; } + + int numOTUs = otuFreq.size(); + + vector weights(numOTUs, 0); + vector change(numOTUs, 1); + vector centroids(numOTUs, -1); + vector cumCount(numOTUs, 0); + + vector tau(numSeqs, 1); + vector anP(numSeqs, 0); + vector anI(numSeqs, 0); + vector anN(numSeqs, 0); + vector > aanI = otuBySeqLookUp; + + while(numIters < minIter || ((maxDelta > minDelta) && (numIters < maxIter))){ + + if (pDataArray->m->control_pressed) { return 0; } + + noise.updateOTUCountData(otuFreq, otuBySeqLookUp, aanI, anP, anI, cumCount); if (pDataArray->m->control_pressed) { return 0; } + maxDelta = noise.calcNewWeights(weights, seqFreq, anI, cumCount, anP, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } + + noise.calcCentroids(anI, anP, change, centroids, cumCount, distances, seqFreq, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } + noise.checkCentroids(weights, centroids); if (pDataArray->m->control_pressed) { return 0; } + + otuFreq.assign(numOTUs, 0); + + int total = 0; + + for(int i=0;im->control_pressed) { return 0; } + + double offset = 1e6; + double norm = 0.0000; + double minWeight = 0.1; + vector currentTau(numOTUs); + + for(int j=0;jm->control_pressed) { return 0; } + if(weights[j] > minWeight && distances[i * numSeqs+centroids[j]] < offset){ + offset = distances[i * numSeqs+centroids[j]]; + } + } + + for(int j=0;jm->control_pressed) { return 0; } + if(weights[j] > minWeight){ + currentTau[j] = exp(pDataArray->sigma * (-distances[(i * numSeqs + centroids[j])] + offset)) * weights[j]; + norm += currentTau[j]; + } + else{ + currentTau[j] = 0.0000; + } + } + + for(int j=0;jm->control_pressed) { return 0; } + currentTau[j] /= norm; + } + + for(int j=0;jm->control_pressed) { return 0; } + + if(currentTau[j] > 1.0e-4){ + int oldTotal = total; + total++; + + tau.resize(oldTotal+1); + tau[oldTotal] = currentTau[j]; + otuBySeqLookUp[j][otuFreq[j]] = oldTotal; + aanI[j][otuFreq[j]] = i; + otuFreq[j]++; + + } + } + + anP.resize(total); + anI.resize(total); + } + + numIters++; + } + + noise.updateOTUCountData(otuFreq, otuBySeqLookUp, aanI, anP, anI, cumCount); if (pDataArray->m->control_pressed) { return 0; } + + vector percentage(numSeqs); + noise.setUpOTUData(otuData, percentage, cumCount, tau, otuFreq, anP, anI); if (pDataArray->m->control_pressed) { return 0; } + noise.finishOTUData(otuData, otuFreq, anP, anI, cumCount, otuBySeqLookUp, aanI, tau); if (pDataArray->m->control_pressed) { return 0; } + + change.assign(numOTUs, 1); + noise.calcCentroids(anI, anP, change, centroids, cumCount, distances, seqFreq, otuFreq, tau); if (pDataArray->m->control_pressed) { return 0; } + + + vector finalTau(numOTUs, 0); + for(int i=0;im->control_pressed) { return 0; } + finalTau[otuData[i]] += int(seqFreq[i]); + } + + noise.writeOutput(pDataArray->newFName+pDataArray->groups[k], pDataArray->newNName+pDataArray->groups[k], pDataArray->newMName+pDataArray->groups[k]+".map", finalTau, centroids, otuData, sequences, uniqueNames, redundantNames, seqFreq, distances); + + /////////////////////////////////////////////////////////////////////////////////////////////////// + + if (pDataArray->m->control_pressed) { return 0; } + + pDataArray->m->appendFiles(pDataArray->newFName+pDataArray->groups[k], pDataArray->newFName); pDataArray->m->mothurRemove(pDataArray->newFName+pDataArray->groups[k]); + pDataArray->m->appendFiles(pDataArray->newNName+pDataArray->groups[k], pDataArray->newNName); pDataArray->m->mothurRemove(pDataArray->newNName+pDataArray->groups[k]); + pDataArray->mapfileNames.push_back(pDataArray->newMName+pDataArray->groups[k]+".map"); + + pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to process group " + pDataArray->groups[k] + "."); pDataArray->m->mothurOutEndLine(); + } } return 0; diff --git a/source/commands/sparcccommand.cpp b/source/commands/sparcccommand.cpp index 81bb5d62..0ea02b11 100644 --- a/source/commands/sparcccommand.cpp +++ b/source/commands/sparcccommand.cpp @@ -196,10 +196,10 @@ int SparccCommand::execute(){ int start = time(NULL); InputData input(sharedfile, "sharedfile"); - vector lookup = input.getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); - int numOTUs = lookup[0]->getNumBins(); + int numOTUs = lookup->getNumBins(); if (numOTUs >= maxIterations) { m->mothurOut("[WARNING]: The number of iterations is set higher than the number of OTUs, reducing to " + toString(numOTUs-1) + "\n"); maxIterations = numOTUs-1; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -207,39 +207,39 @@ int SparccCommand::execute(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }return 0; } + if (m->control_pressed) { delete lookup; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + delete lookup; if (m->control_pressed) { return 0; } @@ -264,14 +264,14 @@ int SparccCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -315,27 +315,28 @@ vector > SparccCommand::shuffleSharedVector(vector > } } //********************************************************************************************************************** -int SparccCommand::process(vector& lookup){ +int SparccCommand::process(SharedRAbundVectors*& shared){ try { cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); vector > sharedVector; vector otuNames = m->currentSharedBinLabels; + vector data = shared->getSharedRAbundVectors(); //fill sharedVector to pass to CalcSparcc - for (int i = 0; i < lookup.size(); i++) { - vector abunds = lookup[i]->getAbundances(); + for (int i = 0; i < data.size(); i++) { + vector abunds = data[i]->get(); vector temp; for (int j = 0; j < abunds.size(); j++) { temp.push_back((float) abunds[j]); } sharedVector.push_back(temp); } int numOTUs = (int)sharedVector[0].size(); - int numGroups = lookup.size(); + int numGroups = data.size(); map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - variables["[distance]"] = lookup[0]->getLabel(); + variables["[distance]"] = shared->getLabel(); string relAbundFileName = getOutputFileName("sparccrelabund", variables); @@ -345,11 +346,11 @@ int SparccCommand::process(vector& lookup){ relAbundFile << "OTU\taveRelAbund\n"; for(int i=0;icontrol_pressed) { relAbundFile.close(); return 0; } + if (m->control_pressed) { for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); relAbundFile.close(); return 0; } double relAbund = 0.0000; for(int j=0;jgetNumSeqs(); + relAbund += sharedVector[j][i]/(double)data[j]->getNumSeqs(); } relAbundFile << otuNames[i] <<'\t' << relAbund / (double) numGroups << endl; } @@ -378,7 +379,7 @@ int SparccCommand::process(vector& lookup){ if(numPermutations != 0){ vector > pValues = createProcesses(sharedVector, origCorrMatrix); - if (m->control_pressed) { return 0; } + if (m->control_pressed) { for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); return 0; } string pValueFileName = getOutputFileName("pvalue", variables); ofstream pValueFile; @@ -397,7 +398,7 @@ int SparccCommand::process(vector& lookup){ } } - + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); return 0; } catch(exception& e) { diff --git a/source/commands/sparcccommand.h b/source/commands/sparcccommand.h index 123c4261..9945b458 100644 --- a/source/commands/sparcccommand.h +++ b/source/commands/sparcccommand.h @@ -42,7 +42,7 @@ class SparccCommand : public Command { vector Groups; vector outputNames; - int process(vector&); + int process(SharedRAbundVectors*&); vector > createProcesses(vector >&, vector >&); vector > driver(vector >&, vector >&, int); vector > shuffleSharedVector(vector >&); diff --git a/source/commands/sracommand.cpp b/source/commands/sracommand.cpp index 2b0aecdc..4e05527f 100644 --- a/source/commands/sracommand.cpp +++ b/source/commands/sracommand.cpp @@ -419,6 +419,9 @@ int SRACommand::execute(){ //////////////////////////////////////////////////////// for (int i = 0; i < Groups.size(); i++) { + string thisGroup = Groups[i]; + thisGroup = m->splitWhiteSpace(thisGroup).front(); //removes leading and trailing spaces if any + if ((!includeScrap) && (Groups[i] == "scrap")) {} //ignore scrap else { if (m->control_pressed) { break; } @@ -428,7 +431,7 @@ int SRACommand::execute(){ out << "\t\t\t\t\n"; out << "\t\t\t\t\t\n"; out << "\t\t\t\t\t\t\n"; - out << "\t\t\t\t\t\t" + Groups[i] + " \n"; + out << "\t\t\t\t\t\t" + thisGroup + " \n"; out << "\t\t\t\t\t\t\n"; out << "\t\t\t\t\t\t\n"; out << "\t\t\t\t\t\t\t" + mimarks[Groups[i]]["sample_title"] + " \n"; @@ -456,7 +459,7 @@ int SRACommand::execute(){ out << "\t\t\t\t\n"; out << "\t\t\t\n"; out << "\t\t\t\n"; - out << "\t\t\t\t" + Groups[i] + "\n"; + out << "\t\t\t\t" + thisGroup + "\n"; out << "\t\t\t\n"; out << "\t\t\n"; out << "\t\n"; @@ -468,6 +471,9 @@ int SRACommand::execute(){ //////////////////////////////////////////////////////// for (int i = 0; i < Groups.size(); i++) { + string thisGroup = Groups[i]; + thisGroup = m->splitWhiteSpace(thisGroup).front(); //removes leading and trailing spaces if any + if ((!includeScrap) && (Groups[i] == "scrap")) {} //ignore scrap else { @@ -487,14 +493,14 @@ int SRACommand::execute(){ //cout << Groups[i] << '\t' << thisGroupsFiles.size() << endl; for (int j = 0; j < thisGroupsFiles.size(); j++) { - string libId = m->getSimpleName(thisGroupsFiles[j]) + "." + Groups[i]; + string libId = m->getSimpleName(thisGroupsFiles[j]) + "." + thisGroup; if (m->control_pressed) { break; } out << "\t\n"; out << "\t\t\n"; if (libLayout == "paired") { //adjust the libID because the thisGroupsFiles[j] contains two filenames vector pieces = m->splitWhiteSpace(thisGroupsFiles[j]); - libId = m->getSimpleName(pieces[0]) + "." + Groups[i]; + libId = m->getSimpleName(pieces[0]) + "." + thisGroup; out << "\t\t\tgetSimpleName(pieces[0]) + "\">\n"; out << "\t\t\t\tgeneric-data \n"; out << "\t\t\t\n"; @@ -599,14 +605,14 @@ int SRACommand::execute(){ //////////////////bioSample info out << "\t\t\t\n"; out << "\t\t\t\t\n"; - out << "\t\t\t\t\t" + Groups[i] + "\n"; + out << "\t\t\t\t\t" + thisGroup + "\n"; out << "\t\t\t\t\n"; out << "\t\t\t\n"; //libID out << "\t\t\t\n"; if (libLayout == "paired") { //adjust the libID because the thisGroupsFiles[j] contains two filenames vector pieces = m->splitWhiteSpace(thisGroupsFiles[j]); - libId = m->getSimpleName(pieces[0]) + "." + Groups[i]; + libId = m->getSimpleName(pieces[0]) + "." + thisGroup; } out << "\t\t\t\t" + libId + "\n"; out << "\t\t\t\n"; diff --git a/source/commands/subsamplecommand.cpp b/source/commands/subsamplecommand.cpp index 3bc37413..ae2bc277 100644 --- a/source/commands/subsamplecommand.cpp +++ b/source/commands/subsamplecommand.cpp @@ -830,79 +830,61 @@ int SubSampleCommand::readNames() { int SubSampleCommand::getSubSampleShared() { try { - InputData* input = new InputData(sharedfile, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); - + InputData input(sharedfile, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; if (size == 0) { //user has not set size, set size = smallest samples size - size = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < size) { size = thisSize; } - } - }else { - m->clearGroups(); - Groups.clear(); - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < size) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; - m->setGroups(Groups); + size = lookup->getNumSeqsSmallestGroup(); + }else { + lookup->removeGroups(size); + Groups = m->getGroups(); } - - if (lookup.size() == 0) { m->mothurOut("The size you selected is too large, skipping shared file."); m->mothurOutEndLine(); delete input; return 0; } + if (lookup->size() == 0) { m->mothurOut("The size you selected is too large, skipping shared file."); m->mothurOutEndLine(); return 0; } m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine(); //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } return 0; } + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + if (m->control_pressed) { if (lookup != NULL) { delete lookup; lookup = NULL; } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + if (lookup != NULL) { delete lookup; lookup = NULL; } - lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + lookup = input.getSharedRAbundVectors(lastLabel); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } + if (lookup != NULL) { delete lookup; lookup = NULL; } //get next line to process - lookup = input->getSharedRAbundVectors(); + lookup = input.getSharedRAbundVectors(); } @@ -923,18 +905,16 @@ int SubSampleCommand::getSubSampleShared() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + if (lookup != NULL) { delete lookup; lookup = NULL; } + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); processShared(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + if (lookup != NULL) { delete lookup; lookup = NULL; } } - delete input; - return 0; } @@ -944,7 +924,7 @@ int SubSampleCommand::getSubSampleShared() { } } //********************************************************************************************************************** -int SubSampleCommand::processShared(vector& thislookup) { +int SubSampleCommand::processShared(SharedRAbundVectors*& thislookup) { try { //save mothurOut's binLabels to restore for next label @@ -955,9 +935,10 @@ int SubSampleCommand::processShared(vector& thislookup) { map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[extension]"] = m->getExtension(sharedfile); - variables["[distance]"] = thislookup[0]->getLabel(); + variables["[distance]"] = thislookup->getLabel(); string outputFileName = getOutputFileName("shared", variables); SubSample sample; + vector subsampledLabels = sample.getSample(thislookup, size); if (m->control_pressed) { return 0; } @@ -968,14 +949,9 @@ int SubSampleCommand::processShared(vector& thislookup) { m->currentSharedBinLabels = subsampledLabels; - thislookup[0]->printHeaders(out); - - for (int i = 0; i < thislookup.size(); i++) { - out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; - thislookup[i]->print(out); - } - out.close(); - + thislookup->printHeaders(out); + thislookup->print(out); + out.close(); //save mothurOut's binLabels to restore for next label m->currentSharedBinLabels = saveBinLabels; diff --git a/source/commands/subsamplecommand.h b/source/commands/subsamplecommand.h index db4001a5..f8b46bef 100644 --- a/source/commands/subsamplecommand.h +++ b/source/commands/subsamplecommand.h @@ -11,7 +11,7 @@ */ #include "command.hpp" -#include "sharedrabundvector.h" + #include "listvector.hpp" #include "rabundvector.hpp" #include "inputdata.h" @@ -54,7 +54,7 @@ class SubSampleCommand : public Command { int getSubSampleRabund(); int getSubSampleSabund(); int getSubSampleFasta(); - int processShared(vector&); + int processShared(SharedRAbundVectors*&); int processRabund(RAbundVector*&, ofstream&); int processSabund(SAbundVector*&, ofstream&); int processList(ListVector*&, set&); diff --git a/source/commands/summarycommand.cpp b/source/commands/summarycommand.cpp index 35f3925c..2e4b4c04 100644 --- a/source/commands/summarycommand.cpp +++ b/source/commands/summarycommand.cpp @@ -405,8 +405,8 @@ int SummaryCommand::execute(){ } } - input = new InputData(inputFileNames[p], format); - sabund = input->getSAbundVector(); + InputData input(inputFileNames[p], format); + sabund = input.getSAbundVector(); string lastLabel = sabund->getLabel(); for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel()) == 1){ @@ -444,7 +444,7 @@ int SummaryCommand::execute(){ process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel(); delete sabund; - sabund = input->getSAbundVector(lastLabel); + sabund = input.getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); @@ -460,7 +460,7 @@ int SummaryCommand::execute(){ process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel(); delete sabund; - sabund = input->getSAbundVector(); + sabund = input.getSAbundVector(); } - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i::iterator it; @@ -491,12 +491,12 @@ int SummaryCommand::execute(){ //run last label if you need to if (needToRun == true) { if (sabund != NULL) { delete sabund; } - sabund = input->getSAbundVector(lastLabel); + sabund = input.getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i SummaryCommand::parseSharedFile(string filename) { map files; map::iterator it3; - input = new InputData(filename, "sharedfile"); - vector lookup = input->getSharedRAbundVectors(); - - string sharedFileRoot = m->getRootName(filename); - + InputData input(filename, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + /******************************************************/ + //user has not set size, set size = smallest samples size if (subsample) { - if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } - }else { - m->clearGroups(); - vector Groups; - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; - m->setGroups(Groups); - } + if (subsampleSize == -1) { subsampleSize = lookup->getNumSeqsSmallestGroup(); } + else { lookup->removeGroups(subsampleSize); } - if (lookup.size() < 1) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; delete input; return filenames; } + if (lookup->size() < 1) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return filenames; } } - - /******************************************************/ + groups = lookup->getNamesGroups(); //clears file before we start to write to it below - for (int i=0; igetRootName(filename); + for (int i=0; igetGroup(); + string group = groups[i]; m->openOutputFile((sharedFileRoot + group + ".rabund"), temp); filenames.push_back((sharedFileRoot + group + ".rabund")); files[group] = (sharedFileRoot + group + ".rabund"); - groups.push_back(group); } - while(lookup[0] != NULL) { + while(lookup != NULL) { - for (int i = 0; i < lookup.size(); i++) { - RAbundVector rav = lookup[i]->getRAbundVector(); + vector data = lookup->getSharedRAbundVectors(); + for (int i = 0; i < data.size(); i++) { ofstream temp; - string group = lookup[i]->getGroup(); + string group = data[i]->getGroup(); m->openOutputFileAppend(files[group], temp); - rav.print(temp); + data[i]->getRAbundVector().print(temp); temp.close(); + delete data[i]; } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + delete lookup; + lookup = input.getSharedRAbundVectors(); } - delete input; - return filenames; } catch(exception& e) { diff --git a/source/commands/summarycommand.h b/source/commands/summarycommand.h index 891d1570..4b24a7eb 100644 --- a/source/commands/summarycommand.h +++ b/source/commands/summarycommand.h @@ -37,7 +37,6 @@ class SummaryCommand : public Command { private: vector sumCalculators; - InputData* input; SAbundVector* sabund; int abund, size, iters, subsampleSize, alpha; diff --git a/source/commands/summaryqualcommand.cpp b/source/commands/summaryqualcommand.cpp index 05cdf497..57ed2750 100644 --- a/source/commands/summaryqualcommand.cpp +++ b/source/commands/summaryqualcommand.cpp @@ -306,7 +306,7 @@ int SummaryQualCommand::driverCreateSummary(vector& position, vector& for (int i = 0; i < thisScores.size(); i++) { position[i] += num; averageQ[i] += (thisScores[i] * num); //weighting for namesfile - if (thisScores[i] > 40) { m->mothurOut("[ERROR]: " + current.getName() + " has a quality scores of " + toString(thisScores[i]) + ", expecting values to be less than 40."); m->mothurOutEndLine(); m->control_pressed = true; } + if (thisScores[i] > 41) { m->mothurOut("[ERROR]: " + current.getName() + " has a quality scores of " + toString(thisScores[i]) + ", expecting values to be less than 40."); m->mothurOutEndLine(); m->control_pressed = true; } else { scores[i][thisScores[i]] += num; } } diff --git a/source/commands/summaryqualcommand.h b/source/commands/summaryqualcommand.h index 2099d415..ca53dd22 100644 --- a/source/commands/summaryqualcommand.h +++ b/source/commands/summaryqualcommand.h @@ -130,7 +130,7 @@ static DWORD WINAPI MySeqSumQualThreadFunction(LPVOID lpParam){ for (int i = 0; i < thisScores.size(); i++) { pDataArray->position.at(i) += num; pDataArray->averageQ.at(i) += (thisScores[i] * num); //weighting for namesfile - if (thisScores[i] > 40) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " has a quality scores of " + toString(thisScores[i]) + ", expecting values to be less than 40."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + if (thisScores[i] > 41) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " has a quality scores of " + toString(thisScores[i]) + ", expecting values to be less than 40."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } else { pDataArray->scores.at(i)[thisScores[i]] += num; } } diff --git a/source/commands/summarysharedcommand.cpp b/source/commands/summarysharedcommand.cpp index b3876edb..0664f93b 100644 --- a/source/commands/summarysharedcommand.cpp +++ b/source/commands/summarysharedcommand.cpp @@ -335,9 +335,9 @@ int SummarySharedCommand::execute(){ } } - input = new InputData(sharedfile, "sharedfile"); - lookup = input->getSharedRAbundVectors(); - string lastLabel = lookup[0]->getLabel(); + InputData input(sharedfile, "sharedfile"); + SharedRAbundVectors* lookup = input.getSharedRAbundVectors(); + string lastLabel = lookup->getLabel(); /******************************************************/ //output headings for files @@ -369,16 +369,16 @@ int SummarySharedCommand::execute(){ outAll.close(); } - if (lookup.size() < 2) { + if (lookup->size() < 2) { m->mothurOut("I cannot run the command without at least 2 valid groups."); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; //close files and clean up m->mothurRemove(outputFileName); if (mult == true) { m->mothurRemove(outAllFileName); } return 0; //if you only have 2 groups you don't need a .sharedmultiple file - }else if ((lookup.size() == 2) && (mult == true)) { + }else if ((lookup->size() == 2) && (mult == true)) { mult = false; m->mothurRemove(outAllFileName); outputNames.pop_back(); @@ -386,9 +386,8 @@ int SummarySharedCommand::execute(){ if (m->control_pressed) { if (mult) { m->mothurRemove(outAllFileName); } - m->mothurRemove(outputFileName); - delete input; - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + m->mothurRemove(outputFileName); + delete lookup; for(int i=0;iclearGroups(); return 0; @@ -396,36 +395,19 @@ int SummarySharedCommand::execute(){ /******************************************************/ if (subsample) { if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } + subsampleSize = lookup->getNumSeqsSmallestGroup(); }else { - m->clearGroups(); - Groups.clear(); - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - } - } - lookup = temp; - m->setGroups(Groups); + lookup->removeGroups(subsampleSize); + Groups = lookup->getNamesGroups(); } - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; delete input; return 0; } + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } /******************************************************/ //comparison breakup to be used by different processes later - numGroups = lookup.size(); + numGroups = lookup->size(); lines.resize(processors); for (int i = 0; i < processors; i++) { lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); @@ -438,54 +420,56 @@ int SummarySharedCommand::execute(){ set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { if (mult) { m->mothurRemove(outAllFileName); } m->mothurRemove(outputFileName); - delete input; - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; for(int i=0;iclearGroups(); return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - process(lookup, outputFileName, outAllFileName); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + process(data, outputFileName, outAllFileName); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - process(lookup, outputFileName, outAllFileName); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + process(data, outputFileName, outAllFileName); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process //prevent memory leak - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + delete lookup; + lookup = input.getSharedRAbundVectors(); } if (m->control_pressed) { if (mult) { m->mothurRemove(outAllFileName); } - m->mothurRemove(outputFileName); - delete input; + m->mothurRemove(outputFileName); for(int i=0;iclearGroups(); return 0; @@ -506,12 +490,14 @@ int SummarySharedCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - process(lookup, outputFileName, outAllFileName); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + vector data = lookup->getSharedRAbundVectors(); + process(data, outputFileName, outAllFileName); + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); + delete lookup; } @@ -519,7 +505,6 @@ int SummarySharedCommand::execute(){ m->clearGroups(); for(int i=0;icontrol_pressed) { m->mothurRemove(outAllFileName); @@ -542,7 +527,7 @@ int SummarySharedCommand::execute(){ } } /***********************************************************/ -int SummarySharedCommand::printSims(ostream& out, vector< vector >& simMatrix) { +int SummarySharedCommand::printSims(ostream& out, vector< vector >& simMatrix, vector theseGroups) { try { out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -552,7 +537,7 @@ int SummarySharedCommand::printSims(ostream& out, vector< vector >& simM if (output == "lt") { for (int b = 0; b < simMatrix.size(); b++) { - out << lookup[b]->getGroup(); + out << theseGroups[b]; for (int n = 0; n < b; n++) { if (m->control_pressed) { return 0; } out << '\t' << simMatrix[b][n]; @@ -561,7 +546,7 @@ int SummarySharedCommand::printSims(ostream& out, vector< vector >& simM } }else{ for (int b = 0; b < simMatrix.size(); m++) { - out << lookup[b]->getGroup(); + out << theseGroups[b]; for (int n = 0; n < simMatrix[b].size(); n++) { if (m->control_pressed) { return 0; } out << '\t' << simMatrix[b][n]; @@ -594,18 +579,12 @@ int SummarySharedCommand::process(vector thisLookup, string //make copy of lookup so we don't get access violations vector newLookup; for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); + SharedRAbundVector* temp = new SharedRAbundVector(*thisItersLookup[k]); //deep copy temp->setLabel(thisItersLookup[k]->getLabel()); temp->setGroup(thisItersLookup[k]->getGroup()); newLookup.push_back(temp); } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - + tempLabels = sample.getSample(newLookup, subsampleSize); thisItersLookup = newLookup; } @@ -784,19 +763,12 @@ int SummarySharedCommand::process(vector thisLookup, string //make copy of lookup so we don't get access violations vector newLookup; - for (int k = 0; k < thisLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisLookup[k]->getLabel()); - temp->setGroup(thisLookup[k]->getGroup()); + for (int k = 0; k < thisItersLookup.size(); k++) { + SharedRAbundVector* temp = new SharedRAbundVector(*thisItersLookup[k]); //deep copy + temp->setLabel(thisItersLookup[k]->getLabel()); + temp->setGroup(thisItersLookup[k]->getGroup()); newLookup.push_back(temp); } - - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } // Allocate memory for thread data. summarySharedData* tempSum = new summarySharedData((sumFileName+toString(i)+".temp"), m, lines[i].start, lines[i].end, Estimators, newLookup); @@ -823,8 +795,7 @@ int SummarySharedCommand::process(vector thisLookup, string m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName); m->mothurRemove((sumFileName + toString(processIDS[i]) + ".temp")); - for (int j = 0; j < pDataArray[i]->thisLookup.size(); j++) { delete pDataArray[i]->thisLookup[j]; } - + delete pDataArray[i]->thisLookup; if (createPhylip) { for (int k = 0; k < calcDists.size(); k++) { int size = pDataArray[i]->calcDists[k].size(); @@ -853,7 +824,8 @@ int SummarySharedCommand::process(vector thisLookup, string //initialize matrix vector< vector > matrix; //square matrix to represent the distance matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + vector GroupNames; + for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); GroupNames.push_back(thisLookup[k]->getGroup()); } for (int j = 0; j < calcDists[i].size(); j++) { int row = calcDists[i][j].seq1; @@ -876,7 +848,7 @@ int SummarySharedCommand::process(vector thisLookup, string m->openOutputFile(distFileName, outDist); outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); - printSims(outDist, matrix); + printSims(outDist, matrix, GroupNames); outDist.close(); } @@ -900,7 +872,8 @@ int SummarySharedCommand::process(vector thisLookup, string vector< vector > stdmatrix; //square matrix to represent the stdDev stdmatrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { stdmatrix[k].resize(thisLookup.size(), 0.0); } + vector GroupNames; + for (int k = 0; k < thisLookup.size(); k++) { stdmatrix[k].resize(thisLookup.size(), 0.0); GroupNames.push_back(thisLookup[k]->getGroup()); } for (int j = 0; j < calcAverages[i].size(); j++) { @@ -927,7 +900,7 @@ int SummarySharedCommand::process(vector thisLookup, string m->openOutputFile(distFileName, outAve); outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint); - printSims(outAve, matrix); + printSims(outAve, matrix, GroupNames); outAve.close(); @@ -938,7 +911,7 @@ int SummarySharedCommand::process(vector thisLookup, string m->openOutputFile(distFileName, outSTD); outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint); - printSims(outSTD, stdmatrix); + printSims(outSTD, stdmatrix, GroupNames); outSTD.close(); @@ -953,7 +926,7 @@ int SummarySharedCommand::process(vector thisLookup, string } } /**************************************************************************************************/ -int SummarySharedCommand::driver(vector thisLookup, int start, int end, string sumFile, string sumAllFile, vector< vector >& calcDists) { +int SummarySharedCommand::driver(vector thisLookup, int start, int end, string sumFile, string sumAllFile, vector< vector >& calcDists) { try { //loop through calculators and add to file all for all calcs that can do mutiple groups diff --git a/source/commands/summarysharedcommand.h b/source/commands/summarysharedcommand.h index 09714b77..a001d76a 100644 --- a/source/commands/summarysharedcommand.h +++ b/source/commands/summarysharedcommand.h @@ -11,7 +11,6 @@ #include "command.hpp" -#include "sharedrabundvector.h" #include "inputdata.h" #include "calculator.h" #include "validcalculator.h" @@ -81,19 +80,18 @@ class SummarySharedCommand : public Command { private: vector lines; - vector sumCalculators; - InputData* input; + vector sumCalculators; bool abort, allLines, mult, all, createPhylip, subsample; set labels; //holds labels to be used string label, calc, groups, sharedfile, output; vector Estimators, Groups, outputNames; - vector lookup; + string format, outputDir; int numGroups, processors, subsampleSize, iters; int process(vector, string, string); int driver(vector, int, int, string, string, vector< vector >&); - int printSims(ostream&, vector< vector >&); + int printSims(ostream&, vector< vector >&, vector); }; diff --git a/source/commands/treegroupscommand.cpp b/source/commands/treegroupscommand.cpp index 3b8cc00b..6ec5a15c 100644 --- a/source/commands/treegroupscommand.cpp +++ b/source/commands/treegroupscommand.cpp @@ -411,10 +411,10 @@ int TreeGroupCommand::execute(){ if (treeCalculators.size() == 0) { m->mothurOut("You have given no valid calculators."); m->mothurOutEndLine(); return 0; } input = new InputData(sharedfile, "sharedfile"); - lookup = input->getSharedRAbundVectors(); - lastLabel = lookup[0]->getLabel(); + SharedRAbundVectors* lookup = input->getSharedRAbundVectors(); + lastLabel = lookup->getLabel(); - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0; } + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0; } //used in tree constructor m->runParse = false; @@ -434,18 +434,15 @@ int TreeGroupCommand::execute(){ //clear globaldatas old tree names if any m->Treenames.clear(); - //fills globaldatas tree names - //m->Treenames = m->getGroups(); - for (int k = 0; k < lookup.size(); k++) { - m->Treenames.push_back(lookup[k]->getGroup()); - } - + //fills tree names with shared files groups + m->Treenames = lookup->getNamesGroups(); + if (m->control_pressed) { return 0; } //create tree file - makeSimsShared(); + makeSimsShared(lookup); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } }else{ //read in dist file filename = inputfile; @@ -636,39 +633,21 @@ vector< vector > TreeGroupCommand::makeSimsDist(SparseDistanceMatrix* ma } /***********************************************************/ -int TreeGroupCommand::makeSimsShared() { +int TreeGroupCommand::makeSimsShared(SharedRAbundVectors*& lookup) { try { if (subsample) { if (subsampleSize == -1) { //user has not set size, set size = smallest samples size - subsampleSize = lookup[0]->getNumSeqs(); - for (int i = 1; i < lookup.size(); i++) { - int thisSize = lookup[i]->getNumSeqs(); - - if (thisSize < subsampleSize) { subsampleSize = thisSize; } - } + subsampleSize = lookup->getNumSeqsSmallestGroup(); }else { - m->clearGroups(); - Groups.clear(); - m->Treenames.clear(); - vector temp; - for (int i = 0; i < lookup.size(); i++) { - if (lookup[i]->getNumSeqs() < subsampleSize) { - m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); - delete lookup[i]; - }else { - Groups.push_back(lookup[i]->getGroup()); - temp.push_back(lookup[i]); - m->Treenames.push_back(lookup[i]->getGroup()); - } - } - lookup = temp; - m->setGroups(Groups); + lookup->removeGroups(subsampleSize); + Groups = m->getGroups(); + m->Treenames = Groups; } - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } + if (lookup->size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } - numGroups = lookup.size(); + numGroups = lookup->size(); //sanity check to make sure processors < numComparisions int numDists = 0; @@ -690,41 +669,41 @@ int TreeGroupCommand::makeSimsShared() { set userLabels = labels; //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; } + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + if (m->control_pressed) { delete lookup; for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + lookup->setLabels(saveLabel); } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; } + if (m->control_pressed) { for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } return 1; } //output error messages about any remaining user labels set::iterator it; @@ -741,12 +720,12 @@ int TreeGroupCommand::makeSimsShared() { //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } + delete lookup; lookup = input->getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); process(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + delete lookup; } for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } @@ -760,36 +739,21 @@ int TreeGroupCommand::makeSimsShared() { } /***********************************************************/ -int TreeGroupCommand::process(vector thisLookup) { +int TreeGroupCommand::process(SharedRAbundVectors*& thisLookup) { try{ vector< vector< vector > > calcDistsTotals; //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files vector< vector > calcDists; calcDists.resize(treeCalculators.size()); for (int thisIter = 0; thisIter < iters; thisIter++) { - vector thisItersLookup = thisLookup; + SharedRAbundVectors* thisItersLookup = new SharedRAbundVectors(*thisLookup); + vector namesOfGroups = thisItersLookup->getNamesGroups(); - if (subsample) { + if (subsample && (thisIter != 0)) { SubSample sample; vector tempLabels; //dont need since we arent printing the sampled sharedRabunds - //make copy of lookup so we don't get access violations - vector newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - - tempLabels = sample.getSample(newLookup, subsampleSize); - thisItersLookup = newLookup; + tempLabels = sample.getSample(thisItersLookup, subsampleSize); } if(processors == 1){ @@ -849,7 +813,7 @@ int TreeGroupCommand::process(vector thisLookup) { /******************************************************/ //comparison breakup to be used by different processes later lines.clear(); - numGroups = thisLookup.size(); + numGroups = thisLookup->size(); lines.resize(processors); for (int i = 0; i < processors; i++) { lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); @@ -941,20 +905,7 @@ int TreeGroupCommand::process(vector thisLookup) { for( int i=1; i newLookup; - for (int k = 0; k < thisItersLookup.size(); k++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thisItersLookup[k]->getLabel()); - temp->setGroup(thisItersLookup[k]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } - } - + vector newLookup = thisItersLookup->getSharedRabundVectors(); // Allocate memory for thread data. treeSharedData* tempSum = new treeSharedData(m, lines[i].start, lines[i].end, Estimators, newLookup); pDataArray.push_back(tempSum); @@ -990,14 +941,11 @@ int TreeGroupCommand::process(vector thisLookup) { calcDistsTotals.push_back(calcDists); - if (subsample) { - + if (subsample) { //clean up memory - for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } - thisItersLookup.clear(); - for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } - } + for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } } + delete thisItersLookup; if (m->debug) { m->mothurOut("[DEBUG]: iter = " + toString(thisIter) + ".\n"); } } @@ -1012,8 +960,8 @@ int TreeGroupCommand::process(vector thisLookup) { //create average tree for each calc for (int i = 0; i < calcDists.size(); i++) { vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + matrix.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { matrix[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcAverages[i].size(); j++) { int row = calcAverages[i][j].seq1; @@ -1028,7 +976,7 @@ int TreeGroupCommand::process(vector thisLookup) { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); variables["[calc]"] = treeCalculators[i]->getName(); - variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[distance]"] = thisLookup->getLabel(); variables["[tag]"] = "ave"; string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); @@ -1049,7 +997,7 @@ int TreeGroupCommand::process(vector thisLookup) { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); variables["[calc]"] = treeCalculators[i]->getName(); - variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[distance]"] = thisLookup->getLabel(); variables["[tag]"] = "all"; string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); @@ -1064,8 +1012,8 @@ int TreeGroupCommand::process(vector thisLookup) { //initialize matrix vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + matrix.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { matrix[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcDistsTotals[myIter][i].size(); j++) { int row = calcDistsTotals[myIter][i][j].seq1; @@ -1112,8 +1060,8 @@ int TreeGroupCommand::process(vector thisLookup) { //initialize matrix vector< vector > matrix; //square matrix to represent the distance - matrix.resize(thisLookup.size()); - for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } + matrix.resize(thisLookup->size()); + for (int k = 0; k < thisLookup->size(); k++) { matrix[k].resize(thisLookup->size(), 0.0); } for (int j = 0; j < calcDists[i].size(); j++) { int row = calcDists[i][j].seq1; @@ -1128,7 +1076,7 @@ int TreeGroupCommand::process(vector thisLookup) { map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); variables["[calc]"] = treeCalculators[i]->getName(); - variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[distance]"] = thisLookup->getLabel(); variables["[tag]"] = ""; string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); @@ -1147,9 +1095,10 @@ int TreeGroupCommand::process(vector thisLookup) { } } /**************************************************************************************************/ -int TreeGroupCommand::driver(vector thisLookup, int start, int end, vector< vector >& calcDists) { +int TreeGroupCommand::driver(SharedRAbundVectors*& thislookup, int start, int end, vector< vector >& calcDists) { try { vector subset; + vector thisLookup = thislookup->getSharedRAbundVectors(); for (int k = start; k < end; k++) { // pass cdd each set of groups to compare for (int l = 0; l < k; l++) { @@ -1171,7 +1120,7 @@ int TreeGroupCommand::driver(vector thisLookup, int start, vector tempdata = treeCalculators[i]->getValues(subset); //saves the calculator outputs - if (m->control_pressed) { return 1; } + if (m->control_pressed) { for (int i = 0; i < thisLookup.size(); i++) { delete thisLookup[i]; } return 1; } seqDist temp(l, k, -(tempdata[0]-1.0)); calcDists[i].push_back(temp); @@ -1180,6 +1129,8 @@ int TreeGroupCommand::driver(vector thisLookup, int start, } } + for (int i = 0; i < thisLookup.size(); i++) { delete thisLookup[i]; } + return 0; } catch(exception& e) { diff --git a/source/commands/treegroupscommand.h b/source/commands/treegroupscommand.h index f5c4418a..dfd89043 100644 --- a/source/commands/treegroupscommand.h +++ b/source/commands/treegroupscommand.h @@ -95,10 +95,10 @@ class TreeGroupCommand : public Command { Tree* createTree(vector< vector >&); void printSims(ostream&, vector< vector >&); - int makeSimsShared(); + int makeSimsShared(SharedRAbundVectors*&); vector< vector > makeSimsDist(SparseDistanceMatrix*); int writeTree(string, Tree*); - int driver(vector, int, int, vector< vector >&); + int driver(SharedRAbundVectors*&, int, int, vector< vector >&); NameAssignment* nameMap; ListVector* list; @@ -106,7 +106,6 @@ class TreeGroupCommand : public Command { Tree* t; InputData* input; vector treeCalculators; - vector lookup; string lastLabel; string format, groupNames, filename, sharedfile, countfile, inputfile; int numGroups, subsampleSize, iters, processors; @@ -119,7 +118,7 @@ class TreeGroupCommand : public Command { vector Estimators, Groups, outputNames; //holds estimators to be used //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. - int process(vector); + int process(SharedRAbundVectors*&); diff --git a/source/commands/venncommand.cpp b/source/commands/venncommand.cpp index c7355b3f..5e88b819 100644 --- a/source/commands/venncommand.cpp +++ b/source/commands/venncommand.cpp @@ -283,17 +283,18 @@ int VennCommand::execute(){ if (vennCalculators.size() == 0) { m->mothurOut("No valid calculators given, please correct."); m->mothurOutEndLine(); return 0; } venn = new Venn(outputDir, nseqs, inputfile, fontsize, sharedOtus); - input = new InputData(inputfile, format); + InputData input(inputfile, format); string lastLabel; + SharedRAbundVectors* lookup = NULL; if (format == "sharedfile") { - lookup = input->getSharedRAbundVectors(); - lastLabel = lookup[0]->getLabel(); + lookup = input.getSharedRAbundVectors(); + lastLabel = lookup->getLabel(); - if ((lookup.size() > 4)) { combos = findCombinations(lookup.size()); } + if ((lookup->size() > 4)) { combos = findCombinations(lookup->size()); } }else if (format == "list") { - sabund = input->getSAbundVector(); + sabund = input.getSAbundVector(); lastLabel = sabund->getLabel(); } @@ -304,83 +305,83 @@ int VennCommand::execute(){ if (format != "list") { //as long as you are not at the end of the file or done wih the lines you want - while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((lookup != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - m->clearGroups(); delete venn; delete input; + delete lookup; m->clearGroups(); delete venn; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); - - - - if (lookup.size() > 4) { + if(allLines == 1 || labels.count(lookup->getLabel()) == 1){ + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); + + vector data = lookup->getSharedRAbundVectors(); + if (lookup->size() > 4) { set< set >::iterator it3; set::iterator it2; for (it3 = combos.begin(); it3 != combos.end(); it3++) { set poss = *it3; vector subset; - for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } + for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(data[*it2]); } vector outfilenames = venn->getPic(subset, vennCalculators); for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } } }else { - vector outfilenames = venn->getPic(lookup, vennCalculators); + vector outfilenames = venn->getPic(data, vennCalculators); for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } - } + } + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); } - if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = lookup[0]->getLabel(); + if ((m->anyLabelsToProcess(lookup->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = lookup->getLabel(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); - if (lookup.size() > 4) { - set< set >::iterator it3; - set::iterator it2; - for (it3 = combos.begin(); it3 != combos.end(); it3++) { - - set poss = *it3; - vector subset; - for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } - - vector outfilenames = venn->getPic(subset, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } - } - }else { - vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } - } - - //restore real lastlabel to save below - lookup[0]->setLabel(saveLabel); + vector data = lookup->getSharedRAbundVectors(); + if (lookup->size() > 4) { + set< set >::iterator it3; + set::iterator it2; + for (it3 = combos.begin(); it3 != combos.end(); it3++) { + + set poss = *it3; + vector subset; + for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(data[*it2]); } + + vector outfilenames = venn->getPic(subset, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } + } + }else { + vector outfilenames = venn->getPic(data, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } + } + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); + + lookup->setLabels(saveLabel); //restore real lastlabel to save below } - lastLabel = lookup[0]->getLabel(); + lastLabel = lookup->getLabel(); //get next line to process - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + delete lookup; + lookup = input.getSharedRAbundVectors(); } if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - m->clearGroups(); delete venn; delete input; + m->clearGroups(); delete venn; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -401,31 +402,32 @@ int VennCommand::execute(){ //run last label if you need to if (needToRun == true) { - for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } - lookup = input->getSharedRAbundVectors(lastLabel); + delete lookup; + lookup = input.getSharedRAbundVectors(lastLabel); - m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - processedLabels.insert(lookup[0]->getLabel()); - userLabels.erase(lookup[0]->getLabel()); + m->mothurOut(lookup->getLabel()); m->mothurOutEndLine(); + processedLabels.insert(lookup->getLabel()); + userLabels.erase(lookup->getLabel()); - if (lookup.size() > 4) { - set< set >::iterator it3; - set::iterator it2; - for (it3 = combos.begin(); it3 != combos.end(); it3++) { - - set poss = *it3; - vector subset; - for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(lookup[*it2]); } - - vector outfilenames = venn->getPic(subset, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } - } - }else { - vector outfilenames = venn->getPic(lookup, vennCalculators); - for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } - } - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } + vector data = lookup->getSharedRAbundVectors(); + if (lookup->size() > 4) { + set< set >::iterator it3; + set::iterator it2; + for (it3 = combos.begin(); it3 != combos.end(); it3++) { + + set poss = *it3; + vector subset; + for (it2 = poss.begin(); it2 != poss.end(); it2++) { subset.push_back(data[*it2]); } + + vector outfilenames = venn->getPic(subset, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } + } + }else { + vector outfilenames = venn->getPic(data, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { if (outfilenames[i] != "control" ) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } } + } + for (int i = 0; i < data.size(); i++) { delete data[i]; } data.clear(); + delete lookup; } @@ -433,7 +435,7 @@ int VennCommand::execute(){ m->clearGroups(); if (m->control_pressed) { - m->clearGroups(); delete venn; delete input; + m->clearGroups(); delete venn; for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; @@ -446,7 +448,7 @@ int VennCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - delete sabund; delete venn; delete input; + delete sabund; delete venn; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } @@ -466,7 +468,7 @@ int VennCommand::execute(){ string saveLabel = sabund->getLabel(); delete sabund; - sabund = input->getSAbundVector(lastLabel); + sabund = input.getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector outfilenames = venn->getPic(sabund, vennCalculators); @@ -483,14 +485,13 @@ int VennCommand::execute(){ lastLabel = sabund->getLabel(); delete sabund; - sabund = input->getSAbundVector(); + sabund = input.getSAbundVector(); } if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } - delete venn; delete input; - return 0; + delete venn; return 0; } //output error messages about any remaining user labels @@ -509,7 +510,7 @@ int VennCommand::execute(){ //run last label if you need to if (needToRun == true) { if (sabund != NULL) { delete sabund; } - sabund = input->getSAbundVector(lastLabel); + sabund = input.getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); vector outfilenames = venn->getPic(sabund, vennCalculators); @@ -520,7 +521,7 @@ int VennCommand::execute(){ } if (m->control_pressed) { - delete venn; delete input; + delete venn; for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; @@ -528,7 +529,7 @@ int VennCommand::execute(){ } for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - delete venn; delete input; + delete venn; m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/source/commands/venncommand.h b/source/commands/venncommand.h index 4762902c..93326ad2 100644 --- a/source/commands/venncommand.h +++ b/source/commands/venncommand.h @@ -35,11 +35,9 @@ class VennCommand : public Command { void help() { m->mothurOut(getHelpString()); } private: - InputData* input; SharedListVector* SharedList; Venn* venn; - vector vennCalculators; - vector lookup; + vector vennCalculators; set< set > combos; SAbundVector* sabund; int abund, fontsize, perm; diff --git a/source/datastructures/counttable.cpp b/source/datastructures/counttable.cpp index cf078fc1..24f7d173 100644 --- a/source/datastructures/counttable.cpp +++ b/source/datastructures/counttable.cpp @@ -385,6 +385,17 @@ int CountTable::printTable(string file) { } } /************************************************************/ +vector CountTable::getHardCodedHeaders() { + try { + vector headers; headers.push_back("Representative_Sequence"); headers.push_back("total"); + return headers; + } + catch(exception& e) { + m->errorOut(e, "CountTable", "printHeaders"); + exit(1); + } +} +/************************************************************/ int CountTable::printHeaders(ofstream& out) { try { out << "Representative_Sequence\ttotal"; diff --git a/source/datastructures/counttable.h b/source/datastructures/counttable.h index 58838007..9c9151b7 100644 --- a/source/datastructures/counttable.h +++ b/source/datastructures/counttable.h @@ -54,6 +54,7 @@ class CountTable { int printTable(string); int printHeaders(ofstream&); + vector getHardCodedHeaders(); //Representative_Sequence, total int printSeq(ofstream&, string); bool testGroups(string file); //used to check if file has group data without reading it bool testGroups(string file, vector&); //used to check if file has group data without reading it, return groups if found. diff --git a/source/datastructures/datavector.hpp b/source/datastructures/datavector.hpp index 1fc89923..fd29eb80 100644 --- a/source/datastructures/datavector.hpp +++ b/source/datastructures/datavector.hpp @@ -8,52 +8,46 @@ /* This class is parent to listvector, ordervector, rabundvector, sabundvector, sharedordervector, sharedrabundvector, sharedsabundvector. The child classes all contain OTU information in different forms. */ - +class SharedSAbundVector; +class SharedRAbundVectors; class RAbundVector; +class RAbundFloatVector; class SAbundVector; class OrderVector; class SharedListVector; class SharedOrderVector; -class SharedSAbundVector; -class SharedRAbundVector; -class SharedRAbundFloatVector; class GroupMap; class DataVector { public: - DataVector(){ m = MothurOut::getInstance(); }// : maxRank(0), numBins(0), numSeqs(0){}; + DataVector(){ m = MothurOut::getInstance(); } DataVector(string l) : label(l) { m = MothurOut::getInstance();}; - DataVector(const DataVector& dv) : label(dv.label){ m = MothurOut::getInstance();};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {}; + DataVector(const DataVector& dv) : label(dv.label){ m = MothurOut::getInstance();}; DataVector(ifstream&) {m = MothurOut::getInstance();} DataVector(ifstream&, GroupMap*){m = MothurOut::getInstance();} virtual ~DataVector(){}; - -// virtual int getNumBins() { return numBins; } -// virtual int getNumSeqs() { return numSeqs; } -// virtual int getMaxRank() { return maxRank; } - - virtual void resize(int) = 0; - virtual int size() = 0; + + virtual int size() = 0; + virtual void clear() = 0; virtual void print(ostream&) = 0; + virtual RAbundVector getRAbundVector() = 0; + virtual SAbundVector getSAbundVector() = 0; + virtual OrderVector getOrderVector(map* hold = NULL) = 0; + virtual void resize(int) = 0; + virtual void print(ostream&, map&) {} virtual void print(ostream&, bool) { m->mothurOut("[ERROR]: no print function\n"); } - virtual void printHeaders(ostream&) {}; - virtual void clear() = 0; - - void setLabel(string l) { label = l; } - string getLabel() { return label; } - - virtual RAbundVector getRAbundVector() = 0; - virtual SAbundVector getSAbundVector() = 0; - virtual OrderVector getOrderVector(map* hold = NULL) = 0; + virtual void printHeaders(ostream&) {}; + + void setLabel(string l) { label = l; } + string getLabel() { return label; } + protected: string label; MothurOut* m; -// int maxRank; -// int numBins; -// int numSeqs; + }; /***********************************************************************/ diff --git a/source/datastructures/distancedb.hpp b/source/datastructures/distancedb.hpp index 41509305..a19645ed 100644 --- a/source/datastructures/distancedb.hpp +++ b/source/datastructures/distancedb.hpp @@ -12,7 +12,7 @@ #include "mothur.h" -#include "dist.h" +#include "calculator.h" class DistanceDB : public Database { @@ -28,7 +28,7 @@ class DistanceDB : public Database { private: vector data; - Dist* distCalculator; + DistCalc* distCalculator; int templateSeqsLength; bool templateAligned; diff --git a/source/datastructures/fastqread.cpp b/source/datastructures/fastqread.cpp index d1f40ea4..b400bda0 100644 --- a/source/datastructures/fastqread.cpp +++ b/source/datastructures/fastqread.cpp @@ -180,46 +180,50 @@ FastqRead::FastqRead(boost::iostreams::filtering_istream& in, bool& ignore, stri ignore = false; format = f; - //fill convert table - goes from solexa to sanger. Used fq_all2std.pl as a reference. - for (int i = -64; i < 65; i++) { - char temp = (char) ((int)(33 + 10*log(1+pow(10,(i/10.0)))/log(10)+0.499)); - convertTable.push_back(temp); - } - - //read sequence name - string line = ""; std::getline(in, line); m->gobble(in); - vector pieces = m->splitWhiteSpace(line); - name = ""; if (pieces.size() != 0) { name = pieces[0]; } - if (name == "") { m->mothurOut("[WARNING]: Blank fasta name, ignoring read."); m->mothurOutEndLine(); ignore=true; } - else if (name[0] != '@') { m->mothurOut("[WARNING]: reading " + name + " expected a name with @ as a leading character, ignoring read."); m->mothurOutEndLine(); ignore=true; } - else { name = name.substr(1); } - if (pieces.size() > 1) { pieces.erase(pieces.begin()); comment = m->getStringFromVector(pieces, " "); } - - //read sequence - std::getline(in, sequence); m->gobble(in); - if (sequence == "") { m->mothurOut("[WARNING]: missing sequence for " + name + ", ignoring."); ignore=true; } - - //read sequence name - line = ""; std::getline(in, line); m->gobble(in); - pieces = m->splitWhiteSpace(line); - string name2 = ""; if (pieces.size() != 0) { name2 = pieces[0]; } - if (name2 == "") { m->mothurOut("[WARNING]: expected a name with + as a leading character, ignoring."); ignore=true; } - else if (name2[0] != '+') { m->mothurOut("[WARNING]: reading " + name2 + " expected a name with + as a leading character, ignoring."); ignore=true; } - else { name2 = name2.substr(1); if (name2 == "") { name2 = name; } } - //read quality scores - string quality = ""; std::getline(in, quality); m->gobble(in); - if (quality == "") { m->mothurOut("[WARNING]: missing quality for " + name2 + ", ignoring."); ignore=true; } - - //sanity check sequence length and number of quality scores match - if (name2 != "") { if (name != name2) { m->mothurOut("[WARNING]: names do not match. read " + name + " for fasta and " + name2 + " for quality, ignoring."); ignore=true; } } - if (quality.length() != sequence.length()) { m->mothurOut("[WARNING]: Lengths do not match for sequence " + name + ". Read " + toString(sequence.length()) + " characters for fasta and " + toString(quality.length()) + " characters for quality scores, ignoring read."); ignore=true; } - - scoreString = quality; - scores = convertQual(quality); - m->checkName(name); - - if (m->debug) { m->mothurOut("[DEBUG]: " + name + " " + sequence + " " + quality + "\n"); } + if (in.eof()) { ignore = true; } + else { + //fill convert table - goes from solexa to sanger. Used fq_all2std.pl as a reference. + for (int i = -64; i < 65; i++) { + char temp = (char) ((int)(33 + 10*log(1+pow(10,(i/10.0)))/log(10)+0.499)); + convertTable.push_back(temp); + } + + //read sequence name + string line = ""; std::getline(in, line); m->gobble(in); + vector pieces = m->splitWhiteSpace(line); + name = ""; if (pieces.size() != 0) { name = pieces[0]; } + if (name == "") { m->mothurOut("[WARNING]: Blank fasta name, ignoring read."); m->mothurOutEndLine(); ignore=true; } + else if (name[0] != '@') { m->mothurOut("[WARNING]: reading " + name + " expected a name with @ as a leading character, ignoring read."); m->mothurOutEndLine(); ignore=true; } + else { name = name.substr(1); } + if (pieces.size() > 1) { pieces.erase(pieces.begin()); comment = m->getStringFromVector(pieces, " "); } + + //read sequence + std::getline(in, sequence); m->gobble(in); + if (sequence == "") { m->mothurOut("[WARNING]: missing sequence for " + name + ", ignoring."); ignore=true; } + + //read sequence name + line = ""; std::getline(in, line); m->gobble(in); + pieces = m->splitWhiteSpace(line); + string name2 = ""; if (pieces.size() != 0) { name2 = pieces[0]; } + if (name2 == "") { m->mothurOut("[WARNING]: expected a name with + as a leading character, ignoring."); ignore=true; } + else if (name2[0] != '+') { m->mothurOut("[WARNING]: reading " + name2 + " expected a name with + as a leading character, ignoring."); ignore=true; } + else { name2 = name2.substr(1); if (name2 == "") { name2 = name; } } + + //read quality scores + string quality = ""; std::getline(in, quality); m->gobble(in); + if (quality == "") { m->mothurOut("[WARNING]: missing quality for " + name2 + ", ignoring."); ignore=true; } + + //sanity check sequence length and number of quality scores match + if (name2 != "") { if (name != name2) { m->mothurOut("[WARNING]: names do not match. read " + name + " for fasta and " + name2 + " for quality, ignoring."); ignore=true; } } + if (quality.length() != sequence.length()) { m->mothurOut("[WARNING]: Lengths do not match for sequence " + name + ". Read " + toString(sequence.length()) + " characters for fasta and " + toString(quality.length()) + " characters for quality scores, ignoring read."); ignore=true; } + + scoreString = quality; + scores = convertQual(quality); + m->checkName(name); + + if (m->debug) { m->mothurOut("[DEBUG]: " + name + " " + sequence + " " + quality + "\n"); } + } } catch(exception& e) { diff --git a/source/datastructures/optimatrix.cpp b/source/datastructures/optimatrix.cpp index 9670f5ed..f0f29de5 100644 --- a/source/datastructures/optimatrix.cpp +++ b/source/datastructures/optimatrix.cpp @@ -16,8 +16,10 @@ OptiMatrix::OptiMatrix(string d, string df, double c, bool s) : distFile(d), dis m = MothurOut::getInstance(); countfile = ""; namefile = ""; - if (distFormat == "phylip") { readPhylip(); } - else { readColumn(); } + setBlastVariables(5, 0.10, true); + if (distFormat == "phylip") { readPhylip(); } + else if (distFormat == "column") { readColumn(); } + else if (distFormat == "blast") { readBlast(); } } /***********************************************************************/ OptiMatrix::OptiMatrix(string d, string nc, string f, string df, double c, bool s) : distFile(d), distFormat(df), format(f), cutoff(c), sim(s) { @@ -27,9 +29,83 @@ OptiMatrix::OptiMatrix(string d, string nc, string f, string df, double c, bool else if (format == "count") { countfile = nc; namefile = ""; } else { countfile = ""; namefile = ""; } - if (distFormat == "phylip") { readPhylip(); } - else { readColumn(); } + setBlastVariables(5, 0.10, true); + if (distFormat == "phylip") { readPhylip(); } + else if (distFormat == "column") { readColumn(); } + else if (distFormat == "blast") { readBlast(); } + } +/*********************************************************************** +OptiMatrix::OptiMatrix(SparseDistanceMatrix* sparseMatrix, string nc, string f) : format(f) { + m = MothurOut::getInstance(); + + if (format == "name") { namefile = nc; countfile = ""; } + else if (format == "count") { countfile = nc; namefile = ""; } + else { countfile = ""; namefile = ""; } + + //sparse matrix contains singletons and "names" in matrix are the indexes provided by nameassignment class. + //This code converts the sparse matrix to an opti matrix by removing the singletons and changing the names. + //The singletons are stored separately by the OptiMatrix class. + + map nameAssignment; + if (namefile != "") { nameAssignment = m->readNames(namefile); } + else { CountTable ct; ct.readTable(countfile, false, true); nameAssignment = ct.getNameMap(); } + int count = 0; + map indexSwap; + map reverseNameAssignment; + for (map::iterator it = nameAssignment.begin(); it!= nameAssignment.end(); it++) { //nameMap now contains unique names and index into vector + reverseNameAssignment[it->second] = it->first; + indexSwap[it->second] = count; count++; + nameMap.push_back(it->first); + } + nameAssignment.clear(); + + //index i in seqVec = indexSwap->first. IndexMap->second = index into closeness + //singletonIndexSwap[IndexMap->second] = newIndexIntoCloseness + vector singleton; singleton.resize(nameAssignment.size(), true); + map singletonIndexSwap; + for (int i = 0; i < sparseMatrix->seqVec.size(); i++) { + if (sparseMatrix->seqVec[i].size() != 0) { singleton[i] = false; } + singletonIndexSwap[indexSwap[i]] = indexSwap[i]; + } + + int nonSingletonCount = 0; + for (int i = 0; i < singleton.size(); i++) { + if (!singleton[i]) { //if you are a singleton + singletonIndexSwap[indexSwap[i]] = nonSingletonCount; + nonSingletonCount++; + }else { singletons.push_back(nameMap[i]); } + } + singleton.clear(); + + closeness.resize(nonSingletonCount); + + map names; + if (namefile != "") { + m->readNames(namefile, names); + for (int i = 0; i < singletons.size(); i++) { + singletons[i] = names[singletons[i]]; + } + } + + for (int i = 0; i < sparseMatrix->seqVec.size(); i++) { + int seq1 = singletonIndexSwap[indexSwap[i]]; + string name = reverseNameAssignment[i]; + if (namefile != "") { name = names[reverseNameAssignment[i]]; } + nameMap[seq1] = name; + + if (sparseMatrix->seqVec[i].size() == 0) { }//singleton + else { + for (int j = 0; j < sparseMatrix->seqVec[i].size(); j++) { + int seq2 = singletonIndexSwap[indexSwap[sparseMatrix->seqVec[i][j].index]]; + closeness[seq1].insert(seq2); + closeness[seq2].insert(seq1); + } + sparseMatrix->seqVec[i].clear(); //save memory + } + } +}*/ + /***********************************************************************/ int OptiMatrix::readFile(string d, string nc, string f, string df, double c, bool s) { distFile = d; format = f; cutoff = c; sim = s; distFormat = df; @@ -38,8 +114,10 @@ int OptiMatrix::readFile(string d, string nc, string f, string df, double c, boo else if (format == "count") { countfile = nc; namefile = ""; } else { countfile = ""; namefile = ""; } - if (distFormat == "phylip") { readPhylip(); } - else { readColumn(); } + setBlastVariables(5, 0.10, true); + if (distFormat == "phylip") { readPhylip(); } + else if (distFormat == "column") { readColumn(); } + else if (distFormat == "blast") { readBlast(); } return 0; } @@ -52,10 +130,7 @@ ListVector* OptiMatrix::getListSingle() { else { singlelist = new ListVector(); - for (int i = 0; i < singletons.size(); i++) { - string otu = singletons[i]; - singlelist->push_back(otu); - } + for (int i = 0; i < singletons.size(); i++) { singlelist->push_back(singletons[i]); } } return singlelist; @@ -87,6 +162,7 @@ long int OptiMatrix::print(ostream& out) { /***********************************************************************/ string OptiMatrix::getName(int index) { try { + //return toString(index); if (index > closeness.size()) { m->mothurOut("[ERROR]: index is not valid.\n"); m->control_pressed = true; return ""; } string name = nameMap[index]; return name; @@ -97,37 +173,28 @@ string OptiMatrix::getName(int index) { } } /***********************************************************************/ -bool OptiMatrix::isClose(int i, int toFind){ +string OptiMatrix::getOverlapName(int index) { try { - bool found = false; - if (closeness[i].count(toFind) != 0) { found = true; } - return found; - + //return toString(index); + if (index > blastOverlap.size()) { m->mothurOut("[ERROR]: index is not valid.\n"); m->control_pressed = true; return ""; } + string name = overlapNameMap[index]; + return name; } catch(exception& e) { - m->errorOut(e, "OptiMatrix", "isClose"); + m->errorOut(e, "OptiMatrix", "getOverlapName"); exit(1); } } /***********************************************************************/ - -string OptiMatrix::findDistFormat(string distFile){ +bool OptiMatrix::isClose(int i, int toFind){ try { - string fileFormat = "column"; - - ifstream fileHandle; - string numTest; - - m->openInputFile(distFile, fileHandle); - fileHandle >> numTest; - fileHandle.close(); - - if (m->isContainingOnlyDigits(numTest)) { fileFormat = "phylip"; } + bool found = false; + if (closeness[i].count(toFind) != 0) { found = true; } + return found; - return fileFormat; } catch(exception& e) { - m->errorOut(e, "OptiMatrix", "findDistFormat"); + m->errorOut(e, "OptiMatrix", "isClose"); exit(1); } } @@ -338,9 +405,8 @@ int OptiMatrix::readColumn(){ ///////////////////// Read to eliminate singletons /////////////////////// ifstream fileHandle; m->openInputFile(distFile, fileHandle); - - map singletonIndexSwap; vector singleton; singleton.resize(nameAssignment.size(), true); + map singletonIndexSwap; while(fileHandle){ //let's assume it's a triangular matrix... fileHandle >> firstName; m->gobble(fileHandle); @@ -381,9 +447,6 @@ int OptiMatrix::readColumn(){ } singleton.clear(); - ifstream in; - m->openInputFile(distFile, in); - closeness.resize(nonSingletonCount); map names; @@ -394,6 +457,9 @@ int OptiMatrix::readColumn(){ } } + ifstream in; + m->openInputFile(distFile, in); + while(in){ //let's assume it's a triangular matrix... in >> firstName; m->gobble(in); @@ -434,6 +500,9 @@ int OptiMatrix::readColumn(){ in.close(); nameAssignment.clear(); + if (m->debug) { unsigned long long ramUsed = m->getRAMUsed(); unsigned long long total = m->getTotalRAM(); + m->mothurOut("\nCurrent RAM usage: " + toString(ramUsed/(double)GIG) + " Gigabytes. Total Ram: " + toString(total/(double)GIG) + " Gigabytes.\n"); } + return 1; } @@ -443,3 +512,530 @@ int OptiMatrix::readColumn(){ } } /***********************************************************************/ +int OptiMatrix::readBlast(){ + try { + map nameAssignment; + if (namefile != "") { nameAssignment = m->readNames(namefile); } + else if (countfile != "") { CountTable ct; ct.readTable(countfile, false, true); nameAssignment = ct.getNameMap(); } + else { readBlastNames(nameAssignment); } + int count = 0; + for (map::iterator it = nameAssignment.begin(); it!= nameAssignment.end(); it++) { + it->second = count; count++; + nameMap.push_back(it->first); + overlapNameMap.push_back(it->first); + } + + m->mothurOut("Reading Blast File... "); cout.flush(); + + string firstName, secondName, eScore, currentRow; currentRow = ""; + string repeatName = ""; + float distance, thisoverlap, refScore; + float percentId; + float numBases, mismatch, gap, startQuery, endQuery, startRef, endRef, score, lengthThisSeq; + map thisRowsBlastScores; + + ///////////////////// Read to eliminate singletons /////////////////////// + ifstream fileHandle; + m->openInputFile(distFile, fileHandle); + + map singletonIndexSwap; + map blastSingletonIndexSwap; + vector singleton; singleton.resize(nameAssignment.size(), true); + vector overlapSingleton; overlapSingleton.resize(nameAssignment.size(), true); + vector< map > dists; dists.resize(nameAssignment.size()); + + if (!fileHandle.eof()) { + //read in line from file + fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; + m->gobble(fileHandle); + + currentRow = firstName; + lengthThisSeq = numBases; + repeatName = firstName + secondName; + + if (firstName == secondName) { refScore = score; } + else{ + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + thisRowsBlastScores[secondName] = score; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + overlapSingleton[indexA] = false; + overlapSingleton[indexB] = false; + blastSingletonIndexSwap[indexA] = indexA; + blastSingletonIndexSwap[indexB] = indexB; + } + } + }else { m->mothurOut("Error in your blast file, cannot read."); m->mothurOutEndLine(); exit(1); } + + + while(fileHandle){ //let's assume it's a triangular matrix... + + if (m->control_pressed) { fileHandle.close(); return 0; } + + //read in line from file + fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; + m->gobble(fileHandle); + + string temp = firstName + secondName; //to check if this file has repeat lines, ie. is this a blast instead of a blscreen file + + //if this is a new pairing + if (temp != repeatName) { + repeatName = temp; + + if (currentRow == firstName) { + if (firstName == secondName) { refScore = score; } + else{ + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + //save score + thisRowsBlastScores[secondName] = score; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + overlapSingleton[indexA] = false; + overlapSingleton[indexB] = false; + blastSingletonIndexSwap[indexA] = indexA; + blastSingletonIndexSwap[indexB] = indexB; + } + } //end else + }else { //end row + //convert blast scores to distance and add cell to sparse matrix if we can + map::iterator it; + map::iterator itDist; + for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) { + distance = 1.0 - (it->second / refScore); + + //do we already have the distance calculated for b->a + map::iterator itA = nameAssignment.find(currentRow); + map::iterator itB = nameAssignment.find(it->first); + itDist = dists[itB->second].find(itA->first); + + //if we have it then compare + if (itDist != dists[itB->second].end()) { + + //if you want the minimum blast score ratio, then pick max distance + if(minWanted) { distance = max(itDist->second, distance); } + else{ distance = min(itDist->second, distance); } + + //is this distance below cutoff + if (distance < cutoff) { + int indexA = (itA->second); + int indexB = (itB->second); + singleton[indexA] = false; + singleton[indexB] = false; + singletonIndexSwap[indexA] = indexA; + singletonIndexSwap[indexB] = indexB; + } + //not going to need this again + dists[itB->second].erase(itDist); + }else { //save this value until we get the other ratio + dists[itA->second][it->first] = distance; + } + } + //clear out last rows info + thisRowsBlastScores.clear(); + + currentRow = firstName; + lengthThisSeq = numBases; + + //add this row to thisRowsBlastScores + if (firstName == secondName) { refScore = score; } + else{ //add this row to thisRowsBlastScores + + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + thisRowsBlastScores[secondName] = score; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + overlapSingleton[indexA] = false; + overlapSingleton[indexB] = false; + blastSingletonIndexSwap[indexA] = indexA; + blastSingletonIndexSwap[indexB] = indexB; + } + } + }//end if current row + }//end if repeat + } + fileHandle.close(); + + //convert blast scores to distance and add cell to sparse matrix if we can + map::iterator it; + map::iterator itDist; + for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) { + distance = 1.0 - (it->second / refScore); + + //do we already have the distance calculated for b->a + map::iterator itA = nameAssignment.find(currentRow); + map::iterator itB = nameAssignment.find(it->first); + itDist = dists[itB->second].find(itA->first); + + //if we have it then compare + if (itDist != dists[itB->second].end()) { + + //if you want the minimum blast score ratio, then pick max distance + if(minWanted) { distance = max(itDist->second, distance); } + else{ distance = min(itDist->second, distance); } + + //is this distance below cutoff + if (distance < cutoff) { + int indexA = (itA->second); + int indexB = (itB->second); + singleton[indexA] = false; + singleton[indexB] = false; + singletonIndexSwap[indexA] = indexA; + singletonIndexSwap[indexB] = indexB; + } + //not going to need this again + dists[itB->second].erase(itDist); + }else { //save this value until we get the other ratio + dists[itA->second][it->first] = distance; + } + } + //clear out info + thisRowsBlastScores.clear(); + dists.clear(); + + ////////////////////////////////////////////////////////////////////////// + int nonSingletonCount = 0; + for (int i = 0; i < singleton.size(); i++) { + if (!singleton[i]) { //if you are a singleton + singletonIndexSwap[i] = nonSingletonCount; + nonSingletonCount++; + }else { singletons.push_back(nameMap[i]); } + } + singleton.clear(); + + int overlapNonSingletonCount = 0; + for (int i = 0; i < overlapSingleton.size(); i++) { + if (!overlapSingleton[i]) { //if you are a singleton + blastSingletonIndexSwap[i] = overlapNonSingletonCount; + overlapNonSingletonCount++; + } + } + overlapSingleton.clear(); + + ifstream in; + m->openInputFile(distFile, in); + + dists.resize(nameAssignment.size()); + closeness.resize(nonSingletonCount); + blastOverlap.resize(overlapNonSingletonCount); + + map names; + if (namefile != "") { + m->readNames(namefile, names); + for (int i = 0; i < singletons.size(); i++) { + singletons[i] = names[singletons[i]]; + } + } + + m->mothurOut(" halfway ... "); cout.flush(); + + if (!in.eof()) { + //read in line from file + in >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; + m->gobble(fileHandle); + + currentRow = firstName; + lengthThisSeq = numBases; + repeatName = firstName + secondName; + + if (firstName == secondName) { refScore = score; } + else{ + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + thisRowsBlastScores[secondName] = score; + + if (namefile != "") { + firstName = names[firstName]; //redundant names + secondName = names[secondName]; //redundant names + } + + nameMap[singletonIndexSwap[itA->second]] = firstName; + nameMap[singletonIndexSwap[itB->second]] = secondName; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + + int newB = blastSingletonIndexSwap[indexB]; + int newA = blastSingletonIndexSwap[indexA]; + blastOverlap[newA].insert(newB); + blastOverlap[newB].insert(newA); + + overlapNameMap[newA] = firstName; + overlapNameMap[newB] = secondName; + } + } + }else { m->mothurOut("Error in your blast file, cannot read."); m->mothurOutEndLine(); exit(1); } + + + while(in){ //let's assume it's a triangular matrix... + + if (m->control_pressed) { fileHandle.close(); return 0; } + + //read in line from file + in >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score; + m->gobble(fileHandle); + + string temp = firstName + secondName; //to check if this file has repeat lines, ie. is this a blast instead of a blscreen file + + //if this is a new pairing + if (temp != repeatName) { + repeatName = temp; + + if (currentRow == firstName) { + if (firstName == secondName) { refScore = score; } + else{ + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + //save score + thisRowsBlastScores[secondName] = score; + + if (namefile != "") { + firstName = names[firstName]; //redundant names + secondName = names[secondName]; //redundant names + } + + nameMap[singletonIndexSwap[itA->second]] = firstName; + nameMap[singletonIndexSwap[itB->second]] = secondName; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + + int newB = blastSingletonIndexSwap[indexB]; + int newA = blastSingletonIndexSwap[indexA]; + blastOverlap[newA].insert(newB); + blastOverlap[newB].insert(newA); + + overlapNameMap[newA] = firstName; + overlapNameMap[newB] = secondName; } + } //end else + }else { //end row + //convert blast scores to distance and add cell to sparse matrix if we can + map::iterator it; + map::iterator itDist; + for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) { + distance = 1.0 - (it->second / refScore); + + //do we already have the distance calculated for b->a + map::iterator itA = nameAssignment.find(currentRow); + map::iterator itB = nameAssignment.find(it->first); + itDist = dists[itB->second].find(itA->first); + + //if we have it then compare + if (itDist != dists[itB->second].end()) { + + //if you want the minimum blast score ratio, then pick max distance + if(minWanted) { distance = max(itDist->second, distance); } + else{ distance = min(itDist->second, distance); } + + //is this distance below cutoff + if (distance < cutoff) { + int indexA = (itA->second); + int indexB = (itB->second); + + int newB = singletonIndexSwap[indexB]; + int newA = singletonIndexSwap[indexA]; + closeness[newA].insert(newB); + closeness[newB].insert(newA); + } + //not going to need this again + dists[itB->second].erase(itDist); + }else { //save this value until we get the other ratio + dists[itA->second][it->first] = distance; + } + } + //clear out last rows info + thisRowsBlastScores.clear(); + + currentRow = firstName; + lengthThisSeq = numBases; + + //add this row to thisRowsBlastScores + if (firstName == secondName) { refScore = score; } + else{ //add this row to thisRowsBlastScores + + //convert name to number + map::iterator itA = nameAssignment.find(firstName); + map::iterator itB = nameAssignment.find(secondName); + if(itA == nameAssignment.end()){ m->mothurOut("AError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1); } + if(itB == nameAssignment.end()){ m->mothurOut("BError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1); } + + thisRowsBlastScores[secondName] = score; + + //calc overlap score + thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty); + + //if there is a valid overlap, add it + if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) { + int indexA = (itA->second); + int indexB = (itB->second); + + int newB = blastSingletonIndexSwap[indexB]; + int newA = blastSingletonIndexSwap[indexA]; + blastOverlap[newA].insert(newB); + blastOverlap[newB].insert(newA); + + overlapNameMap[newA] = firstName; + overlapNameMap[newB] = secondName; + } + } + }//end if current row + }//end if repeat + } + in.close(); + + //convert blast scores to distance and add cell to sparse matrix if we can + for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) { + distance = 1.0 - (it->second / refScore); + + //do we already have the distance calculated for b->a + map::iterator itA = nameAssignment.find(currentRow); + map::iterator itB = nameAssignment.find(it->first); + itDist = dists[itB->second].find(itA->first); + + //if we have it then compare + if (itDist != dists[itB->second].end()) { + + //if you want the minimum blast score ratio, then pick max distance + if(minWanted) { distance = max(itDist->second, distance); } + else{ distance = min(itDist->second, distance); } + + //is this distance below cutoff + if (distance < cutoff) { + int indexA = (itA->second); + int indexB = (itB->second); + + int newB = singletonIndexSwap[indexB]; + int newA = singletonIndexSwap[indexA]; + closeness[newA].insert(newB); + closeness[newB].insert(newA); + } + //not going to need this again + dists[itB->second].erase(itDist); + }else { //save this value until we get the other ratio + dists[itA->second][it->first] = distance; + } + } + //clear out info + thisRowsBlastScores.clear(); + dists.clear(); + nameAssignment.clear(); + + m->mothurOut(" done."); m->mothurOutEndLine(); + + return 1; + + } + catch(exception& e) { + m->errorOut(e, "OptiMatrix", "readBlast"); + exit(1); + } +} +/*********************************************************************************************/ +int OptiMatrix::readBlastNames(map& nameAssignment) { + try { + m->mothurOut("Reading names... "); cout.flush(); + + string name, hold, prevName; + int num = 0; + + ifstream in; + m->openInputFile(distFile, in); + + //read first line + in >> prevName; + + for (int i = 0; i < 11; i++) { in >> hold; } + m->gobble(in); + + //save name in nameMap + nameAssignment[prevName] = num; num++; + + map::iterator it; + while (!in.eof()) { + if (m->control_pressed) { in.close(); return 0; } + + //read line + in >> name; + + for (int i = 0; i < 11; i++) { in >> hold; } + m->gobble(in); + + //is this a new name? + if (name != prevName) { + prevName = name; + + it = nameAssignment.find(name); + if (it != nameAssignment.end()) { m->mothurOut("[ERROR]: trying to exact names from blast file, and I found dups. Are you sequence names unique? quitting.\n"); m->control_pressed = true; } + else { + nameAssignment[name] = num; num++; + } + } + } + + in.close(); + + if (m->control_pressed) { return 0; } + + m->mothurOut(toString(num) + " names read."); m->mothurOutEndLine(); + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "OptiMatrix", "readBlastNames"); + exit(1); + } +} + +/***********************************************************************/ + diff --git a/source/datastructures/optimatrix.h b/source/datastructures/optimatrix.h index d16f98bf..35d05bc0 100644 --- a/source/datastructures/optimatrix.h +++ b/source/datastructures/optimatrix.h @@ -11,48 +11,59 @@ #include "mothurout.h" #include "listvector.hpp" +#include "sparsedistancematrix.h" class OptiMatrix { #ifdef UNIT_TEST friend class TestOptiMatrix; + friend class FakeOptiMatrix; #endif public: + OptiMatrix() { m = MothurOut::getInstance(); } OptiMatrix(string, string, double, bool); //distfile, distformat, cutoff, sim OptiMatrix(string, string, string, string, double, bool); //distfile, name or count, format, distformat, cutoff, sim + //OptiMatrix(SparseDistanceMatrix*, string, string); //sparse matrix, name or count, format ~OptiMatrix(){ } + int readFile(string, string, string, string, double, bool); //distfile, name or count, format, distformat, cutoff, sim set getCloseSeqs(int i) { return closeness[i]; } - //int get(int i, int j) { return closeness[i][j]; } bool isClose(int, int); int getNumClose(int index) { return closeness[index].size(); } int getNumSeqs() { return closeness.size(); } int getNumSingletons() { return singletons.size(); } - //map getNameMap() { return nameMap; } + string getName(int); //name from nameMap index ListVector* getListSingle(); long int print(ostream&); - int readFile(string, string, string, string, double, bool); //distfile, name or count, format, distformat, cutoff, sim -private: + //for mgcluster - reading blast files + vector< set > getBlastOverlap() { return blastOverlap; } + void setBlastVariables(int l, float p, bool m) { length = l; penalty = p; minWanted = m; }//length, penalty, minWanted + string getOverlapName(int); //name from nameMap index + +protected: + MothurOut* m; vector< set > closeness; //closeness[0] contains indexes of seqs "close" to seq 0. + vector< set > blastOverlap; //empty unless reading a blast file. vector singletons; vector nameMap; + vector overlapNameMap; string distFile, namefile, countfile, format, distFormat; double cutoff; - bool sim; - - MothurOut* m; - - string findDistFormat(string distFile); + bool sim, minWanted; + float penalty; + int length; + int readPhylip(); int readColumn(); - map readNames(string namefile, vector&); + int readBlast(); + int readBlastNames(map& nameAssignment); }; diff --git a/source/datastructures/rabundfloatvector.cpp b/source/datastructures/rabundfloatvector.cpp new file mode 100644 index 00000000..cc7584e3 --- /dev/null +++ b/source/datastructures/rabundfloatvector.cpp @@ -0,0 +1,350 @@ +// +// rabundfloatvector.cpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "rabundfloatvector.hpp" +#include "rabundvector.hpp" +#include "sabundvector.hpp" +#include "ordervector.hpp" + + +/***********************************************************************/ + +RAbundFloatVector::RAbundFloatVector() : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0), group("") {} + +/***********************************************************************/ + +RAbundFloatVector::RAbundFloatVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(0), numSeqs(0), group("") {} + +/***********************************************************************/ + +//RAbundVector::RAbundVector(const RAbundVector& rav) : DataVector(rav), data(rav.data), (rav.label), (rav.maxRank), (rav.numBins), (rav.numSeqs){} + + +/***********************************************************************/ + +RAbundFloatVector::RAbundFloatVector(string id, vector rav) : DataVector(id), data(rav), group("") { + try { + numBins = 0; + maxRank = 0; + numSeqs = 0; + + for(int i=0;i maxRank) { maxRank = data[i]; } + numSeqs += data[i]; + } + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "RAbundFloatVector"); + exit(1); + } +} + +/***********************************************************************/ + +RAbundFloatVector::RAbundFloatVector(vector rav, float mr, int nb, float ns) : group(""){ + try { + numBins = nb; + maxRank = mr; + numSeqs = ns; + data = rav; + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "RAbundFloatVector"); + exit(1); + } +} +/***********************************************************************/ + + +RAbundFloatVector::RAbundFloatVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0), group("") { + try { + int hold; + f >> label >> hold; + + data.assign(hold, 0); + float inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "RAbundFloatVector"); + exit(1); + } +} + +/***********************************************************************/ +RAbundFloatVector::RAbundFloatVector(ifstream& f, string l, string g) : DataVector(), maxRank(0), numBins(0), numSeqs(0), group(g) { + try { + int hold; + label = l; + f >> numBins; + + float inputData; + for(int i=0;i> inputData; + push_back(inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "RAbundFloatVector"); + exit(1); + } +} + +/***********************************************************************/ + +RAbundFloatVector::~RAbundFloatVector() {} + +/***********************************************************************/ + +void RAbundFloatVector::set(int binNumber, float newBinSize){ + try { + float oldBinSize = data[binNumber]; + data[binNumber] = newBinSize; + + if(oldBinSize == 0) { numBins++; } + if(newBinSize == 0) { numBins--; } + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs += (newBinSize - oldBinSize); + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "set"); + exit(1); + } +} + +/***********************************************************************/ + +float RAbundFloatVector::get(int index){ + return data[index]; + +} +/***********************************************************************/ + +void RAbundFloatVector::clear(){ + numBins = 0; + maxRank = 0; + numSeqs = 0; + data.clear(); + +} +/***********************************************************************/ + +void RAbundFloatVector::push_back(float binSize){ + try { + data.push_back(binSize); + numBins++; + + if(binSize > maxRank){ + maxRank = binSize; + } + + numSeqs += binSize; + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "push_back"); + exit(1); + } +} + +/***********************************************************************/ + +void RAbundFloatVector::pop_back(){ + + return data.pop_back(); +} + +/***********************************************************************/ + +void RAbundFloatVector::resize(int size){ + + data.resize(size); +} + +/***********************************************************************/ + +int RAbundFloatVector::size(){ + return data.size(); +} + +/***********************************************************************/ + +void RAbundFloatVector::quicksort(){ + sort(data.rbegin(), data.rend()); +} + +/***********************************************************************/ + +float RAbundFloatVector::sum(){ + return sum(0); +} + +/***********************************************************************/ + +float RAbundFloatVector::sum(int index){ + float sum = 0; + for(int i = index; i < data.size(); i++) { sum += data[i]; } + return sum; +} +/***********************************************************************/ + +float RAbundFloatVector::remove(int bin){ + try { + float abund = data[bin]; + data.erase(data.begin()+bin); + numBins--; + + if(abund == maxRank){ + maxRank = m->max(data); + } + + numSeqs -= abund; + + return abund; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "remove"); + exit(1); + } +} + +/***********************************************************************/ + +int RAbundFloatVector::numNZ(){ + int numNZ = 0; + for(int i = 0; i < data.size(); i++) { if(data[i] != 0) { numNZ++; } } + return numNZ; +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundFloatVector::rbegin(){ + return data.rbegin(); +} + +/***********************************************************************/ + +vector::reverse_iterator RAbundFloatVector::rend(){ + return data.rend(); +} + +/***********************************************************************/ +void RAbundFloatVector::nonSortedPrint(ostream& output){ + try { + output << label; + if (group != "") { output << '\t' << group; } + output << '\t' << numBins; + + + for(int i=0;ierrorOut(e, "RAbundFloatVector", "nonSortedPrint"); + exit(1); + } +} +/***********************************************************************/ +void RAbundFloatVector::print(ostream& output){ + try { + output << label; + if (group != "") { output << '\t' << group; } + output << '\t' << numBins; + + vector hold = data; + sort(hold.rbegin(), hold.rend()); + + for(int i=0;ierrorOut(e, "RAbundFloatVector", "print"); + exit(1); + } +} +/***********************************************************************/ +int RAbundFloatVector::getNumBins(){ + return numBins; +} + +/***********************************************************************/ + +float RAbundFloatVector::getNumSeqs(){ + return numSeqs; +} + +/***********************************************************************/ + +float RAbundFloatVector::getMaxRank(){ + return maxRank; +} + +/***********************************************************************/ + +RAbundFloatVector RAbundFloatVector::getRAbundFloatVector(){ + return *this; +} +/***********************************************************************/ + +RAbundVector RAbundFloatVector::getRAbundVector(){ + RAbundVector rav; + rav.setLabel(label); + for (int i = 0; i < data.size(); i++) { rav.push_back((int)data[i]); } + return rav; +} +/***********************************************************************/ + +SAbundVector RAbundFloatVector::getSAbundVector() { + try { + SAbundVector sav(maxRank+1); + + for(int i=0;ierrorOut(e, "RAbundFloatVector", "getSAbundVector"); + exit(1); + } +} + +/***********************************************************************/ + +OrderVector RAbundFloatVector::getOrderVector(map* nameMap = NULL) { + try { + OrderVector ov; + + for(int i=0;imothurRandomShuffle(ov); + ov.setLabel(label); + ov.getNumBins(); + + return ov; + } + catch(exception& e) { + m->errorOut(e, "RAbundFloatVector", "getOrderVector"); + exit(1); + } +} + +/***********************************************************************/ diff --git a/source/datastructures/rabundfloatvector.hpp b/source/datastructures/rabundfloatvector.hpp new file mode 100644 index 00000000..42c3f5b5 --- /dev/null +++ b/source/datastructures/rabundfloatvector.hpp @@ -0,0 +1,78 @@ +// +// rabundfloatvector.hpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef rabundfloatvector_hpp +#define rabundfloatvector_hpp + +#include "datavector.hpp" + +/* Data Structure for a rabund file. + This class is a child to datavector. It represents OTU information at a certain distance. + A rabundvector can be converted into and ordervector, listvector or sabundvector. + Each member of the internal container "data" represents an individual OTU. + So data[0] = 6, because there are six member in that OTU. + example: listvector = a,b,c,d,e,f g,h,i j,k l m + rabundvector = 6 3 2 1 1 + sabundvector = 2 1 1 0 0 1 + ordervector = 1 1 1 1 1 1 2 2 2 3 3 4 5 */ + +class RAbundFloatVector : public DataVector { + +public: + RAbundFloatVector(); + RAbundFloatVector(int); + RAbundFloatVector(vector, float, int, float); + RAbundFloatVector(string, vector); + RAbundFloatVector(const RAbundFloatVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs), group(bv.group) {}; + RAbundFloatVector(ifstream&); + RAbundFloatVector(ifstream& f, string l, string g); //label, group + ~RAbundFloatVector(); + + int getNumBins(); + float getNumSeqs(); + float getMaxRank(); + + void set(int, float); + float get(int); + vector get() { return data; } + void push_back(float); + float remove(int); + void pop_back(); + void resize(int); + int size(); + void quicksort(); + float sum(); + float sum(int); + int numNZ(); + void clear(); + vector::reverse_iterator rbegin(); + vector::reverse_iterator rend(); + + void print(ostream&); + void nonSortedPrint(ostream&); + + RAbundFloatVector getRAbundFloatVector(); + RAbundVector getRAbundVector(); + SAbundVector getSAbundVector(); + OrderVector getOrderVector(map*); + + string getGroup() { return group; } //group = "" for rabunds without groupInfo + void setGroup(string g) { group = g; } + +private: + vector data; + float maxRank; + int numBins; + float numSeqs; + + string group; +}; + + + +#endif /* rabundfloatvector_hpp */ diff --git a/source/datastructures/rabundvector.cpp b/source/datastructures/rabundvector.cpp index 83530034..fbf6ea0c 100644 --- a/source/datastructures/rabundvector.cpp +++ b/source/datastructures/rabundvector.cpp @@ -10,7 +10,7 @@ #include "rabundvector.hpp" #include "sabundvector.hpp" #include "ordervector.hpp" -#include "calculator.h" +#include "rabundfloatvector.hpp" /***********************************************************************/ @@ -45,6 +45,17 @@ RAbundVector::RAbundVector(string id, vector rav) : DataVector(id), data(ra exit(1); } } +/***********************************************************************/ + +RAbundVector::RAbundVector(vector rav) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + for(int i=0;ierrorOut(e, "RAbundVector", "RAbundVector"); + exit(1); + } +} /***********************************************************************/ @@ -60,19 +71,38 @@ RAbundVector::RAbundVector(vector rav, int mr, int nb, int ns) { exit(1); } } - /***********************************************************************/ RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + int hold; + f >> label >> hold; + + data.assign(hold, 0); + int inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "RAbundVector"); + exit(1); + } +} + +/***********************************************************************/ +RAbundVector::RAbundVector(ifstream& f, string l) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - int hold; - f >> label >> hold; + label = l; + f >> numBins; + data.assign(numBins, 0); - data.assign(hold, 0); int inputData; - - for(int i=0;i> inputData; set(i, inputData); } @@ -142,7 +172,27 @@ void RAbundVector::push_back(int binSize){ exit(1); } } +/***********************************************************************/ +int RAbundVector::remove(int bin){ + try { + int abund = data[bin]; + data.erase(data.begin()+bin); + numBins--; + + if(abund == maxRank){ + maxRank = m->max(data); + } + + numSeqs -= abund; + + return abund; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "remove"); + exit(1); + } +} /***********************************************************************/ void RAbundVector::pop_back(){ @@ -172,24 +222,31 @@ void RAbundVector::quicksort(){ /***********************************************************************/ int RAbundVector::sum(){ - VecCalc vecCalc; - return vecCalc.sumElements(data); + return m->sum(data); } /***********************************************************************/ int RAbundVector::sum(int index){ - VecCalc vecCalc; - return vecCalc.sumElements(data, index); + int sum = 0; + for(int i = index; i < data.size(); i++) { sum += data[i]; } + return sum; } /***********************************************************************/ int RAbundVector::numNZ(){ - VecCalc vecCalc; - return vecCalc.numNZ(data); + int numNZ = 0; + for(int i = 0; i < data.size(); i++) { if(data[i] != 0) { numNZ++; } } + return numNZ; } +/***********************************************************************/ +vector RAbundVector::getSortedD(){ + vector temp; temp = data; + sort(temp.begin()+1, temp.end()); + return temp; +} /***********************************************************************/ vector::reverse_iterator RAbundVector::rbegin(){ @@ -205,7 +262,8 @@ vector::reverse_iterator RAbundVector::rend(){ /***********************************************************************/ void RAbundVector::nonSortedPrint(ostream& output){ try { - output << label << '\t' << numBins; + output << label; + output << '\t' << numBins; for(int i=0;i hold = data; - sort(hold.rbegin(), hold.rend()); - - for(int i=0;ierrorOut(e, "RAbundVector", "print"); - exit(1); - } -} - - -/***********************************************************************/ void RAbundVector::print(ostream& output){ try { - output << label << '\t' << numBins; + output << label; + output << '\t' << numBins; vector hold = data; sort(hold.rbegin(), hold.rend()); @@ -249,7 +290,6 @@ void RAbundVector::print(ostream& output){ exit(1); } } - /***********************************************************************/ int RAbundVector::getNumBins(){ return numBins; @@ -272,6 +312,13 @@ int RAbundVector::getMaxRank(){ RAbundVector RAbundVector::getRAbundVector(){ return *this; } +/***********************************************************************/ + +RAbundFloatVector RAbundVector::getRAbundFloatVector(){ + RAbundFloatVector rav; rav.setLabel(label); + for(int i=0;i, int, int, int); -// RAbundVector(const RAbundVector&); + RAbundVector(vector); RAbundVector(string, vector); - RAbundVector(const RAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs){}; + RAbundVector(const RAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs) {}; RAbundVector(ifstream&); - ~RAbundVector(); + RAbundVector(ifstream& f, string l); //filehandle, label + ~RAbundVector(); - int getNumBins(); + int getNumBins(); int getNumSeqs(); int getMaxRank(); + int remove(int); void set(int, int); int get(int); + vector get() { return data; } void push_back(int); void pop_back(); void resize(int); @@ -42,23 +45,24 @@ class RAbundVector : public DataVector { int sum(); int sum(int); int numNZ(); + vector getSortedD(); void clear(); vector::reverse_iterator rbegin(); vector::reverse_iterator rend(); - void print(ostream&); - void print(string, ostream&); - void nonSortedPrint(ostream&); + void print(ostream&); //sorted + void nonSortedPrint(ostream&); //nonsorted RAbundVector getRAbundVector(); + RAbundFloatVector getRAbundFloatVector(); SAbundVector getSAbundVector(); OrderVector getOrderVector(map*); - + private: vector data; int maxRank; int numBins; - int numSeqs; + int numSeqs; }; diff --git a/source/datastructures/sabundvector.cpp b/source/datastructures/sabundvector.cpp index 6aa9b7f2..e04cefbf 100644 --- a/source/datastructures/sabundvector.cpp +++ b/source/datastructures/sabundvector.cpp @@ -8,7 +8,6 @@ */ #include "sabundvector.hpp" -#include "calculator.h" /***********************************************************************/ @@ -126,8 +125,7 @@ void SAbundVector::quicksort(){ /***********************************************************************/ int SAbundVector::sum(){ - VecCalc vecCalc; - return vecCalc.sumElements(data); + return m->sum(data); } /***********************************************************************/ diff --git a/source/datastructures/sequencedb.cpp b/source/datastructures/sequencedb.cpp index 55d4ef1e..e75d7ca2 100644 --- a/source/datastructures/sequencedb.cpp +++ b/source/datastructures/sequencedb.cpp @@ -40,7 +40,7 @@ SequenceDB::SequenceDB(ifstream& filehandle) { if (newSequence.getName() != "") { if (length == 0) { length = newSequence.getAligned().length(); } - if (length != newSequence.getAligned().length()) { samelength = false; } + if (length != newSequence.getAligned().length()) { samelength = false; } data.push_back(newSequence); } diff --git a/source/datastructures/sharedlistvector.cpp b/source/datastructures/sharedlistvector.cpp index 07c77c36..5c9b8a06 100644 --- a/source/datastructures/sharedlistvector.cpp +++ b/source/datastructures/sharedlistvector.cpp @@ -341,72 +341,33 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ } } /***********************************************************************/ -SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { +SharedRAbundVectors* SharedListVector::getSharedRAbundVector() { try { m->currentSharedBinLabels = binLabels; - SharedRAbundVector rav(data.size()); - - for(int i=0;i binNames; - m->splitAtComma(names, binNames); - for (int j = 0; j < binNames.size(); j++) { - if (m->control_pressed) { return rav; } - if (m->groupMode == "group") { - string group = groupmap->getGroup(binNames[j]); - if(group == "not found") { m->mothurOut("Error: Sequence '" + binNames[j] + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } - if (group == groupName) { //this name is in the group you want the vector for. - rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in - } - }else { - int count = countTable->getGroupCount(binNames[j], groupName); - rav.set(i, rav.getAbundance(i) + count, groupName); - } - } - } - - rav.setLabel(label); - rav.setGroup(groupName); - - return rav; - - } - catch(exception& e) { - m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); - exit(1); - } -} -/***********************************************************************/ -vector SharedListVector::getSharedRAbundVector() { - try { - m->currentSharedBinLabels = binLabels; - - SharedUtil* util; - util = new SharedUtil(); - vector lookup; //contains just the groups the user selected - vector lookupDelete; - map finder; //contains all groups in groupmap - + SharedUtil util; vector Groups = m->getGroups(); vector allGroups; if (m->groupMode == "group") { allGroups = groupmap->getNamesOfGroups(); } else { allGroups = countTable->getNamesOfGroups(); } - util->setGroups(Groups, allGroups); + util.setGroups(Groups, allGroups); m->setGroups(Groups); - delete util; + vector lookup; //contains just the groups the user selected + vector groups; + map finder; //contains all groups in groupmap + map::iterator it; + for (int i = 0; i < allGroups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(data.size()); - finder[allGroups[i]] = temp; - finder[allGroups[i]]->setLabel(label); - finder[allGroups[i]]->setGroup(allGroups[i]); if (m->inUsersGroups(allGroups[i], m->getGroups())) { //if this group is in user groups + SharedRAbundVector* temp = new SharedRAbundVector(numBins); + finder[allGroups[i]] = temp; + finder[allGroups[i]]->setLabel(label); + finder[allGroups[i]]->setGroup(allGroups[i]); lookup.push_back(finder[allGroups[i]]); - }else { - lookupDelete.push_back(finder[allGroups[i]]); - } - } + groups.push_back(allGroups[i]); + } + } //fill vectors for(int i=0;i SharedListVector::getSharedRAbundVector() { if (m->groupMode == "group") { string group = groupmap->getGroup(binNames[j]); if(group == "not found") { m->mothurOut("Error: Sequence '" + binNames[j] + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } - finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in + it = finder.find(group); + if (it != finder.end()) { it->second->set(i, it->second->get(i) + 1); } //i represents what bin you are in }else{ vector counts = countTable->getGroupCounts(binNames[j]); for (int k = 0; k < allGroups.size(); k++) { - finder[allGroups[k]]->set(i, finder[allGroups[k]]->getAbundance(i) + counts[k], allGroups[k]); + it = finder.find(allGroups[k]); + if (it != finder.end()) { it->second->set(i, it->second->get(i) + counts[k]); } //i represents what bin you are in } } } } - for (int j = 0; j < lookupDelete.size(); j++) { delete lookupDelete[j]; } + SharedRAbundVectors* shared = new SharedRAbundVectors(); + for (int j = 0; j < lookup.size(); j++) { shared->push_back(lookup[j]); } + shared->eliminateZeroOTUS(); - return lookup; + return shared; } catch(exception& e) { m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } - /***********************************************************************/ -SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) { - try { - SharedSAbundVector sav; - SharedRAbundVector rav; - - rav = this->getSharedRAbundVector(groupName); - sav = rav.getSharedSAbundVector(); - - return sav; - } - catch(exception& e) { - m->errorOut(e, "SharedListVector", "getSharedSAbundVector"); - exit(1); - } +SharedRAbundFloatVectors* SharedListVector::getSharedRAbundFloatVector() { + try { + SharedRAbundVectors* shared = getSharedRAbundVector(); + vector thisLookup = shared->getSharedRAbundFloatVectors(); + SharedRAbundFloatVectors* sharedFloat = new SharedRAbundFloatVectors(); + for (int j = 0; j < thisLookup.size(); j++) { sharedFloat->push_back(thisLookup[j]); } + return sharedFloat; + } + catch(exception& e) { + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); + exit(1); + } } + /***********************************************************************/ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ diff --git a/source/datastructures/sharedlistvector.h b/source/datastructures/sharedlistvector.h index 13fed979..7baf7685 100644 --- a/source/datastructures/sharedlistvector.h +++ b/source/datastructures/sharedlistvector.h @@ -13,8 +13,8 @@ #include "datavector.hpp" #include "groupmap.h" #include "counttable.h" -#include "sharedrabundvector.h" -#include "sharedsabundvector.h" +#include "sharedrabundvectors.hpp" +#include "sharedrabundfloatvectors.hpp" /* This class is a child to datavector. It represents OTU information at a certain distance. A sharedlistvector can be converted into a sharedordervector, sharedrabundvector or sharedsabundvectorand @@ -54,9 +54,8 @@ class SharedListVector : public DataVector { SAbundVector getSAbundVector(); OrderVector getOrderVector(map*); SharedOrderVector* getSharedOrderVector(); - SharedRAbundVector getSharedRAbundVector(string); //get sharedrabundvector for a certain group - SharedSAbundVector getSharedSAbundVector(string); //get sharedsabundvector for a certain group - vector getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups + SharedRAbundVectors* getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups + SharedRAbundFloatVectors* getSharedRAbundFloatVector(); //returns sharedRabundVectors for all the users groups private: vector data; //data[i] is a list of names of sequences in the ith OTU. diff --git a/source/datastructures/sharedordervector.cpp b/source/datastructures/sharedordervector.cpp index 379fced4..99725545 100644 --- a/source/datastructures/sharedordervector.cpp +++ b/source/datastructures/sharedordervector.cpp @@ -155,9 +155,6 @@ int SharedOrderVector::getMaxRank(){ /***********************************************************************/ - - - void SharedOrderVector::set(int index, int binNumber, int abund, string groupName){ data[index].group = groupName; @@ -295,19 +292,22 @@ SAbundVector SharedOrderVector::getSAbundVector(){ } /***********************************************************************/ -SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) { +SharedRAbundVectors* SharedOrderVector::getSharedRAbundVector(string group) { try { - SharedRAbundVector sharedRav(data.size()); + SharedRAbundVector* sharedRav = new SharedRAbundVector(data.size()); - sharedRav.setLabel(label); - sharedRav.setGroup(group); + sharedRav->setLabel(label); + sharedRav->setGroup(group); for (int i = 0; i < data.size(); i++) { if (data[i].group == group) { - sharedRav.set(data[i].abundance, sharedRav.getAbundance(data[i].abundance) + 1, data[i].group); + sharedRav->set(data[i].abundance, sharedRav->get(data[i].abundance) + 1); } } - return sharedRav; + + SharedRAbundVectors* lookup = new SharedRAbundVectors(); + lookup->push_back(sharedRav); + return lookup; } catch(exception& e) { m->errorOut(e, "SharedOrderVector", "getSharedRAbundVector"); @@ -315,16 +315,15 @@ SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) { } } /***********************************************************************/ -vector SharedOrderVector::getSharedRAbundVector() { +SharedRAbundVectors* SharedOrderVector::getSharedRAbundVector() { try { SharedUtil* util; util = new SharedUtil(); - vector lookup; vector Groups = m->getGroups(); vector allGroups = m->getAllGroups(); util->setGroups(Groups, allGroups); - util->getSharedVectors(Groups, lookup, this); + SharedRAbundVectors* lookup = util->getSharedVectors(Groups, this); m->setGroups(Groups); m->setAllGroups(allGroups); @@ -336,20 +335,6 @@ vector SharedOrderVector::getSharedRAbundVector() { } } /***********************************************************************/ -SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) { - try { - - SharedRAbundVector sharedRav(this->getSharedRAbundVector(group)); - return sharedRav.getSharedSAbundVector(); - - } - catch(exception& e) { - m->errorOut(e, "SharedOrderVector", "getSharedSAbundVector"); - exit(1); - } -} - -/***********************************************************************/ SharedOrderVector SharedOrderVector::getSharedOrderVector(){ m->mothurRandomShuffle(*this); diff --git a/source/datastructures/sharedordervector.h b/source/datastructures/sharedordervector.h index 7d383ac8..f6899cc3 100644 --- a/source/datastructures/sharedordervector.h +++ b/source/datastructures/sharedordervector.h @@ -16,6 +16,10 @@ #include "datavector.hpp" +#include "sabundvector.hpp" +#include "rabundvector.hpp" +#include "sharedrabundvectors.hpp" +#include "groupmap.h" struct individual { string group; @@ -37,13 +41,6 @@ struct individualFloat { individualFloat() { group = ""; bin = 0; abundance = 0.0; } }; - -#include "sabundvector.hpp" -#include "rabundvector.hpp" -#include "sharedrabundvector.h" -#include "sharedsabundvector.h" -#include "groupmap.h" - class SharedOrderVector : public DataVector { public: @@ -74,9 +71,8 @@ class SharedOrderVector : public DataVector { SAbundVector getSAbundVector(); OrderVector getOrderVector(map*); SharedOrderVector getSharedOrderVector(); - SharedRAbundVector getSharedRAbundVector(string); //get the sharedRabundvector for a sepecific group - SharedSAbundVector getSharedSAbundVector(string); //get the sharedSabundvector for a sepecific group - vector getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups + SharedRAbundVectors* getSharedRAbundVector(string); //get the sharedRabundvector for a sepecific group + SharedRAbundVectors* getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups private: GroupMap* groupmap; diff --git a/source/datastructures/sharedrabundfloatvector.cpp b/source/datastructures/sharedrabundfloatvector.cpp index a8e0772b..215d4031 100644 --- a/source/datastructures/sharedrabundfloatvector.cpp +++ b/source/datastructures/sharedrabundfloatvector.cpp @@ -1,583 +1,239 @@ -/* - * sharedrabundfloatvector.cpp - * Mothur - * - * Created by westcott on 8/18/10. - * Copyright 2010 Schloss Lab. All rights reserved. - * - */ - -#include "sharedrabundfloatvector.h" -#include "sharedutilities.h" +// +// sharedrabundfloatvector.cpp +// Mothur +// +// Created by Sarah Westcott on 7/25/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// -/***********************************************************************/ +#include "sharedrabundfloatvector.hpp" -SharedRAbundFloatVector::SharedRAbundFloatVector() : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) {} /***********************************************************************/ -SharedRAbundFloatVector::~SharedRAbundFloatVector() {} +SharedRAbundFloatVector::SharedRAbundFloatVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0), group("") {} /***********************************************************************/ -SharedRAbundFloatVector::SharedRAbundFloatVector(int n) : DataVector(), maxRank(0.0), numBins(n), numSeqs(0.0) { - - individualFloat newGuy; - //initialize data - for (int i=0; i< n; i++) { - newGuy.bin = i; - newGuy.abundance = 0.0; - data.push_back(newGuy); - } -} -/***********************************************************************/ -//reads a shared file -SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) { - try { - - m->clearAllGroups(); - vector allGroups; - - int num, count; - float inputData; - count = 0; - string holdLabel, nextLabel, groupN; - individualFloat newguy; - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - lookup.clear(); - - //are we at the beginning of the file?? - if (m->saveNextLabel == "") { - f >> label; - - //is this a shared file that has headers - if (label == "label") { - //gets "group" - f >> label; m->gobble(f); - - //gets "numOtus" - f >> label; m->gobble(f); - - //eat rest of line - label = m->getline(f); m->gobble(f); - - //parse labels to save - istringstream iStringStream(label); - m->sharedBinLabelsInFile.clear(); - while(!iStringStream.eof()){ - if (m->control_pressed) { break; } - string temp; - iStringStream >> temp; m->gobble(iStringStream); - - m->sharedBinLabelsInFile.push_back(temp); - } - - f >> label >> groupN >> num; - }else { - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - - //make binlabels because we don't have any - string snumBins = toString(num); - m->sharedBinLabelsInFile.clear(); - for (int i = 0; i < num; i++) { - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - m->sharedBinLabelsInFile.push_back(binLabel); - } - } - }else { - label = m->saveNextLabel; - - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - } - - //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling - m->currentSharedBinLabels = m->sharedBinLabelsInFile; - - holdLabel = label; - - //add new vector to lookup - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - lookup.push_back(temp); - lookup[0]->setLabel(label); - lookup[0]->setGroup(groupN); - - allGroups.push_back(groupN); - - //fill vector. data = first sharedrabund in file - for(int i=0;i> inputData; - - lookup[0]->push_back(inputData, groupN); //abundance, bin, group - push_back(inputData, groupN); - - if (inputData > maxRank) { maxRank = inputData; } - } - - m->gobble(f); - - if (f.eof() != true) { f >> nextLabel; } - - //read the rest of the groups info in - while ((nextLabel == holdLabel) && (f.eof() != true)) { - f >> groupN >> num; - - count++; - - allGroups.push_back(groupN); - - //add new vector to lookup - temp = new SharedRAbundFloatVector(); - lookup.push_back(temp); - lookup[count]->setLabel(label); - lookup[count]->setGroup(groupN); - - //fill vector. - for(int i=0;i> inputData; - lookup[count]->push_back(inputData, groupN); //abundance, bin, group - } - - m->gobble(f); - - if (f.eof() != true) { f >> nextLabel; } - } - - m->saveNextLabel = nextLabel; - m->setAllGroups(allGroups); - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); - exit(1); - } -} -/***********************************************************************/ +SharedRAbundFloatVector::SharedRAbundFloatVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(n), numSeqs(0), group("") {} -void SharedRAbundFloatVector::set(int binNumber, float newBinSize, string groupname){ - try { - float oldBinSize = data[binNumber].abundance; - data[binNumber].abundance = newBinSize; - data[binNumber].group = groupname; - - if(newBinSize > maxRank) { newBinSize = newBinSize; } - - numSeqs += (newBinSize - oldBinSize); - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "set"); - exit(1); - } -} /***********************************************************************/ -void SharedRAbundFloatVector::clear(){ - numBins = 0; - maxRank = 0; - numSeqs = 0; - data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - lookup.clear(); +SharedRAbundFloatVector::SharedRAbundFloatVector(vector rav) : DataVector(), maxRank(0), numBins(rav.size()), numSeqs(0), group("") { + try { + data.assign(numBins, 0); + for(int i=0;ierrorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); + exit(1); + } } + /***********************************************************************/ -float SharedRAbundFloatVector::getAbundance(int index){ - return data[index].abundance; + +SharedRAbundFloatVector::SharedRAbundFloatVector(vector rav, int mr, int nb, int ns) : DataVector(), group(""){ + try { + numBins = nb; + maxRank = mr; + numSeqs = ns; + data = rav; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); + exit(1); + } } /***********************************************************************/ -//returns vector of abundances -vector SharedRAbundFloatVector::getAbundances(){ - vector abunds; - for (int i = 0; i < data.size(); i++) { - abunds.push_back(data[i].abundance); + + +SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + f >> label >> group >> numBins; + + data.assign(numBins, 0); + float inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); + exit(1); } - - return abunds; } + /***********************************************************************/ -//returns vector of abundances -vector SharedRAbundFloatVector::getAbundances(string makeDouble){ - vector abunds; - for (int i = 0; i < data.size(); i++) { - abunds.push_back((double)(data[i].abundance)); +SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f, string l, string g, int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) { + try { + label = l; + group = g; + data.assign(numBins, 0); + + float inputData; + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); + exit(1); } - - return abunds; } + /***********************************************************************/ -individualFloat SharedRAbundFloatVector::get(int index){ - return data[index]; -} + +SharedRAbundFloatVector::~SharedRAbundFloatVector() { } + /***********************************************************************/ -void SharedRAbundFloatVector::push_back(float binSize, string groupName){ - try { - individualFloat newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = data.size(); - - data.push_back(newGuy); - numBins++; - - if(binSize > maxRank){ maxRank = binSize; } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "push_back"); - exit(1); - } + +void SharedRAbundFloatVector::set(int binNumber, float newBinSize){ + try { + int oldBinSize = data[binNumber]; + data[binNumber] = newBinSize; + + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs += (newBinSize - oldBinSize); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "set"); + exit(1); + } } + /***********************************************************************/ -void SharedRAbundFloatVector::insert(float binSize, int otu, string groupName){ - try { - individualFloat newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = otu; - - data.insert(data.begin()+otu, newGuy); - numBins++; - - if(binSize > maxRank){ maxRank = binSize; } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "insert"); - exit(1); - } -} +float SharedRAbundFloatVector::get(int index){ return data[index]; } /***********************************************************************/ -void SharedRAbundFloatVector::push_front(float binSize, int otu, string groupName){ - try { - individualFloat newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = otu; - - data.insert(data.begin(), newGuy); - numBins++; - - if(binSize > maxRank){ maxRank = binSize; } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "push_front"); - exit(1); - } -} -/**********************************************************************/ -void SharedRAbundFloatVector::pop_back(){ - numSeqs -= data[data.size()-1].abundance; - numBins--; - data.pop_back(); + +void SharedRAbundFloatVector::clear(){ + numBins = 0; + maxRank = 0; + numSeqs = 0; + group = ""; + data.clear(); +} +/***********************************************************************/ + +void SharedRAbundFloatVector::push_back(float binSize){ + try { + data.push_back(binSize); + numBins++; + + if(binSize > maxRank){ maxRank = binSize; } + + numSeqs += binSize; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "push_back"); + exit(1); + } } /***********************************************************************/ -void SharedRAbundFloatVector::resize(int size){ - data.resize(size); -} -/**********************************************************************/ -int SharedRAbundFloatVector::size(){ - return data.size(); + +float SharedRAbundFloatVector::remove(int bin){ + try { + float abund = data[bin]; + data.erase(data.begin()+bin); + numBins--; + + if(abund == maxRank){ maxRank = m->max(data); } + + numSeqs -= abund; + + return abund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "remove"); + exit(1); + } } /***********************************************************************/ -void SharedRAbundFloatVector::printHeaders(ostream& output){ - try { - string snumBins = toString(numBins); - output << "label\tGroup\tnumOtus"; - if (m->sharedHeaderMode == "tax") { - for (int i = 0; i < numBins; i++) { - - //if there is a bin label use it otherwise make one - string binLabel = "PhyloType"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - output << '\t' << binLabel; - } - output << endl; - }else { - for (int i = 0; i < numBins; i++) { - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - output << '\t' << binLabel; - } - - output << endl; - } - - m->printedSharedHeaders = true; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "printHeaders"); - exit(1); - } -} +void SharedRAbundFloatVector::resize(int size){ data.resize(size); } +/***********************************************************************/ +int SharedRAbundFloatVector::size(){ return data.size(); } /***********************************************************************/ void SharedRAbundFloatVector::print(ostream& output){ - try { - output << numBins; - - for(int i=0;ierrorOut(e, "SharedRAbundFloatVector", "print"); - exit(1); - } + try { + output << label; + output << '\t' << group << '\t' << numBins; + + for(int i=0;ierrorOut(e, "SharedRAbundVector", "nonSortedPrint"); + exit(1); + } } /***********************************************************************/ -string SharedRAbundFloatVector::getGroup(){ - return group; +int SharedRAbundFloatVector::getNumBins(){ + return numBins; } + /***********************************************************************/ -void SharedRAbundFloatVector::setGroup(string groupName){ - group = groupName; + +float SharedRAbundFloatVector::getNumSeqs(){ + return numSeqs; } + /***********************************************************************/ -int SharedRAbundFloatVector::getGroupIndex() { return index; } -/***********************************************************************/ -void SharedRAbundFloatVector::setGroupIndex(int vIndex) { index = vIndex; } -/***********************************************************************/ -int SharedRAbundFloatVector::getNumBins(){ return numBins; } -/***********************************************************************/ -float SharedRAbundFloatVector::getNumSeqs(){ return numSeqs; } -/***********************************************************************/ -float SharedRAbundFloatVector::getMaxRank(){ return maxRank; } -/***********************************************************************/ -SharedRAbundFloatVector SharedRAbundFloatVector::getSharedRAbundFloatVector(){ - return *this; -} -/*********************************************************************** -SharedRAbundVector SharedRAbundFloatVector::getSharedRAbundVector(){ - try { - SharedRAbundVector rav(numBins); - rav.setLabel(label); - rav.setGroup(group); - - for (int i = 0; i < data.size(); i++) { - - rav.push_back(data[i].abundance); - } - - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getSharedRAbundVector"); - exit(1); - } -} -***********************************************************************/ -vector SharedRAbundFloatVector::getSharedRAbundFloatVectors(){ - try { - SharedUtil* util; - util = new SharedUtil(); - - vector Groups = m->getGroups(); - vector allGroups = m->getAllGroups(); - util->setGroups(Groups, allGroups); - m->setGroups(Groups); - - bool remove = false; - for (int i = 0; i < lookup.size(); i++) { - //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookup[i]->getGroup(), m->getGroups()) == false) { - delete lookup[i]; lookup[i] = NULL; - lookup.erase(lookup.begin()+i); - i--; - remove = true; - } - } - - delete util; - - if (remove) { eliminateZeroOTUS(); } - - return lookup; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getSharedRAbundFloatVectors"); - exit(1); - } + +float SharedRAbundFloatVector::getMaxRank(){ + return maxRank; } /***********************************************************************/ -RAbundVector SharedRAbundFloatVector::getRAbundVector() { - try { - RAbundVector rav(numBins); - - //this is not functional, not sure how to handle it yet, but I need the stub because it is a pure function - - rav.setLabel(label); - return rav; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getRAbundVector"); - exit(1); - } +RAbundVector SharedRAbundFloatVector::getRAbundVector(){ + RAbundVector rav; + for(int i = 0; i < data.size(); i++) { rav.push_back(int(data[i])); } + rav.setLabel(label); + return rav; } -/*********************************************************************** - -SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){ - try { - SharedSAbundVector sav(maxRank+1); - - for(int i=0;ierrorOut(e, "SharedRAbundVector", "getSharedSAbundVector"); - exit(1); - } +/***********************************************************************/ + +SharedRAbundVector SharedRAbundFloatVector::getSharedRAbundVector(){ + SharedRAbundVector rav; rav.setLabel(label); rav.setGroup(group); + for(int i = 0; i < data.size(); i++) { rav.push_back(int(data[i])); } + return rav; } -***********************************************************************/ +/***********************************************************************/ SAbundVector SharedRAbundFloatVector::getSAbundVector() { - try { - SAbundVector sav(ceil(maxRank)+1); - - //this is not functional, not sure how to handle it yet, but I need the stub because it is a pure function - - sav.set(0, 0); - sav.setLabel(label); - return sav; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getSAbundVector"); - exit(1); - } + try { + SAbundVector sav(int(maxRank+1)); + + for(int i=0;ierrorOut(e, "SharedRAbundFloatVector", "getSAbundVector"); + exit(1); + } } -/*********************************************************************** - -SharedOrderVector SharedRAbundFloatVector::getSharedOrderVector() { - try { - SharedOrderVector ov; - - for(int i=0;imothurRandomShuffle(ov); - - ov.setLabel(label); - ov.updateStats(); - - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getSharedOrderVector"); - exit(1); - } -} -***********************************************************************/ -//this is not functional, not sure how to handle it yet, but I need the stub because it is a pure function +/***********************************************************************/ + OrderVector SharedRAbundFloatVector::getOrderVector(map* nameMap = NULL) { - try { - OrderVector ov; - - for(int i=0;imothurRandomShuffle(ov); - - ov.setLabel(label); - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "getOrderVector"); - exit(1); - } -} -//********************************************************************************************************************** -int SharedRAbundFloatVector::eliminateZeroOTUS() { - try { - - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(lookup[0]->getNumBins()); - for (int i = 0; i < lookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < lookup.size(); j++) { - if (lookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < lookup.size(); j++) { - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - - lookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundFloatVector", "eliminateZeroOTUS"); - exit(1); - } + try { + m->mothurOut("[ERROR]: can not convert SharedRAbundVectors to an ordervector, ordervectors assume no zero OTUS.\n"); m->control_pressed = true; + OrderVector o; return o; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVector", "getOrderVector"); + exit(1); + } } + /***********************************************************************/ diff --git a/source/datastructures/sharedrabundfloatvector.h b/source/datastructures/sharedrabundfloatvector.h deleted file mode 100644 index cb03143c..00000000 --- a/source/datastructures/sharedrabundfloatvector.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef SHAREDRABUNDFLOATVECTOR_H -#define SHAREDRABUNDFLOATVECTOR_H - -/* - * sharedrabundfloatvector.h - * Mothur - * - * Created by westcott on 8/18/10. - * Copyright 2010 Schloss Lab. All rights reserved. - * - */ - - -#include "datavector.hpp" -#include "sharedordervector.h" -#include "sharedsabundvector.h" -#include "rabundvector.hpp" -//#include "groupmap.h" - -/* This class is a child to datavector. It represents OTU information at a certain distance. - It is similiar to an rabundvector except each member of data knows which group it belongs to. - Each member of the internal container "data" is a struct of type individualFloat. - An individual which knows the OTU from which it came, - the group it is in and its abundance. */ - - -class SharedRAbundFloatVector : public DataVector { - -public: - SharedRAbundFloatVector(); - SharedRAbundFloatVector(int); - SharedRAbundFloatVector(const SharedRAbundFloatVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs), group(bv.group), index(bv.index){}; - SharedRAbundFloatVector(ifstream&); - ~SharedRAbundFloatVector(); - - int getNumBins(); - float getNumSeqs(); - float getMaxRank(); - string getGroup(); - void setGroup(string); - int getGroupIndex(); - void setGroupIndex(int); - - void set(int, float, string); //OTU, abundance, groupname - individualFloat get(int); - vector getData(); - float getAbundance(int); - vector getAbundances(); - vector getAbundances(string); - void push_front(float, int, string); //abundance, otu, groupname - void insert(float, int, string); //abundance, otu, groupname - void push_back(float, string); //abundance, groupname - void pop_back(); - void resize(int); - void clear(); - int size(); - - void print(ostream&); - void printHeaders(ostream&); - - RAbundVector getRAbundVector(); - SAbundVector getSAbundVector(); - OrderVector getOrderVector(map*); - //SharedOrderVector getSharedOrderVector(); - //SharedSAbundVector getSharedSAbundVector(); - //SharedRAbundVector getSharedRAbundVector(); - SharedRAbundFloatVector getSharedRAbundFloatVector(); - vector getSharedRAbundFloatVectors(); - -private: - int eliminateZeroOTUS(); - vector data; - vector lookup; - //GlobalData* globaldata; - //GroupMap* groupmap; - float maxRank; - int numBins; - float numSeqs; - string group; - int index; - - -}; - - -#endif - - diff --git a/source/datastructures/sharedrabundfloatvector.hpp b/source/datastructures/sharedrabundfloatvector.hpp new file mode 100644 index 00000000..b8857fec --- /dev/null +++ b/source/datastructures/sharedrabundfloatvector.hpp @@ -0,0 +1,87 @@ +// +// sharedrabundfloatvector.hpp +// Mothur +// +// Created by Sarah Westcott on 7/25/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef sharedrabundfloatvector_hpp +#define sharedrabundfloatvector_hpp + +#include "datavector.hpp" +#include "rabundvector.hpp" +#include "sabundvector.hpp" +#include "ordervector.hpp" + +/* Data Structure for a rabund file. + This class is a child to datavector. It represents OTU information at a certain distance. + A rabundvector can be converted into and ordervector, listvector or sabundvector. + Each member of the internal container "data" represents an individual OTU. + So data[0] = 6, because there are six member in that OTU. + example: listvector = a,b,c,d,e,f g,h,i j,k l m + rabundvector = 6 3 2 1 1 + sabundvector = 2 1 1 0 0 1 + ordervector = 1 1 1 1 1 1 2 2 2 3 3 4 5 + + a,b,g,j,l = sample A + c,d,h,i = sample B + e,f,k,m = sample C + + The sharedRabund class is very similar to rabund. SharedRabund allows for 0 otus in a sample, rabunds do not. SharedRabund also know their group. SharedRabunds are stored as floats, but printed as integers or floats depending on whether it represents a shared or relabund file. + sharedrabund = A 5 2 1 1 1 0 + B 5 2 2 0 0 0 + C 5 2 0 1 0 1 + */ + + +//class RAbundFloatVector; +//class OrderVector; + +class SharedRAbundFloatVector : public DataVector { + +public: + SharedRAbundFloatVector(); + SharedRAbundFloatVector(int); + SharedRAbundFloatVector(vector, int, int, int); + SharedRAbundFloatVector(vector); + SharedRAbundFloatVector(const SharedRAbundFloatVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs), group(bv.group) {}; + SharedRAbundFloatVector(ifstream&); + SharedRAbundFloatVector(ifstream& f, string l, string g, int); //filehandle, label + ~SharedRAbundFloatVector(); + + int getNumBins(); + float getNumSeqs(); + float getMaxRank(); + + float remove(int); + void set(int, float); + float get(int); + vector get() { return data; } + void push_back(float); + void resize(int); + int size(); + void clear(); + + void print(ostream&); //nonsorted + + RAbundVector getRAbundVector(); + SharedRAbundVector getSharedRAbundVector(); + RAbundFloatVector getRAbundFloatVector(); + SAbundVector getSAbundVector(); + OrderVector getOrderVector(map*); + + string getGroup() { return group; } //group = "" for rabunds without groupInfo + void setGroup(string g) { group = g; } + +private: + vector data; + int maxRank; + int numBins; + int numSeqs; + string group; +}; + + + +#endif /* sharedrabundfloatvector_hpp */ diff --git a/source/datastructures/sharedrabundfloatvectors.cpp b/source/datastructures/sharedrabundfloatvectors.cpp new file mode 100644 index 00000000..0d3c6b94 --- /dev/null +++ b/source/datastructures/sharedrabundfloatvectors.cpp @@ -0,0 +1,510 @@ +// +// sharedrabundfloatvectors.cpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "sharedrabundfloatvectors.hpp" +#include "sharedutilities.h" + +/***********************************************************************/ +//reads a shared file +SharedRAbundFloatVectors::SharedRAbundFloatVectors(ifstream& f) : DataVector() { + try { + m->clearAllGroups(); + vector allGroups; + + int num; + string holdLabel, nextLabel, groupN; + + for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; lookup[i] = NULL; } } lookup.clear(); + + //are we at the beginning of the file?? + if (m->saveNextLabel == "") { + f >> label; + + //is this a shared file that has headers + if (label == "label") { + //gets "group" + f >> label; m->gobble(f); + + //gets "numOtus" + f >> label; m->gobble(f); + + //eat rest of line + label = m->getline(f); m->gobble(f); + + //parse labels to save + istringstream iStringStream(label); + m->sharedBinLabelsInFile.clear(); + while(!iStringStream.eof()){ + if (m->control_pressed) { break; } + string temp; + iStringStream >> temp; m->gobble(iStringStream); + + m->sharedBinLabelsInFile.push_back(temp); + } + + f >> label >> groupN >> num; + }else { + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + + //make binlabels because we don't have any + string snumBins = toString(num); + m->sharedBinLabelsInFile.clear(); + for (int i = 0; i < num; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + m->sharedBinLabelsInFile.push_back(binLabel); + } + } + }else { + label = m->saveNextLabel; + + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + } + + //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling + m->currentSharedBinLabels = m->sharedBinLabelsInFile; + + holdLabel = label; + allGroups.push_back(groupN); + numBins = num; + + //add new vector to lookup + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(f, label, groupN, numBins); m->gobble(f); + push_back(temp); + + if (!(f.eof())) { f >> nextLabel; } + + //read the rest of the groups info in + while ((nextLabel == holdLabel) && (f.eof() != true)) { + f >> groupN >> num; + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(f, label, groupN, numBins); m->gobble(f); + push_back(temp); + allGroups.push_back(groupN); + + if (f.eof() != true) { f >> nextLabel; } + } + eliminateZeroOTUS(); + m->saveNextLabel = nextLabel; + m->setAllGroups(allGroups); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "SharedRAbundFloatVectors"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundFloatVectors::printHeaders(ostream& output){ + try { + string snumBins = toString(numBins); + output << "label\tGroup\tnumOtus"; + if (m->sharedHeaderMode == "tax") { + for (int i = 0; i < numBins; i++) { + + //if there is a bin label use it otherwise make one + string binLabel = "PhyloType"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } + + output << '\t' << binLabel ; + } + output << endl; + }else { + for (int i = 0; i < numBins; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } + + output << '\t' << binLabel; + } + + output << endl; + } + m->printedSharedHeaders = true; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "printHeaders"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundFloatVectors::print(ostream& output){ + try { + sort(lookup.begin(), lookup.end(), compareRAbundFloats); + for (int i = 0; i < lookup.size(); i++) { + if (m->control_pressed) { break; } + lookup[i]->print(output); + } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "print"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundFloatVectors::push_back(SharedRAbundFloatVector* thisLookup){ + try { + if (numBins == 0) { numBins = thisLookup->getNumBins(); } + lookup.push_back(thisLookup); + sort(lookup.begin(), lookup.end(), compareRAbundFloats); + if (label == "") { label = thisLookup->getLabel(); } + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + return lookup.size(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "push_back"); + exit(1); + } +} +/***********************************************************************/ +float SharedRAbundFloatVectors::getOTUTotal(int bin){ + try { + float totalOTUAbund = 0; + for (int i = 0; i < lookup.size(); i++) { totalOTUAbund += lookup[i]->get(bin); } + return totalOTUAbund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getOTUTotal"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundFloatVectors::getOTU(int bin){ + try { + vector abunds; + for (int i = 0; i < lookup.size(); i++) { abunds.push_back(lookup[i]->get(bin)); } + return abunds; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getOTU"); + exit(1); + } +} + +/***********************************************************************/ +void SharedRAbundFloatVectors::setLabels(string l){ + try { + label = l; + for (int i = 0; i < lookup.size(); i++) { lookup[i]->setLabel(l); } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "setLabels"); + exit(1); + } +} +/***********************************************************************/ +float SharedRAbundFloatVectors::get(int bin, string group){ + try { + float abund = 0; + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { abund = lookup[it->second]->get(bin); } + return abund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "get"); + exit(1); + } +} +/***********************************************************************/ +float SharedRAbundFloatVectors::getNumSeqs(string group){ + try { + float numSeqs = 0; + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { numSeqs = lookup[it->second]->getNumSeqs(); } + + return numSeqs; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getNumSeqs"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundFloatVectors::set(int bin, float binSize, string group){ + try { + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { lookup[it->second]->set(bin, binSize); } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "set"); + exit(1); + } +} +/***********************************************************************/ +float SharedRAbundFloatVectors::removeOTU(int bin){ + try { + float totalOTUAbund = 0; + for (int i = 0; i < lookup.size(); i ++) { + totalOTUAbund += lookup[i]->remove(bin); + } + + m->currentSharedBinLabels.erase(m->currentSharedBinLabels.begin()+bin); + numBins--; + + return totalOTUAbund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "removeOTU"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundFloatVectors::getNamesGroups(){ + try { + vector names; + for (int i = 0; i < lookup.size(); i ++) { names.push_back(lookup[i]->getGroup()); } + return names; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getNamesGroups"); + exit(1); + } +} +/***********************************************************************/ +float SharedRAbundFloatVectors::getNumSeqsSmallestGroup(){ + try { + float smallest = 1e6; + for (int i = 0; i < lookup.size(); i++) { + if (lookup[i]->getNumSeqs() < smallest) { smallest = lookup[i]->getNumSeqs(); } + } + return smallest; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getNumSeqsSmallestGroup"); + exit(1); + } +} +/***********************************************************************/ +RAbundVector SharedRAbundFloatVectors::getRAbundVector(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + RAbundVector rav; + for (int i = 0; i < numBins; i++) { + float abund = getOTUTotal(i); + rav.push_back((int)abund); + } + + return rav; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +SAbundVector SharedRAbundFloatVectors::getSAbundVector(){ + try { + RAbundVector rav = getRAbundVector(); + return rav.getSAbundVector(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getSharedRAbundVectors"); + exit(1); + } +} +/*********************************************************************** +OrderVector SharedRAbundFloatVectors::getOrderVector(map* nameMap = NULL){ + try { + RAbundVector rav = getRAbundVector(); + return rav.getOrderVector(NULL); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundFloatVectors::getSharedRAbundFloatVectors(){ + try { + SharedUtil util; + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + vector newLookup; + for (int i = 0; i < lookup.size(); i++) { + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(*lookup[i]); + newLookup.push_back(temp); + } + + return newLookup; + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundFloatVectors::getSharedRAbundVectors(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + vector newLookup; + for (int i = 0; i < lookup.size(); i++) { + SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getSharedRAbundVector()); + newLookup.push_back(temp); + } + + return newLookup; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundFloatVectors::removeGroups(vector g){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), g) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "removeGroups"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundFloatVectors::removeGroups(int minSize, bool silent){ + try { + vector Groups; + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + if ((*it)->getNumSeqs() < minSize) { + if (!silent) { m->mothurOut((*it)->getGroup() + " contains " + toString((*it)->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); } + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { + Groups.push_back((*it)->getGroup()); + ++it; + } + } + m->setGroups(Groups); + + if (remove) { eliminateZeroOTUS(); } + + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + + return lookup.size(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "removeGroups"); + exit(1); + } +} +/**********************************************************************************************************************/ +void SharedRAbundFloatVectors::eliminateZeroOTUS() { + try { + for (int i = 0; i < lookup[0]->getNumBins();) { + if (m->control_pressed) { break; } + + float total = getOTUTotal(i); + + //if they are not all zero add this bin + if (total == 0) { removeOTU(i); } + else { ++i; } + } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundFloatVectors", "eliminateZeroOTUS"); + exit(1); + } +} +/***********************************************************************/ + diff --git a/source/datastructures/sharedrabundfloatvectors.hpp b/source/datastructures/sharedrabundfloatvectors.hpp new file mode 100644 index 00000000..7b682a5d --- /dev/null +++ b/source/datastructures/sharedrabundfloatvectors.hpp @@ -0,0 +1,76 @@ +// +// sharedrabundfloatvectors.hpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef sharedrabundfloatvectors_hpp +#define sharedrabundfloatvectors_hpp + +#include "datavector.hpp" +#include "rabundvector.hpp" +#include "sharedrabundfloatvector.hpp" +#include "sharedordervector.h" +#include "ordervector.hpp" + +/* DataStructure for a relabund file. */ +//******************************************************************************************************************** +inline bool compareRAbundFloats(SharedRAbundFloatVector* left, SharedRAbundFloatVector* right){ return (left->getGroup() < right->getGroup()); } +//******************************************************************************************************************** + + +class SharedRAbundFloatVectors : public DataVector { + +public: + SharedRAbundFloatVectors() : DataVector() { label = ""; numBins = 0; } + SharedRAbundFloatVectors(ifstream&); + SharedRAbundFloatVectors(SharedRAbundFloatVectors& bv) : DataVector(bv), numBins(bv.numBins) { + vector data = bv.getSharedRAbundFloatVectors(); + for (int i = 0; i < data.size(); i++) { push_back(data[i]); } + eliminateZeroOTUS(); + setLabels(bv.getLabel()); + } + ~SharedRAbundFloatVectors() { for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; lookup[i] = NULL; } } lookup.clear(); } + + float getOTUTotal(int bin); + vector getOTU(int bin); + void setLabels(string l); + float removeOTU(int bin); + float get(int bin, string group); + void set(int bin, float binSize, string group); + + int push_back(SharedRAbundFloatVector*); + void removeGroups(vector g); + int removeGroups(int minSize, bool silent=false); // removes any groups with numSeqs < minSize + void resize(int n) { m->mothurOut("[ERROR]: can not use resize for SharedRAbundFloatVectors.\n"); } + void clear() { for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; lookup[i] = NULL; } } lookup.clear(); groupNames.clear(); numBins = 0; } + int size() { return lookup.size(); } + int getNumGroups() { return lookup.size(); } + int getNumBins() { return numBins; } + float getNumSeqs(string); //group + float getNumSeqsSmallestGroup(); + + void print(ostream&); + void printHeaders(ostream&); + + vector getSharedRAbundVectors(); + vector getSharedRAbundFloatVectors(); + RAbundVector getRAbundVector(); + SAbundVector getSAbundVector(); + OrderVector getOrderVector(map*) { m->mothurOut("[ERROR]: can not convert SharedRAbundVectors to an ordervector, ordervectors assume no zero OTUS.\n"); m->control_pressed = true; OrderVector o; return o; } + + vector getNamesGroups(); + void eliminateZeroOTUS(); //run after push_backs if groups are chosen + +private: + vector lookup; + map groupNames; + int numBins; + +}; + +#endif /* sharedrabundfloatvectors_hpp */ + + diff --git a/source/datastructures/sharedrabundvector.cpp b/source/datastructures/sharedrabundvector.cpp index 4df30f96..f9752662 100644 --- a/source/datastructures/sharedrabundvector.cpp +++ b/source/datastructures/sharedrabundvector.cpp @@ -1,711 +1,250 @@ -/* - * sharedvector.cpp - * Dotur - * - * Created by Sarah Westcott on 12/5/08. - * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. - * - */ +// +// sharedrabundvector.cpp +// Mothur +// +// Created by Sarah Westcott on 7/24/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// -#include "sharedrabundvector.h" -#include "sabundvector.hpp" -#include "ordervector.hpp" -#include "sharedutilities.h" +#include "sharedrabundvector.hpp" /***********************************************************************/ -SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {} -/***********************************************************************/ - -SharedRAbundVector::~SharedRAbundVector() { - //for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } -} +SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0), group("") {} /***********************************************************************/ -SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) { - individual newGuy; - //initialize data - for (int i=0; i< n; i++) { - newGuy.bin = i; - newGuy.abundance = 0; - data.push_back(newGuy); - } -} - -/*********************************************************************** - -SharedRAbundVector::SharedRAbundVector(string id, vector rav) : DataVector(id), data(rav) { - try { - numBins = 0; - maxRank = 0; - numSeqs = 0; - - for(int i=0;i maxRank) { maxRank = data[i].abundance; } - numSeqs += data[i].abundance; - } - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); - exit(1); - } -} - - -***********************************************************************/ -//reads a shared file -SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { - try { - m->clearAllGroups(); - vector allGroups; - - int num, inputData, count; - count = 0; - string holdLabel, nextLabel, groupN; - individual newguy; - - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } lookup.clear(); - - //are we at the beginning of the file?? - if (m->saveNextLabel == "") { - f >> label; - - //is this a shared file that has headers - if (label == "label") { - //gets "group" - f >> label; m->gobble(f); - - //gets "numOtus" - f >> label; m->gobble(f); - - //eat rest of line - label = m->getline(f); m->gobble(f); - - //parse labels to save - istringstream iStringStream(label); - m->sharedBinLabelsInFile.clear(); - while(!iStringStream.eof()){ - if (m->control_pressed) { break; } - string temp; - iStringStream >> temp; m->gobble(iStringStream); - - m->sharedBinLabelsInFile.push_back(temp); - } - - f >> label >> groupN >> num; - }else { - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - - //make binlabels because we don't have any - string snumBins = toString(num); - m->sharedBinLabelsInFile.clear(); - for (int i = 0; i < num; i++) { - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - m->sharedBinLabelsInFile.push_back(binLabel); - } - } - }else { - label = m->saveNextLabel; - - //read in first row since you know there is at least 1 group. - f >> groupN >> num; - - if (m->debug) { m->mothurOut("[DEBUG]: "+ groupN + '\t' + toString(num)); } - } - - //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling - m->currentSharedBinLabels = m->sharedBinLabelsInFile; - - holdLabel = label; - - //add new vector to lookup - SharedRAbundVector* temp = new SharedRAbundVector(); - lookup.push_back(temp); - lookup[0]->setLabel(label); - lookup[0]->setGroup(groupN); - - allGroups.push_back(groupN); - - //fill vector. data = first sharedrabund in file - for(int i=0;i> inputData; - if (m->debug) { m->mothurOut("[DEBUG]: OTU" + toString(i+1)+ '\t' +toString(inputData)); } - - lookup[0]->push_back(inputData, groupN); //abundance, bin, group - push_back(inputData, groupN); - - if (inputData > maxRank) { maxRank = inputData; } - } - - m->gobble(f); - - if (!(f.eof())) { f >> nextLabel; } - - //read the rest of the groups info in - while ((nextLabel == holdLabel) && (f.eof() != true)) { - f >> groupN >> num; - if (m->debug) { m->mothurOut("[DEBUG]: "+ groupN + '\t' + toString(num)); } - count++; - - allGroups.push_back(groupN); - - //add new vector to lookup - temp = new SharedRAbundVector(); - lookup.push_back(temp); - lookup[count]->setLabel(label); - lookup[count]->setGroup(groupN); - - //fill vector. - for(int i=0;i> inputData; - if (m->debug) { m->mothurOut("[DEBUG]: OTU" + toString(i+1)+ '\t' +toString(inputData)); } - - lookup[count]->push_back(inputData, groupN); //abundance, bin, group - } - - m->gobble(f); - - if (f.eof() != true) { f >> nextLabel; } - } - m->saveNextLabel = nextLabel; - m->setAllGroups(allGroups); - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); - exit(1); - } -} +SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), data(n,0) , maxRank(0), numBins(n), numSeqs(0), group("") {} /***********************************************************************/ -void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){ - try { - int oldBinSize = data[binNumber].abundance; - data[binNumber].abundance = newBinSize; - data[binNumber].group = groupname; - - if(newBinSize > maxRank) { maxRank = newBinSize; } - - numSeqs += (newBinSize - oldBinSize); - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "set"); - exit(1); - } -} -/***********************************************************************/ - -void SharedRAbundVector::setData(vector newData){ - data = newData; +SharedRAbundVector::SharedRAbundVector(vector rav) : DataVector(), maxRank(0), numBins(rav.size()), numSeqs(0), group("") { + try { + data.assign(numBins, 0); + for(int i=0;ierrorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + exit(1); + } } /***********************************************************************/ -int SharedRAbundVector::getAbundance(int index){ - return data[index].abundance; - -} -/***********************************************************************/ -//returns vector of abundances -vector SharedRAbundVector::getAbundances(){ - vector abunds; - for (int i = 0; i < data.size(); i++) { - abunds.push_back(data[i].abundance); +SharedRAbundVector::SharedRAbundVector(vector rav, int mr, int nb, int ns) : DataVector(), group(""){ + try { + numBins = nb; + maxRank = mr; + numSeqs = ns; + data = rav; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + exit(1); } - - return abunds; } - - /***********************************************************************/ -int SharedRAbundVector::numNZ(){ - int sum = 0; - for(int i = 1; i < numBins; i++) - if(data[i].abundance > 0) - sum++; - return sum; -} -/***********************************************************************/ -void SharedRAbundVector::sortD(){ - struct individual indObj; - sort(data.begin()+1, data.end(), indObj); +SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { + try { + f >> label >> group >> numBins; + + data.assign(numBins, 0); + int inputData; + + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + exit(1); + } } -/***********************************************************************/ -individual SharedRAbundVector::get(int index){ - return data[index]; - -} /***********************************************************************/ - -vector SharedRAbundVector::getData(){ - return data; +SharedRAbundVector::SharedRAbundVector(ifstream& f, string l, string g, int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) { + try { + label = l; + group = g; + data.assign(numBins, 0); + + int inputData; + for(int i=0;i> inputData; + set(i, inputData); + } + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + exit(1); + } } -/***********************************************************************/ -void SharedRAbundVector::clear(){ - numBins = 0; - maxRank = 0; - numSeqs = 0; - data.clear(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - lookup.clear(); -} /***********************************************************************/ -void SharedRAbundVector::push_back(int binSize, string groupName){ - try { - individual newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = data.size(); - - data.push_back(newGuy); - numBins++; - - if(binSize > maxRank){ - maxRank = binSize; - } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "push_back"); - exit(1); - } -} +SharedRAbundVector::~SharedRAbundVector() { } /***********************************************************************/ -void SharedRAbundVector::insert(int binSize, int otu, string groupName){ - try { - individual newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = otu; - - data.insert(data.begin()+otu, newGuy); - numBins++; - - if(binSize > maxRank){ - maxRank = binSize; - } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "insert"); - exit(1); - } +void SharedRAbundVector::set(int binNumber, int newBinSize){ + try { + int oldBinSize = data[binNumber]; + data[binNumber] = newBinSize; + + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs += (newBinSize - oldBinSize); + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "set"); + exit(1); + } } - /***********************************************************************/ -void SharedRAbundVector::push_front(int binSize, int otu, string groupName){ - try { - individual newGuy; - newGuy.abundance = binSize; - newGuy.group = groupName; - newGuy.bin = otu; - - data.insert(data.begin(), newGuy); - numBins++; - - if(binSize > maxRank){ - maxRank = binSize; - } - - numSeqs += binSize; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "push_front"); - exit(1); - } +int SharedRAbundVector::increment(int binNumber){ + try { + data[binNumber]++; + int newBinSize = data[binNumber]; + + if(newBinSize > maxRank) { maxRank = newBinSize; } + + numSeqs++; + + return newBinSize; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "increment"); + exit(1); + } } /***********************************************************************/ -void SharedRAbundVector::pop_back(){ - numSeqs -= data[data.size()-1].abundance; - numBins--; - return data.pop_back(); -} +int SharedRAbundVector::get(int index){ return data[index]; } /***********************************************************************/ - -vector::reverse_iterator SharedRAbundVector::rbegin(){ - return data.rbegin(); -} - -/***********************************************************************/ - -vector::reverse_iterator SharedRAbundVector::rend(){ - return data.rend(); -} - -/***********************************************************************/ -void SharedRAbundVector::resize(int size){ - - data.resize(size); +void SharedRAbundVector::clear(){ + numBins = 0; + maxRank = 0; + numSeqs = 0; + group = ""; + data.clear(); +} +/***********************************************************************/ + +void SharedRAbundVector::push_back(int binSize){ + try { + data.push_back(binSize); + numBins++; + + if(binSize > maxRank){ maxRank = binSize; } + + numSeqs += binSize; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "push_back"); + exit(1); + } } - /***********************************************************************/ -int SharedRAbundVector::size(){ - return data.size(); -} - - -/***********************************************************************/ -void SharedRAbundVector::printHeaders(ostream& output){ - try { - string snumBins = toString(numBins); - output << "label\tGroup\tnumOtus"; - if (m->sharedHeaderMode == "tax") { - for (int i = 0; i < numBins; i++) { - - //if there is a bin label use it otherwise make one - string binLabel = "PhyloType"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - output << '\t' << binLabel ; - } - output << endl; - }else { - for (int i = 0; i < numBins; i++) { - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - output << '\t' << binLabel; - } - - output << endl; - } - m->printedSharedHeaders = true; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "printHeaders"); - exit(1); - } +int SharedRAbundVector::remove(int bin){ + try { + int abund = data[bin]; + data.erase(data.begin()+bin); + numBins--; + + if(abund == maxRank){ maxRank = m->max(data); } + + numSeqs -= abund; + + return abund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "remove"); + exit(1); + } } /***********************************************************************/ -void SharedRAbundVector::print(ostream& output) { - try { - output << numBins; - - for(int i=0;ierrorOut(e, "SharedRAbundVector", "print"); - exit(1); - } -} +void SharedRAbundVector::resize(int size){ data.resize(size); } /***********************************************************************/ -string SharedRAbundVector::getGroup(){ - return group; -} - +int SharedRAbundVector::size(){ return data.size(); } /***********************************************************************/ - -void SharedRAbundVector::setGroup(string groupName){ - group = groupName; +void SharedRAbundVector::print(ostream& output){ + try { + output << label; + output << '\t' << group << '\t' << numBins; + + for(int i=0;ierrorOut(e, "SharedRAbundVector", "nonSortedPrint"); + exit(1); + } } /***********************************************************************/ -int SharedRAbundVector::getGroupIndex() { return index; } -/***********************************************************************/ -void SharedRAbundVector::setGroupIndex(int vIndex) { index = vIndex; } -/***********************************************************************/ int SharedRAbundVector::getNumBins(){ - return numBins; + return numBins; } /***********************************************************************/ int SharedRAbundVector::getNumSeqs(){ - return numSeqs; + return numSeqs; } /***********************************************************************/ int SharedRAbundVector::getMaxRank(){ - return maxRank; + return maxRank; } /***********************************************************************/ -SharedRAbundVector SharedRAbundVector::getSharedRAbundVector(){ - return *this; -} -/***********************************************************************/ -vector SharedRAbundVector::getSharedRAbundVectors(){ - try { - SharedUtil* util; - util = new SharedUtil(); - - vector Groups = m->getGroups(); - vector allGroups = m->getAllGroups(); - util->setGroups(Groups, allGroups); - m->setGroups(Groups); - - bool remove = false; - for (int i = 0; i < lookup.size(); i++) { - //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookup[i]->getGroup(), m->getGroups()) == false) { - remove = true; - delete lookup[i]; lookup[i] = NULL; - lookup.erase(lookup.begin()+i); - i--; - } - } - - delete util; - - if (remove) { eliminateZeroOTUS(); } - - return lookup; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); - exit(1); - } -} -//********************************************************************************************************************** -int SharedRAbundVector::eliminateZeroOTUS() { - try { - - vector newLookup; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(lookup[0]->getNumBins()); - for (int i = 0; i < lookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < lookup.size(); j++) { - if (lookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < lookup.size(); j++) { - newLookup[j]->push_back(lookup[j]->getAbundance(i), lookup[j]->getGroup()); - } - - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < lookup.size(); j++) { delete lookup[j]; } - - lookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "eliminateZeroOTUS"); - exit(1); - } - } - -/***********************************************************************/ -vector SharedRAbundVector::getSharedRAbundFloatVectors(vector thislookup){ - try { - vector newLookupFloat; - for (int i = 0; i < lookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookupFloat.push_back(temp); - } - - for (int i = 0; i < thislookup.size(); i++) { - - for (int j = 0; j < thislookup[i]->getNumBins(); j++) { - - if (m->control_pressed) { return newLookupFloat; } - - int abund = thislookup[i]->getAbundance(j); - - float relabund = abund / (float) thislookup[i]->getNumSeqs(); - - newLookupFloat[i]->push_back(relabund, thislookup[i]->getGroup()); - } - } - - return newLookupFloat; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); - exit(1); - } -} -/***********************************************************************/ - -RAbundVector SharedRAbundVector::getRAbundVector() { - try { - RAbundVector rav; - - for (int i = 0; i < data.size(); i++) { - if(data[i].abundance != 0) { - rav.push_back(data[i].abundance); - } - } - - rav.setLabel(label); - return rav; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getRAbundVector"); - exit(1); - } -} -/***********************************************************************/ - -RAbundVector SharedRAbundVector::getRAbundVector2() { - try { - RAbundVector rav; - for(int i = 0; i < numBins; i++) - if(data[i].abundance != 0) - rav.push_back(data[i].abundance-1); - return rav; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getRAbundVector2"); - exit(1); - } -} -/***********************************************************************/ - -SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){ - try { - SharedSAbundVector sav(maxRank+1); - - for(int i=0;ierrorOut(e, "SharedRAbundVector", "getSharedSAbundVector"); - exit(1); - } +RAbundVector SharedRAbundVector::getRAbundVector(){ + RAbundVector rav; + for(int i = 0; i < data.size(); i++) { if (data[i] != 0) { rav.push_back(int(data[i])); } } + rav.setLabel(label); + return rav; } /***********************************************************************/ SAbundVector SharedRAbundVector::getSAbundVector() { - try { - SAbundVector sav(maxRank+1); - - for(int i=0;ierrorOut(e, "SharedRAbundVector", "getSAbundVector"); - exit(1); - } + try { + SAbundVector sav(int(maxRank+1)); + + for(int i=0;ierrorOut(e, "RAbundVector", "getSAbundVector"); + exit(1); + } } /***********************************************************************/ -SharedOrderVector SharedRAbundVector::getSharedOrderVector() { - try { - SharedOrderVector ov; - - for(int i=0;imothurRandomShuffle(ov); - - ov.setLabel(label); - ov.updateStats(); - - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getSharedOrderVector"); - exit(1); - } -} -/***********************************************************************/ - OrderVector SharedRAbundVector::getOrderVector(map* nameMap = NULL) { - try { - OrderVector ov; - for(int i=0;imothurRandomShuffle(ov); - - ov.setLabel(label); - - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedRAbundVector", "getOrderVector"); - exit(1); - } + try { + m->mothurOut("[ERROR]: can not convert SharedRAbundVectors to an ordervector, ordervectors assume no zero OTUS.\n"); m->control_pressed = true; + OrderVector o; return o; + } + catch(exception& e) { + m->errorOut(e, "RAbundVector", "getOrderVector"); + exit(1); + } } /***********************************************************************/ - diff --git a/source/datastructures/sharedrabundvector.h b/source/datastructures/sharedrabundvector.h deleted file mode 100644 index e4898882..00000000 --- a/source/datastructures/sharedrabundvector.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef SHAREDRABUNDVECTOR_H -#define SHAREDRABUNDVECTOR_H - -/* - * sharedrabundvector.h - * Dotur - * - * Created by Sarah Westcott on 12/5/08. - * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "datavector.hpp" -#include "sharedordervector.h" -#include "sharedsabundvector.h" -#include "sharedrabundfloatvector.h" -#include "rabundvector.hpp" -//#include "groupmap.h" - -/* DataStructure for a shared file. - This class is a child to datavector. It represents OTU information at a certain distance. - It is similiar to an rabundvector except each member of data knows which group it belongs to. - Each member of the internal container "data" is a struct of type individual. - An individual which knows the OTU from which it came, - the group it is in and its abundance. */ - - -class SharedRAbundVector : public DataVector { - -public: - SharedRAbundVector(); - SharedRAbundVector(int); - //SharedRAbundVector(string, vector); - SharedRAbundVector(const SharedRAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs), group(bv.group), index(bv.index){}; - SharedRAbundVector(ifstream&); - ~SharedRAbundVector(); - - int getNumBins(); - int getNumSeqs(); - int getMaxRank(); - string getGroup(); - void setGroup(string); - string getBinLabel(); - void setBinLabel(string); - int getGroupIndex(); - void setGroupIndex(int); - - void set(int, int, string); //OTU, abundance, groupname - void setData(vector ); - individual get(int); - vector getData(); - int getAbundance(int); - vector getAbundances(); - int numNZ(); - void sortD(); //Sorts the data in descending order. - void push_front(int, int, string); //abundance, otu, groupname - void insert(int, int, string); //abundance, otu, groupname - void push_back(int, string); //abundance, groupname - void pop_back(); - void resize(int); - int size(); - void clear(); - vector::reverse_iterator rbegin(); - vector::reverse_iterator rend(); - - void print(ostream&); - void printHeaders(ostream&); - - RAbundVector getRAbundVector(); - RAbundVector getRAbundVector2(); - SAbundVector getSAbundVector(); - OrderVector getOrderVector(map*); - SharedOrderVector getSharedOrderVector(); - SharedSAbundVector getSharedSAbundVector(); - SharedRAbundVector getSharedRAbundVector(); - vector getSharedRAbundVectors(); - vector getSharedRAbundFloatVectors(vector); - -private: - int eliminateZeroOTUS(); - vector data; - vector lookup; - //GlobalData* globaldata; - //GroupMap* groupmap; - int maxRank; - int numBins; - int numSeqs; - string group; - int index; -}; - - -#endif - diff --git a/source/datastructures/sharedrabundvector.hpp b/source/datastructures/sharedrabundvector.hpp new file mode 100644 index 00000000..561458fd --- /dev/null +++ b/source/datastructures/sharedrabundvector.hpp @@ -0,0 +1,88 @@ +// +// sharedrabundvector.hpp +// Mothur +// +// Created by Sarah Westcott on 7/24/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef sharedrabundvector_hpp +#define sharedrabundvector_hpp + +#include "datavector.hpp" +#include "ordervector.hpp" +#include "rabundvector.hpp" +#include "sabundvector.hpp" + + +/* Data Structure for a rabund file. + This class is a child to datavector. It represents OTU information at a certain distance. + A rabundvector can be converted into and ordervector, listvector or sabundvector. + Each member of the internal container "data" represents an individual OTU. + So data[0] = 6, because there are six member in that OTU. + example: listvector = a,b,c,d,e,f g,h,i j,k l m + rabundvector = 6 3 2 1 1 + sabundvector = 2 1 1 0 0 1 + ordervector = 1 1 1 1 1 1 2 2 2 3 3 4 5 + + a,b,g,j,l = sample A + c,d,h,i = sample B + e,f,k,m = sample C + + The sharedRabund class is very similar to rabund. SharedRabund allows for 0 otus in a sample, rabunds do not. SharedRabund also know their group. SharedRabunds are stored as floats, but printed as integers or floats depending on whether it represents a shared or relabund file. + sharedrabund = A 5 2 1 1 1 0 + B 5 2 2 0 0 0 + C 5 2 0 1 0 1 + */ + + +//class RAbundFloatVector; +class OrderVector; + +class SharedRAbundVector : public DataVector { + +public: + SharedRAbundVector(); + SharedRAbundVector(int); + SharedRAbundVector(vector, int, int, int); + SharedRAbundVector(vector); + SharedRAbundVector(const SharedRAbundVector& bv) : DataVector(bv), data(bv.data), maxRank(bv.maxRank), numBins(bv.numBins), numSeqs(bv.numSeqs), group(bv.group) { }; + SharedRAbundVector(ifstream&); + SharedRAbundVector(ifstream& f, string l, string g, int); //filehandle, label, numBins + ~SharedRAbundVector(); + + int getNumBins(); + int getNumSeqs(); + int getMaxRank(); + + int remove(int); + void set(int, int); + int get(int); + vector get() { return data; } + int increment(int); //add 1 to bin + void push_back(int); + void resize(int); + int size(); + void clear(); + + void print(ostream&); //nonsorted + + RAbundVector getRAbundVector(); + RAbundFloatVector getRAbundFloatVector(); + SAbundVector getSAbundVector(); + OrderVector getOrderVector(map*); + + string getGroup() { return group; } //group = "" for rabunds without groupInfo + void setGroup(string g) { group = g; } + +private: + vector data; + int maxRank; + int numBins; + int numSeqs; + string group; +}; + + + +#endif /* sharedrabundvector_hpp */ diff --git a/source/datastructures/sharedrabundvectors.cpp b/source/datastructures/sharedrabundvectors.cpp new file mode 100644 index 00000000..fffaa884 --- /dev/null +++ b/source/datastructures/sharedrabundvectors.cpp @@ -0,0 +1,637 @@ +// +// sharedrabundvectors.cpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "sharedrabundvectors.hpp" +#include "sharedutilities.h" + +/***********************************************************************/ +//reads a shared file +SharedRAbundVectors::SharedRAbundVectors(ifstream& f) : DataVector(){ + try { + m->clearAllGroups(); + vector allGroups; + + int num, count; + count = 0; + string holdLabel, nextLabel, groupN; + + for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; lookup[i] = NULL; } } lookup.clear(); + + //are we at the beginning of the file?? + if (m->saveNextLabel == "") { + f >> label; + + //is this a shared file that has headers + if (label == "label") { + //gets "group" + f >> label; m->gobble(f); + + //gets "numOtus" + f >> label; m->gobble(f); + + //eat rest of line + label = m->getline(f); m->gobble(f); + + //parse labels to save + istringstream iStringStream(label); + m->sharedBinLabelsInFile.clear(); + while(!iStringStream.eof()){ + if (m->control_pressed) { break; } + string temp; + iStringStream >> temp; m->gobble(iStringStream); + + m->sharedBinLabelsInFile.push_back(temp); + } + + f >> label >> groupN >> num; + }else { + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + + //make binlabels because we don't have any + string snumBins = toString(num); + m->sharedBinLabelsInFile.clear(); + for (int i = 0; i < num; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + m->sharedBinLabelsInFile.push_back(binLabel); + } + } + }else { + label = m->saveNextLabel; + + //read in first row since you know there is at least 1 group. + f >> groupN >> num; + } + + //reset labels, currentLabels may have gotten changed as otus were eliminated because of group choices or sampling + m->currentSharedBinLabels = m->sharedBinLabelsInFile; + + holdLabel = label; + allGroups.push_back(groupN); + numBins = num; + + //add new vector to lookup + SharedRAbundVector* temp = new SharedRAbundVector(f, label, groupN, numBins); m->gobble(f); + push_back(temp); + + if (!(f.eof())) { f >> nextLabel; } + + //read the rest of the groups info in + while ((nextLabel == holdLabel) && (f.eof() != true)) { + f >> groupN >> num; + SharedRAbundVector* temp = new SharedRAbundVector(f, label, groupN, numBins); m->gobble(f); + push_back(temp); + allGroups.push_back(groupN); + + if (f.eof() != true) { f >> nextLabel; } + } + m->saveNextLabel = nextLabel; + m->setAllGroups(allGroups); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "SharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVectors::print(ostream& output){ + try { + sort(lookup.begin(), lookup.end(), compareRAbunds); + for (int i = 0; i < lookup.size(); i++) { + if (m->control_pressed) { break; } + lookup[i]->print(output); + } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "print"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVectors::printHeaders(ostream& output){ + try { + string snumBins = toString(numBins); + output << "label\tGroup\tnumOtus"; + + if (m->sharedHeaderMode == "tax") { + for (int i = 0; i < numBins; i++) { + + //if there is a bin label use it otherwise make one + string binLabel = "PhyloType"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } + + output << '\t' << binLabel ; + } + output << endl; + }else { + for (int i = 0; i < numBins; i++) { + //if there is a bin label use it otherwise make one + string binLabel = "Otu"; + + if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } + else { + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; + } + + output << '\t' << binLabel; + } + + output << endl; + } + m->printedSharedHeaders = true; + } + catch(exception& e) { + m->errorOut(e, "SharedVector", "printHeaders"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::push_back(SharedRAbundVector* thisLookup){ + try { + + if (numBins == 0) { numBins = thisLookup->getNumBins(); } + lookup.push_back(thisLookup); + sort(lookup.begin(), lookup.end(), compareRAbunds); + if (label == "") { label = thisLookup->getLabel(); } + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + + return lookup.size(); + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "push_back"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::push_back(vector abunds, string binLabel){ + try { + if (abunds.size() != lookup.size()) { m->mothurOut("[ERROR]: you have provided " + toString(abunds.size()) + " abundances, but mothur was expecting " + toString(lookup.size()) + ", please correct.\n"); m->control_pressed = true; return 0; } + + for (int i = 0; i < lookup.size(); i ++) { lookup[i]->push_back(abunds[i]); } + + if (binLabel == "") { //create one + map::iterator it; + int otuNum = 0; bool notDone = true; + + //find label prefix + string prefix = "Otu"; + if (m->currentSharedBinLabels[m->currentSharedBinLabels.size()-1][0] == 'P') { prefix = "PhyloType"; } + + string tempLabel = m->currentSharedBinLabels[m->currentSharedBinLabels.size()-1]; + string simpleLastLabel = m->getSimpleLabel(tempLabel); + m->mothurConvert(simpleLastLabel, otuNum); otuNum++; + string potentialLabel = toString(otuNum); + + while (notDone) { + if (m->control_pressed) { notDone = false; break; } + + potentialLabel = toString(otuNum); + vector::iterator it = find(m->currentSharedBinLabels.begin(), m->currentSharedBinLabels.end(), potentialLabel); + if (it == m->currentSharedBinLabels.end()) { + potentialLabel = prefix + toString(otuNum); + it = find(m->currentSharedBinLabels.begin(), m->currentSharedBinLabels.end(), potentialLabel); + if (it == m->currentSharedBinLabels.end()) { + notDone = false; break; + } + } + otuNum++; + } + + binLabel = potentialLabel; + } + m->sharedBinLabelsInFile.push_back(binLabel); + m->currentSharedBinLabels.push_back(binLabel); + + return lookup.size(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "push_back"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::getOTUTotal(int bin){ + try { + int totalOTUAbund = 0; + for (int i = 0; i < lookup.size(); i++) { totalOTUAbund += lookup[i]->get(bin); } + return totalOTUAbund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "push_back"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundVectors::getOTU(int bin){ + try { + vector abunds; + for (int i = 0; i < lookup.size(); i++) { abunds.push_back(lookup[i]->get(bin)); } + return abunds; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "push_back"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVectors::setLabels(string l){ + try { + label = l; + for (int i = 0; i < lookup.size(); i++) { lookup[i]->setLabel(l); } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "setLabels"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::get(int bin, string group){ + try { + int abund = 0; + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { abund = lookup[it->second]->get(bin); } + + return abund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "get"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::getNumSeqs(string group){ + try { + int numSeqs = 0; + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { numSeqs = lookup[it->second]->getNumSeqs(); } + + return numSeqs; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "getNumSeqs"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVectors::set(int bin, int binSize, string group){ + try { + map::iterator it = groupNames.find(group); + if (it == groupNames.end()) { m->mothurOut("[ERROR]: can not find group " + group + ".\n"); m->control_pressed = true; } + else { lookup[it->second]->set(bin, binSize); } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "set"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::removeOTU(int bin){ + try { + int totalOTUAbund = 0; + for (int i = 0; i < lookup.size(); i ++) { + totalOTUAbund += lookup[i]->remove(bin); + } + m->currentSharedBinLabels.erase(m->currentSharedBinLabels.begin()+bin); + numBins--; + + return totalOTUAbund; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "removeOTU"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundVectors::getNamesGroups(){ + try { + vector names; names.clear(); + for (int i = 0; i < lookup.size(); i ++) { names.push_back(lookup[i]->getGroup()); } + return names; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "getNamesGroups"); + exit(1); + } +} +/***********************************************************************/ +SharedOrderVector SharedRAbundVectors::getSharedOrderVector(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + SharedOrderVector order; + for (int i = 0; i < lookup.size(); i++) { + for (int j = 0; j < lookup[i]->getNumBins(); j++) { + int abund = lookup[i]->get(j); + int bin = j+1; + if (abund != 0) { + for (int k = 0; k < abund; k++) { order.push_back(j, j, lookup[i]->getGroup()); } + } + } + } + + return order; + + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedOrderVector"); + exit(1); + } +} +/***********************************************************************/ +void SharedRAbundVectors::removeGroups(vector g){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), g) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "removeGroups"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::removeGroups(int minSize, bool silent){ + try { + vector Groups; + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + if ((*it)->getNumSeqs() < minSize) { + if (!silent) { m->mothurOut((*it)->getGroup() + " contains " + toString((*it)->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); } + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { + Groups.push_back((*it)->getGroup()); + ++it; + } + } + m->setGroups(Groups); + + if (remove) { eliminateZeroOTUS(); } + + groupNames.clear(); + for (int i = 0; i < lookup.size(); i ++) { groupNames[lookup[i]->getGroup()] = i; } + + return lookup.size(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "removeGroups"); + exit(1); + } +} +/***********************************************************************/ +int SharedRAbundVectors::getNumSeqsSmallestGroup(){ + try { + int smallest = 1e6; + for (int i = 0; i < lookup.size(); i++) { + if (m->debug) { m->mothurOut("[DEBUG]: " + lookup[i]->getGroup() + " numSeqs = " + toString(lookup[i]->getNumSeqs()) + "\n"); } + if (lookup[i]->getNumSeqs() < smallest) { smallest = lookup[i]->getNumSeqs(); } + } + return smallest; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getNumSeqsSmallestGroup"); + exit(1); + } +} + +/***********************************************************************/ +vector SharedRAbundVectors::getSharedRAbundVectors(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + vector newLookup; + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + if (m->control_pressed) { return newLookup; } + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + for (int i = 0; i < lookup.size(); i++) { + if (m->control_pressed) { return newLookup; } + SharedRAbundVector* temp = new SharedRAbundVector(*lookup[i]); + newLookup.push_back(temp); + } + + return newLookup; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +vector SharedRAbundVectors::getSharedRAbundFloatVectors(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + vector newLookup; + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + if (m->control_pressed) { return newLookup; } + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + for (int i = 0; i < lookup.size(); i++) { + if (m->control_pressed) { return newLookup; } + vector abunds; + vector data = lookup[i]->get(); + string group = lookup[i]->getGroup(); + for (int j = 0; j < data.size(); j++) { abunds.push_back((float)data[j]); } + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(abunds); + temp->setLabel(label); + temp->setGroup(group); + newLookup.push_back(temp); + } + + return newLookup; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +RAbundVector SharedRAbundVectors::getRAbundVector(){ + try { + SharedUtil util; + + vector Groups = m->getGroups(); + vector allGroups = m->getAllGroups(); + util.setGroups(Groups, allGroups); + m->setGroups(Groups); + + bool remove = false; + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if (util.isValidGroup((*it)->getGroup(), m->getGroups()) == false) { + remove = true; + delete (*it); (*it) = NULL; + it = lookup.erase(it); + }else { ++it; } + } + + if (remove) { eliminateZeroOTUS(); } + + RAbundVector rav; + for (int i = 0; i < numBins; i++) { + int abund = getOTUTotal(i); + rav.push_back(abund); + } + + return rav; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + exit(1); + } +} +/***********************************************************************/ +RAbundVector SharedRAbundVectors::getRAbundVector(string group){ + try { + RAbundVector rav; + rav.setLabel(label); + + for (vector::iterator it = lookup.begin(); it != lookup.end();) { + //if this sharedrabund is not from a group the user wants then delete it. + if ((*it)->getGroup() == group) { + for (int i = 0; i < (*it)->getNumBins(); i++) { rav.push_back((*it)->get(i)); } + }else { ++it; } + } + + return rav; + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getRAbundVector"); + exit(1); + } +} +/***********************************************************************/ +SAbundVector SharedRAbundVectors::getSAbundVector(){ + try { + RAbundVector rav = getRAbundVector(); + return rav.getSAbundVector(); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + exit(1); + } +} +/*********************************************************************** +OrderVector SharedRAbundVectors::getOrderVector(map* nameMap = NULL){ + try { + RAbundVector rav = getRAbundVector(); + return rav.getOrderVector(NULL); + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + exit(1); + } +} +/**********************************************************************************************************************/ +void SharedRAbundVectors::eliminateZeroOTUS() { + try { + + for (int i = 0; i < lookup[0]->getNumBins();) { + if (m->control_pressed) { break; } + + int total = getOTUTotal(i); + + //if they are not all zero add this bin + if (total == 0) { removeOTU(i); } + else { i++; } + } + } + catch(exception& e) { + m->errorOut(e, "SharedRAbundVectors", "eliminateZeroOTUS"); + exit(1); + } +} +/***********************************************************************/ + + diff --git a/source/datastructures/sharedrabundvectors.hpp b/source/datastructures/sharedrabundvectors.hpp new file mode 100644 index 00000000..eef034c8 --- /dev/null +++ b/source/datastructures/sharedrabundvectors.hpp @@ -0,0 +1,78 @@ +// +// sharedrabundvectors.hpp +// Mothur +// +// Created by Sarah Westcott on 5/15/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef sharedrabundvectors_hpp +#define sharedrabundvectors_hpp + +#include "datavector.hpp" +#include "rabundvector.hpp" +#include "rabundfloatvector.hpp" +#include "sharedordervector.h" +#include "sharedrabundvector.hpp" +#include "sharedrabundfloatvector.hpp" + +/* DataStructure for a shared file. */ + +//******************************************************************************************************************** +inline bool compareRAbunds(SharedRAbundVector* left, SharedRAbundVector* right){ return (left->getGroup() < right->getGroup()); } +//******************************************************************************************************************** + +class SharedRAbundVectors : public DataVector { + +public: + SharedRAbundVectors() : DataVector() { label = ""; numBins = 0; } + SharedRAbundVectors(ifstream&); + SharedRAbundVectors(SharedRAbundVectors& bv) : DataVector(bv), numBins(bv.numBins) { + vector data = bv.getSharedRAbundVectors(); + for (int i = 0; i < data.size(); i++) { push_back(data[i]); } + eliminateZeroOTUS(); + setLabels(bv.getLabel()); + } + ~SharedRAbundVectors() { clear(); } + + void setLabels(string l); + int getOTUTotal(int bin); + vector getOTU(int bin); + int push_back(vector, string binLabel=""); //add otu. mothur assumes abunds are in same order as groups. + int get(int bin, string group); + void set(int bin, int binSize, string group); + int push_back(SharedRAbundVector*); + + void eliminateZeroOTUS(); //run after push_backs if groups are chosen + int removeOTU(int bin); + void removeGroups(vector g); + int removeGroups(int minSize, bool silent=false); // removes any groups with numSeqs < minSize + int size() { return lookup.size(); } + int getNumBins() { return numBins; } + int getNumSeqsSmallestGroup(); + vector getNamesGroups(); //same order as Rabunds + int getNumGroups() { return lookup.size(); } + int getNumSeqs(string); //group + void resize(int n) { m->mothurOut("[ERROR]: can not use resize for SharedRAbundVectors.\n"); m->control_pressed = true; } + void clear() { for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; lookup[i] = NULL; } } lookup.clear(); groupNames.clear(); numBins = 0; } + + void print(ostream&); + void printHeaders(ostream&); + + RAbundVector getRAbundVector(); + RAbundVector getRAbundVector(string); //group you want the rabund for + SAbundVector getSAbundVector(); + OrderVector getOrderVector(map*) { m->mothurOut("[ERROR]: can not convert SharedRAbundVectors to an ordervector, ordervectors assume no zero OTUS.\n"); m->control_pressed = true; OrderVector o; return o; } + SharedOrderVector getSharedOrderVector(); + vector getSharedRAbundVectors(); + vector getSharedRAbundFloatVectors(); + +private: + vector lookup; + map groupNames; + int numBins; + +}; + + +#endif /* sharedrabundvectors_hpp */ diff --git a/source/datastructures/sharedsabundvector.cpp b/source/datastructures/sharedsabundvector.cpp deleted file mode 100644 index 303936fd..00000000 --- a/source/datastructures/sharedsabundvector.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * sharedSharedSAbundVector.cpp - * Dotur - * - * Created by Sarah Westcott on 12/10/08. - * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "sharedsabundvector.h" -#include "sabundvector.hpp" - - -/***********************************************************************/ - -SharedSAbundVector::SharedSAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ } - -/***********************************************************************/ - -SharedSAbundVector::SharedSAbundVector(int size) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { - individual newGuy; - //initialize data - for (int i=0; i< size; i++) { - newGuy.bin = i; - newGuy.abundance = 0; - data.push_back(newGuy); - } -} - -/***********************************************************************/ - -void SharedSAbundVector::set(int bin, int abundance, string groupName){ - try { - - int initSize = data[bin].abundance; - data[bin].abundance = abundance; - data[bin].group = groupName; - - if(bin != 0){ - numBins += (abundance - initSize); - } - - numSeqs += bin * (abundance - initSize); - - if(bin > maxRank) { maxRank = bin; } - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "set"); - exit(1); - } -} - -/***********************************************************************/ - -individual SharedSAbundVector::get(int index){ - return data[index]; -} -/***********************************************************************/ - -int SharedSAbundVector::getAbundance(int index){ - return data[index].abundance; -} - -/***********************************************************************/ - -void SharedSAbundVector::push_back(int abundance, int bin, string groupName){ - try { - individual newGuy; - newGuy.abundance = abundance; - newGuy.bin = bin; - newGuy.group = groupName; - - data.push_back(newGuy); - - maxRank++; - - numBins += abundance; - - numSeqs += (maxRank * abundance); - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "push_back"); - exit(1); - } -} - -/***********************************************************************/ - -void SharedSAbundVector::resize(int size){ - data.resize(size); -} - -/***********************************************************************/ - -int SharedSAbundVector::size(){ - return data.size(); -} - -/***********************************************************************/ -void SharedSAbundVector::print(ostream& output){ - try { - output << label << '\t' << maxRank; - - for(int i=1;i<=maxRank;i++){ - output << '\t' << data[i].abundance; - } - output << endl; - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "print"); - exit(1); - } -} -/***********************************************************************/ -string SharedSAbundVector::getGroup(){ - return group; -} - -/***********************************************************************/ - -void SharedSAbundVector::setGroup(string groupName){ - group = groupName; -} - -/**********************************************************************/ -int SharedSAbundVector::getNumBins(){ - return numBins; -} - -/***********************************************************************/ - -int SharedSAbundVector::getNumSeqs(){ - return numSeqs; -} - -/***********************************************************************/ - -int SharedSAbundVector::getMaxRank(){ - return maxRank; -} -/***********************************************************************/ -RAbundVector SharedSAbundVector::getRAbundVector(){ - try { - RAbundVector rav; - - for(int i=1;ierrorOut(e, "SharedSAbundVector", "getRAbundVector"); - exit(1); - } -} -/***********************************************************************/ -SAbundVector SharedSAbundVector::getSAbundVector(){ - try { - RAbundVector rav; - SAbundVector sav; - - rav = getRAbundVector(); - sav = rav.getSAbundVector(); - return sav; - - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "getSAbundVector"); - exit(1); - } -} - -/***********************************************************************/ - -bool compareMembers (individual member, individual member2){ - - if(member.abundance < member2.abundance){ - return true; } - else{ - return false; - } -} - -/***********************************************************************/ -SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){ - try { - SharedRAbundVector rav; - - for(int i=1;ierrorOut(e, "SharedSAbundVector", "getSharedRAbundVector"); - exit(1); - } -} - - -/***********************************************************************/ - -SharedSAbundVector SharedSAbundVector::getSharedSAbundVector(){ - return *this; -} - -/***********************************************************************/ -SharedOrderVector SharedSAbundVector::getSharedOrderVector() { - try { - SharedRAbundVector rav; - SharedOrderVector ov; - - rav = this->getSharedRAbundVector(); - ov = rav.getSharedOrderVector(); - - ov.updateStats(); - - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "getSharedOrderVector"); - exit(1); - } -} -/***********************************************************************/ - -void SharedSAbundVector::clear(){ - numBins = 0; - maxRank = 0; - numSeqs = 0; - data.clear(); -} - -/***********************************************************************/ -OrderVector SharedSAbundVector::getOrderVector(map* hold = NULL){ - try { - OrderVector ov; - - int binIndex = 0; - - for(int i=1;imothurRandomShuffle(ov); - - ov.setLabel(label); - ov.getNumBins(); - return ov; - } - catch(exception& e) { - m->errorOut(e, "SharedSAbundVector", "getOrderVector"); - exit(1); - } -} - -/***********************************************************************/ - diff --git a/source/datastructures/sharedsabundvector.h b/source/datastructures/sharedsabundvector.h deleted file mode 100644 index cd78a2e1..00000000 --- a/source/datastructures/sharedsabundvector.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef SHAREDSABUND_H -#define SHAREDSABUND_H - - -/* - * sharedSharedSAbundVector.h - * Dotur - * - * Created by Sarah Westcott on 12/10/08. - * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "datavector.hpp" -#include "rabundvector.hpp" -#include "ordervector.hpp" -#include "sharedordervector.h" -#include "sharedrabundvector.h" - -/* This class is a child to datavector. It represents OTU information at a certain distance. - It is similiar to an sabundvector except each member of data knows which group it belongs to. - Each member of the internal container "data" is a struct of type individual. - An individual which knows the OTU from which it came, - the group it is in and its abundance. */ - - -class SharedSAbundVector : public DataVector { - -public: - SharedSAbundVector(); - SharedSAbundVector(int); - SharedSAbundVector(const SharedSAbundVector& rv) : DataVector(rv.label), data(rv.data), maxRank(rv.maxRank), numBins(rv.numBins), numSeqs(rv.numSeqs){}; - ~SharedSAbundVector(){}; - - int getNumBins(); - int getNumSeqs(); - int getMaxRank(); - string getGroup(); - void setGroup(string); - - void set(int, int, string); //OTU, abundance, group - individual get(int); - int getAbundance(int); - void push_back(int, int, string); //abundance, OTU, group - void pop_back(); - void resize(int); - int size(); - void clear(); - - void print(ostream&); - - RAbundVector getRAbundVector(); - SAbundVector getSAbundVector(); - OrderVector getOrderVector(map*); - SharedSAbundVector getSharedSAbundVector(); - SharedRAbundVector getSharedRAbundVector(); - SharedOrderVector getSharedOrderVector(); - -private: - vector data; - - int maxRank; - int numBins; - int numSeqs; - string group; -}; - -#endif - diff --git a/source/display.h b/source/display.h index 979caa51..083e754b 100644 --- a/source/display.h +++ b/source/display.h @@ -1,12 +1,9 @@ #ifndef DISPLAY_H #define DISPLAY_H -#include "sabundvector.hpp" -#include "sharedsabundvector.h" #include "calculator.h" #include "fileoutput.h" - /***********************************************************************/ class Display { @@ -17,9 +14,9 @@ class Display { virtual void init(string) = 0; virtual void reset() = 0; virtual void close() = 0; + virtual bool isCalcMultiple() = 0; virtual void outputTempFiles(string) {} virtual void inputTempFiles(string) {} - virtual bool isCalcMultiple() = 0; virtual void setAll(bool){} virtual bool hasLciHci(){ return false; } virtual bool getAll() { bool a; return a; } diff --git a/source/heatmap.cpp b/source/heatmap.cpp index 254b7066..54f5bbfc 100644 --- a/source/heatmap.cpp +++ b/source/heatmap.cpp @@ -109,10 +109,10 @@ string HeatMap::getPic(RAbundVector* rabund) { //********************************************************************************************************************** -string HeatMap::getPic(vector lookup) { +string HeatMap::getPic(vector lookup, vector groups) { try { - int numBinsToDisplay = lookup[0]->size(); + int numBinsToDisplay = lookup[0]->getNumBins(); if (numOTU != 0) { //user want to display a portion of the otus if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; } @@ -129,7 +129,7 @@ string HeatMap::getPic(vector lookup) { for(int i = 0; i < lookup.size(); i++){ for(int j=0; jsize(); j++){ - float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs(); + float relAbund = lookup[i]->get(j) / (float)lookup[i]->getNumSeqs(); if(relAbund > maxRelAbund[i]){ maxRelAbund[i] = relAbund; } } if(maxRelAbund[i] > superMaxRelAbund){ superMaxRelAbund = maxRelAbund[i]; } @@ -140,9 +140,9 @@ string HeatMap::getPic(vector lookup) { scaleRelAbund[i].assign(numBinsToDisplay, ""); for(int j=0;jcontrol_pressed) { return "control"; } - float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs(); + float relAbund = lookup[i]->get(j) / (float)lookup[i]->getNumSeqs(); - if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0. + if (lookup[i]->get(j) != 0) { //don't want log value of 0. if (scaler == "log10") { if (maxRelAbund[i] == 1) { maxRelAbund[i] -= 0.001; } if (relAbund == 1) { relAbund -= 0.001; } @@ -182,7 +182,7 @@ string HeatMap::getPic(vector lookup) { string tempLabel = "OTU"; outsvg << "" + tempLabel + "\n"; }else { - outsvg << "getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "\n"; + outsvg << "" + groups[h-1] + "\n"; } } @@ -219,7 +219,7 @@ string HeatMap::getPic(vector lookup) { } //********************************************************************************************************************** -vector HeatMap::sortSharedVectors(vector& lookup){ +vector HeatMap::sortSharedVectors(vector lookup){ try { vector looktemp; @@ -241,31 +241,26 @@ vector HeatMap::sortSharedVectors(vector& lookup){ /******************* create copy of lookup *********************/ //create and initialize looktemp as a copy of lookup for (int i = 0; i < lookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getNumBins()); + SharedRAbundVector* temp = new SharedRAbundVector(*lookup[i]); temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - //copy lookup i's info - for (int j = 0; j < lookup[i]->size(); j++) { - temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup()); - } looktemp.push_back(temp); } /************************ fill lookup in order given by place *********************/ //for each bin - for (int i = 0; i < looktemp[0]->size(); i++) { //place + for (int i = 0; i < looktemp[0]->getNumBins(); i++) { //place //fill lookup // 2 -> 1 for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2 - int newAbund = looktemp[j]->getAbundance(i); // 1 -> 3 - lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group + int newAbund = looktemp[j]->get(i); // 1 -> 3 + lookup[j]->set(place[i], newAbund); //binNumber, abundance, group } sortedLabels[place[i]] = m->currentSharedBinLabels[i]; } //delete looktemp -- Sarah look at - this is causing segmentation faults for (int j = 0; j < looktemp.size(); j++) { -// delete looktemp[j]; - } + //delete looktemp[j]; + } return sortedLabels; @@ -276,7 +271,7 @@ vector HeatMap::sortSharedVectors(vector& lookup){ } } //********************************************************************************************************************** -map HeatMap::orderShared(vector& lookup){ +map HeatMap::orderShared(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -286,11 +281,11 @@ map HeatMap::orderShared(vector& lookup){ vector uniqueBins; //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { + for (int i = 0; i < lookup[0]->getNumBins(); i++) { int count = 0; //is this bin shared - for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->getAbundance(i) != 0) { count++; } } + for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->get(i) != 0) { count++; } } if (count < 2) { uniqueBins.push_back(i); } else { sharedBins.push_back(i); } @@ -309,7 +304,7 @@ map HeatMap::orderShared(vector& lookup){ } } //********************************************************************************************************************** -map HeatMap::orderTopOtu(vector& lookup){ +map HeatMap::orderTopOtu(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -318,10 +313,10 @@ map HeatMap::orderTopOtu(vector& lookup){ vector totals; //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { + for (int i = 0; i < lookup[0]->getNumBins(); i++) { int total = 0; - for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->getAbundance(i); } + for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->get(i); } binCount temp(i, total); @@ -342,7 +337,7 @@ map HeatMap::orderTopOtu(vector& lookup){ } } //********************************************************************************************************************** -map HeatMap::orderTopGroup(vector& lookup){ +map HeatMap::orderTopGroup(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -352,9 +347,9 @@ map HeatMap::orderTopGroup(vector& lookup){ totals.resize(lookup.size()); //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { + for (int i = 0; i < lookup[0]->getNumBins(); i++) { for (int j = 0; j < lookup.size(); j++) { - binCount temp(i, (lookup[j]->getAbundance(i))); + binCount temp(i, (lookup[j]->get(i))); totals[j].push_back(temp); } } @@ -425,10 +420,10 @@ void HeatMap::printLegend(int y, float maxbin) { } //********************************************************************************************************************** -string HeatMap::getPic(vector lookup) { +string HeatMap::getPic(vector lookup, vector groups) { try { - int numBinsToDisplay = lookup[0]->size(); + int numBinsToDisplay = lookup[0]->getNumBins(); if (numOTU != 0) { //user want to display a portion of the otus if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; } @@ -443,9 +438,9 @@ string HeatMap::getPic(vector lookup) { float superMaxRelAbund = 0; for(int i = 0; i < lookup.size(); i++){ - for(int j=0; jsize(); j++){ + for(int j=0; jgetAbundance(j); + float relAbund = lookup[i]->get(j); if(relAbund > maxRelAbund[i]){ maxRelAbund[i] = relAbund; } } if(maxRelAbund[i] > superMaxRelAbund){ superMaxRelAbund = maxRelAbund[i]; } @@ -456,9 +451,9 @@ string HeatMap::getPic(vector lookup) { scaleRelAbund[i].assign(numBinsToDisplay, ""); for(int j=0;jcontrol_pressed) { return "control"; } - float relAbund = lookup[i]->getAbundance(j); + float relAbund = lookup[i]->get(j); - if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0. + if (lookup[i]->get(j) != 0) { //don't want log value of 0. if (scaler == "log10") { if (maxRelAbund[i] == 1) { maxRelAbund[i] -= 0.001; } if (relAbund == 1) { relAbund -= 0.001; } @@ -498,7 +493,7 @@ string HeatMap::getPic(vector lookup) { string tempLabel = "OTU"; outsvg << "" + tempLabel + "\n"; }else { - outsvg << "getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "\n"; + outsvg << "" + groups[h-1] + "\n"; } } @@ -534,7 +529,7 @@ string HeatMap::getPic(vector lookup) { } } //********************************************************************************************************************** -vector HeatMap::sortSharedVectors(vector& lookup){ +vector HeatMap::sortSharedVectors(vector lookup){ try { vector looktemp; @@ -556,14 +551,9 @@ vector HeatMap::sortSharedVectors(vector& look /******************* create copy of lookup *********************/ //create and initialize looktemp as a copy of lookup for (int i = 0; i < lookup.size(); i++) { - SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(lookup[i]->getNumBins()); + SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(*lookup[i]); temp->setLabel(lookup[i]->getLabel()); - temp->setGroup(lookup[i]->getGroup()); - //copy lookup i's info - for (int j = 0; j < lookup[i]->size(); j++) { - temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup()); - } - looktemp.push_back(temp); + looktemp.push_back(temp); } /************************ fill lookup in order given by place *********************/ @@ -571,8 +561,8 @@ vector HeatMap::sortSharedVectors(vector& look for (int i = 0; i < looktemp[0]->size(); i++) { //place //fill lookup // 2 -> 1 for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2 - float newAbund = looktemp[j]->getAbundance(i); // 1 -> 3 - lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group + float newAbund = looktemp[j]->get(i); // 1 -> 3 + lookup[j]->set(place[i], newAbund); //binNumber, abundance, group sortedLabels[place[i]] = m->currentSharedBinLabels[i]; } } @@ -591,7 +581,7 @@ vector HeatMap::sortSharedVectors(vector& look } } //********************************************************************************************************************** -int HeatMap::sortRabund(RAbundVector*& r){ +int HeatMap::sortRabund(RAbundVector* r){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. map::iterator it; @@ -636,7 +626,7 @@ int HeatMap::sortRabund(RAbundVector*& r){ } } //********************************************************************************************************************** -map HeatMap::orderShared(vector& lookup){ +map HeatMap::orderShared(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -646,11 +636,11 @@ map HeatMap::orderShared(vector& lookup){ vector uniqueBins; //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { + for (int i = 0; i < lookup[0]->getNumBins(); i++) { int count = 0; //is this bin shared - for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->getAbundance(i) != 0) { count++; } } + for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->get(i) != 0) { count++; } } if (count < 2) { uniqueBins.push_back(i); } else { sharedBins.push_back(i); } @@ -669,7 +659,7 @@ map HeatMap::orderShared(vector& lookup){ } } //********************************************************************************************************************** -map HeatMap::orderTopOtu(vector& lookup){ +map HeatMap::orderTopOtu(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -681,7 +671,7 @@ map HeatMap::orderTopOtu(vector& lookup){ for (int i = 0; i < lookup[0]->size(); i++) { int total = 0; - for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->getAbundance(i); } + for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->get(i); } binCountFloat temp(i, total); @@ -702,7 +692,7 @@ map HeatMap::orderTopOtu(vector& lookup){ } } //********************************************************************************************************************** -map HeatMap::orderTopGroup(vector& lookup){ +map HeatMap::orderTopGroup(vector lookup){ try { map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. @@ -714,7 +704,7 @@ map HeatMap::orderTopGroup(vector& lookup){ //for each bin for (int i = 0; i < lookup[0]->size(); i++) { for (int j = 0; j < lookup.size(); j++) { - binCountFloat temp(i, (lookup[j]->getAbundance(i))); + binCountFloat temp(i, (lookup[j]->get(i))); totals[j].push_back(temp); } } diff --git a/source/heatmap.h b/source/heatmap.h index 922147cc..407e01d8 100644 --- a/source/heatmap.h +++ b/source/heatmap.h @@ -9,11 +9,9 @@ * */ +#include "sharedrabundvector.hpp" #include "rabundvector.hpp" -#include "sharedrabundvector.h" -#include "sharedrabundfloatvector.h" -#include "datavector.hpp" - +#include "sharedrabundfloatvector.hpp" /***********************************************************************/ struct binCount { @@ -47,13 +45,13 @@ class HeatMap { ~HeatMap(){}; string getPic(RAbundVector*); - string getPic(vector); - string getPic(vector); + string getPic(vector, vector); + string getPic(vector, vector); private: - vector sortSharedVectors(vector& ); - vector sortSharedVectors(vector& ); - int sortRabund(RAbundVector*&); + vector sortSharedVectors(vector); + vector sortSharedVectors(vector); + int sortRabund(RAbundVector*); void printLegend(int, float); string format, sorted, groupComb, scaler, outputDir, inputfile; @@ -61,12 +59,12 @@ class HeatMap { MothurOut* m; int numOTU, fontSize; - map orderTopGroup(vector&); - map orderTopOtu(vector&); - map orderShared(vector&); - map orderTopGroup(vector&); - map orderTopOtu(vector&); - map orderShared(vector&); + map orderTopGroup(vector); + map orderTopOtu(vector); + map orderShared(vector); + map orderTopGroup(vector); + map orderTopOtu(vector); + map orderShared(vector); }; diff --git a/source/heatmapsim.cpp b/source/heatmapsim.cpp index 8db4aebe..98767a63 100644 --- a/source/heatmapsim.cpp +++ b/source/heatmapsim.cpp @@ -24,7 +24,7 @@ HeatMapSim::HeatMapSim(string dir, string i, int f) : outputDir(dir), inputfile( m = MothurOut::getInstance(); } //********************************************************************************************************************** -vector HeatMapSim::getPic(vector lookup, vector calcs) { +vector HeatMapSim::getPic(vector lookup, vector calcs, vector groups) { try { EstOutput data; vector sims; @@ -49,8 +49,8 @@ vector HeatMapSim::getPic(vector lookup, vectorgetGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "\n"; - outsvg << "getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "\n"; + outsvg << "" + groups[h] + "\n"; + outsvg << "" + groups[h] + "\n"; } sims.clear(); diff --git a/source/heatmapsim.h b/source/heatmapsim.h index 2c0c9316..3c991492 100644 --- a/source/heatmapsim.h +++ b/source/heatmapsim.h @@ -9,9 +9,6 @@ * */ - -#include "sharedrabundvector.h" -#include "datavector.hpp" #include "calculator.h" /***********************************************************************/ @@ -22,7 +19,7 @@ class HeatMapSim { HeatMapSim(string, string, int); ~HeatMapSim(){}; - vector getPic(vector, vector); + vector getPic(vector, vector, vector); string getPic(vector< vector >, vector); private: diff --git a/source/inputdata.cpp b/source/inputdata.cpp index c9142b7a..0c9d4a63 100644 --- a/source/inputdata.cpp +++ b/source/inputdata.cpp @@ -11,6 +11,7 @@ #include "ordervector.hpp" #include "listvector.hpp" #include "rabundvector.hpp" +#include "sharedrabundvectors.hpp" /***********************************************************************/ @@ -416,39 +417,36 @@ OrderVector* InputData::getOrderVector(string label){ exit(1); } } - /***********************************************************************/ -//this is used when you don't need the order vector -vector InputData::getSharedRAbundVectors(){ - try { - if(fileHandle){ - if (format == "sharedfile") { - SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle); - if (SharedRAbund != NULL) { - return SharedRAbund->getSharedRAbundVectors(); - } - }else if (format == "shared") { - SharedList = new SharedListVector(fileHandle); - - if (SharedList != NULL) { - return SharedList->getSharedRAbundVector(); - } - } - m->gobble(fileHandle); - } - - //this is created to signal to calling function that the input file is at eof - vector null; null.push_back(NULL); - return null; - - } - catch(exception& e) { - m->errorOut(e, "InputData", "getSharedRAbundVectors"); - exit(1); - } +SharedRAbundVectors* InputData::getSharedRAbundVectors(){ + try { + if(fileHandle){ + if (format == "sharedfile") { + SharedRAbundVectors* shared = new SharedRAbundVectors(fileHandle); + return shared; + }else if (format == "shared") { + SharedList = new SharedListVector(fileHandle); + + if (SharedList != NULL) { + return SharedList->getSharedRAbundVector(); + } + } + m->gobble(fileHandle); + } + + //this is created to signal to calling function that the input file is at eof + SharedRAbundVectors* null; null = NULL; + return null; + + } + catch(exception& e) { + m->errorOut(e, "InputData", "getSharedRAbundVectors"); + exit(1); + } } + /***********************************************************************/ -vector InputData::getSharedRAbundVectors(string label){ +SharedRAbundVectors* InputData::getSharedRAbundVectors(string label){ try { ifstream in; string thisLabel; @@ -460,16 +458,13 @@ vector InputData::getSharedRAbundVectors(string label){ if (format == "sharedfile") { while (in.eof() != true) { - SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in); + SharedRAbundVectors* SharedRAbund = new SharedRAbundVectors(in); if (SharedRAbund != NULL) { thisLabel = SharedRAbund->getLabel(); //if you are at the last label - if (thisLabel == label) { in.close(); return SharedRAbund->getSharedRAbundVectors(); } + if (thisLabel == label) { in.close(); return SharedRAbund; } else { - //so you don't loose this memory - vector lookup = SharedRAbund->getSharedRAbundVectors(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } delete SharedRAbund; } }else{ break; } @@ -498,7 +493,7 @@ vector InputData::getSharedRAbundVectors(string label){ } //this is created to signal to calling function that the input file is at eof - vector null; null.push_back(NULL); + SharedRAbundVectors* null; null = (NULL); in.close(); return null; @@ -511,21 +506,21 @@ vector InputData::getSharedRAbundVectors(string label){ /***********************************************************************/ //this is used when you don't need the order vector -vector InputData::getSharedRAbundFloatVectors(){ +SharedRAbundFloatVectors* InputData::getSharedRAbundFloatVectors(){ try { if(fileHandle){ if (format == "relabund") { - SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(fileHandle); - if (SharedRelAbund != NULL) { - return SharedRelAbund->getSharedRAbundFloatVectors(); - } + SharedRAbundFloatVectors* SharedRelAbund = new SharedRAbundFloatVectors(fileHandle); + return SharedRelAbund; }else if (format == "sharedfile") { - SharedRAbundVector* SharedRAbund = new SharedRAbundVector(fileHandle); + SharedRAbundVectors* SharedRAbund = new SharedRAbundVectors(fileHandle); if (SharedRAbund != NULL) { - vector lookup = SharedRAbund->getSharedRAbundVectors(); - vector lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear(); - return lookupFloat; + vector lookup = SharedRAbund->getSharedRAbundFloatVectors(); + vector groups = SharedRAbund->getNamesGroups(); + SharedRAbundFloatVectors* SharedRelAbund = new SharedRAbundFloatVectors(); + for (int i = 0; i < lookup.size(); i++) { SharedRelAbund->push_back(lookup[i]); } + delete SharedRAbund; + return SharedRelAbund; } } @@ -533,9 +528,8 @@ vector InputData::getSharedRAbundFloatVectors(){ } //this is created to signal to calling function that the input file is at eof - vector null; null.push_back(NULL); + SharedRAbundFloatVectors* null; null = (NULL); return null; - } catch(exception& e) { m->errorOut(e, "InputData", "getSharedRAbundFloatVectors"); @@ -543,7 +537,7 @@ vector InputData::getSharedRAbundFloatVectors(){ } } /***********************************************************************/ -vector InputData::getSharedRAbundFloatVectors(string label){ +SharedRAbundFloatVectors* InputData::getSharedRAbundFloatVectors(string label){ try { ifstream in; string thisLabel; @@ -555,40 +549,32 @@ vector InputData::getSharedRAbundFloatVectors(string l if (format == "relabund") { while (in.eof() != true) { - SharedRAbundFloatVector* SharedRelAbund = new SharedRAbundFloatVector(in); + SharedRAbundFloatVectors* SharedRelAbund = new SharedRAbundFloatVectors(in); if (SharedRelAbund != NULL) { thisLabel = SharedRelAbund->getLabel(); //if you are at the last label - if (thisLabel == label) { in.close(); return SharedRelAbund->getSharedRAbundFloatVectors(); } - else { - //so you don't loose this memory - vector lookup = SharedRelAbund->getSharedRAbundFloatVectors(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - delete SharedRelAbund; - } + if (thisLabel == label) { in.close(); return SharedRelAbund; } + else { delete SharedRelAbund; } }else{ break; } m->gobble(in); } }else if (format == "sharedfile") { while (in.eof() != true) { - SharedRAbundVector* SharedRAbund = new SharedRAbundVector(in); + SharedRAbundVectors* SharedRAbund = new SharedRAbundVectors(in); if (SharedRAbund != NULL) { thisLabel = SharedRAbund->getLabel(); //if you are at the last label if (thisLabel == label) { in.close(); - vector lookup = SharedRAbund->getSharedRAbundVectors(); - vector lookupFloat = SharedRAbund->getSharedRAbundFloatVectors(lookup); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear(); - return lookupFloat; - }else { - //so you don't loose this memory - vector lookup = SharedRAbund->getSharedRAbundVectors(); - for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup.clear(); - delete SharedRAbund; - } + vector lookup = SharedRAbund->getSharedRAbundFloatVectors(); + vector groups = SharedRAbund->getNamesGroups(); + SharedRAbundFloatVectors* SharedRelAbund = new SharedRAbundFloatVectors(); + for (int i = 0; i < lookup.size(); i++) { SharedRelAbund->push_back(lookup[i]); } + delete SharedRAbund; + return SharedRelAbund; + }else { delete SharedRAbund; } }else{ break; } m->gobble(in); } @@ -597,7 +583,7 @@ vector InputData::getSharedRAbundFloatVectors(string l //this is created to signal to calling function that the input file is at eof - vector null; null.push_back(NULL); + SharedRAbundFloatVectors* null; null = (NULL); in.close(); return null; diff --git a/source/inputdata.h b/source/inputdata.h index 658b21d8..c851f422 100644 --- a/source/inputdata.h +++ b/source/inputdata.h @@ -6,7 +6,8 @@ #include "sharedlistvector.h" #include "sharedordervector.h" #include "listvector.hpp" -#include "sharedrabundfloatvector.h" +#include "sharedrabundvectors.hpp" +#include "sharedrabundfloatvectors.hpp" class InputData { @@ -28,11 +29,11 @@ class InputData { SAbundVector* getSAbundVector(string); //pass the label you want RAbundVector* getRAbundVector(); RAbundVector* getRAbundVector(string); //pass the label you want - vector getSharedRAbundVectors(); - vector getSharedRAbundVectors(string); //pass the label you want - vector getSharedRAbundFloatVectors(); - vector getSharedRAbundFloatVectors(string); //pass the label you want - + SharedRAbundVectors* getSharedRAbundVectors(); + SharedRAbundVectors* getSharedRAbundVectors(string); //pass the label you want + SharedRAbundFloatVectors* getSharedRAbundFloatVectors(); + SharedRAbundFloatVectors* getSharedRAbundFloatVectors(string); //pass the label you want + private: string format; ifstream fileHandle; diff --git a/source/mothur.cpp b/source/mothur.cpp index 5bcaf667..5e99cfe1 100644 --- a/source/mothur.cpp +++ b/source/mothur.cpp @@ -117,6 +117,11 @@ int main(int argc, char *argv[]){ m->mothurOutJustToLog("Using ReadLine"); m->mothurOutEndLine(); m->mothurOutEndLine(); #endif + + #ifdef USE_BOOST + m->mothurOutJustToLog("Using Boost"); + m->mothurOutEndLine(); m->mothurOutEndLine(); + #endif #ifdef MOTHUR_FILES m->mothurOutJustToLog("Using default file location " + temp); @@ -167,8 +172,8 @@ int main(int argc, char *argv[]){ m->mothurOutEndLine(); } - //srand(54321); - srand( (unsigned)time( NULL ) ); + //m->setRandomSeed(54321); + m->setRandomSeed( (unsigned)time( NULL ) ); Engine* mothur = NULL; bool bail = 0; diff --git a/source/mothur.h b/source/mothur.h index fae675eb..e4b79512 100644 --- a/source/mothur.h +++ b/source/mothur.h @@ -413,7 +413,13 @@ string toString(const T&x){ return output.str(); } - +//********************************************************************************************************************** +template +void mothurSwap(T&x, T&y){ + T temp = y; + y = x; + x = temp; +} //********************************************************************************************************************** template diff --git a/source/mothurout.cpp b/source/mothurout.cpp index 088ffc80..de24e900 100644 --- a/source/mothurout.cpp +++ b/source/mothurout.cpp @@ -10,7 +10,8 @@ #include "mothurout.h" #include "ordervector.hpp" #include "sharedordervector.h" -#include "sharedrabundvector.h" + +#include "counttable.h" //needed for testing project @@ -2161,6 +2162,38 @@ int MothurOut::readConsTax(string inputfile, map& taxes){ exit(1); } } +//********************************************************************************************************************** +bool MothurOut::isCountFile(string inputfile){ + try { + bool isCount = true; + + ifstream in; + openInputFile(inputfile, in); + + //read headers + string line = getline(in); + + in.close(); + + vector pieces = splitWhiteSpace(line); + + if (pieces.size() >= 2) { + CountTable ct; + vector defaultHeaders = ct.getHardCodedHeaders(); + if (defaultHeaders.size() >= 2) { + if (pieces[0] != defaultHeaders[0]) { isCount = false; } + if (pieces[1] != defaultHeaders[1]) { isCount = false; } + }else { isCount = false; } + }else { isCount = false; } + + + return isCount; + } + catch(exception& e) { + errorOut(e, "MothurOut", "readConsTax"); + exit(1); + } +} /**************************************************************************************************/ vector MothurOut::setFilePosEachLine(string filename, int& num) { try { @@ -4096,6 +4129,75 @@ double MothurOut::sum(vector x) { } } /***********************************************************************/ +int MothurOut::max(vector x) { + try { + int value = 0; + + for (int i = 0; i < x.size(); i++) { + if (control_pressed) { break; } + if (value < x[i]) { value = x[i]; } + } + + return value; + } + catch(exception& e) { + errorOut(e, "MothurOut", "max - int"); + exit(1); + } +} +/***********************************************************************/ +float MothurOut::max(vector x) { + try { + int value = 0; + + for (int i = 0; i < x.size(); i++) { + if (control_pressed) { break; } + if (value < x[i]) { value = x[i]; } + } + + return value; + } + catch(exception& e) { + errorOut(e, "MothurOut", "max - float"); + exit(1); + } +} +/***********************************************************************/ +int MothurOut::min(vector x) { + try { + int value = 1e6; + + for (int i = 0; i < x.size(); i++) { + if (control_pressed) { break; } + if (value > x[i]) { value = x[i]; } + } + + return value; + } + catch(exception& e) { + errorOut(e, "MothurOut", "min - int"); + exit(1); + } +} +/***********************************************************************/ +float MothurOut::min(vector x) { + try { + int value = 1e6; + + for (int i = 0; i < x.size(); i++) { + if (control_pressed) { break; } + if (value > x[i]) { value = x[i]; } + } + + return value; + } + catch(exception& e) { + errorOut(e, "MothurOut", "min - float"); + exit(1); + } +} + +/***********************************************************************/ int MothurOut::factorial(int num){ try { int total = 1; diff --git a/source/mothurout.h b/source/mothurout.h index 04c2c294..e7b1afc3 100644 --- a/source/mothurout.h +++ b/source/mothurout.h @@ -31,6 +31,7 @@ struct logger { /***********************************************/ class OrderVector; class SharedOrderVector; +class RAbundVector; class SharedRAbundVector; class MothurOut { @@ -107,6 +108,7 @@ class MothurOut { string getSimpleName(string); string getRootName(string); bool isBlank(string); + bool isCountFile(string); int openOutputFile(string, ofstream&); int openOutputFileBinary(string, ofstream&); int openOutputFileAppend(string, ofstream&); @@ -216,7 +218,7 @@ class MothurOut { int mothurRandomShuffle(OrderVector&); int mothurRandomShuffle(SharedOrderVector&); int mothurRandomShuffle(vector&); - void setRandomSeed(unsigned s) { mersenne_twister_engine.seed(s); } + void setRandomSeed(unsigned s) { mersenne_twister_engine.seed(s); srand(s); } //math operation @@ -224,6 +226,10 @@ class MothurOut { int min(int, int); double max(vector&); //returns largest value in vector double min(vector&); //returns smallest value in vector + int max(vector); + float max(vector); + int min(vector); + float min(vector); int factorial(int num); vector > binomial(int); float ceilDist(float, int); @@ -234,6 +240,7 @@ class MothurOut { int average(vector); int sum(vector); double sum(vector); + int getRandomIndex(int); //highest int getRandomNumber(); double getRandomDouble0to1(); @@ -246,7 +253,6 @@ class MothurOut { vector< vector > getStandardDeviation(vector< vector< vector > >&, vector< vector >&); vector< vector > getAverages(vector< vector< vector > >&, string); vector< vector > getAverages(vector< vector< vector > >&); - int control_pressed; bool executing, runParse, jumble, gui, mothurCalling, debug, quietMode; diff --git a/source/opticluster.cpp b/source/opticluster.cpp index 0b90d68f..60e75f88 100644 --- a/source/opticluster.cpp +++ b/source/opticluster.cpp @@ -42,7 +42,7 @@ int OptiCluster::initialize(double& value, bool randomize, string initialize) { for (map::iterator it = seqBin.begin(); it != seqBin.end(); it++) { if (it->second == -1) { } else { - long long numCloseSeqs = (matrix->getCloseSeqs(it->first)).size(); //does not include self + long long numCloseSeqs = (matrix->getNumClose(it->first)); //does not include self falseNegatives += numCloseSeqs; } } @@ -64,7 +64,7 @@ int OptiCluster::initialize(double& value, bool randomize, string initialize) { for (map::iterator it = seqBin.begin(); it != seqBin.end(); it++) { if (it->second == -1) { } else { - long long numCloseSeqs = (matrix->getCloseSeqs(it->first)).size(); //does not include self + long long numCloseSeqs = (matrix->getNumClose(it->first)); //does not include self truePositives += numCloseSeqs; } } @@ -72,22 +72,8 @@ int OptiCluster::initialize(double& value, bool randomize, string initialize) { falsePositives = numSeqs * (numSeqs-1)/2 - (trueNegatives + falseNegatives + truePositives); } - value = 0; - if (metric == "mcc") { value = calcMCC(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "sens") { value = calcSens(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "spec") { value = calcSpec(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tptn") { value = calcTPTN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tp") { value = calcTP(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tn") { value = calcTN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fp") { value = calcFP(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fn") { value = calcFN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fpfn") { value = calcFPFN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "f1score") { value = calcF1Score(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "accuracy") { value = calcAccuracy(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "ppv") { value = calcPPV(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "npv") { value = calcNPV(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fdr") { value = calcFDR(truePositives, trueNegatives, falsePositives, falseNegatives); } - + value = metric->getValue(truePositives, trueNegatives, falsePositives, falseNegatives); + return value; } catch(exception& e) { @@ -121,25 +107,19 @@ bool OptiCluster::update(double& listMetric) { long long bestBin, bestTp, bestTn, bestFn, bestFp; tn = trueNegatives; tp = truePositives; fp = falsePositives; fn = falseNegatives; - //this calculation is used to save time in the move and adjust function. - //we don't need to calculate the cost of moving out of our current bin each time we - //test moving into a new bin. Only calc this once per iteration. - long long cCount = 0; long long fCount = 0; - for (int i = 0; i < bins[binNumber].size(); i++) { //how many close sequences are in the old bin? - if (seqNumber == bins[binNumber][i]) {} - else if (!matrix->isClose(seqNumber, bins[binNumber][i])) { fCount++; } - else { cCount++; } - } + //close / far count in current bin + vector results = getCloseFarCounts(seqNumber, binNumber); + long long cCount = results[0]; long long fCount = results[1]; //metric in current bin - bestMetric = calcScoreCurrentBin(tp, tn, fp, fn); bestBin = binNumber; bestTp = tp; bestTn = tn; bestFp = fp; bestFn = fn; + bestMetric = metric->getValue(tp, tn, fp, fn); bestBin = binNumber; bestTp = tp; bestTn = tn; bestFp = fp; bestFn = fn; //if not already singleton, then calc value if singleton was created if (!((bins[binNumber].size()) == 1)) { //make a singleton //move out of old bin fn+=cCount; tn+=fCount; fp-=fCount; tp-=cCount; - double singleMetric = moveAdjustTFValues(binNumber, seqNumber, -1, tp, tn, fp, fn); + double singleMetric = metric->getValue(tp, tn, fp, fn); if (singleMetric > bestMetric) { bestBin = -1; bestTp = tp; bestTn = tn; bestFp = fp; bestFn = fn; bestMetric = singleMetric; @@ -153,9 +133,10 @@ bool OptiCluster::update(double& listMetric) { //merge into each "close" otu for (set::iterator it = binsToTry.begin(); it != binsToTry.end(); it++) { tn = trueNegatives; tp = truePositives; fp = falsePositives; fn = falseNegatives; - fn+=cCount; tn+=fCount; fp-=fCount; tp-=cCount; - double newMetric = moveAdjustTFValues(binNumber, seqNumber, *it, tp, tn, fp, fn); - + fn+=cCount; tn+=fCount; fp-=fCount; tp-=cCount; //move out of old bin + results = getCloseFarCounts(seqNumber, *it); + fn-=results[0]; tn-=results[1]; tp+=results[0]; fp+=results[1]; //move into new bin + double newMetric = metric->getValue(tp, tn, fp, fn); //score when sequence is moved //new best if (newMetric > bestMetric) { bestMetric = newMetric; bestBin = (*it); bestTp = tp; bestTn = tn; bestFp = fp; bestFn = fn; } } @@ -178,20 +159,9 @@ bool OptiCluster::update(double& listMetric) { } } - if (metric == "mcc") { listMetric = calcMCC(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "sens") { listMetric = calcSens(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "spec") { listMetric = calcSpec(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tptn") { listMetric = calcTPTN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tp") { listMetric = calcTP(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "tn") { listMetric = calcTN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fp") { listMetric = calcFP(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fn") { listMetric = calcFN(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "f1score") { listMetric = calcF1Score(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "accuracy") { listMetric = calcAccuracy(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "ppv") { listMetric = calcPPV(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "npv") { listMetric = calcNPV(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fdr") { listMetric = calcFDR(truePositives, trueNegatives, falsePositives, falseNegatives); } - else if (metric == "fpfn") { listMetric = calcFPFN(truePositives, trueNegatives, falsePositives, falseNegatives); } + listMetric = metric->getValue(truePositives, trueNegatives, falsePositives, falseNegatives); + + if (m->debug) { ListVector* list = getList(); list->print(cout); delete list; } return 0; @@ -202,315 +172,28 @@ bool OptiCluster::update(double& listMetric) { } } /***********************************************************************/ -double OptiCluster::moveAdjustTFValues(int bin, int seq, int newBin, long long& tp, long long& tn, long long& fp, long long& fn) { +vector OptiCluster::getCloseFarCounts(int seq, int newBin) { try { - - //making a singleton bin. Close but we are forcing apart. - if (newBin == -1) { - }else { //merging a bin - long long ncCount = 0; long long nfCount = 0; - for (int i = 0; i < bins[newBin].size(); i++) { //how many close sequences are in the old bin? - if (seq == bins[newBin][i]) {} - else if (!matrix->isClose(seq, bins[newBin][i])) { nfCount++; } - else { ncCount++; } + vector results; results.push_back(0); results.push_back(0); + + if (newBin == -1) { } //making a singleton bin. Close but we are forcing apart. + else { //merging a bin + for (int i = 0; i < bins[newBin].size(); i++) { + if (seq == bins[newBin][i]) {} //ignore self + else if (!matrix->isClose(seq, bins[newBin][i])) { results[1]++; } //this sequence is "far away" from sequence i - above the cutoff + else { results[0]++; } //this sequence is "close" to sequence i - distance between them is less than cutoff } - - //move into new bin - fn-=ncCount; tn-=nfCount; tp+=ncCount; fp+=nfCount; - } - - double result = 0.0; - if (metric == "mcc") { - result = calcMCC(tp, tn, fp, fn); - }else if (metric == "sens") { - result = calcSens(tp, tn, fp, fn); - }else if (metric == "spec") { - result = calcSpec(tp, tn, fp, fn); - }else if (metric == "tptn") { - result = calcTPTN(tp, tn, fp, fn); - }else if (metric == "tp") { - result = calcTP(tp, tn, fp, fn); - }else if (metric == "tn") { - result = calcTN(tp, tn, fp, fn); - }else if (metric == "fp") { - result = calcFP(tp, tn, fp, fn); - }else if (metric == "fn") { - result = calcFN(tp, tn, fp, fn); - }else if (metric == "f1score") { - result = calcF1Score(tp, tn, fp, fn); - }else if (metric == "accuracy") { - result = calcAccuracy(tp, tn, fp, fn); - }else if (metric == "ppv") { - result = calcPPV(tp, tn, fp, fn); - }else if (metric == "npv") { - result = calcNPV(tp, tn, fp, fn); - }else if (metric == "fdr") { - result = calcFDR(tp, tn, fp, fn); - }else if (metric == "fpfn") { - result = calcFPFN(tp, tn, fp, fn); - } - - return result; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "moveAdjustTFValues"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcScoreCurrentBin( long long tp, long long tn, long long fp, long long fn) { - try { - - if (metric == "mcc") { - return calcMCC(tp, tn, fp, fn); - }else if (metric == "sens") { - return calcSens(tp, tn, fp, fn); - }else if (metric == "spec") { - return calcSpec(tp, tn, fp, fn); - }else if (metric == "tptn") { - return calcTPTN(tp, tn, fp, fn); - }else if (metric == "tp") { - return calcTP(tp, tn, fp, fn); - }else if (metric == "tn") { - return calcTN(tp, tn, fp, fn); - }else if (metric == "fp") { - return calcFP(tp, tn, fp, fn); - }else if (metric == "fn") { - return calcFN(tp, tn, fp, fn); - }else if (metric == "f1score") { - return calcF1Score(tp, tn, fp, fn); - }else if (metric == "accuracy") { - return calcAccuracy(tp, tn, fp, fn); - }else if (metric == "ppv") { - return calcPPV(tp, tn, fp, fn); - }else if (metric == "npv") { - return calcNPV(tp, tn, fp, fn); - }else if (metric == "fdr") { - return calcFDR(tp, tn, fp, fn); - }else if (metric == "fpfn") { - return calcFPFN(tp, tn, fp, fn); } - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcScoreCurrentBin"); - exit(1); - } -} - -/***********************************************************************/ -double OptiCluster::calcMCC( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = tp + fn; - long long n = fp + tn; - long long pPrime = tp + fp; - long long nPrime = tn + fn; - - double matthewsCorrCoef = ((tp * tn) - (fp * fn)) / (double) sqrt(p * n * pPrime * nPrime); - if(p == 0 || n == 0 || pPrime == 0 || nPrime == 0){ matthewsCorrCoef = 0; } - - return matthewsCorrCoef; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcMCC"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcSens( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = tp + fn; - double sensitivity = tp / (double) p; - - if(p == 0) { sensitivity = 0; } - - return sensitivity; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcSens"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcSpec( long long tp, long long tn, long long fp, long long fn) { - try { - long long n = fp + tn; - double specificity = tn / (double) n; - - if(n == 0) { specificity = 0; } - - return specificity; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcSpec"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcTPTN( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = tp + tn; - - double tptn = p / (double)(tp + tn + fp + fn); - - return tptn; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcTPTN"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcTP( long long tp, long long tn, long long fp, long long fn) { - try { - - double tpmax = tp / (double)(tp + tn + fp + fn); - - return tpmax; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcTP"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcTN( long long tp, long long tn, long long fp, long long fn) { - try { - - double tnmax = tn / (double)(tp + tn + fp + fn); - - return tnmax; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcTN"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcFP( long long tp, long long tn, long long fp, long long fn) { - try { - - double fpmin = fp / (double)(tp + tn + fp + fn); - - return (1.0 - fpmin); - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcFP"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcFN( long long tp, long long tn, long long fp, long long fn) { - try { - - double fnmin = fn / (double)(tp + tn + fp + fn); - return (1.0 - fnmin); + return results; } catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcFN"); + m->errorOut(e, "OptiCluster", "getCloseFarCounts"); exit(1); } } /***********************************************************************/ -double OptiCluster::calcFPFN( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = fp + fn; - - double fpfn = 1.0 - (p / (double)(tp + tn + fp + fn)); //minimize - - return fpfn; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcFPFN"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcF1Score( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = tp + fn; - long long pPrime = tp + fp; - double f1Score = 2.0 * tp / (double) (p + pPrime); - - if(p + pPrime == 0) { f1Score = 0; } - - return f1Score; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcF1Score"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcAccuracy( long long tp, long long tn, long long fp, long long fn) { - try { - - long long p = tp + fn; - long long n = fp + tn; - double accuracy = (tp + tn) / (double) (p + n); - if(p + n == 0) { accuracy = 0; } - return accuracy; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcAccuracy"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcPPV( long long tp, long long tn, long long fp, long long fn) { - try { - - long long pPrime = tp + fp; - double positivePredictiveValue = tp / (double) pPrime; - - if(pPrime == 0) { positivePredictiveValue = 0; } - - return positivePredictiveValue; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcPPV"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcNPV( long long tp, long long tn, long long fp, long long fn) { - try { - - long long nPrime = tn + fn; - double negativePredictiveValue = tn / (double) nPrime; - - if(nPrime == 0) { negativePredictiveValue = 0; } - - return negativePredictiveValue; - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcNPV"); - exit(1); - } -} -/***********************************************************************/ -double OptiCluster::calcFDR( long long tp, long long tn, long long fp, long long fn) { - try { - - long long pPrime = tp + fp; - double falseDiscoveryRate = fp / (double) pPrime; - - if(pPrime == 0) { falseDiscoveryRate = 0; } - - return (1.0-falseDiscoveryRate); - } - catch(exception& e) { - m->errorOut(e, "OptiCluster", "calcFDR"); - exit(1); - } -} -/***********************************************************************/ vector OptiCluster::getStats( long long& tp, long long& tn, long long& fp, long long& fn) { try { long long singletn = matrix->getNumSingletons() + numSingletons; @@ -521,34 +204,16 @@ vector OptiCluster::getStats( long long& tp, long long& tn, long long& fn = falseNegatives; tn = tempnumSeqs * (tempnumSeqs-1)/2 - (falsePositives + falseNegatives + truePositives); //adds singletons to tn - long long p = tp + fn; - long long n = fp + tn; - long long pPrime = tp + fp; - long long nPrime = tn + fn; - - double sensitivity = tp /(double) p; - double specificity = tn / (double)n; - double positivePredictiveValue = tp / (double)pPrime; - double negativePredictiveValue = tn / (double)nPrime; - double falseDiscoveryRate = fp / (double)pPrime; - - double accuracy = (tp + tn) / (double)(p + n); - double matthewsCorrCoef = (tp * tn - fp * fn) / (double) sqrt(p * n * pPrime * nPrime); if(p == 0 || n == 0){ matthewsCorrCoef = 0; } - double f1Score = 2.0 * tp / (double)(p + pPrime); - - - if(p == 0) { sensitivity = 0; matthewsCorrCoef = 0; } - if(n == 0) { specificity = 0; matthewsCorrCoef = 0; } - if(p + n == 0) { accuracy = 0; } - if(p + pPrime == 0) { f1Score = 0; } - if(pPrime == 0) { positivePredictiveValue = 0; falseDiscoveryRate = 0; matthewsCorrCoef = 0; } - if(nPrime == 0) { negativePredictiveValue = 0; matthewsCorrCoef = 0; } - vector results; - //results.push_back(truePositives); results.push_back(tn); results.push_back(falsePositives); results.push_back(falseNegatives); - results.push_back(sensitivity); results.push_back(specificity); results.push_back(positivePredictiveValue); results.push_back(negativePredictiveValue); - results.push_back(falseDiscoveryRate); results.push_back(accuracy); results.push_back(matthewsCorrCoef); results.push_back(f1Score); + Sensitivity sens; double sensitivity = sens.getValue(tp, tn, fp, fn); results.push_back(sensitivity); + Specificity spec; double specificity = spec.getValue(tp, tn, fp, fn); results.push_back(specificity); + PPV ppv; double positivePredictiveValue = ppv.getValue(tp, tn, fp, fn); results.push_back(positivePredictiveValue); + NPV npv; double negativePredictiveValue = npv.getValue(tp, tn, fp, fn); results.push_back(negativePredictiveValue); + FDR fdr; double falseDiscoveryRate = fdr.getValue(tp, tn, fp, fn); results.push_back(falseDiscoveryRate); + Accuracy acc; double accuracy = acc.getValue(tp, tn, fp, fn); results.push_back(accuracy); + MCC mcc; double matthewsCorrCoef = mcc.getValue(tp, tn, fp, fn); results.push_back(matthewsCorrCoef); + F1Score f1; double f1Score = f1.getValue(tp, tn, fp, fn); results.push_back(f1Score); return results; } @@ -613,18 +278,18 @@ long long OptiCluster::getNumBins() { int OptiCluster::findInsert() { try { - //for each sequence (singletons removed on read) + //initially there are bins for each sequence (excluding singletons removed on read) for (int i = 0; i < bins.size(); i++) { if (m->control_pressed) { break; } - if (bins[i].size() == 0) { return i; } + if (bins[i].size() == 0) { return i; } //this bin is empty } return -1; } catch(exception& e) { - m->errorOut(e, "OptiCluster", "getList"); + m->errorOut(e, "OptiCluster", "findInsert"); exit(1); } } diff --git a/source/opticluster.h b/source/opticluster.h index 515406fc..20fb5780 100644 --- a/source/opticluster.h +++ b/source/opticluster.h @@ -11,6 +11,21 @@ #include "cluster.hpp" #include "optimatrix.h" +#include "calculator.h" +#include "mcc.hpp" +#include "sensitivity.hpp" +#include "specificity.hpp" +#include "fdr.hpp" +#include "npv.hpp" +#include "ppv.hpp" +#include "f1score.hpp" +#include "tp.hpp" +#include "fp.hpp" +#include "fpfn.hpp" +#include "tptn.hpp" +#include "tn.hpp" +#include "fn.hpp" +#include "accuracy.hpp" /***********************************************************************/ @@ -21,47 +36,32 @@ class OptiCluster : public Cluster { #ifdef UNIT_TEST friend class TestOptiCluster; OptiCluster() : Cluster() { m = MothurOut::getInstance(); truePositives = 0; trueNegatives = 0; falseNegatives = 0; falsePositives = 0; } //for testing class - void setVariables(OptiMatrix* mt, string met) { matrix = mt; metric = met; } + void setVariables(OptiMatrix* mt, ClusterMetric* met) { matrix = mt; metric = met; } #endif - OptiCluster(OptiMatrix* mt, string met, long long ns) : Cluster() { + OptiCluster(OptiMatrix* mt, ClusterMetric* met, long long ns) : Cluster() { m = MothurOut::getInstance(); matrix = mt; metric = met; truePositives = 0; trueNegatives = 0; falseNegatives = 0; falsePositives = 0; numSingletons = ns; } ~OptiCluster() {} bool updateDistance(PDistCell& colCell, PDistCell& rowCell) { return false; } //inheritance compliant - string getTag() { string tag = "opti_" + metric; return tag; } + string getTag() { string tag = "opti_" + metric->getName(); return tag; } long long getNumBins(); int initialize(double&, bool, string); //randomize and place in "best" OTUs bool update(double&); //returns whether list changed and MCC vector getStats( long long&, long long&, long long&, long long&); ListVector* getList(); -private: +protected: MothurOut* m; map seqBin; //sequence# -> bin# OptiMatrix* matrix; vector randomizeSeqs; vector< vector > bins; //bin[0] -> seqs in bin[0] - string metric; + ClusterMetric* metric; long long truePositives, trueNegatives, falsePositives, falseNegatives, numSeqs, insertLocation, totalPairs, numSingletons; int findInsert(); - double calcMCC(long long, long long, long long, long long); - double calcSens( long long, long long, long long, long long); - double calcSpec( long long, long long, long long, long long); - double calcTPTN( long long, long long, long long, long long); - double calcTP( long long, long long, long long, long long); - double calcTN( long long, long long, long long, long long); - double calcFP( long long, long long, long long, long long); - double calcFN( long long, long long, long long, long long); - double calcFPFN( long long, long long, long long, long long); - double calcF1Score( long long, long long, long long, long long); - double calcAccuracy( long long, long long, long long, long long); - double calcPPV( long long, long long, long long, long long); - double calcNPV( long long, long long, long long, long long); - double calcFDR( long long, long long, long long, long long); - double calcScoreCurrentBin( long long tp, long long tn, long long fp, long long fn); - double moveAdjustTFValues(int bin, int seq, int newBin, long long&, long long&, long long&, long long&); + vector getCloseFarCounts(int seq, int newBin); }; #endif /* defined(__Mothur__opticluster__) */ diff --git a/source/randomnumber.cpp b/source/randomnumber.cpp index fdf52cb2..22986798 100644 --- a/source/randomnumber.cpp +++ b/source/randomnumber.cpp @@ -16,7 +16,7 @@ /**************************************************************************************************/ RandomNumberGenerator::RandomNumberGenerator(){ -// srand( (unsigned)time( NULL ) ); +// m->setRandomSeed( (unsigned)time( NULL ) ); } /**************************************************************************************************/ diff --git a/source/rarefact.cpp b/source/rarefact.cpp index a032db79..49942315 100644 --- a/source/rarefact.cpp +++ b/source/rarefact.cpp @@ -249,18 +249,14 @@ try { displays[i]->init(label); } - if (m->jumble == true) { - //randomize the groups - m->mothurRandomShuffle(lookup); - } + //randomize the groups + if (m->jumble == true) { m->mothurRandomShuffle(lookup); } //make merge the size of lookup[0] - SharedRAbundVector* merge = new SharedRAbundVector(lookup[0]->size()); + SharedRAbundVector* merge = new SharedRAbundVector(lookup[0]->getNumBins()); //make copy of lookup zero - for(int i = 0; isize(); i++) { - merge->set(i, lookup[0]->getAbundance(i), "merge"); - } + for(int i = 0; igetNumBins(); i++) { merge->set(i, lookup[0]->get(i)); } vector subset; //send each group one at a time @@ -299,9 +295,9 @@ try { /**************************************************************************************/ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* shared2) { try{ - for (int k = 0; k < shared1->size(); k++) { + for (int k = 0; k < shared1->getNumBins(); k++) { //merge new species into shared1 - shared1->set(k, (shared1->getAbundance(k) + shared2->getAbundance(k)), "combo"); //set to 'combo' since this vector now contains multiple groups + shared1->set(k, (shared1->get(k) + shared2->get(k))); //set to 'combo' since this vector now contains multiple groups } } catch(exception& e) { diff --git a/source/rarefact.h b/source/rarefact.h index 3497d6fb..57907997 100644 --- a/source/rarefact.h +++ b/source/rarefact.h @@ -27,7 +27,7 @@ class Rarefact { string label; set ends; void mergeVectors(SharedRAbundVector*, SharedRAbundVector*); - vector lookup; + vector lookup; MothurOut* m; int createProcesses(vector&, RarefactionCurveData*, int, int); diff --git a/source/sharedutilities.cpp b/source/sharedutilities.cpp index df75eb26..ea9aaaa2 100644 --- a/source/sharedutilities.cpp +++ b/source/sharedutilities.cpp @@ -8,21 +8,14 @@ */ #include "sharedutilities.h" -#include "sharedrabundvector.h" #include "sharedordervector.h" /**************************************************************************************************/ -void SharedUtil::getSharedVectors(vector Groups, vector& lookup, SharedOrderVector* order) { +SharedRAbundVectors* SharedUtil::getSharedVectors(vector Groups, SharedOrderVector* order) { try { - //delete each sharedrabundvector in lookup - for (int j = 0; j < lookup.size(); j++) { - delete lookup[j]; - } - - lookup.clear(); - + SharedRAbundVectors* lookup = new SharedRAbundVectors(); sort(Groups.begin(), Groups.end()); //create and initialize vector of sharedvectors, one for each group @@ -30,7 +23,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorgetNumBins()); temp->setLabel(order->getLabel()); temp->setGroup(Groups[i]); - lookup.push_back(temp); + lookup->push_back(temp); } int numSeqs = order->size(); @@ -38,17 +31,10 @@ void SharedUtil::getSharedVectors(vector Groups, vectorget(i); - int abundance; - - //set info for sharedvector in chosens group - for (int j = 0; j < lookup.size(); j++) { - if (chosen.group == lookup[j]->getGroup()) { - abundance = lookup[j]->getAbundance(chosen.bin); - lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); - break; - } - } + int abundance = lookup->get(chosen.bin, chosen.group); + lookup->set(chosen.bin, (abundance + 1), chosen.group); } + return lookup; } catch(exception& e) { m->errorOut(e, "SharedUtil", "getSharedVectors"); @@ -56,51 +42,6 @@ void SharedUtil::getSharedVectors(vector Groups, vector Groups, vector& lookup, SharedOrderVector* order) { - try { - - //delete each sharedrabundvector in lookup - for (int j = 0; j < lookup.size(); j++) { - delete lookup[j]; - } - lookup.clear(); - - //create and initialize vector of sharedvectors, one for each group - for (int i = 0; i < Groups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins()); - temp->setLabel(order->getLabel()); - temp->setGroup(Groups[i]); - lookup.push_back(temp); - } - - int numSeqs = order->size(); - - //sample all the members - for(int i=0;igetRandomIndex(i); - individual chosen = order->get(random); - - int abundance; - //set info for sharedvector in chosens group - for (int j = 0; j < lookup.size(); j++) { - if (chosen.group == lookup[j]->getGroup()) { - abundance = lookup[j]->getAbundance(chosen.bin); - lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); - break; - } - } - } - - } - catch(exception& e) { - m->errorOut(e, "SharedUtil", "getSharedVectorswithReplacement"); - exit(1); - } -} - -/**************************************************************************************************/ //need to have mode because different commands require different number of valid groups void SharedUtil::setGroups(vector& userGroups, vector& allGroups) { try { diff --git a/source/sharedutilities.h b/source/sharedutilities.h index df7e8d30..541ee4ad 100644 --- a/source/sharedutilities.h +++ b/source/sharedutilities.h @@ -12,7 +12,7 @@ #include "mothur.h" #include "mothurout.h" -class SharedRAbundVector; +class SharedRAbundVectors; class SharedOrderVector; /**************************************************************************************************/ @@ -22,8 +22,7 @@ class SharedUtil { SharedUtil() { m = MothurOut::getInstance(); } ~SharedUtil() {}; - void getSharedVectors(vector, vector&, SharedOrderVector*); - void getSharedVectorswithReplacement(vector, vector&, SharedOrderVector*); + SharedRAbundVectors* getSharedVectors(vector, SharedOrderVector*); void setGroups(vector&, vector&); //globaldata->Groups, your tree or group map void setGroups(vector&, vector&, string); //globaldata->Groups, your tree or group map, mode void setGroups(vector&, vector&, string&, int&, string); //globaldata->Groups, your tree or group map, allgroups, numGroups, mode diff --git a/source/subsample.cpp b/source/subsample.cpp index 940a4bd8..a4531ea5 100644 --- a/source/subsample.cpp +++ b/source/subsample.cpp @@ -105,51 +105,79 @@ map SubSample::deconvolute(map whole, vector SubSample::getSample(vector& thislookup, int size) { +vector SubSample::getSample(vector& rabunds, int size) { + try { + + //save mothurOut's binLabels to restore for next label + vector saveBinLabels = m->currentSharedBinLabels; + SharedRAbundVectors* newLookup = new SharedRAbundVectors(); + + int numBins = rabunds[0]->getNumBins(); + for (int i = 0; i < rabunds.size(); i++) { + int thisSize = rabunds[i]->getNumSeqs(); + + if (thisSize != size) { + + vector order; + for (int j = 0; j < rabunds[i]->size(); j++) { + int abund = rabunds[i]->get(j); + for(int k=0;kmothurRandomShuffle(order); + + SharedRAbundVector* temp = new SharedRAbundVector(numBins); + temp->setLabel(rabunds[i]->getLabel()); + temp->setGroup(rabunds[i]->getGroup()); + + for (int j = 0; j < size; j++) { + + if (m->control_pressed) { return m->currentSharedBinLabels; } + + int bin = order[j]; + temp->increment(bin); + } + newLookup->push_back(temp); + }else { SharedRAbundVector* temp = new SharedRAbundVector(*rabunds[i]); newLookup->push_back(temp); } + } + + newLookup->eliminateZeroOTUS(); + + for (int i = 0; i < rabunds.size(); i++) { delete rabunds[i]; } rabunds.clear(); + rabunds = newLookup->getSharedRAbundVectors(); + + delete newLookup; + if (m->control_pressed) { return m->currentSharedBinLabels; } + + //save mothurOut's binLabels to restore for next label + vector subsampleBinLabels = m->currentSharedBinLabels; + m->currentSharedBinLabels = saveBinLabels; + + return subsampleBinLabels; + + } + catch(exception& e) { + m->errorOut(e, "SubSample", "getSample-shared"); + exit(1); + } +} +//********************************************************************************************************************** +vector SubSample::getSample(SharedRAbundVectors*& thislookup, int size) { try { - //save mothurOut's binLabels to restore for next label vector saveBinLabels = m->currentSharedBinLabels; + vector rabunds = thislookup->getSharedRAbundVectors(); + + vector subsampleBinLabels = getSample(rabunds, size); + SharedRAbundVectors* newLookup = new SharedRAbundVectors(); - int numBins = thislookup[0]->getNumBins(); - for (int i = 0; i < thislookup.size(); i++) { - int thisSize = thislookup[i]->getNumSeqs(); - - if (thisSize != size) { - - string thisgroup = thislookup[i]->getGroup(); - - OrderVector order = thislookup[i]->getOrderVector(NULL); - - m->mothurRandomShuffle(order); - - SharedRAbundVector* temp = new SharedRAbundVector(numBins); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - - delete thislookup[i]; - thislookup[i] = temp; - - - for (int j = 0; j < size; j++) { - - if (m->control_pressed) { return m->currentSharedBinLabels; } - - int bin = order.get(j); - - int abund = thislookup[i]->getAbundance(bin); - thislookup[i]->set(bin, (abund+1), thisgroup); - } - } - } - - //subsampling may have created some otus with no sequences in them - eliminateZeroOTUS(thislookup); + for (int i = 0; i < rabunds.size(); i++) { newLookup->push_back(rabunds[i]); } + delete thislookup; + thislookup = newLookup; if (m->control_pressed) { return m->currentSharedBinLabels; } //save mothurOut's binLabels to restore for next label - vector subsampleBinLabels = m->currentSharedBinLabels; m->currentSharedBinLabels = saveBinLabels; return subsampleBinLabels; @@ -161,63 +189,6 @@ vector SubSample::getSample(vector& thislookup, int } } //********************************************************************************************************************** -int SubSample::eliminateZeroOTUS(vector& thislookup) { - try { - - vector newLookup; - for (int i = 0; i < thislookup.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(); - temp->setLabel(thislookup[i]->getLabel()); - temp->setGroup(thislookup[i]->getGroup()); - newLookup.push_back(temp); - } - - //for each bin - vector newBinLabels; - string snumBins = toString(thislookup[0]->getNumBins()); - for (int i = 0; i < thislookup[0]->getNumBins(); i++) { - if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } - - //look at each sharedRabund and make sure they are not all zero - bool allZero = true; - for (int j = 0; j < thislookup.size(); j++) { - if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; } - } - - //if they are not all zero add this bin - if (!allZero) { - for (int j = 0; j < thislookup.size(); j++) { - newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); - } - //if there is a bin label use it otherwise make one - string binLabel = "Otu"; - string sbinNumber = toString(i+1); - if (sbinNumber.length() < snumBins.length()) { - int diff = snumBins.length() - sbinNumber.length(); - for (int h = 0; h < diff; h++) { binLabel += "0"; } - } - binLabel += sbinNumber; - if (i < m->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; } - - newBinLabels.push_back(binLabel); - } - } - - for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } - thislookup.clear(); - - thislookup = newLookup; - m->currentSharedBinLabels = newBinLabels; - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "SubSample", "eliminateZeroOTUS"); - exit(1); - } -} -//********************************************************************************************************************** int SubSample::getSample(SAbundVector*& sabund, int size) { try { diff --git a/source/subsample.h b/source/subsample.h index ebb5dc18..9b5ebbfa 100644 --- a/source/subsample.h +++ b/source/subsample.h @@ -10,10 +10,12 @@ // #include "mothurout.h" -#include "sharedrabundvector.h" +#include "rabundvector.hpp" +#include "ordervector.hpp" #include "treemap.h" #include "tree.h" #include "counttable.h" +#include "sharedrabundvectors.hpp" //subsampling overwrites the sharedRabunds. If you need to reuse the original use the getSamplePreserve function. @@ -25,6 +27,7 @@ class SubSample { SubSample() { m = MothurOut::getInstance(); } ~SubSample() {} + vector getSample(SharedRAbundVectors*&, int); //returns the bin labels for the subsample, mothurOuts binlabels are preserved so you can run this multiple times. Overwrites original vector passed in, if you need to preserve it deep copy first. vector getSample(vector&, int); //returns the bin labels for the subsample, mothurOuts binlabels are preserved so you can run this multiple times. Overwrites original vector passed in, if you need to preserve it deep copy first. Tree* getSample(Tree*, CountTable*, CountTable*, int); //creates new subsampled tree. Uses first counttable to fill new counttable with sabsampled seqs. Sets groups of seqs not in subsample to "doNotIncludeMe". int getSample(SAbundVector*&, int); //destroys sabundvector passed in, so copy it if you need it @@ -34,8 +37,7 @@ class SubSample { private: MothurOut* m; - int eliminateZeroOTUS(vector&); - map deconvolute(map wholeSet, vector& subsampleWanted); //returns new nameMap containing only subsampled names, and removes redundants from subsampled wanted because it makes the new nameMap. + map deconvolute(map wholeSet, vector& subsampleWanted); //returns new nameMap containing only subsampled names, and removes redundants from subsampled wanted because it makes the new nameMap. }; diff --git a/source/summary.cpp b/source/summary.cpp new file mode 100644 index 00000000..001c2c38 --- /dev/null +++ b/source/summary.cpp @@ -0,0 +1,1833 @@ +// +// summary.cpp +// Mothur +// +// Created by Sarah Westcott on 3/27/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#include "summary.hpp" + + +//********************************************************************************************************************** +void Summary::processNameCount(string n) { //name or count file to include in counts + try { + nameMap.clear(); nameCountNumUniques = 0; + if (n != "") { + hasNameOrCount = true; + if (m->isCountFile(n)) { + CountTable ct; + ct.readTable(n, false, false); + nameMap = ct.getNameMap(); + type = "count"; + }else { nameMap = m->readNames(n); type = "name"; } + } + nameCountNumUniques = nameMap.size(); + } + catch(exception& e) { + m->errorOut(e, "Summary", "Summary"); + exit(1); + } +} + +//********************************************************************************************************************** +string Summary::addSeq(Sequence seq) { + try { + long long num = 1; + + if (hasNameOrCount) { + //make sure this sequence is in the namefile, else error + itFindName = nameMap.find(seq.getName()); + + if (itFindName == nameMap.end()) { m->mothurOut("[ERROR]: '" + seq.getName() + "' is not in your name or count file, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } + else { num = itFindName->second; } + } + + int thisStartPosition = seq.getStartPos(); + it = startPosition.find(thisStartPosition); + if (it == startPosition.end()) { startPosition[thisStartPosition] = num; } //first finding of this start position, set count. + else { it->second += num; } //add counts + + int thisEndPosition = seq.getEndPos(); + it = endPosition.find(thisEndPosition); + if (it == endPosition.end()) { endPosition[thisEndPosition] = num; } //first finding of this end position, set count. + else { it->second += num; } //add counts + + int thisSeqLength = seq.getNumBases(); + it = seqLength.find(thisSeqLength); + if (it == seqLength.end()) { seqLength[thisSeqLength] = num; } //first finding of this length, set count. + else { it->second += num; } //add counts + + int thisAmbig = seq.getAmbigBases(); + it = ambigBases.find(thisAmbig); + if (it == ambigBases.end()) { ambigBases[thisAmbig] = num; } //first finding of this ambig, set count. + else { it->second += num; } //add counts + + int thisHomoP = seq.getLongHomoPolymer(); + it = longHomoPolymer.find(thisHomoP); + if (it == longHomoPolymer.end()) { longHomoPolymer[thisHomoP] = num; } //first finding of this homop, set count. + else { it->second += num; } //add counts + + int numns = seq.getNumNs(); + it = numNs.find(numns); + if (it == numNs.end()) { numNs[numns] = num; } //first finding of this homop, set count. + else { it->second += num; } //add counts + + numUniques++; + total += num; + + string output = ""; + output += seq.getName() + '\t'; + output += toString(thisStartPosition) + '\t' + toString(thisEndPosition) + '\t'; + output += toString(thisSeqLength) + '\t' + toString(thisAmbig) + '\t'; + output += toString(thisHomoP) + '\t' + toString(num); + + return output; + } + catch(exception& e) { + m->errorOut(e, "Summary", "addSeq - FastaFile"); + exit(1); + } +} +//********************************************************************************************************************** +//string seqInfo = addSeq(name, start, end, length, ambigs, polymer, numReps); +string Summary::addSeq(string name, int start, int end, int length, int ambigs, int polymer, long long numReps) { + try { + + if ((numReps == 1) && hasNameOrCount) { + //make sure this sequence is in the namefile, else error + itFindName = nameMap.find(name); + + if (itFindName == nameMap.end()) { m->mothurOut("[ERROR]: '" + name + "' is not in your name or count file, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } + else { numReps = itFindName->second; } + } + + it = startPosition.find(start); + if (it == startPosition.end()) { startPosition[start] = numReps; } //first finding of this start position, set count. + else { it->second += numReps; } //add counts + + it = endPosition.find(end); + if (it == endPosition.end()) { endPosition[end] = numReps; } //first finding of this end position, set count. + else { it->second += numReps; } //add counts + + it = seqLength.find(length); + if (it == seqLength.end()) { seqLength[length] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + it = ambigBases.find(ambigs); + if (it == ambigBases.end()) { ambigBases[ambigs] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + it = longHomoPolymer.find(polymer); + if (it == longHomoPolymer.end()) { longHomoPolymer[polymer] = numReps; } //first finding of this homop, set count. + else { it->second += numReps; } //add counts + + numUniques++; + total += numReps; + + string output = ""; + output += name + '\t'; + output += toString(start) + '\t' + toString(end) + '\t'; + output += toString(length) + '\t' + toString(ambigs) + '\t'; + output += toString(polymer) + '\t' + toString(numReps); + + return output; + } + catch(exception& e) { + m->errorOut(e, "Summary", "addSeq - FastaSummaryFile"); + exit(1); + } +} +//********************************************************************************************************************** +//string seqInfo = addSeq(name, length, OLength, thisOStart, thisOEnd, numMisMatches, numns); +string Summary::addSeq(string name, int length, int olength, int ostart, int oend, int mismatches, int numns) { + try { + long long numReps = 1; + if (hasNameOrCount) { + //make sure this sequence is in the namefile, else error + itFindName = nameMap.find(name); + + if (itFindName == nameMap.end()) { m->mothurOut("[ERROR]: '" + name + "' is not in your name or count file, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } + else { numReps = itFindName->second; } + } + + it = ostartPosition.find(ostart); + if (it == ostartPosition.end()) { ostartPosition[ostart] = numReps; } //first finding of this start position, set count. + else { it->second += numReps; } //add counts + + it = oendPosition.find(oend); + if (it == oendPosition.end()) { oendPosition[oend] = numReps; } //first finding of this end position, set count. + else { it->second += numReps; } //add counts + + it = oseqLength.find(olength); + if (it == oseqLength.end()) { oseqLength[olength] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + it = seqLength.find(length); + if (it == seqLength.end()) { seqLength[length] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + it = misMatches.find(mismatches); + if (it == misMatches.end()) { misMatches[mismatches] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + it = numNs.find(numns); + if (it == numNs.end()) { numNs[numns] = numReps; } //first finding of this homop, set count. + else { it->second += numReps; } //add counts + + numUniques++; + total += numReps; + + string output = ""; + output += name + '\t'; + output += toString(ostart) + '\t' + toString(oend) + '\t'; + output += toString(length) + '\t' + toString(olength) + '\t'+ toString(mismatches) + '\t'; + output += toString(numns) + '\t' + toString(numReps); + + return output; + } + catch(exception& e) { + m->errorOut(e, "Summary", "addSeq - ContigsSummaryFile"); + exit(1); + } +} +//********************************************************************************************************************** +//string seqInfo = addSeq(name, sim, score, insert); +string Summary::addSeq(string name, int length, float SimBtwnQueryTemplate, float SearchScore, int LongestInserts) { + try { + long long numReps = 1; + if (hasNameOrCount) { + //make sure this sequence is in the namefile, else error + itFindName = nameMap.find(name); + + if (itFindName == nameMap.end()) { m->mothurOut("[ERROR]: '" + name + "' is not in your name or count file, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } + else { numReps = itFindName->second; } + } + + map:: iterator itFloat = sims.find(SimBtwnQueryTemplate); + if (itFloat == sims.end()) { sims[SimBtwnQueryTemplate] = numReps; } //first finding of this similarity score, set count. + else { itFloat->second += numReps; } //add counts + + itFloat = scores.find(SearchScore); + if (itFloat == scores.end()) { scores[SearchScore] = numReps; } //first finding of this end position, set count. + else { itFloat->second += numReps; } //add counts + + it = inserts.find(LongestInserts); + if (it == inserts.end()) { inserts[LongestInserts] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + it = seqLength.find(length); + if (it == seqLength.end()) { seqLength[length] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + numUniques++; + total += numReps; + + string output = ""; + output += name + '\t'; + output += toString(SimBtwnQueryTemplate) + '\t' + toString(SearchScore) + '\t'; + output += toString(LongestInserts) + '\t' + toString(numReps); + + return output; + } + catch(exception& e) { + m->errorOut(e, "Summary", "addSeq - ContigsSummaryFile"); + exit(1); + } +} +//********************************************************************************************************************** +vector Summary::getDefaults() { + try { + vector locations; + + long long ptile0_25 = 1+(long long)(total * 0.025); //number of sequences at 2.5% + long long ptile25 = 1+(long long)(total * 0.250); //number of sequences at 25% + long long ptile50 = 1+(long long)(total * 0.500); + long long ptile75 = 1+(long long)(total * 0.750); + long long ptile97_5 = 1+(long long)(total * 0.975); + long long ptile100 = (long long)(total); + + locations.push_back(1); locations.push_back(ptile0_25); locations.push_back(ptile25); locations.push_back(ptile50); + locations.push_back(ptile75); locations.push_back(ptile97_5); locations.push_back(ptile100); + + return locations; + } + catch(exception& e) { + m->errorOut(e, "Summary", "getDefaults"); + exit(1); + } +} +//********************************************************************************************************************** +vector Summary::getValues(map& positions) { + try { + vector defaults = getDefaults(); + vector results; results.resize(7,0); + long long meanPosition; meanPosition = 0; + long long totalSoFar = 0; + int lastValue = 0; + + //minimum + if ((positions.begin())->first == -1) { results[0] = 0; } + else {results[0] = (positions.begin())->first; } + results[1] = results[0]; results[2] = results[0]; results[3] = results[0]; results[4] = results[0]; results[5] = results[0]; + + for (map::iterator it = positions.begin(); it != positions.end(); it++) { + int value = it->first; if (value == -1) { value = 0; } + meanPosition += (value*it->second); + totalSoFar += it->second; + if (((totalSoFar <= defaults[1]) && (totalSoFar > 1)) || ((lastValue < defaults[1]) && (totalSoFar > defaults[1]))){ results[1] = value; } //save value + if (((totalSoFar <= defaults[2]) && (totalSoFar > defaults[1])) || ((lastValue < defaults[2]) && (totalSoFar > defaults[2]))) { results[2] = value; } //save value + if (((totalSoFar <= defaults[3]) && (totalSoFar > defaults[2])) || ((lastValue < defaults[3]) && (totalSoFar > defaults[3]))) { results[3] = value; } //save value + if (((totalSoFar <= defaults[4]) && (totalSoFar > defaults[3])) || ((lastValue < defaults[4]) && (totalSoFar > defaults[4]))) { results[4] = value; } //save value + if (((totalSoFar <= defaults[5]) && (totalSoFar > defaults[4])) || ((lastValue < defaults[5]) && (totalSoFar > defaults[5]))) { results[5] = value; } //save value + if ((totalSoFar <= defaults[6]) && (totalSoFar > defaults[5])) { results[6] = value; } //save value + lastValue = totalSoFar; + } + results[6] = (positions.rbegin())->first; + + double meansPosition = meanPosition / (double) total; + results.push_back(meansPosition); + + return results; + } + catch(exception& e) { + m->errorOut(e, "Summary", "getValues"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::getValue(map& spots, double value) { + try { + long long percentage = 1+(long long)(total * value * 0.01); + long long result = 0; + long long totalSoFar = 0; + long long lastValue = 0; + + //minimum + if ((spots.begin())->first == -1) { result = 0; } + else {result = (spots.begin())->first; } + + for (it = spots.begin(); it != spots.end(); it++) { + long long value = it->first; if (value == -1) { value = 0; } + totalSoFar += it->second; + + if (((totalSoFar <= percentage) && (totalSoFar > 1)) || ((lastValue < percentage) && (totalSoFar > percentage))){ result = value; } //save value + lastValue = totalSoFar; + } + + return result; + } + catch(exception& e) { + m->errorOut(e, "Summary", "getValue"); + exit(1); + } +} +//********************************************************************************************************************** +vector Summary::getValues(map& positions) { + try { + vector defaults = getDefaults(); + vector results; results.resize(7,0); + long long meanPosition; meanPosition = 0; + long long totalSoFar = 0; + int lastValue = 0; + + //minimum + if ((positions.begin())->first == -1) { results[0] = 0; } + else {results[0] = (positions.begin())->first; } + results[1] = results[0]; results[2] = results[0]; results[3] = results[0]; results[4] = results[0]; results[5] = results[0]; + + for (map::iterator it = positions.begin(); it != positions.end(); it++) { + long long value = it->first; if (value == -1) { value = 0; } + meanPosition += (value*it->second); + totalSoFar += it->second; + if (((totalSoFar <= defaults[1]) && (totalSoFar > 1)) || ((lastValue < defaults[1]) && (totalSoFar > defaults[1]))){ results[1] = value; } //save value + if (((totalSoFar <= defaults[2]) && (totalSoFar > defaults[1])) || ((lastValue < defaults[2]) && (totalSoFar > defaults[2]))) { results[2] = value; } //save value + if (((totalSoFar <= defaults[3]) && (totalSoFar > defaults[2])) || ((lastValue < defaults[3]) && (totalSoFar > defaults[3]))) { results[3] = value; } //save value + if (((totalSoFar <= defaults[4]) && (totalSoFar > defaults[3])) || ((lastValue < defaults[4]) && (totalSoFar > defaults[4]))) { results[4] = value; } //save value + if (((totalSoFar <= defaults[5]) && (totalSoFar > defaults[4])) || ((lastValue < defaults[5]) && (totalSoFar > defaults[5]))) { results[5] = value; } //save value + if ((totalSoFar <= defaults[6]) && (totalSoFar > defaults[5])) { results[6] = value; } //save value + lastValue = totalSoFar; + } + results[6] = (positions.rbegin())->first; + + double meansPosition = meanPosition / (double) total; + results.push_back(meansPosition); + + return results; + } + catch(exception& e) { + m->errorOut(e, "Summary", "getValues"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::getValue(map& positions, double value) { + try { + long long percentage = 1+(long long)(total * value * 0.01); + long long result = 0; + long long totalSoFar = 0; + long long lastValue = 0; + + //minimum + if ((positions.begin())->first == -1) { result = 0; } + else { result = (positions.begin())->first; } + + for (map::iterator it = positions.begin(); it != positions.end(); it++) { + long long value = it->first; if (value == -1) { value = 0; } + totalSoFar += it->second; + + if (((totalSoFar <= percentage) && (totalSoFar > 1)) || ((lastValue < percentage) && (totalSoFar > percentage))){ result = value; } //save value + lastValue = totalSoFar; + } + + return result; + } + catch(exception& e) { + m->errorOut(e, "Summary", "getValue"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::summarizeFasta(string fastafile, string n, string output) { + try { + //fill namemap + processNameCount(n); + return (summarizeFasta(fastafile, output)); + } + catch(exception& e) { + m->errorOut(e, "Summary", "getHomop"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::summarizeFasta(string fastafile, string output) { + try { + long long num = 0; + vector lines; + string p = m->getProcessors(); + int processors = 1; m->mothurConvert(p, processors); + vector positions; +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + positions = m->divideFile(fastafile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } +#else + positions = m->setFilePosFasta(fastafile, num); + if (num < processors) { processors = num; } + + //figure out how many sequences you have to process + int numSeqsPerProcessor = num / processors; + for (int i = 0; i < processors; i++) { + int startIndex = i * numSeqsPerProcessor; + if(i == (processors - 1)){ numSeqsPerProcessor = num - i * numSeqsPerProcessor; } + lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); + } +#endif + + int process = 1; + vector processIDS; + bool recalc = false; + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driverSummarize(fastafile, (output + m->mothurGetpid(process) + ".temp"), lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << startPosition.size() << endl; + for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << endPosition.size() << endl; + for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << ambigBases.size() << endl; + for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << longHomoPolymer.size() << endl; + for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + out << numNs.size() << endl; + for (map::iterator it = numNs.begin(); it != numNs.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + //wait to die + for (int i=0;icontrol_pressed = false; + for (int i=0;imothurRemove((toString(processIDS[i]) + ".num.temp")); + } + recalc = true; + break; + } + } + + if (recalc) { + //test line, also set recalc to true. + //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); + + //redo file divide + lines.clear(); + vector positions = m->divideFile(fastafile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } + + startPosition.clear(); + endPosition.clear(); + seqLength.clear(); + ambigBases.clear(); + longHomoPolymer.clear(); + + num = 0; + processIDS.resize(0); + process = 1; + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + string outputName = output + m->mothurGetpid(process) + ".temp"; + if (output == "") { outputName = ""; } + num = driverSummarize(fastafile, outputName, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << startPosition.size() << endl; + for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << endPosition.size() << endl; + for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << ambigBases.size() << endl; + for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << longHomoPolymer.size() << endl; + for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << numNs.size() << endl; + for (map::iterator it = numNs.begin(); it != numNs.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } + } + } + + //do your part + num = driverSummarize(fastafile, output, lines[0]); + + //force parent to wait until all the processes are done + for (int i=0;iopenInputFile(tempFilename, in); + + long long tempNum; + in >> tempNum; m->gobble(in); num += tempNum; + in >> tempNum; m->gobble(in); total += tempNum; + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = startPosition.find(first); + if (it == startPosition.end()) { startPosition[first] = second; } //first finding of this start position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = endPosition.find(first); + if (it == endPosition.end()) { endPosition[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = seqLength.find(first); + if (it == seqLength.end()) { seqLength[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = ambigBases.find(first); + if (it == ambigBases.end()) { ambigBases[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = longHomoPolymer.find(first); + if (it == longHomoPolymer.end()) { longHomoPolymer[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = numNs.find(first); + if (it == numNs.end()) { numNs[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + + in.close(); + m->mothurRemove(tempFilename); + } + +#else + ////////////////////////////////////////////////////////////////////////////////////////////////////// + //Windows version shared memory, so be careful when passing variables through the seqSumData struct. + //Above fork() will clone, so memory is separate, but that's not the case with windows, + //Taking advantage of shared memory to allow both threads to add info to vectors. + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + vector pDataArray; + DWORD dwThreadIdArray[processors-1]; + HANDLE hThreadArray[processors-1]; + + //Create processor worker threads. + for( int i=0; icount; + total += pDataArray[i]->total; + if (pDataArray[i]->count != pDataArray[i]->end) { + m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; + } + for (map::iterator it = pDataArray[i]->startPosition.begin(); it != pDataArray[i]->startPosition.end(); it++) { + map::iterator itMain = startPosition.find(it->first); + if (itMain == startPosition.end()) { //newValue + startPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->endPosition.begin(); it != pDataArray[i]->endPosition.end(); it++) { + map::iterator itMain = endPosition.find(it->first); + if (itMain == endPosition.end()) { //newValue + endPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->seqLength.begin(); it != pDataArray[i]->seqLength.end(); it++) { + map::iterator itMain = seqLength.find(it->first); + if (itMain == seqLength.end()) { //newValue + seqLength[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->ambigBases.begin(); it != pDataArray[i]->ambigBases.end(); it++) { + map::iterator itMain = ambigBases.find(it->first); + if (itMain == ambigBases.end()) { //newValue + ambigBases[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->longHomoPolymer.begin(); it != pDataArray[i]->longHomoPolymer.end(); it++) { + map::iterator itMain = longHomoPolymer.find(it->first); + if (itMain == longHomoPolymer.end()) { //newValue + longHomoPolymer[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->numNs.begin(); it != pDataArray[i]->numNs.end(); it++) { + map::iterator itMain = numNs.find(it->first); + if (itMain == numNs.end()) { //newValue + numNs[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + CloseHandle(hThreadArray[i]); + delete pDataArray[i]; + } +#endif + //append files + for(int i=0;iappendFiles((output + toString(processIDS[i]) + ".temp"), output); + m->mothurRemove((output + toString(processIDS[i]) + ".temp")); + } + } + + if (hasNameOrCount) { + if (nameCountNumUniques != num) { // do fasta and name/count files match + m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(nameCountNumUniques) + " unique sequences, but your fasta file contains " + toString(num) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true; + } + } + + numUniques = num; + + return num; //number of uniques + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFasta"); + exit(1); + } +} +//********************************************************************************************************************** +int Summary::driverSummarize(string fastafile, string output, linePair lines) { + try { + ofstream out; + if (output != "") { m->openOutputFile(output, out); } + + ifstream in; + m->openInputFile(fastafile, in); + + in.seekg(lines.start); + + //print header if you are process 0 + if (lines.start == 0) { + m->zapGremlins(in); m->gobble(in); + //print header if you are process 0 + if (output != "") { out << "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs" << endl; } + } + + bool done = false; + long long count = 0; + + while (!done) { + + if (m->control_pressed) { in.close(); return 1; } + + Sequence current(in); m->gobble(in); + + if (current.getName() != "") { + + if (m->debug) { m->mothurOut("[DEBUG]: " + current.getName() + "\t" + toString(current.getStartPos()) + "\t" + toString(current.getEndPos()) + "\t" + toString(current.getNumBases()) + "\n"); } + + string seqInfo = addSeq(current); count++; + if (output != "") { out << seqInfo << endl; } + } + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + unsigned long long pos = in.tellg(); + if ((pos == -1) || (pos >= lines.end)) { break; } +#else + if (in.eof()) { break; } +#endif + } + + if (output != "") { out.close(); } + in.close(); + + return count; + } + catch(exception& e) { + m->errorOut(e, "Summary", "driverSummarize"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::summarizeFastaSummary(string summaryfile, string n) { + try { + //fill namemap + processNameCount(n); + return (summarizeFastaSummary(summaryfile)); + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFastaSummary"); + exit(1); + } +} +/**********************************************************************************************************************/ +long long Summary::summarizeFastaSummary(string summaryfile) { + try { + long long num = 0; + vector positions; + vector lines; + string p = m->getProcessors(); + int processors = 1; m->mothurConvert(p, processors); +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } +#else + positions = m->setFilePosFasta(fastafile, num); + if (num < processors) { processors = num; } + + //figure out how many sequences you have to process + int numSeqsPerProcessor = num / processors; + for (int i = 0; i < processors; i++) { + int startIndex = i * numSeqsPerProcessor; + if(i == (processors - 1)){ numSeqsPerProcessor = num - i * numSeqsPerProcessor; } + lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); + } +#endif + + int process = 1; + + vector processIDS; + bool recalc = false; + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driverFastaSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << startPosition.size() << endl; + for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << endPosition.size() << endl; + for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << ambigBases.size() << endl; + for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << longHomoPolymer.size() << endl; + for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + //wait to die + for (int i=0;icontrol_pressed = false; + for (int i=0;imothurRemove((toString(processIDS[i]) + ".num.temp")); + } + recalc = true; + break; + } + } + + if (recalc) { + //test line, also set recalc to true. + //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); + + //redo file divide + lines.clear(); + vector positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } + + startPosition.clear(); + endPosition.clear(); + seqLength.clear(); + ambigBases.clear(); + longHomoPolymer.clear(); + + num = 0; + processIDS.resize(0); + process = 1; + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + + num = driverFastaSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << startPosition.size() << endl; + for (map::iterator it = startPosition.begin(); it != startPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << endPosition.size() << endl; + for (map::iterator it = endPosition.begin(); it != endPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << ambigBases.size() << endl; + for (map::iterator it = ambigBases.begin(); it != ambigBases.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << longHomoPolymer.size() << endl; + for (map::iterator it = longHomoPolymer.begin(); it != longHomoPolymer.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } + } + } + + //do your part + num = driverFastaSummarySummarize(summaryfile, lines[0]); + + //force parent to wait until all the processes are done + for (int i=0;iopenInputFile(tempFilename, in); + + long long tempNum; + in >> tempNum; m->gobble(in); num += tempNum; + in >> tempNum; m->gobble(in); total += tempNum; + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = startPosition.find(first); + if (it == startPosition.end()) { startPosition[first] = second; } //first finding of this start position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = endPosition.find(first); + if (it == endPosition.end()) { endPosition[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = seqLength.find(first); + if (it == seqLength.end()) { seqLength[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = ambigBases.find(first); + if (it == ambigBases.end()) { ambigBases[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = longHomoPolymer.find(first); + if (it == longHomoPolymer.end()) { longHomoPolymer[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + + in.close(); + m->mothurRemove(tempFilename); + } + +#else + ////////////////////////////////////////////////////////////////////////////////////////////////////// + //Windows version shared memory, so be careful when passing variables through the seqSumData struct. + //Above fork() will clone, so memory is separate, but that's not the case with windows, + //Taking advantage of shared memory to allow both threads to add info to vectors. + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + vector pDataArray; + DWORD dwThreadIdArray[processors-1]; + HANDLE hThreadArray[processors-1]; + + //Create processor worker threads. + for( int i=0; icount; + total += pDataArray[i]->total; + if (pDataArray[i]->count != pDataArray[i]->end) { + m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; + } + for (map::iterator it = pDataArray[i]->startPosition.begin(); it != pDataArray[i]->startPosition.end(); it++) { + map::iterator itMain = startPosition.find(it->first); + if (itMain == startPosition.end()) { //newValue + startPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->endPosition.begin(); it != pDataArray[i]->endPosition.end(); it++) { + map::iterator itMain = endPosition.find(it->first); + if (itMain == endPosition.end()) { //newValue + endPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->seqLength.begin(); it != pDataArray[i]->seqLength.end(); it++) { + map::iterator itMain = seqLength.find(it->first); + if (itMain == seqLength.end()) { //newValue + seqLength[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->ambigBases.begin(); it != pDataArray[i]->ambigBases.end(); it++) { + map::iterator itMain = ambigBases.find(it->first); + if (itMain == ambigBases.end()) { //newValue + ambigBases[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->longHomoPolymer.begin(); it != pDataArray[i]->longHomoPolymer.end(); it++) { + map::iterator itMain = longHomoPolymer.find(it->first); + if (itMain == longHomoPolymer.end()) { //newValue + longHomoPolymer[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + CloseHandle(hThreadArray[i]); + delete pDataArray[i]; + } +#endif + + if (hasNameOrCount) { + if (nameCountNumUniques != num) { // do fasta and name/count files match + m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(nameCountNumUniques) + " unique sequences, but your fasta file contains " + toString(num) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true; + } + } + + numUniques = num; + + return num; //number of uniques + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFastaSummary"); + exit(1); + } +} +//********************************************************************************************************************** +int Summary::driverFastaSummarySummarize(string fastafile, linePair lines) { + try { + ifstream in; + m->openInputFile(fastafile, in); + + in.seekg(lines.start); + + //print header if you are process 0 + if (lines.start == 0) { m->zapGremlins(in); m->getline(in); m->gobble(in); } + + bool done = false; + long long count = 0; + string name; + int start, end, length, ambigs, polymer; + long long numReps; + + while (!done) { + + if (m->control_pressed) { in.close(); return 1; } + + //seqname start end nbases ambigs polymer numSeqs + in >> name >> start >> end >> length >> ambigs >> polymer >> numReps; m->gobble(in); + + if (m->debug) { m->mothurOut("[DEBUG]: " + name + "\t" + toString(start) + "\t" + toString(end) + "\t" + toString(length) + "\n"); } + + if (name != "") { addSeq(name, start, end, length, ambigs, polymer, numReps); count++; } + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + unsigned long long pos = in.tellg(); + if ((pos == -1) || (pos >= lines.end)) { break; } +#else + if (in.eof()) { break; } +#endif + } + + in.close(); + + return count; + } + catch(exception& e) { + m->errorOut(e, "Summary", "driverSummarize"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::summarizeContigsSummary(string summaryfile, string n) { + try { + //fill namemap + processNameCount(n); + return (summarizeContigsSummary(summaryfile)); + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFastaSummary"); + exit(1); + } +} +/**********************************************************************************************************************/ +long long Summary::summarizeContigsSummary(string summaryfile) { + try { + long long num = 0; + vector positions; + vector lines; + string p = m->getProcessors(); + int processors = 1; m->mothurConvert(p, processors); +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } +#else + positions = m->setFilePosFasta(fastafile, num); + if (num < processors) { processors = num; } + + //figure out how many sequences you have to process + int numSeqsPerProcessor = num / processors; + for (int i = 0; i < processors; i++) { + int startIndex = i * numSeqsPerProcessor; + if(i == (processors - 1)){ numSeqsPerProcessor = num - i * numSeqsPerProcessor; } + lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); + } +#endif + + int process = 1; + + vector processIDS; + bool recalc = false; + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driverContigsSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << ostartPosition.size() << endl; + for (map::iterator it = ostartPosition.begin(); it != ostartPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << oendPosition.size() << endl; + for (map::iterator it = oendPosition.begin(); it != oendPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << oseqLength.size() << endl; + for (map::iterator it = oseqLength.begin(); it != oseqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << misMatches.size() << endl; + for (map::iterator it = misMatches.begin(); it != misMatches.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << numNs.size() << endl; + for (map::iterator it = numNs.begin(); it != numNs.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + //wait to die + for (int i=0;icontrol_pressed = false; + for (int i=0;imothurRemove((toString(processIDS[i]) + ".num.temp")); + } + recalc = true; + break; + } + } + + if (recalc) { + //test line, also set recalc to true. + //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); + + //redo file divide + lines.clear(); + vector positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } + + ostartPosition.clear(); + oendPosition.clear(); + oseqLength.clear(); + seqLength.clear(); + misMatches.clear(); + numNs.clear(); + + num = 0; + processIDS.resize(0); + process = 1; + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + + num = driverContigsSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << ostartPosition.size() << endl; + for (map::iterator it = ostartPosition.begin(); it != ostartPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << oendPosition.size() << endl; + for (map::iterator it = oendPosition.begin(); it != oendPosition.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << oseqLength.size() << endl; + for (map::iterator it = oseqLength.begin(); it != oseqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << misMatches.size() << endl; + for (map::iterator it = misMatches.begin(); it != misMatches.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << numNs.size() << endl; + for (map::iterator it = numNs.begin(); it != numNs.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } + } + } + + //do your part + num = driverContigsSummarySummarize(summaryfile, lines[0]); + + //force parent to wait until all the processes are done + for (int i=0;iopenInputFile(tempFilename, in); + + long long tempNum; + in >> tempNum; m->gobble(in); num += tempNum; + in >> tempNum; m->gobble(in); total += tempNum; + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = ostartPosition.find(first); + if (it == ostartPosition.end()) { ostartPosition[first] = second; } //first finding of this start position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = oendPosition.find(first); + if (it == oendPosition.end()) { oendPosition[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = oseqLength.find(first); + if (it == oseqLength.end()) { oseqLength[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = seqLength.find(first); + if (it == seqLength.end()) { seqLength[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = misMatches.find(first); + if (it == misMatches.end()) { misMatches[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = numNs.find(first); + if (it == numNs.end()) { numNs[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + + in.close(); + m->mothurRemove(tempFilename); + } + +#else + ////////////////////////////////////////////////////////////////////////////////////////////////////// + //Windows version shared memory, so be careful when passing variables through the seqSumData struct. + //Above fork() will clone, so memory is separate, but that's not the case with windows, + //Taking advantage of shared memory to allow both threads to add info to vectors. + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + vector pDataArray; + DWORD dwThreadIdArray[processors-1]; + HANDLE hThreadArray[processors-1]; + + //Create processor worker threads. + for( int i=0; icount; + total += pDataArray[i]->total; + if (pDataArray[i]->count != pDataArray[i]->end) { + m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; + } + for (map::iterator it = pDataArray[i]->ostartPosition.begin(); it != pDataArray[i]->ostartPosition.end(); it++) { + map::iterator itMain = ostartPosition.find(it->first); + if (itMain == ostartPosition.end()) { //newValue + ostartPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->oendPosition.begin(); it != pDataArray[i]->oendPosition.end(); it++) { + map::iterator itMain = oendPosition.find(it->first); + if (itMain == oendPosition.end()) { //newValue + oendPosition[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->oseqLength.begin(); it != pDataArray[i]->oseqLength.end(); it++) { + map::iterator itMain = oseqLength.find(it->first); + if (itMain == oseqLength.end()) { //newValue + oseqLength[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->seqLength.begin(); it != pDataArray[i]->seqLength.end(); it++) { + map::iterator itMain = seqLength.find(it->first); + if (itMain == seqLength.end()) { //newValue + seqLength[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->misMatches.begin(); it != pDataArray[i]->misMatches.end(); it++) { + map::iterator itMain = misMatches.find(it->first); + if (itMain == misMatches.end()) { //newValue + misMatches[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->numNs.begin(); it != pDataArray[i]->numNs.end(); it++) { + map::iterator itMain = numNs.find(it->first); + if (itMain == numNs.end()) { //newValue + numNs[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + CloseHandle(hThreadArray[i]); + delete pDataArray[i]; + } +#endif + + if (hasNameOrCount) { + if (nameCountNumUniques != num) { // do fasta and name/count files match + m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(nameCountNumUniques) + " unique sequences, but your fasta file contains " + toString(num) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true; + } + } + + numUniques = num; + + return num; //number of uniques + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFastaSummary"); + exit(1); + } +} +//********************************************************************************************************************** +long long Summary::summarizeAlignSummary(string summaryfile, string n) { + try { + //fill namemap + processNameCount(n); + return (summarizeAlignSummary(summaryfile)); + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeFastaSummary"); + exit(1); + } +} +//********************************************************************************************************************** +int Summary::driverContigsSummarySummarize(string fastafile, linePair lines) { + try { + ifstream in; + m->openInputFile(fastafile, in); + + in.seekg(lines.start); + + //print header if you are process 0 + if (lines.start == 0) { m->zapGremlins(in); m->getline(in); m->gobble(in); } + + bool done = false; + long long count = 0; + string name; + int length, OLength, thisOStart, thisOEnd, numMisMatches, numns; //Name Length Overlap_Length Overlap_Start Overlap_End MisMatches Num_Ns + + while (!done) { + + if (m->control_pressed) { in.close(); return 1; } + + //seqname start end nbases ambigs polymer numSeqs + in >> name >> length >> OLength >> thisOStart >> thisOEnd >> numMisMatches >> numns; m->gobble(in); + + if (m->debug) { m->mothurOut("[DEBUG]: " + name + "\t" + toString(thisOStart) + "\t" + toString(thisOEnd) + "\t" + toString(length) + "\n"); } + + if (name != "") { + string seqInfo = addSeq(name, length, OLength, thisOStart, thisOEnd, numMisMatches, numns); count++; + } + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + unsigned long long pos = in.tellg(); + if ((pos == -1) || (pos >= lines.end)) { break; } +#else + if (in.eof()) { break; } +#endif + } + + in.close(); + + return count; + } + catch(exception& e) { + m->errorOut(e, "Summary", "driverContigsSummarySummarize"); + exit(1); + } +} +/**********************************************************************************************************************/ +long long Summary::summarizeAlignSummary(string summaryfile) { + try { + long long num = 0; + vector positions; + vector lines; + string p = m->getProcessors(); + int processors = 1; m->mothurConvert(p, processors); +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } +#else + positions = m->setFilePosFasta(fastafile, num); + if (num < processors) { processors = num; } + + //figure out how many sequences you have to process + int numSeqsPerProcessor = num / processors; + for (int i = 0; i < processors; i++) { + int startIndex = i * numSeqsPerProcessor; + if(i == (processors - 1)){ numSeqsPerProcessor = num - i * numSeqsPerProcessor; } + lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); + } +#endif + + int process = 1; + + vector processIDS; + bool recalc = false; + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + num = driverAlignSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << sims.size() << endl; + for (map::iterator it = sims.begin(); it != sims.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << scores.size() << endl; + for (map::iterator it = scores.begin(); it != scores.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << inserts.size() << endl; + for (map::iterator it = inserts.begin(); it != inserts.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + //wait to die + for (int i=0;icontrol_pressed = false; + for (int i=0;imothurRemove((toString(processIDS[i]) + ".num.temp")); + } + recalc = true; + break; + } + } + + if (recalc) { + //test line, also set recalc to true. + //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;icontrol_pressed = false; for (int i=0;imothurRemove(fastafile + (toString(processIDS[i]) + ".num.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); + + //redo file divide + lines.clear(); + vector positions = m->divideFile(summaryfile, processors); + for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } + + sims.clear(); + scores.clear(); + inserts.clear(); + + num = 0; + processIDS.resize(0); + process = 1; + + //loop through and create all the processes you want + while (process != processors) { + pid_t pid = fork(); + + if (pid > 0) { + processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later + process++; + }else if (pid == 0){ + + num = driverContigsSummarySummarize(summaryfile, lines[process]); + + //pass numSeqs to parent + ofstream out; + string tempFile = m->mothurGetpid(process) + ".num.temp"; + m->openOutputFile(tempFile, out); + + out << num << endl; + out << total << endl; + out << sims.size() << endl; + for (map::iterator it = sims.begin(); it != sims.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << scores.size() << endl; + for (map::iterator it = scores.begin(); it != scores.end(); it++) { out << it->first << '\t' << it->second << endl; } + out << inserts.size() << endl; + for (map::iterator it = inserts.begin(); it != inserts.end(); it++) { out << it->first << '\t' << it->second << endl; } + out.close(); + out << seqLength.size() << endl; + for (map::iterator it = seqLength.begin(); it != seqLength.end(); it++) { out << it->first << '\t' << it->second << endl; } + + exit(0); + }else { + m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); + for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } + exit(0); + } + } + } + + //do your part + num = driverAlignSummarySummarize(summaryfile, lines[0]); + + //force parent to wait until all the processes are done + for (int i=0;iopenInputFile(tempFilename, in); + + long long tempNum; + in >> tempNum; m->gobble(in); num += tempNum; + in >> tempNum; m->gobble(in); total += tempNum; + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + float first; long long second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = sims.find(first); + if (it == sims.end()) { sims[first] = second; } //first finding of this start position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + float first; long long second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = scores.find(first); + if (it == scores.end()) { scores[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = inserts.find(first); + if (it == inserts.end()) { inserts[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in >> tempNum; m->gobble(in); + for (int k = 0; k < tempNum; k++) { + long long first, second; + in >> first; m->gobble(in); in >> second; m->gobble(in); + map::iterator it = seqLength.find(first); + if (it == seqLength.end()) { seqLength[first] = second; } //first finding of this end position, set count. + else { it->second += second; } //add counts + } + m->gobble(in); + in.close(); + m->mothurRemove(tempFilename); + } + +#else + ////////////////////////////////////////////////////////////////////////////////////////////////////// + //Windows version shared memory, so be careful when passing variables through the seqSumData struct. + //Above fork() will clone, so memory is separate, but that's not the case with windows, + //Taking advantage of shared memory to allow both threads to add info to vectors. + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + vector pDataArray; + DWORD dwThreadIdArray[processors-1]; + HANDLE hThreadArray[processors-1]; + + //Create processor worker threads. + for( int i=0; icount; + total += pDataArray[i]->total; + if (pDataArray[i]->count != pDataArray[i]->end) { + m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; + } + for (map::iterator it = pDataArray[i]->sims.begin(); it != pDataArray[i]->sims.end(); it++) { + map::iterator itMain = sims.find(it->first); + if (itMain == sims.end()) { //newValue + sims[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->scores.begin(); it != pDataArray[i]->scores.end(); it++) { + map::iterator itMain = scores.find(it->first); + if (itMain == scores.end()) { //newValue + scores[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->inserts.begin(); it != pDataArray[i]->inserts.end(); it++) { + map::iterator itMain = inserts.find(it->first); + if (itMain == inserts.end()) { //newValue + inserts[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + for (map::iterator it = pDataArray[i]->seqLength.begin(); it != pDataArray[i]->seqLength.end(); it++) { + map::iterator itMain = seqLength.find(it->first); + if (itMain == seqLength.end()) { //newValue + seqLength[it->first] = it->second; + }else { itMain->second += it->second; } //merge counts + } + CloseHandle(hThreadArray[i]); + delete pDataArray[i]; + } +#endif + + if (hasNameOrCount) { + if (nameCountNumUniques != num) { // do fasta and name/count files match + m->mothurOut("[ERROR]: Your " + type + " file contains " + toString(nameCountNumUniques) + " unique sequences, but your fasta file contains " + toString(num) + ". File mismatch detected, quitting command.\n"); m->control_pressed = true; + } + } + + numUniques = num; + + return num; //number of uniques + } + catch(exception& e) { + m->errorOut(e, "Summary", "summarizeAlignSummary"); + exit(1); + } +} +//********************************************************************************************************************** +int Summary::driverAlignSummarySummarize(string alignfile, linePair lines) { + try { + ifstream in; + m->openInputFile(alignfile, in); + + in.seekg(lines.start); + + //print header if you are process 0 + if (lines.start == 0) { m->zapGremlins(in); m->getline(in); m->gobble(in); } + + bool done = false; + long long count = 0; + string name, TemplateName, SearchMethod, AlignmentMethod; + int length, TemplateLength, QueryStart, QueryEnd, TemplateStart, TemplateEnd, PairwiseAlignmentLength, GapsInQuery, GapsInTemplate, LongestInsert; + float SearchScore, SimBtwnQueryTemplate; //QueryName QueryLength TemplateName TemplateLength SearchMethod SearchScore AlignmentMethod QueryStart QueryEnd TemplateStart TemplateEnd PairwiseAlignmentLength GapsInQuery GapsInTemplate LongestInsert SimBtwnQuery&Template + //checking for minScore, maxInsert, minSim + + while (!done) { + + if (m->control_pressed) { in.close(); return 1; } + + in >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; m->gobble(in); + + + if (m->debug) { m->mothurOut("[DEBUG]: " + name + "\t" + toString(TemplateName) + "\t" + toString(SearchScore) + "\t" + toString(length) + "\n"); } + + if (name != "") { + string seqInfo = addSeq(name, length, SimBtwnQueryTemplate, SearchScore, LongestInsert); count++; + } + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) + unsigned long long pos = in.tellg(); + if ((pos == -1) || (pos >= lines.end)) { break; } +#else + if (in.eof()) { break; } +#endif + } + + in.close(); + + return count; + } + catch(exception& e) { + m->errorOut(e, "Summary", "driverAlignSummarySummarize"); + exit(1); + } +} +//********************************************************************************************************************** + + + + + + + diff --git a/source/summary.hpp b/source/summary.hpp new file mode 100644 index 00000000..db4f7d89 --- /dev/null +++ b/source/summary.hpp @@ -0,0 +1,487 @@ +// +// summary.hpp +// Mothur +// +// Created by Sarah Westcott on 3/27/17. +// Copyright © 2017 Schloss Lab. All rights reserved. +// + +#ifndef summary_hpp +#define summary_hpp + +#include "mothurout.h" +#include "sequence.hpp" +#include "counttable.h" + +class Summary { + +public: + +#ifdef UNIT_TEST + friend class TestSummary; +#endif + + Summary() { m = MothurOut::getInstance(); total = 0; numUniques = 0; hasNameOrCount = false; nameCountNumUniques = 0; type = "count"; } + ~Summary() {} + + long long summarizeFasta(string f, string n, string o); //provide fasta file to summarize (paralellized) and optional nameorCountfile and optional outputfile for individual seqs info. To skip nameCount or output file, n="" and / or o="" + long long summarizeFasta(string f, string o); //provide fasta file to summarize (paralellized) and optional outputfile for individual seqs info. To skip output file, o="" + long long summarizeFastaSummary(string f); //provide summary of fasta file to summarize (paralellized) + long long summarizeFastaSummary(string f, string n); //provide summary of fasta file and name or count file to summarize (paralellized) + long long summarizeContigsSummary(string f); //provide summary of contigs summary file to summarize (paralellized) + long long summarizeContigsSummary(string f, string n); //provide summary of contigs summary file and name or count file to summarize (paralellized) + long long summarizeAlignSummary(string f); //provide summary of contigs summary file to summarize (paralellized) + long long summarizeAlignSummary(string f, string n); //provide summary of contigs summary file and name or count file to summarize (paralellized) + + vector getDefaults(); + //fasta and summary + vector getStart() { return (getValues(startPosition)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getStart(double value) { return (getValue(startPosition, value)); } //2.5 = 2.5% of sequences of sequences start before, 25 = location 25% of sequences start before + vector getEnd() { return (getValues(endPosition)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getEnd(double value) { return (getValue(endPosition, value)); } //2.5 = 2.5% of sequences of sequences end after, 25 = location 25% of sequences end after + vector getAmbig() { return (getValues(ambigBases)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getAmbig(double value) { return (getValue(ambigBases, value)); } //25 = max abigous bases 25% of sequences contain + vector getLength() { return (getValues(seqLength)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getLength(double value) { return (getValue(seqLength, value)); } // 25 = min length of 25% of sequences + vector getHomop() { return (getValues(longHomoPolymer)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getHomop(double value) { return (getValue(longHomoPolymer, value)); } + + //contigs + vector getOStart() { return (getValues(ostartPosition)); } //contigs overlap start - returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getOStart(double value) { return (getValue(ostartPosition, value)); } //contigs overlap start - 2.5 = 2.5% of sequences of sequences start before, 25 = location 25% of sequences start before + vector getOEnd() { return (getValues(oendPosition)); } //contigs overlap end -returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getOEnd(double value) { return (getValue(oendPosition, value)); } //contigs overlap end -2.5 = 2.5% of sequences of sequences end after, 25 = location 25% of sequences end after + vector getOLength() { return (getValues(oseqLength)); } //contigs overlap length - returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getOLength(double value) { return (getValue(oseqLength, value)); } //contigs overlap length - 25 = min length of 25% of sequences + vector getMisMatches() { return (getValues(misMatches)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getMisMatches(double value) { return (getValue(misMatches, value)); } + vector getNumNs() { return (getValues(numNs)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getNumNs(double value) { return (getValue(numNs, value)); } //25 = max abigous bases 25% of sequences contain + vector getSims() { return (getValues(sims)); } //contigs overlap length - returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getSims(double value) { return (getValue(sims, value)); } //contigs overlap length - 25 = min length of 25% of sequences + vector getScores() { return (getValues(scores)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getScores(double value) { return (getValue(scores, value)); } + vector getNumInserts() { return (getValues(inserts)); } //returns vector of 8 locations. (min, 2.5, 25, 50, 75, 97.5, max, mean) + long long getNumInserts(double value) { return (getValue(inserts, value)); } //25 = max abigous bases 25% of sequences contain + + + long long getTotalSeqs() { return total; } + long long getUniqueSeqs() { return numUniques; } + +private: + + MothurOut* m; + long long total, numUniques, nameCountNumUniques; + bool hasNameOrCount; + string type; + map startPosition; + map endPosition; + map seqLength; + map ambigBases; + map longHomoPolymer; + map ostartPosition; + map oendPosition; + map oseqLength; + map misMatches; + map numNs; + map sims; + map scores; + map inserts; + + map nameMap; + map::iterator itFindName; + map::iterator it; + + string addSeq(Sequence); //return summary output line + string addSeq(string name, int length, int olength, int ostart, int oend, int mismatches, int numns); + string addSeq(string name, int start, int end, int length, int ambigs, int polymer, long long numReps); + string addSeq(string name, int length, float SimBtwnQueryTemplate, float SearchScore, int LongestInsert); + int driverSummarize(string, string, linePair lines); //fastafile, outputfile (optional set to "" to ignore), file positions + void processNameCount(string n); //determines whether name or count and fills nameMap, ignored if n = "" + int driverFastaSummarySummarize(string, linePair lines); //summaryfile, file positions + int driverContigsSummarySummarize(string, linePair lines); //summaryfile, file positions + int driverAlignSummarySummarize(string, linePair lines); //summaryfile, file positions + vector getValues(map& positions); + long long getValue(map& positions, double); + vector getValues(map& positions); + long long getValue(map& positions, double); + + + +}; +/**************************************************************************************************/ +//custom data structure for threads to use. +// This is passed by void pointer so it can be any data type +// that can be passed using a single void pointer (LPVOID). +struct seqSumData { + map startPosition; + map endPosition; + map seqLength; + map ambigBases; + map longHomoPolymer; + map ostartPosition; + map oendPosition; + map oseqLength; + map misMatches; + map numNs; + map sims; + map scores; + map inserts; + + + string filename, summaryFile, contigsfile; + unsigned long long start; + unsigned long long end; + long long count; + long long total; + MothurOut* m; + bool hasNameMap; + map nameMap; + + + seqSumData(){} + //FastaSummarize + seqSumData(string f, string sum, MothurOut* mout, unsigned long long st, unsigned long long en, bool na, map nam) { + filename = f; + m = mout; + start = st; + end = en; + hasNameMap = na; + nameMap = nam; + count = 0; + summaryFile = sum; + } + + //FastaSummarySummarize + seqSumData(string f, MothurOut* mout, unsigned long long st, unsigned long long en, bool na, map nam) { + filename = f; + m = mout; + start = st; + end = en; + hasNameMap = na; + nameMap = nam; + count = 0; + } +}; + +/**************************************************************************************************/ +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) +#else +static DWORD WINAPI MySeqSumThreadFunction(LPVOID lpParam){ + seqSumData* pDataArray; + pDataArray = (seqSumData*)lpParam; + + try { + ofstream out; + if (pDataArray->summaryFile != "") { pDataArray->m->openOutputFile(pDataArray->summaryFile, out); } + + ifstream in; + pDataArray->m->openInputFile(pDataArray->filename, in); + + //print header if you are process 0 + if ((pDataArray->start == 0) || (pDataArray->start == 1)) { + in.seekg(0); + pDataArray->m->zapGremlins(in); + out << "seqname\tstart\tend\tnbases\tambigs\tpolymer\tnumSeqs" << endl; + }else { //this accounts for the difference in line endings. + in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); + } + + for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process + + if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } + + Sequence current(in); pDataArray->m->gobble(in); + + if (current.getName() != "") { + + long long num = 1; + if (pDataArray->hasNameMap){ + //make sure this sequence is in the namefile, else error + map::iterator it = pDataArray->nameMap.find(current.getName()); + + if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + current.getName() + " is not in your name or count file, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + else { num = it->second; } + } + + int thisStartPosition = current.getStartPos(); + map::iterator it = pDataArray->startPosition.find(thisStartPosition); + if (it == pDataArray->startPosition.end()) { pDataArray->startPosition[thisStartPosition] = num; } //first finding of this start position, set count. + else { it->second += num; } //add counts + + int thisEndPosition = current.getEndPos(); + it = pDataArray->endPosition.find(thisEndPosition); + if (it == pDataArray->endPosition.end()) { pDataArray->endPosition[thisEndPosition] = num; } //first finding of this end position, set count. + else { it->second += num; } //add counts + + int thisSeqLength = current.getNumBases(); + it = pDataArray->seqLength.find(thisSeqLength); + if (it == pDataArray->seqLength.end()) { pDataArray->seqLength[thisSeqLength] = num; } //first finding of this length, set count. + else { it->second += num; } //add counts + + int thisAmbig = current.getAmbigBases(); + it = pDataArray->ambigBases.find(thisAmbig); + if (it == pDataArray->ambigBases.end()) { pDataArray->ambigBases[thisAmbig] = num; } //first finding of this ambig, set count. + else { it->second += num; } //add counts + + int thisHomoP = current.getLongHomoPolymer(); + it = pDataArray->longHomoPolymer.find(thisHomoP); + if (it == pDataArray->longHomoPolymer.end()) { pDataArray->longHomoPolymer[thisHomoP] = num; } //first finding of this homop, set count. + else { it->second += num; } //add counts + + int thisNumNs = current.getNumNs(); + it = pDataArray->numNs.find(thisNumNs); + if (it == pDataArray->numNs.end()) { pDataArray->numNs[thisNumNs] = num; } //first finding of this homop, set count. + else { it->second += num; } //add counts + + pDataArray->count++; + + string output = ""; + output += current.getName() + '\t'; + output += toString(thisStartPosition) + '\t' + toString(thisEndPosition) + '\t'; + output += toString(thisSeqLength) + '\t' + toString(thisAmbig) + '\t'; + output += toString(thisHomoP) + '\t' + toString(num); + + if (pDataArray->summaryFile != "") { out << output << endl; } + } + } + + if (pDataArray->summaryFile != "") { out.close(); } + in.close(); + + return 0; + + } + catch(exception& e) { + pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqSumThreadFunction"); + exit(1); + } +} +/**************************************************************************************************/ + +static DWORD WINAPI MySeqFastaSumThreadFunction(LPVOID lpParam){ + seqSumData* pDataArray; + pDataArray = (seqSumData*)lpParam; + + try { + ifstream in; + pDataArray->m->openInputFile(pDataArray->summaryFile, in); + + //print header if you are process 0 + if ((pDataArray->start == 0) || (pDataArray->start == 1)) { + in.seekg(0); + pDataArray->m->zapGremlins(in); + }else { //this accounts for the difference in line endings. + in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); + } + + string name; + int start, end, length, ambigs, polymer, numReps; + + for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process + + if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } + + //seqname start end nbases ambigs polymer numSeqs + in >> name >> start >> end >> length >> ambigs >> polymer >> numReps; pDataArray->m->gobble(in); + + if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: " + name + "\t" + toString(start) + "\t" + toString(end) + "\t" + toString(length) + "\n"); } + + if (name != "") { + + if ((numReps == 1) && pDataArray->hasNameMap){ + //make sure this sequence is in the namefile, else error + map::iterator it = pDataArray->nameMap.find(name); + + if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + name + " is not in your name or count file, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + else { numReps = it->second; } + } + + map::iterator it = pDataArray->startPosition.find(start); + if (it == pDataArray->startPosition.end()) { pDataArray->startPosition[start] = numReps; } //first finding of this start position, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->endPosition.find(end); + if (it == pDataArray->endPosition.end()) { pDataArray->endPosition[end] = numReps; } //first finding of this end position, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->seqLength.find(length); + if (it == pDataArray->seqLength.end()) { pDataArray->seqLength[length] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts +; + it = pDataArray->ambigBases.find(ambigs); + if (it == pDataArray->ambigBases.end()) { pDataArray->ambigBases[ambigs] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->longHomoPolymer.find(polymer); + if (it == pDataArray->longHomoPolymer.end()) { pDataArray->longHomoPolymer[polymer] = numReps; } //first finding of this homop, set count. + else { it->second += numReps; } //add counts + + pDataArray->count++; + } + } + in.close(); + + return 0; + + } + catch(exception& e) { + pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqFastaSumThreadFunction"); + exit(1); + } +} +/**************************************************************************************************/ +static DWORD WINAPI MySeqContigsSumThreadFunction(LPVOID lpParam){ + seqSumData* pDataArray; + pDataArray = (seqSumData*)lpParam; + + try { + ifstream in; + pDataArray->m->openInputFile(pDataArray->filename, in); + + //print header if you are process 0 + if ((pDataArray->start == 0) || (pDataArray->start == 1)) { + in.seekg(0); + pDataArray->m->zapGremlins(in); pDataArray->m->gobble(in); + pDataArray->m->getline(in); pDataArray->m->gobble(in); + }else { //this accounts for the difference in line endings. + in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); + } + + string name; + int length, OLength, thisOStart, thisOEnd, numMisMatches, numns, numReps; //Name Length Overlap_Length Overlap_Start Overlap_End MisMatches Num_Ns + + + for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process + + if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } + + //seqname start end nbases ambigs polymer numSeqs + in >> name >> length >> OLength >> thisOStart >> thisOEnd >> numMisMatches >> numns; pDataArray->m->gobble(in); + + if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: " + name + "\t" + toString(thisOStart) + "\t" + toString(thisOEnd) + "\t" + toString(OLength) + "\n"); } + + numReps = 1; + if (name != "") { + if (pDataArray->hasNameMap){ + //make sure this sequence is in the namefile, else error + map::iterator it = pDataArray->nameMap.find(name); + + if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + name + " is not in your name or count file, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + else { numReps = it->second; } + } + + map::iterator it = pDataArray->ostartPosition.find(thisOStart); + if (it == pDataArray->ostartPosition.end()) { pDataArray->ostartPosition[thisOStart] = numReps; } //first finding of this start position, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->oendPosition.find(thisOEnd); + if (it == pDataArray->oendPosition.end()) { pDataArray->oendPosition[thisOEnd] = numReps; } //first finding of this end position, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->seqLength.find(length); + if (it == pDataArray->seqLength.end()) { pDataArray->seqLength[length] = numReps; } //first finding of this length, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->oseqLength.find(OLength); + if (it == pDataArray->oseqLength.end()) { pDataArray->oseqLength[OLength] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->misMatches.find(numMisMatches); + if (it == pDataArray->misMatches.end()) { pDataArray->misMatches[numMisMatches] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + it = pDataArray->numNs.find(numns); + if (it == pDataArray->numNs.end()) { pDataArray->numNs[numns] = numReps; } //first finding of this homop, set count. + else { it->second += numReps; } //add counts + + pDataArray->count++; + } + } + in.close(); + + return 0; + + } + catch(exception& e) { + pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqContigsSumThreadFunction"); + exit(1); + } +} +/**************************************************************************************************/ +static DWORD WINAPI MySeqAlignSumThreadFunction(LPVOID lpParam){ + seqSumData* pDataArray; + pDataArray = (seqSumData*)lpParam; + + try { + ifstream in; + pDataArray->m->openInputFile(pDataArray->filename, in); + + //print header if you are process 0 + if ((pDataArray->start == 0) || (pDataArray->start == 1)) { + in.seekg(0); + pDataArray->m->zapGremlins(in); pDataArray->m->gobble(in); + pDataArray->m->getline(in); pDataArray->m->gobble(in); + }else { //this accounts for the difference in line endings. + in.seekg(pDataArray->start-1); pDataArray->m->gobble(in); + } + + string name, TemplateName, SearchMethod, AlignmentMethod; + int length, TemplateLength, QueryStart, QueryEnd, TemplateStart, TemplateEnd, PairwiseAlignmentLength, GapsInQuery, GapsInTemplate, LongestInsert, numReps; + float SearchScore, SimBtwnQueryTemplate; //QueryName QueryLength TemplateName TemplateLength SearchMethod SearchScore AlignmentMethod QueryStart QueryEnd TemplateStart TemplateEnd PairwiseAlignmentLength GapsInQuery GapsInTemplate LongestInsert SimBtwnQuery&Template + //checking for minScore, maxInsert, minSim + + for(int i = 0; i < pDataArray->end; i++){ //end is the number of sequences to process + + if (pDataArray->m->control_pressed) { in.close(); pDataArray->count = 1; return 1; } + + in >> name >> length >> TemplateName >> TemplateLength >> SearchMethod >> SearchScore >> AlignmentMethod >> QueryStart >> QueryEnd >> TemplateStart >> TemplateEnd >> PairwiseAlignmentLength >> GapsInQuery >> GapsInTemplate >> LongestInsert >> SimBtwnQueryTemplate; pDataArray->m->gobble(in); + + if (pDataArray->m->debug) { pDataArray->m->mothurOut("[DEBUG]: " + name + "\t" + toString(length) + "\t" + toString(SearchScore) + "\t" + toString(SimBtwnQueryTemplate) + "\n"); } + + numReps = 1; + if (name != "") { + if (pDataArray->hasNameMap){ + //make sure this sequence is in the namefile, else error + map::iterator it = pDataArray->nameMap.find(name); + + if (it == pDataArray->nameMap.end()) { pDataArray->m->mothurOut("[ERROR]: " + name + " is not in your name or count file, please correct."); pDataArray->m->mothurOutEndLine(); pDataArray->m->control_pressed = true; } + else { numReps = it->second; } + } + + map::iterator it = pDataArray->seqLength.find(length); + if (it == pDataArray->seqLength.end()) { pDataArray->seqLength[length] = numReps; } //first finding of this start position, set count. + else { it->second += numReps; } //add counts + + map::iterator itFloat = pDataArray->sims.find(SimBtwnQueryTemplate); + if (itFloat == pDataArray->sims.end()) { pDataArray->sims[SimBtwnQueryTemplate] = numReps; } //first finding of this end position, set count. + else { itFloat->second += numReps; } //add counts + + itFloat = pDataArray->scores.find(SearchScore); + if (itFloat == pDataArray->scores.end()) { pDataArray->scores[SearchScore] = numReps; } //first finding of this length, set count. + else { itFloat->second += numReps; } //add counts + + it = pDataArray->inserts.find(LongestInsert); + if (it == pDataArray->inserts.end()) { pDataArray->inserts[LongestInsert] = numReps; } //first finding of this ambig, set count. + else { it->second += numReps; } //add counts + + pDataArray->count++; + } + } + in.close(); + + return 0; + + } + catch(exception& e) { + pDataArray->m->errorOut(e, "SeqSummaryCommand", "MySeqAlignSumThreadFunction"); + exit(1); + } +} +/**************************************************************************************************/ + +#endif + + + +#endif /* summary_hpp */ diff --git a/source/trimoligos.cpp b/source/trimoligos.cpp index 64096a3b..ecb78ec7 100644 --- a/source/trimoligos.cpp +++ b/source/trimoligos.cpp @@ -11,12 +11,44 @@ #include "alignment.hpp" #include "needlemanoverlap.hpp" - /********************************************************************/ //strip, pdiffs, bdiffs, primers, barcodes, revPrimers +TrimOligos::TrimOligos(int p, int b, int l, int s, map pr, map br, bool hi){ + try { + m = MothurOut::getInstance(); + preProcess(p,b,l,s,pr,br,hi); + } + catch(exception& e) { + m->errorOut(e, "TrimOligos", "TrimOligos"); + exit(1); + } +} +/********************************************************************/ +TrimOligos::TrimOligos(int p, int rd, int b, map pr, map br, vector r){ + try { + m = MothurOut::getInstance(); + int l = 0; int s = 0; vector lk, sp; + preProcess(p,b,l,s,rd,pr,br,r,lk,sp); + } + catch(exception& e) { + m->errorOut(e, "TrimOligos", "TrimOligos"); + exit(1); + } +} +/********************************************************************/ TrimOligos::TrimOligos(int p, int b, int l, int s, map pr, map br, vector r, vector lk, vector sp){ try { m = MothurOut::getInstance(); + preProcess(p,b,l,s,0,pr,br,r,lk,sp); + } + catch(exception& e) { + m->errorOut(e, "TrimOligos", "TrimOligos"); + exit(1); + } +} +/********************************************************************/ +int TrimOligos::preProcess(int p, int b, int l, int s, int rd, map pr, map br, vector r, vector lk, vector sp){ + try { paired = false; hasIndex = false; @@ -24,7 +56,7 @@ TrimOligos::TrimOligos(int p, int b, int l, int s, map pr, map pr, maperrorOut(e, "TrimOligos", "TrimOligos"); + m->errorOut(e, "TrimOligos", "preProcess"); exit(1); } } /********************************************************************/ //strip, pdiffs, bdiffs, primers, barcodes, revPrimers -TrimOligos::TrimOligos(int p, int b, int l, int s, map pr, map br, bool hi){ +int TrimOligos::preProcess(int p, int b, int l, int s, map pr, map br, bool hi){ try { - m = MothurOut::getInstance(); - pdiffs = p; bdiffs = b; ldiffs = l; @@ -132,53 +164,14 @@ TrimOligos::TrimOligos(int p, int b, int l, int s, map pr, map< ipbarcodes = br; ipprimers = pr; + + return 0; } catch(exception& e) { - m->errorOut(e, "TrimOligos", "TrimOligos"); - exit(1); - } -} -/********************************************************************/ -//strip, pdiffs, bdiffs, primers, barcodes, revPrimers -TrimOligos::TrimOligos(int p, int rd, int b, map pr, map br, vector r){ - try { - m = MothurOut::getInstance(); - - pdiffs = p; - bdiffs = b; - rdiffs = rd; - - barcodes = br; - primers = pr; - revPrimer = r; - paired = false; - hasIndex = false; - - maxFBarcodeLength = 0; - for(map::iterator it=barcodes.begin();it!=barcodes.end();it++){ - string oligo = it->first; - if(oligo.length() > maxFBarcodeLength){ - maxFBarcodeLength = oligo.length(); - } - } - maxRBarcodeLength = maxFBarcodeLength; - - maxFPrimerLength = 0; - for(map::iterator it=primers.begin();it!=primers.end();it++){ - string oligo = it->first; - if(oligo.length() > maxFPrimerLength){ - maxFPrimerLength = oligo.length(); - } - } - maxRPrimerLength = maxFPrimerLength; - } - catch(exception& e) { - m->errorOut(e, "TrimOligos", "TrimOligos"); + m->errorOut(e, "TrimOligos", "preProcess"); exit(1); } } -/********************************************************************/ -TrimOligos::~TrimOligos() {} //********************************************************************/ vector TrimOligos::findForward(Sequence& seq, int& primerStart, int& primerEnd){ try { diff --git a/source/trimoligos.h b/source/trimoligos.h index 78b6f1f3..14f3d171 100644 --- a/source/trimoligos.h +++ b/source/trimoligos.h @@ -10,7 +10,6 @@ * */ -#include "mothur.h" #include "mothurout.h" #include "sequence.hpp" #include "qualityscores.h" @@ -20,15 +19,14 @@ class TrimOligos { #ifdef UNIT_TEST friend class TestTrimOligos; - TrimOligos() {}; - //add set variables function when completeing unit tests for this class + TrimOligos() { m = MothurOut::getInstance(); } #endif public: TrimOligos(int,int,int, map, map, vector); //pdiffs, bdiffs, primers, barcodes, revPrimers TrimOligos(int,int, int, int, map, map, vector, vector, vector); //pdiffs, bdiffs, ldiffs, sdiffs, primers, barcodes, revPrimers, linker, spacer TrimOligos(int,int, int, int, map, map, bool); //pdiffs, bdiffs, ldiffs, sdiffs, primers, barcodes, hasIndex - ~TrimOligos(); + ~TrimOligos(){} //codes : 10 means sequence shorter than barcode, 100 means multiple matches, 1e6 no matches, 0 found match. @@ -60,7 +58,7 @@ class TrimOligos { string reverseOligo(string); string getCodeValue(int, int); - private: + protected: int pdiffs, bdiffs, ldiffs, sdiffs, rdiffs; bool paired, hasIndex; @@ -87,6 +85,9 @@ class TrimOligos { vector stripPairedPrimers(Sequence& seq, QualityScores& qual, int& group, bool); vector stripPairedBarcode(Sequence& seq, int& group); vector stripPairedPrimers(Sequence& seq, int& group); + + int preProcess(int,int, int, int, int, map, map, vector, vector, vector); //pdiffs, bdiffs, ldiffs, sdiffs, primers, barcodes, revPrimers, linker, spacer + int preProcess(int p, int b, int l, int s, map pr, map br, bool hi); }; diff --git a/source/venn.cpp b/source/venn.cpp index b3eac046..47848373 100644 --- a/source/venn.cpp +++ b/source/venn.cpp @@ -186,7 +186,6 @@ vector Venn::getPic(vector lookup, vector data = nseqsCalc->getValues(lookup); - cout << data[0] << '\t' << data[1] << endl; sharedVal = data[0] + data[1]; numSeqsA = sabundA->getNumSeqs(); numSeqsB = sabundB->getNumSeqs(); @@ -338,9 +337,7 @@ vector Venn::getPic(vector lookup, vectorgetMultiple() == false) { //merge BC and estimate with shared with A SharedRAbundVector* merge = new SharedRAbundVector(); - for (int j = 0; j < lookup[1]->size(); j++) { - merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), ""); - } + for (int j = 0; j < lookup[1]->size(); j++) { merge->push_back((lookup[1]->get(j) + lookup[2]->get(j))); } subset.clear(); subset.push_back(lookup[0]); subset.push_back(merge); @@ -349,9 +346,7 @@ vector Venn::getPic(vector lookup, vectorsize(); j++) { - merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), ""); - } + for (int j = 0; j < lookup[0]->size(); j++) { merge->push_back((lookup[0]->get(j) + lookup[2]->get(j))); } subset.clear(); subset.push_back(merge); subset.push_back(lookup[1]); @@ -360,9 +355,7 @@ vector Venn::getPic(vector lookup, vectorsize(); j++) { - merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), ""); - } + for (int j = 0; j < lookup[0]->size(); j++) { merge->push_back((lookup[0]->get(j) + lookup[1]->get(j))); } subset.clear(); subset.push_back(lookup[2]); subset.push_back(merge); diff --git a/source/venn.h b/source/venn.h index db26b272..9722e57f 100644 --- a/source/venn.h +++ b/source/venn.h @@ -9,11 +9,8 @@ * */ -#include "sabundvector.hpp" -#include "sharedrabundvector.h" -#include "datavector.hpp" -#include "calculator.h" +#include "calculator.h" /***********************************************************************/