-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremiah Wala
committed
Aug 19, 2015
1 parent
c278f67
commit 180f755
Showing
5 changed files
with
149 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "SnowTools/Fractions.h" | ||
|
||
namespace SnowTools { | ||
|
||
FracRegion::FracRegion(const std::string& c, const std::string& p1, const std::string& p2, bam_hdr_t * h, const std::string& f) : SnowTools::GenomicRegion(c, p1, p2, h) | ||
{ | ||
// convert frac to double | ||
try { | ||
frac = std::stod(f); | ||
} catch (...) { | ||
std::cerr << "FracRegion::FracRegion - Error converting fraction " << f << " to double " << std::endl; | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
size_t Fractions::size() const { | ||
return m_frc.size(); | ||
} | ||
|
||
|
||
std::ostream& operator<<(std::ostream& out, const FracRegion& f) { | ||
out << f.chr << ":" << SnowTools::AddCommas<int32_t>(f.pos1) << "-" << | ||
SnowTools::AddCommas<int32_t>(f.pos2) << " Frac: " << f.frac; | ||
return out; | ||
} | ||
|
||
void Fractions::readFromBed(const std::string& file, bam_hdr_t * h) { | ||
|
||
igzstream iss(file.c_str()); | ||
if (!iss || file.length() == 0) { | ||
std::cerr << "BED file does not exist: " << file << std::endl; | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
std::string line; | ||
std::string curr_chr = "-1"; | ||
while (std::getline(iss, line, '\n')) { | ||
|
||
size_t counter = 0; | ||
std::string chr, pos1, pos2, f; | ||
std::istringstream iss_line(line); | ||
std::string val; | ||
|
||
if (line.find("#") == std::string::npos) { | ||
while(std::getline(iss_line, val, '\t')) { | ||
switch (counter) { | ||
case 0 : chr = val; break; | ||
case 1 : pos1 = val; break; | ||
case 2 : pos2 = val; break; | ||
case 3 : f = val; break; | ||
} | ||
if (counter >= 3) | ||
break; | ||
++counter; | ||
|
||
if (chr != curr_chr) { | ||
//std::cerr << "...reading from BED - chr" << chr << std::endl; | ||
curr_chr = chr; | ||
} | ||
|
||
} | ||
|
||
// construct the GenomicRegion | ||
FracRegion ff(chr, pos1, pos2, h, f); | ||
|
||
if (ff.valid()) { | ||
//gr.pad(pad); | ||
//m_grv.push_back(gr); | ||
m_frc.add(ff); | ||
} | ||
|
||
//} | ||
} // end "keep" conditional | ||
} // end main while | ||
|
||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef SNOWMAN_FRACTIONS_H__ | ||
#define SNOWMAN_FRACTIONS_H__ | ||
|
||
#include "SnowTools/GenomicRegionCollection.h" | ||
#include <string> | ||
|
||
namespace SnowTools { | ||
|
||
class FracRegion : public SnowTools::GenomicRegion { | ||
|
||
public: | ||
|
||
FracRegion() {} | ||
|
||
FracRegion(const std::string& c, const std::string& p1, const std::string& p2, bam_hdr_t * h, const std::string& f); | ||
|
||
friend std::ostream& operator<<(std::ostream& out, const FracRegion& f); | ||
|
||
double frac; | ||
}; | ||
|
||
class Fractions { | ||
|
||
public: | ||
|
||
Fractions() {} | ||
|
||
size_t size() const; | ||
|
||
void readFromBed(const std::string& file, bam_hdr_t * h) ; | ||
|
||
SnowTools::GenomicRegionCollection<FracRegion> m_frc; | ||
|
||
private: | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |