forked from gpertea/stringtie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmerge.h
69 lines (65 loc) · 1.78 KB
/
tmerge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef STRINGTIE_MERGE_H_
#define STRINGTIE_MERGE_H_
#include "GStr.h"
#include "GList.hh"
#include "rlink.h"
extern GStr tmp_path;
extern bool keepTempFiles;
/*struct TInFile {
GStr fpath;
int ftype; //0=bam file, 1=GTF transfrags
TInFile(const char* fn=NULL,int ft=0):fpath(fn),ftype(ft) { }
}*/
struct TInputRecord {
GBamRecord* brec;
int fidx; //index in files and readers
bool operator<(TInputRecord& o) {
//decreasing location sort
GBamRecord& r1=*brec;
GBamRecord& r2=*(o.brec);
int refcmp=strcmp(r1.refName(),r2.refName());
if (refcmp==0) {
//higher coords first
if (r1.start!=r2.start)
return (r1.start>r2.start);
else {
if (r1.end!=r2.end)
return (r1.end>r2.end);
else if (fidx==o.fidx)
return (strcmp(r1.name(), r2.name())>0);
else return fidx>o.fidx;
}
}
else { //use lexicographic order of ref seqs
return (refcmp>0);
}
}
bool operator==(TInputRecord& o) {
GBamRecord& r1=*brec;
GBamRecord& r2=*(o.brec);
return ( strcmp(r1.refName(),r2.refName())==0 && r1.start==r2.start && r1.end==r2.end
&& fidx==o.fidx && strcmp(r1.name(),r2.name())==0);
}
TInputRecord(GBamRecord* b=NULL, int i=0):brec(b),fidx(i) {}
~TInputRecord() {
delete brec;
}
};
struct TInputFiles {
protected:
TInputRecord* crec;
GStr convert2BAM(GStr& gtf, int idx);
public:
GPVec<GBamReader> readers;
GVec<GStr> files; //same order
GVec<GStr> tmpfiles; //all the temp files created by this
GList<TInputRecord> recs; //next record for each
TInputFiles():crec(NULL), readers(true), files(), tmpfiles(),
recs(true, true, true) { }
void Add(const char* fn);
int count() { return files.Count(); }
int start(); //open all files, load 1 record from each
GBamRecord* next();
void stop(); //
};
#endif /* STRINGTIE_MERGE_H_ */