~ubuntu-branches/ubuntu/raring/bedtools/raring

« back to all changes in this revision

Viewing changes to src/mergeBed/mergeBed.cpp

  • Committer: Package Import Robot
  • Author(s): Charles Plessy
  • Date: 2012-11-04 17:59:41 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20121104175941-hahqzy1w8uy650z0
Tags: 2.17.0-1
bb9012e Imported Upstream version 2.16.2.
9006b23 Imported Upstream version 2.17.0.
9112569 Documented BEDTools license as a whole.
325689c Removed Pre-Depends: dpkg (>= 1.15.6).
a781b14 Conforms with Policy 3.9.4.
84b1167 Use Debhelper 9. 
0bf572d Distribute the test suite.
422cd34 Bash completion for BEDTools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
// ===============================================
108
108
// Convenience method for reporting merged blocks
109
109
// ================================================
110
 
void BedMerge::Report(string chrom, int start, int end, 
111
 
                      const vector<string> &names, const vector<string> &scores, int mergeCount) 
 
110
void BedMerge::Report(string chrom, int start, 
 
111
                      int end, const vector<string> &names, 
 
112
                      const vector<string> &scores, int mergeCount) 
112
113
{
113
114
    // ARQ: removed to force all output to be zero-based, BED format, reagrdless of input type
114
115
    //if (_bed->isZeroBased == false) {start++;}
115
116
    
116
117
    printf("%s\t%d\t%d", chrom.c_str(), start, end);
117
118
    // just the merged intervals
118
 
    if (_numEntries == false && _reportNames == false && _reportScores == false) {
 
119
    if (_numEntries == false && _reportNames == false && 
 
120
        _reportScores == false) {
119
121
        printf("\n");
120
122
    }
121
123
    // merged intervals and counts    
122
 
    else if (_numEntries == true && _reportNames == false && _reportScores == false) {
 
124
    else if (_numEntries == true && _reportNames == false && 
 
125
        _reportScores == false) {
123
126
        printf("\t%d\n", mergeCount);
124
127
    }
125
128
    // merged intervals, counts, and scores
126
 
    else if (_numEntries == true && _reportNames == false && _reportScores == true) {
 
129
    else if (_numEntries == true && _reportNames == false && 
 
130
        _reportScores == true) {
127
131
        printf("\t%d", mergeCount);
128
132
        ReportMergedScores(scores);
129
133
        printf("\n");
130
134
    }
131
135
    // merged intervals, counts, and names
132
 
    else if (_numEntries == true && _reportNames == true && _reportScores == false) {
 
136
    else if (_numEntries == true && _reportNames == true && 
 
137
        _reportScores == false) {
133
138
        ReportMergedNames(names);
134
139
        printf("\t%d\n", mergeCount);
135
140
    }
136
141
    // merged intervals, counts, names, and scores
137
 
    else if (_numEntries == true && _reportNames == true && _reportScores == true) {
 
142
    else if (_numEntries == true && _reportNames == true && 
 
143
        _reportScores == true) {
138
144
        ReportMergedNames(names);
139
145
        ReportMergedScores(scores);
140
146
        printf("\t%d\n", mergeCount);
141
147
    }
142
148
    // merged intervals and names        
143
 
    else if (_numEntries == false && _reportNames == true && _reportScores == false) {
 
149
    else if (_numEntries == false && _reportNames == true && 
 
150
        _reportScores == false) {
144
151
        ReportMergedNames(names);
145
152
        printf("\n");
146
153
    }
147
154
    // merged intervals and scores        
148
 
    else if (_numEntries == false && _reportNames == false && _reportScores == true) {
 
155
    else if (_numEntries == false && _reportNames == false && 
 
156
        _reportScores == true) {
149
157
        ReportMergedScores(scores);
150
158
        printf("\n");
151
159
    }
152
160
    // merged intervals, names, and scores        
153
 
    else if (_numEntries == false && _reportNames == true && _reportScores == true) {
 
161
    else if (_numEntries == false && _reportNames == true && 
 
162
        _reportScores == true) {
154
163
        ReportMergedNames(names);
155
164
        ReportMergedScores(scores);
156
165
        printf("\n");
161
170
// =========================================================
162
171
// Convenience method for reporting merged blocks by strand
163
172
// =========================================================
164
 
void BedMerge::ReportStranded(string chrom, int start, int end, 
165
 
                              const vector<string> &names, const vector<string> &scores,
166
 
                              int mergeCount, string strand) 
 
173
void BedMerge::ReportStranded(string chrom, int start, 
 
174
                              int end, const vector<string> &names, 
 
175
                              const vector<string> &scores, int mergeCount,
 
176
                              string strand) 
167
177
{
168
178
    // ARQ: removed to force all output to be zero-based, BED format, reagrdless of input type
169
179
    //if (_bed->isZeroBased == false) {start++;}
170
180
    
171
181
    printf("%s\t%d\t%d", chrom.c_str(), start, end);
172
182
    // just the merged intervals
173
 
    if (_numEntries == false && _reportNames == false && _reportScores == false) {
 
183
    if (_numEntries == false && _reportNames == false && 
 
184
        _reportScores == false) {
174
185
        printf("\t%s\n", strand.c_str());
175
186
    }
176
187
    // merged intervals and counts    
177
 
    else if (_numEntries == true && _reportNames == false && _reportScores == false) {
 
188
    else if (_numEntries == true && _reportNames == false &&
 
189
        _reportScores == false) {
178
190
        printf("\t%d\t%s\n", mergeCount, strand.c_str());
179
191
    }
180
192
    // merged intervals, counts, and scores
181
 
    else if (_numEntries == true && _reportNames == false && _reportScores == true) {
 
193
    else if (_numEntries == true && _reportNames == false &&
 
194
        _reportScores == true) {
182
195
        printf("\t%d", mergeCount);
183
196
        ReportMergedScores(scores);
184
197
        printf("\t%s\n", strand.c_str());
185
198
    }
186
199
    // merged intervals, counts, and names
187
 
    else if (_numEntries == true && _reportNames == true && _reportScores == false) {
 
200
    else if (_numEntries == true && _reportNames == true &&
 
201
        _reportScores == false) {
188
202
        ReportMergedNames(names);
189
203
        printf("\t%d\t%s", mergeCount, strand.c_str());
190
204
        printf("\n");
191
205
    }
192
206
    // merged intervals, counts, names, and scores
193
 
    else if (_numEntries == true && _reportNames == true && _reportScores == true) {
 
207
    else if (_numEntries == true && _reportNames == true &&
 
208
        _reportScores == true) {
194
209
        ReportMergedNames(names);
195
210
        ReportMergedScores(scores);
196
211
        printf("\t%s\t%d", strand.c_str(), mergeCount);
197
212
        printf("\n");
198
213
    }
199
214
    // merged intervals and names        
200
 
    else if (_numEntries == false && _reportNames == true && _reportScores == false) {
 
215
    else if (_numEntries == false && _reportNames == true &&
 
216
        _reportScores == false) {
201
217
        ReportMergedNames(names);
202
218
        printf("\t%s\n", strand.c_str());
203
219
    }
204
220
    // merged intervals and scores        
205
 
    else if (_numEntries == false && _reportNames == false && _reportScores == true) {
 
221
    else if (_numEntries == false && _reportNames == false && 
 
222
        _reportScores == true) {
206
223
        ReportMergedScores(scores);
207
224
        printf("\t%s\n", strand.c_str());
208
225
    }
209
226
    // merged intervals, names, and scores        
210
 
    else if (_numEntries == false && _reportNames == true && _reportScores == true) {
 
227
    else if (_numEntries == false && _reportNames == true && 
 
228
        _reportScores == true) {
211
229
        ReportMergedNames(names);
212
230
        ReportMergedScores(scores);
213
231
        printf("\t%s\n", strand.c_str());
231
249
        if (_bed->_status != BED_VALID)
232
250
            continue;            
233
251
        // new block, no overlap
234
 
        if ( (((int) curr.start - end) > _maxDistance) || (curr.chrom != prev.chrom)) {
 
252
        if ( (((int) curr.start - end) > _maxDistance) || 
 
253
            (curr.chrom != prev.chrom)) 
 
254
        {
235
255
            if (start >= 0) {
236
256
                Report(prev.chrom, start, end, names, scores, mergeCount);
237
257
                // reset
264
284
}
265
285
 
266
286
 
267
 
// ==================================================================================
 
287
// ===============================================================================
268
288
// = Merge overlapping BED entries into a single entry, accounting for strandedness =
269
 
// ==================================================================================
 
289
// ================================================================================
270
290
void BedMerge::MergeBedStranded() {
271
291
 
272
292
    // load the "B" bed file into a map so
302
322
                // is not on the current strand.
303
323
                if (bedItr->strand != strands[s]) { continue; }
304
324
                else { numOnStrand++; }
305
 
                if ( (((int) bedItr->start - end) > _maxDistance) || (end < 0)) {
 
325
                if ( (((int) bedItr->start - end) > _maxDistance) || 
 
326
                    (end < 0)) 
 
327
                {
306
328
                    if (start >= 0) {
307
 
                        ReportStranded(chrom, start, end, names, scores, mergeCount, strands[s]);
 
329
                        ReportStranded(chrom, start, end, names, 
 
330
                                       scores, mergeCount, strands[s]);
308
331
                        // reset
309
332
                        mergeCount = 1;
310
333
                        names.clear();
323
346
                }
324
347
            }
325
348
            if (start >= 0) {
326
 
                ReportStranded(chrom, start, end, names, scores, mergeCount, strands[s]);
 
349
                ReportStranded(chrom, start, end, names, 
 
350
                               scores, mergeCount, strands[s]);
327
351
            }
328
352
        }
329
353
    }