Debian Codegraph @

meryl/dump.C

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "meryl.H"
6 #include "libmeryl.H"
7
8 #include <algorithm>
9
10 void
11 dumpThreshold(merylArgs *args) {
12 merylStreamReader *M = new merylStreamReader(args->inputFile);
13 char str[1025];
14
15 while (M->nextMer()) {
16 if (M->theCount() >= args->numMersEstimated)
17 fprintf(stdout, ">"uint64FMT"\n%s\n",
18 M->theCount(),
19 M->theFMer().merToString(str));
20 }
21
22 delete M;
23 }
24
25
26 void
27 dumpPositions(merylArgs *args) {
28 merylStreamReader *M = new merylStreamReader(args->inputFile);
29 char str[1025];
30
31 if (M->hasPositions() == false) {
32 fprintf(stderr, "File '%s' contains no position information.\n", args->inputFile);
33 } else {
34 while (M->nextMer()) {
35 fprintf(stdout, ">"uint64FMT, M->theCount());
36 for (uint32 i=0; i<M->theCount(); i++)
37 fprintf(stdout, " "uint32FMT, M->getPosition(i));
38 fprintf(stdout, "\n%s\n", M->theFMer().merToString(str));
39 }
40 }
41
42 delete M;
43 }
44
45
46 void
47 countUnique(merylArgs *args) {
48 merylStreamReader *M = new merylStreamReader(args->inputFile);
49
50 #warning make this a test
51 #if 0
52 uint64 numDistinct = 0;
53 uint64 numUnique = 0;
54 uint64 numMers = 0;
55 uint64 c = 0;
56
57 while (M->nextMer()) {
58 c = M->theCount();
59
60 numDistinct++;
61 if (c == 1)
62 numUnique++;
63 numMers += c;
64 }
65
66 assert(numMers == M->numberOfTotalMers());
67 assert(numDistinct == M->numberOfDistinctMers());
68 assert(numUnique == M->numberOfUniqueMers());
69 fprintf(stderr, "OK\n");
70 #endif
71
72 fprintf(stdout, "Found "uint64FMT" mers.\n", M->numberOfTotalMers());
73 fprintf(stdout, "Found "uint64FMT" distinct mers.\n", M->numberOfDistinctMers());
74 fprintf(stdout, "Found "uint64FMT" unique mers.\n", M->numberOfUniqueMers());
75
76 delete M;
77 }
78
79
80 void
81 plotHistogram(merylArgs *args) {
82 uint64 distinct = 0;
83 uint64 total = 0;
84
85 merylStreamReader *M = new merylStreamReader(args->inputFile);
86
87 fprintf(stderr, "Found "uint64FMT" mers.\n", M->numberOfTotalMers());
88 fprintf(stderr, "Found "uint64FMT" distinct mers.\n", M->numberOfDistinctMers());
89 fprintf(stderr, "Found "uint64FMT" unique mers.\n", M->numberOfUniqueMers());
90
91 fprintf(stderr, "Largest mercount is "uint64FMT"; "uint64FMT" mers are too big for histogram.\n",
92 M->histogramMaximumCount(), M->histogramHuge());
93
94 for (uint32 i=1; i<M->histogramLength(); i++) {
95 uint64 hist = M->histogram(i);
96
97 if (hist > 0) {
98 distinct += hist;
99 total += hist * i;
100
101 fprintf(stdout, uint32FMT"\t"uint64FMT"\t%.4f\t%.4f\n",
102 i,
103 hist,
104 distinct / (double)M->numberOfDistinctMers(),
105 total / (double)M->numberOfTotalMers());
106 }
107 }
108
109 delete M;
110 }
111
112
113
114 void
115 dumpDistanceBetweenMers(merylArgs *args) {
116 merylStreamReader *M = new merylStreamReader(args->inputFile);
117
118 // This is now tough because we don't know where the sequences end,
119 // and our positions encode position in the chain.
120
121 uint32 histMax = 64 * 1024 * 1024;
122 uint64 *hist = new uint64 [histMax];
123 uint64 histHuge = 0;
124
125 if (M->hasPositions() == false) {
126 fprintf(stderr, "File '%s' contains no position information.\n", args->inputFile);
127 } else {
128 while (M->nextMer()) {
129 std::sort(M->thePositions(), M->thePositions() + M->theCount());
130
131 for (uint32 i=1; i<M->theCount(); i++) {
132 uint32 d = M->getPosition(i) - M->getPosition(i-1);
133 if (d < histMax)
134 hist[d]++;
135 else
136 histHuge++;
137 }
138 }
139
140 uint32 maxd = 0;
141
142 for (uint32 d=0; d<histMax; d++)
143 if (hist[d])
144 maxd = d+1;
145
146 for (uint32 d=0; d<maxd; d++)
147 if (hist[d])
148 fprintf(stderr, uint32FMT"\t"uint64FMT"\n", d, hist[d]);
149
150 if (histHuge)
151 fprintf(stderr, "huge\t"uint64FMT"\n", histHuge);
152 }
153
154 delete [] hist;
155 delete M;
156 }