/****************************************************************************** * macro to test quantile normalization * * * * note: this code is under the license GPL>=2.0 since it is taken from: * * http://www.bioconductor.org/packages/2.4/bioc/html/xps.html * * * * Author: Christian Stratowa, Vienna, Austria. * ******************************************************************************/ /////////////////////////// // // in new root session(s): // > .L macroQuantileTest.C // > QuantileTest("TestAB.txt", "TestAB_Quantile.txt", 126) // /////////////////////////// #ifndef __CINT__ #include #endif #include "TFile.h" #include "TMath.h" #include "TString.h" #include "TKey.h" #include "TTree.h" TFile *fTmpFile = 0; Double_t *fMean1 = 0; Int_t fNMean1 = 0; Int_t fNData = 0; const Int_t kBufSize = 1024; //______________________________________________________________________________ //void TStat::Rank(Int_t n, Double_t *arr, Int_t *index, Int_t *rank, Bool_t down) void Rank(Int_t n, Double_t *arr, Int_t *index, Int_t *rank, Bool_t down) { if (n <= 0) return; if (n == 1) { index[0] = 0; rank[0] = 0; return; }//if TMath::Sort(n,arr,index,down); for (Int_t i=0; icd(); TString tname = TString(name) + ".rkt"; //rkt - rank together Double_t sort = 0; Float_t rank = 0; Int_t id = 0; Int_t i = 0; // Create tree with data and rank branches TTree *tree = new TTree(tname, "temporary tree"); tree->Branch("sortBr", &sort, "sort/D"); tree->Branch("rankBr", &rank, "rank/F"); // Get size of arrays for PM and MM for (i=0; iFill(); }//for_i tree->Write(); fNData++; if (tree) {tree->Delete(""); tree = 0;} if (rnkd) {delete [] rnkd; rnkd = 0;} if (rnki) {delete [] rnki; rnki = 0;} if (ord) {delete [] ord; ord = 0;} if (idx) {delete [] idx; idx = 0;} if (arr) {delete [] arr; arr = 0;} savedir->cd(); return err; }//AddArray //______________________________________________________________________________ //Double_t *XQuantileNormalizer::GetArray(Int_t n, Double_t *x, Short_t *msk, Double_t *GetArray(Int_t n, Double_t *x, Short_t *msk, const char *name) { TDirectory *savedir = gDirectory; fTmpFile->cd(); // Get tree with name TString tname = TString(name) + ".rkt"; Float_t rank = 0; Int_t frank = 0; TTree *tree = (TTree*)fTmpFile->Get(tname.Data()); tree->SetBranchAddress("rankBr", &rank); // Sort mean in order of original tree data Int_t id = 0; for (Int_t i=0; iGetEntry(id++); frank = (Int_t)floor(rank); x[i] = fMean1[frank - 1]; } else { x[i] = 0; //not necessary? }//if }//for_i tree->Delete(""); tree = 0; savedir->cd(); return x; }//GetArray //______________________________________________________________________________ //Int_t XQuantileNormalizer::Calculate(Int_t n, Double_t *x, Double_t *y, Short_t *msk) Int_t Calculate(Int_t n, Double_t *x, Double_t *y, Short_t *msk) { TDirectory *savedir = gDirectory; fTmpFile->cd(); // Calculate mean TTree **treek = new TTree*[fNData]; Double_t *sortk = new Double_t[fNData]; for (Int_t k=0; kGetListOfKeys()); while ((key = (TKey*)next())) { TTree *tmptree = (TTree*)fTmpFile->Get(key->GetName()); treek[idx] = tmptree; treek[idx]->SetBranchAddress("sortBr", &sortk[idx]); idx++; }//while // Create data array Double_t *arr = new Double_t[fNData]; // Create mean array fNMean1 = treek[0]->GetEntries(); fMean1 = new Double_t[fNMean1]; // Calculate mean values of all tree entries for (Int_t i=0; iGetEntry(i); arr[k] = sortk[k]; }//for_k // calculate mean of array fMean1[i] = Mean(fNData, arr); y[i] = fMean1[i]; }//for_i // Cleanup if (arr) {delete [] arr; arr = 0;} delete [] sortk; for (Int_t k=0; kcd(); return 0; }//Calculate //______________________________________________________________________________ void QuantileTest(const char *infile, const char *outfile, Int_t numrows = 126) { Int_t err = 0; // Reset global variables fNData = 0; fNMean1 = 0; if(fTmpFile) {delete fTmpFile; fTmpFile = 0;} if(fMean1) {delete fMean1; fMean1 = 0;} // Set mask array to 1 Short_t *arrMask = new Short_t[numrows]; for (Int_t i=0; i