void processArray(int argc, char **argv) { int arg = 1; while (arg < argc) { if ((strcmp(argv[arg], "-f") == 0) || (strcmp(argv[arg], "-F") == 0)) { delete fasta; fasta = new seqCache(argv[++arg]); } else if (strcmp(argv[arg], "-i") == 0) { failIfNoSource(); ++arg; if ((argv[arg] == 0L) || (argv[arg][0] == '-')) fprintf(stderr, "ERROR: next arg to -i should be 'name', I got '%s'\n", (argv[arg] == 0L) ? "(nullpointer)" : argv[arg]), exit(1); for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) fprintf(stdout, "G\tseq\t%s:"F_U32"\t"F_U32"\t%s\n", argv[arg], s, fasta->getSequenceLength(s), ">unimplemented"); } else if (strcmp(argv[arg], "-d") == 0) { failIfNoSource(); printf(F_U32"\n", fasta->getNumberOfSequences()); } else if (strcmp(argv[arg], "-L") == 0) { uint32 small = strtouint32(argv[++arg]); uint32 large = strtouint32(argv[++arg]); failIfNoSource(); for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) if ((small <= fasta->getSequenceLength(s)) && (fasta->getSequenceLength(s) < large)) printSequence(s); } else if (strcmp(argv[arg], "-N") == 0) { double small = atof(argv[++arg]); double large = atof(argv[++arg]); failIfNoSource(); for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) { seqInCore *S = fasta->getSequenceInCore(s); uint32 Ns = 0; uint32 len = S->sequenceLength(); char *seq = S->sequence(); for (uint32 i=begPos; i<len && i<endPos; i++) if ((seq[i] == 'n') || (seq[i] == 'N')) Ns++; double Np = 100.0 * Ns / len; if ((small <= Np) && (Np < large)) printSequence(S); delete S; } } else if (strcmp(argv[arg], "-W") == 0) { failIfNoSource(); for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) printSequence(s); } else if (strcmp(argv[arg], "-G") == 0) { uint32 n = strtouint32(argv[++arg]); uint32 s = strtouint32(argv[++arg]); uint32 l = strtouint32(argv[++arg]); char bases[4] = {'A', 'C', 'G', 'T'}; char *def = new char [1024]; char *seq = new char [l + 1]; if (s == 0) s = 1; if (s > l) fprintf(stderr, "leaff: usage: -G num-seqs min-length max-length\n"), exit(1); for (uint32 i=0; i<n; i++) { uint32 j = s + ((l-s == 0) ? 0 : (MT.mtRandom32() % (l-s))); uint32 p = 0; while (p < j) seq[p++] = bases[MT.mtRandom32() & 0x3]; seq[p] = 0; sprintf(def, "random%06"F_U32P, i); printSequence(def, seq, 0, j); } delete [] seq; delete [] def; } else if (strcmp(argv[arg], "-s") == 0) { failIfNoSource(); failIfNotRandomAccess(); // Easy to fix, just read the first N sequences printSequence(argv[++arg]); } else if (strcmp(argv[arg], "-S") == 0) { failIfNoSource(); failIfNotRandomAccess(); // Easy to fix, just read the first N sequences uint32 lowID = fasta->getSequenceIID(argv[++arg]); uint32 highID = fasta->getSequenceIID(argv[++arg]); if (lowID > highID) { uint32 t = lowID; lowID = highID; highID = t; } for (uint32 s=lowID; (s <= highID) && (s <= fasta->getNumberOfSequences()); s++) printSequence(s); } else if (strcmp(argv[arg], "-r") == 0) { uint32 num = strtouint32(argv[++arg]); failIfNoSource(); failIfNotRandomAccess(); // Impossible to fix, or load whole thing into memory if (num >= fasta->getNumberOfSequences()) num = fasta->getNumberOfSequences(); uint32 *seqs = new uint32 [fasta->getNumberOfSequences()]; for (uint32 i=0; i<fasta->getNumberOfSequences(); i++) seqs[i] = i; for (uint32 i=0; i<fasta->getNumberOfSequences(); i++) { uint32 j = MT.mtRandom32() % (fasta->getNumberOfSequences() - i) + i; uint32 t = seqs[j]; seqs[j] = seqs[i]; seqs[i] = t; } for (uint32 i=0; i<num; i++) printSequence(seqs[i]); delete [] seqs; } else if (strcmp(argv[arg], "-q") == 0) { failIfNoSource(); failIfNotRandomAccess(); // Impossible to fix, or load whole thing into memory printIDsFromFile(argv[++arg]); } else if (strcmp(argv[arg], "-6") == 0) { withLineBreaks = 60; if ((argv[arg+1] != 0L) && (argv[arg+1][0] != '-')) withLineBreaks = strtouint32(argv[++arg]); } else if (strcmp(argv[arg], "-w") == 0) { toUppercase = !toUppercase; for (int z=0; z<256; z++) translate[z] = (toUppercase) ? alphabet.toUpper(z) : (char)z; } else if (strcmp(argv[arg], "-R") == 0) { doReverse = !doReverse; } else if (strcmp(argv[arg], "-C") == 0) { doComplement = !doComplement; } else if (strcmp(argv[arg], "-H") == 0) { withDefLine = !withDefLine; specialDefLine = 0L; } else if (strcmp(argv[arg], "-h") == 0) { withDefLine = true; specialDefLine = argv[++arg]; } else if (strcmp(argv[arg], "-e") == 0) { begPos = strtouint32(argv[++arg]); endPos = strtouint32(argv[++arg]); } else if (strcmp(argv[arg], "-ends") == 0) { endExtract = strtouint32(argv[++arg]); } else if (strcmp(argv[arg], "-A") == 0) { processFile(argv[++arg]); } else if (strcmp(argv[arg], "--findduplicates") == 0) { findDuplicates(argv[++arg]); exit(0); } else if (strcmp(argv[arg], "--mapduplicates") == 0) { mapDuplicates(argv[arg+1], argv[arg+2]); exit(0); } else if (strcmp(argv[arg], "--md5") == 0) { md5_s md5; char sum[33]; fasta = new seqCache(argv[++arg]); for (uint32 s=0; s<fasta->getNumberOfSequences(); s++) { seqInCore *S = fasta->getSequenceInCore(s); fprintf(stdout, "%s %s\n", md5_toascii(md5_string(&md5, S->sequence(), S->sequenceLength()), sum), S->header()); delete S; } delete fasta; exit(0); } else if ((strcmp(argv[arg], "--partition") == 0) || (strcmp(argv[arg], "--partitionmap") == 0)) { char *prefix = 0L; if (strcmp(argv[arg], "--partition") == 0) prefix = argv[++arg]; // does the next arg end with gbp, mbp, kbp or bp? If so, // partition by length, else partition into buckets. // int al = strlen(argv[arg+1]); uint64 ps = strtouint64(argv[arg+1]); char a3 = (al<3) ? '0' : alphabet.toLower(argv[arg+1][al-3]); char a2 = (al<2) ? '0' : alphabet.toLower(argv[arg+1][al-2]); char a1 = (al<1) ? '0' : alphabet.toLower(argv[arg+1][al-1]); // partition! if (!isdigit(a1) || !isdigit(a2) || !isdigit(a3)) { if ((a3 == 'g') && (a2 == 'b') && (a1 == 'p')) { ps *= 1000000000; } else if ((a3 == 'm') && (a2 == 'b') && (a1 == 'p')) { ps *= 1000000; } else if ((a3 == 'k') && (a2 == 'b') && (a1 == 'p')) { ps *= 1000; } else if (isdigit(a3) && (a2 == 'b') && (a1 == 'p')) { ps *= 1; } else { fprintf(stderr, "Unknown partition size option '%s'\n", argv[arg+1]), exit(1); } if (ps == 0) fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1); partitionBySize(prefix, ps, argv[arg+2]); } else { if (ps == 0) fprintf(stderr, "Unknown or zero partition size '%s'\n", argv[arg+1]), exit(1); partitionByBucket(prefix, ps, argv[arg+2]); } exit(0); } else if (strcmp(argv[arg], "--segment") == 0) { partitionBySegment(argv[arg+1], strtouint32(argv[arg+2]), argv[arg+3]); exit(0); } else if (strcmp(argv[arg], "--gccontent") == 0) { computeGCcontent(argv[++arg]); exit(0); } else if (strcmp(argv[arg], "--dumpblocks") == 0) { dumpBlocks(argv[++arg]); exit(0); } else if (strcmp(argv[arg], "--stats") == 0) { stats(argv[arg+1], (argv[arg+2] != 0L) ? strtouint64(argv[arg+2]) : 0); exit(0); } else if (strcmp(argv[arg], "--errors") == 0) { int L = strtouint32(argv[++arg]); // Desired length int l = 0; // min of desired length, length of sequence int N = strtouint32(argv[++arg]); // number of copies per sequence int C = strtouint32(argv[++arg]); // number of mutations per copy double P = atof(argv[++arg]); // probability of mutation uint32 i = 0; fasta = new seqCache(argv[++arg]); seqInCore *S = fasta->getSequenceInCore(i++); while (S) { char *seq = S->sequence(); char *hdr = S->header(); int len = S->sequenceLength(); l = len; if ((L > 0) && (L < len)) l = L; simseq(seq, hdr, len, N, l, C, P); delete S; S = fasta->getSequenceInCore(i++); } delete fasta; exit(0); } else if (strcmp(argv[arg], "--seqstore") == 0) { constructSeqStore(argv[++arg], fasta); exit(0); } else if (strcmp(argv[arg], "-help") == 0) { if ((argv[arg+1]) && (strcmp(argv[arg+1], "analysis") == 0)) helpAnalysis(argv[0]); else if ((argv[arg+1]) && (strcmp(argv[arg+1], "examples") == 0)) helpExamples(argv[0]); else helpStandard(argv[0]); exit(0); } else { helpStandard(argv[0]); fprintf(stderr, "Unknown option '%s'\n", argv[arg]); exit(1); } arg++; } delete fasta; fasta = 0L; }
void ATO::Integrator<T>::getSurfaceTris( std::vector< Vector3D >& points, std::vector< Tri >& tris, const Intrepid::FieldContainer<T>& topoVals, const Intrepid::FieldContainer<T>& coordCon, T zeroVal, C compare) //******************************************************************************// { const CellTopologyData& cellData = *(cellTopology->getBaseCellTopologyData()); // find intersections std::vector<Intersection> intersections; uint nEdges = cellData.edge_count; int nDims = coordCon.dimension(1); for(int edge=0; edge<nEdges; edge++){ uint i = cellData.edge[edge].node[0], j = cellData.edge[edge].node[1]; if((topoVals(i)-zeroVal)*(topoVals(j)-zeroVal) < 0.0){ Vector3D newpoint(Intrepid::ZEROS); T factor = fabs(topoVals(i)-zeroVal)/(fabs(topoVals(i)-zeroVal)+fabs(topoVals(j)-zeroVal)); for(uint k=0; k<nDims; k++) newpoint(k) = (1.0-factor)*coordCon(i,k) + factor*coordCon(j,k); std::pair<int,int> newIntx(i,j); if(topoVals(i) > zeroVal){int tmp=newIntx.first; newIntx.first=newIntx.second; newIntx.second=tmp;} intersections.push_back(Intersection(newpoint,newIntx)); } } std::vector<std::pair<Vector3D,Vector3D> > segment; // if there are four intersections, then there are two interfaces: if( intersections.size() == 4 ){ segment.resize(2); int numNodes = basis->getCardinality(); RealType cntrVal = 0.0; for(int node=0; node<numNodes; node++) cntrVal += topoVals(node); cntrVal /= numNodes; // if topoVal at centroid is negative, interssected segments share a positive valued node if( cntrVal < zeroVal ){ int second = intersections[0].connect.second; if( second == intersections[1].connect.second ){ segment[0].first = intersections[0].point; segment[0].second = intersections[1].point; segment[1].first = intersections[2].point; segment[1].second = intersections[3].point; } else if( second == intersections[2].connect.second ){ segment[0].first = intersections[0].point; segment[0].second = intersections[2].point; segment[1].first = intersections[1].point; segment[1].second = intersections[3].point; } else if( second == intersections[3].connect.second ){ segment[0].first = intersections[0].point; segment[0].second = intersections[3].point; segment[1].first = intersections[1].point; segment[1].second = intersections[2].point; } } else { int first = intersections[0].connect.first; if( first == intersections[1].connect.first ){ segment[0].first = intersections[0].point; segment[0].second = intersections[1].point; segment[1].first = intersections[2].point; segment[1].second = intersections[3].point; } else if( first == intersections[2].connect.first ){ segment[0].first = intersections[0].point; segment[0].second = intersections[2].point; segment[1].first = intersections[1].point; segment[1].second = intersections[3].point; } else if( first == intersections[3].connect.first ){ segment[0].first = intersections[0].point; segment[0].second = intersections[3].point; segment[1].first = intersections[1].point; segment[1].second = intersections[2].point; } } } else if( intersections.size() == 2){ segment.resize(1); segment[0].first = intersections[0].point; segment[0].second = intersections[1].point; } std::vector< Teuchos::RCP<MiniPoly> > polys; int npoints = coordCon.dimension(0), ndims = coordCon.dimension(1); Teuchos::RCP<MiniPoly> poly = Teuchos::rcp(new MiniPoly(npoints)); std::vector<Vector3D>& pnts = poly->points; std::vector<int>& map = poly->mapToBase; for(int pt=0; pt<npoints; pt++){ for(int dim=0; dim<ndims; dim++) pnts[pt](dim) = coordCon(pt,dim); map[pt] = pt; } polys.push_back(poly); int nseg = segment.size(); for(int seg=0; seg<nseg; seg++) partitionBySegment(polys, segment[seg]); typename std::vector< Teuchos::RCP<MiniPoly> >::iterator itpoly; for(itpoly=polys.begin(); itpoly!=polys.end(); itpoly++) if( included(*itpoly,topoVals,zeroVal,compare) ) trisFromPoly(points, tris, *itpoly); }