std::string JITDebugRegisterer::MakeELF(const Function *F, DebugInfo &I) { // Stack allocate an empty module with an empty LLVMContext for the ELFWriter // API. We don't use the real module because then the ELFWriter would write // out unnecessary GlobalValues during finalization. LLVMContext Context; Module M("", Context); // Make a buffer for the ELF in memory. std::string Buffer; raw_string_ostream O(Buffer); ELFWriter EW(O, TM); EW.doInitialization(M); // Copy the binary into the .text section. This isn't necessary, but it's // useful to be able to disassemble the ELF by hand. ELFSection &Text = EW.getTextSection(const_cast<Function *>(F)); Text.Addr = (uint64_t)I.FnStart; // TODO: We could eliminate this copy if we somehow used a pointer/size pair // instead of a vector. Text.getData().assign(I.FnStart, I.FnEnd); // Copy the exception handling call frame information into the .eh_frame // section. This allows GDB to get a good stack trace, particularly on // linux x86_64. Mark this as a PROGBITS section that needs to be loaded // into memory at runtime. ELFSection &EH = EW.getSection(".eh_frame", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); // Pointers in the DWARF EH info are all relative to the EH frame start, // which is stored here. EH.Addr = (uint64_t)I.EhStart; // TODO: We could eliminate this copy if we somehow used a pointer/size pair // instead of a vector. EH.getData().assign(I.EhStart, I.EhEnd); // Add this single function to the symbol table, so the debugger prints the // name instead of '???'. We give the symbol default global visibility. ELFSym *FnSym = ELFSym::getGV(F, ELF::STB_GLOBAL, ELF::STT_FUNC, ELF::STV_DEFAULT); FnSym->SectionIdx = Text.SectionIdx; FnSym->Size = I.FnEnd - I.FnStart; FnSym->Value = 0; // Offset from start of section. EW.SymbolList.push_back(FnSym); EW.doFinalization(M); O.flush(); // When trying to debug why GDB isn't getting the debug info right, it's // awfully helpful to write the object file to disk so that it can be // inspected with readelf and objdump. if (JITEmitDebugInfoToDisk) { std::string Filename; raw_string_ostream O2(Filename); O2 << "/tmp/llvm_function_" << I.FnStart << "_" << F->getNameStr() << ".o"; O2.flush(); std::string Errors; raw_fd_ostream O3(Filename.c_str(), Errors); O3 << Buffer; O3.close(); } return Buffer; }
map<Range,vector<int> > Plink::mkBlks(int null1, int null2 ) { // First SNP, vector of SNPs (inc. first) map< int, vector<int> > blocks; // Some constants const double cutHighCI = 0.98; const double cutLowCI = 0.70; const double cutLowCIVar [5] = {0,0,0.80,0.50,0.50}; const double maxDist [5] = {0,0,20000,30000,1000000}; const double recHighCI = 0.90; const double informFrac = 0.95; const double fourGameteCutoff = 0.01; const double mafThresh = 0.05; // Set to skip SNPs with low MAFs // Uses genome-wide reference number: need to allocate for all SNPs here vector<bool> skipMarker(nl_all,false); for (int x = 0; x < nl_all; x++) skipMarker[x] = locus[x]->freq < mafThresh; // Consider each chromosome one at a time; skip X for now int startChromosome = locus[ 0 ]->chr; int finalChromosome = locus[ nl_all - 1 ]->chr; for (int chr = startChromosome ; chr <= finalChromosome; chr++) { if ( scaffold.find(chr) == scaffold.end() ) continue; int fromPosition = scaffold[chr].lstart; int toPosition = scaffold[chr].lstop; int nsnps = toPosition - fromPosition + 1; ///////////////////////////////////////////////////////////////////////// // Make a list of marker pairs in "strong LD", sorted by distance apart set<LDPair,Pair_cmp> strongPairs; map<int2,DPrime> dpStore; int numStrong = 0; int numRec = 0; int numInGroup = 0; // Each pair of markers for (int x = fromPosition; x < toPosition; x++) { if ( ! par::silent ) { std::cerr << "Chromosome " << locus[x]->chr << ", position " << locus[x]->bp/1000000.0 << "Mb \r"; } for (int y = x+1; y <= toPosition; y++) { if ( locus[x]->chr != locus[y]->chr ) continue; if ( ( locus[y]->bp - locus[x]->bp ) > par::disp_r_window_kb ) { continue; } if ( locus[x]->freq == 0 || locus[y]->freq == 0 ) continue; PairwiseLinkage thisPair(x,y); thisPair.calculateLD(); thisPair.calculateCI(); double lod = thisPair.lod; double lowCI = thisPair.dp_lower; double highCI = thisPair.dp_upper; int2 t(x,y); DPrime d; d.dp = thisPair.dp; d.dpl = lowCI; d.dpu = highCI; d.lod = lod; dpStore.insert( make_pair( t,d ) ); // Is this pair in strong LD? if (lod < -90) continue; //missing data if (highCI < cutHighCI || lowCI < cutLowCI) continue; //must pass "strong LD" test // Store this pair LDPair p(x,y, abs( locus[x]->bp - locus[y]->bp ) ); strongPairs.insert( p ); } } // Now we have a list of SNPs in strong LD within this region // Now construct blocks based on this set<int> used; // #blocks: vector<vector<int> > blockArray; int cnt = 0; for ( set<LDPair>::reverse_iterator i = strongPairs.rbegin(); i != strongPairs.rend(); ++i ) { int numStrong = 0; int numRec = 0; int numInGroup = 0; vector<int> thisBlock; int first = i->s1; int last = i->s2; long sep = i->dist; // See if this block overlaps with another: if ( used.find(first) != used.end() || used.find(last) != used.end() ) { continue; } // Next, count the number of markers in the block. // (nb. assume all SNPs belong) for (int x = first; x <=last ; x++) { if( !skipMarker[x] ) numInGroup++; } // Skip it if it is too long in bases for it's size in markers if (numInGroup < 4 && sep > maxDist[numInGroup]) { continue; } // Add first SNP thisBlock.push_back( first ); // Test block: requires 95% of informative markers to be "strong" for (int y = first+1; y <= last; y++) { if (skipMarker[y]) { continue; } thisBlock.push_back(y); //loop over columns in row y for (int x = first; x < y; x++) { if (skipMarker[x]) continue; double lod; double lowCI; double highCI; map<int2,DPrime>::iterator l = dpStore.find( int2(x,y) ); if ( l == dpStore.end() ) { // Recalculate PairwiseLinkage thisPair(x,y); thisPair.calculateLD(); thisPair.calculateCI(); lod = thisPair.lod; lowCI = thisPair.dp_lower; highCI = thisPair.dp_upper; } else { // Get the right bits lod = l->second.lod; lowCI = l->second.dpl; highCI = l->second.dpu; } // Monomorphic marker error if ( lod < -90) continue; // Skip bad markers if ( lod == 0 && lowCI == 0 && highCI == 0) continue; // For small blocks use different CI cutoffs if (numInGroup < 5) { if (lowCI > cutLowCIVar[numInGroup] && highCI >= cutHighCI) numStrong++; } else { if (lowCI > cutLowCI && highCI >= cutHighCI) numStrong++; //strong LD } if (highCI < recHighCI) numRec++; //recombination } } // Change the definition somewhat for small blocks if (numInGroup > 3) { if (numStrong + numRec < 6) { continue; } } else if (numInGroup > 2) { if (numStrong + numRec < 3) { continue; } } else { if (numStrong + numRec < 1) { continue; } } // If this qualifies as a block, add to the block list, but in // order by first marker number: if ( (double)numStrong/(double)(numStrong + numRec) > informFrac) { blocks.insert( make_pair( first , thisBlock )); // Track that these SNPs belong to a block for (int u = first; u <= last; u++) used.insert(u); } } // Next chromosome } if ( ! par::silent ) cerr << "\n"; map<int,vector<int> >::iterator j = blocks.begin(); printLOG(int2str( blocks.size() ) + " blocks called, writing list to [ " + par::output_file_name + ".blocks ]\n"); ofstream O1( (par::output_file_name+".blocks").c_str() , ios::out ); printLOG("Writing extra block details to [ " + par::output_file_name + ".blocks.det ]\n"); ofstream O2( (par::output_file_name+".blocks.det").c_str() , ios::out ); O2 << setw(4) << "CHR" << " " << setw(12) << "BP1" << " " << setw(12) << "BP2" << " " << setw(12) << "KB" << " " << setw(6) << "NSNPS" << " " << setw(4) << "SNPS" << "\n"; while ( j != blocks.end() ) { O1 << "*"; vector<int> & b = j->second; for (int k=0; k<b.size(); k++) O1 << " " << PP->locus[b[k]]->name; O1 << "\n"; O2 << setw(4) << PP->locus[b[0]]->chr << " " << setw(12) << PP->locus[b[0]]->bp << " " << setw(12) << PP->locus[b[b.size()-1]]->bp << " " << setw(12) << (double)(PP->locus[b[b.size()-1]]->bp - PP->locus[b[0]]->bp + 1)/1000.0 << " " << setw(6) << b.size() << " "; for (int k=0; k<b.size(); k++) { if ( k>0 ) O2 << "|" << PP->locus[b[k]]->name; else O2 << PP->locus[b[k]]->name; } O2 << "\n"; ++j; } O1.close(); O2.close(); // List of blocks created here // (dummy; not used) map<Range,vector<int> > blocks0; return blocks0; }
/* * Hash OIDs * * SHA1 = 1.3.14.3.2.26 * MDx = 1.2.840.113549.2.x */ #define O0(a,b) ((a)*40+(b)) #define O2(x) \ (((x)>>7)&0x7F)|0x80, \ ((x)&0x7F) #define O3(x) \ (((x)>>14)&0x7F)|0x80, \ (((x)>>7)&0x7F)|0x80, \ ((x)&0x7F) uchar oidsha1[] = { O0(1, 3), 14, 3, 2, 26 }; uchar oidmd2[] = { O0(1, 2), O2(840), O3(113549), 2, 2 }; uchar oidmd5[] = { O0(1, 2), O2(840), O3(113549), 2, 5 }; /* * DigestInfo ::= SEQUENCE { * digestAlgorithm AlgorithmIdentifier, * digest OCTET STRING * } * * except that OpenSSL seems to sign * * DigestInfo ::= SEQUENCE { * SEQUENCE{ digestAlgorithm AlgorithmIdentifier, NULL } * digest OCTET STRING * } *
Molecule CO2() { int nAtoms = 3; Eigen::Vector3d C1( 0.0000000000, 0.0000000000, 0.0000000000); Eigen::Vector3d O1( 2.1316110791, 0.0000000000, 0.0000000000); Eigen::Vector3d O2(-2.1316110791, 0.0000000000, 0.0000000000); Eigen::MatrixXd geom(3, nAtoms); geom.col(0) = C1.transpose(); geom.col(1) = O1.transpose(); geom.col(2) = O2.transpose(); Eigen::Vector3d charges, masses; charges << 6.0, 8.0, 8.0; masses << 12.00, 15.9949150, 15.9949150; std::vector<Atom> atoms; double radiusC = (1.70 * 1.20) / convertBohrToAngstrom; double radiusO = (1.52 * 1.20) / convertBohrToAngstrom; atoms.push_back( Atom("Carbon", "C", charges(0), masses(0), radiusC, C1, 1.0) ); atoms.push_back( Atom("Oxygen", "O", charges(1), masses(1), radiusO, O1, 1.0) ); atoms.push_back( Atom("Oxygen", "O", charges(2), masses(2), radiusO, O2, 1.0) ); std::vector<Sphere> spheres; Sphere sph1(C1, radiusC); Sphere sph2(O1, radiusO); Sphere sph3(O2, radiusO); spheres.push_back(sph1); spheres.push_back(sph2); spheres.push_back(sph3); enum pointGroup { pgC1, pgC2, pgCs, pgCi, pgD2, pgC2v, pgC2h, pgD2h }; Symmetry pGroup; switch(group) { case(pgC1): pGroup = buildGroup(0, 0, 0, 0); break; case(pgC2): // C2 as generated by C2z pGroup = buildGroup(1, 3, 0, 0); break; case(pgCs): // Cs as generated by Oyz pGroup = buildGroup(1, 1, 0, 0); break; case(pgCi): // Ci as generated by i pGroup = buildGroup(1, 7, 0, 0); break; case(pgD2): // D2 as generated by C2z and C2x pGroup = buildGroup(2, 3, 6, 0); break; case(pgC2v): // C2v as generated by Oyz and Oxz pGroup = buildGroup(2, 1, 2, 0); break; case(pgC2h): // C2h as generated by Oxy and i pGroup = buildGroup(2, 4, 7, 0); break; case(pgD2h): // D2h as generated by Oxy, Oxz and Oyz pGroup = buildGroup(3, 4, 2, 1); break; default: pGroup = buildGroup(0, 0, 0, 0); break; } return Molecule(nAtoms, charges, masses, geom, atoms, spheres, pGroup); };