void split (const string& text, const string& separators, vector<string>& words);
char *strrevcomp(const string& input);
-class Read {
+class Loci {
public:
string chr;
unsigned int pos;
+
+ Loci(string chr, unsigned int pos) { this->chr = chr; this->pos = pos; }
+ Loci(const Loci& l) { this->chr = l.chr; this->pos = l.pos; }
+ Loci& operator=(const Loci& l) { this->chr = l.chr; this->pos = l.pos; return *this; }
+
+ bool operator<(const Loci& a) const { if(this->chr == a.chr) { return this->pos < a.pos; } else { return this->chr < a.chr; } }
+
+};
+
+class Read : public Loci {
+ public:
string seq;
- Read(string chr, unsigned int pos, string seq) { this->chr = chr; this->pos = pos; this->seq = seq; }
- Read(const Read& r) { this->chr = r.chr; this->pos = r.pos; this->seq = r.seq; }
- Read& operator=(const Read& r) {this->chr = r.chr; this->pos = r.pos; this->seq = r.seq; return *this;}
+ Read(string chr, unsigned int pos, string seq) : Loci(chr,pos) { this->seq = seq; }
+ Read(const Read& r) : Loci(r) { this->seq = r.seq; }
+ Read& operator=(const Read& r) { this->chr = r.chr; this->pos = r.pos; this->seq = r.seq; return *this;}
};
-class SNP {
+class SNP : public Loci {
public:
string name;
- string chr;
- unsigned int pos;
char reference_base;
unsigned int A;
unsigned int C;
unsigned int N;
unsigned int total;
- SNP(string name, string chr, unsigned int pos, char reference_base) {
+ SNP(string name, string chr, unsigned int pos, char reference_base) : Loci(chr,pos) {
this->name = name;
- this->chr = chr;
- this->pos = pos;
this->A = 0; this->C = 0; this->G = 0; this->T = 0; this->total = 0;
this->reference_base = reference_base;
}
- SNP(const SNP& h) {
+ SNP(const SNP& h) : Loci(h) {
this->name = h.name;
- this->chr = h.chr;
- this->pos = h.pos;
this->A = h.A; this->C = h.C; this->G = h.G; this->T = h.T; this->total = h.total;
this->reference_base = h.reference_base;
}
}
};
-bool SNP_lt_Read(const SNP& feat, const Read& read) {
- //First compare based on chromosomes
- if(read.chr == feat.chr) { return feat.pos < read.pos; }
- else { return feat.chr < read.chr; }
-}
-
ostream &operator<<( ostream &out, const SNP &h ) {
out << h.name.c_str() << "\t" << h.chr.c_str() << "\t" << h.pos << "\t" << h.reference_base << "\t" << h.A << "\t" << h.C << "\t" << h.G << "\t" << h.T << "\t" << h.total;
return out;
typedef vector<Read> Reads;
typedef vector<SNP> SNPs;
-bool compare_snps(const SNP &a, const SNP &b) { if(a.chr == b.chr) { return a.pos < b.pos; } else { return a.pos < b.pos; } }
-bool compare_reads(const Read &a, const Read &b) { if(a.chr == b.chr) { return a.pos < b.pos; } else { return a.chr < b.chr; } }
-
void read_snps(const char* filename, SNPs& snps) {
string delim("\t");
}
//sort the features so we can run through it once
- std::stable_sort(snps.begin(),snps.end(),compare_snps);
+ std::stable_sort(snps.begin(),snps.end());
feat.close();
cerr << "Found and sorted " << snps.size() << " snps." << endl;
seqs.close();
//sort the data so we can run through it once
- std::sort(features.begin(),features.end(),compare_reads);
+ std::sort(features.begin(),features.end());
cerr << "Found and sorted " << features.size() << " reads." << endl;
}
for(Reads::iterator i = data.begin(); i != data.end(); ++i) {
//skip to first feature after read
string start_chr = snp_it->chr;
- while(snp_it != snps.end() && SNP_lt_Read(*snp_it, *i)) {
+ while(snp_it != snps.end() && *snp_it < *i) {
snp_it++;
}
if(snp_it == snps.end()) { break; }
if(i->pos + read_len > snp_it->pos && i->pos <= snp_it->pos) {
- cout << i->chr.c_str() << "\t" << i->pos << "\t" << i->seq.c_str() << endl;
snp_it->add_read(i->seq[snp_it->pos - i->pos]);
}
}