00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGA_TOOLS_JUNCTION_VCF_WRITER_HPP_
00016 #define CGA_TOOLS_JUNCTION_VCF_WRITER_HPP_
00017
00020
00021
00022
00023 #include "cgatools/core.hpp"
00024 #include "cgatools/junctions/Junction.hpp"
00025 #include "cgatools/junctions/JunctionCompare.hpp"
00026
00027
00028 #include <string>
00029 #include <vector>
00030 #include <map>
00031 #include <set>
00032
00033
00034 #include <boost/shared_ptr.hpp>
00035
00036 namespace cgatools { namespace junctions {
00037
00040 typedef std::map<std::string, junctions::JunctionRefs> JunctionCompatMap;
00041
00043 typedef std::vector<JunctionCompatMap> JunctionCompatMapPerFile;
00044
00046 typedef std::set<JunctionRef> JunctionRefSet;
00047
00049 struct JunctionRefSide
00050 {
00051 JunctionRef jr_;
00052 size_t side_;
00053
00054 JunctionRefSide(const JunctionRef& jr, size_t side)
00055 : jr_(jr), side_(side)
00056 {}
00057
00058 bool operator<(const JunctionRefSide& b) const
00059 {
00060 reference::Location
00061 apos = jr_.it_->sideSections_ [ side_].getBasePos(side_),
00062 bpos = b.jr_.it_->sideSections_[b.side_].getBasePos(b.side_);
00063 if (apos != bpos)
00064 return apos < bpos;
00065 else
00066 return side_ < b.side_;
00067 }
00068 };
00069
00070
00071 class JunctionVcfWriter
00072 {
00073 public:
00074
00075 JunctionVcfWriter ( boost::shared_ptr<reference::CrrFile> ref,
00076 boost::shared_ptr<junctions::JunctionFiles> junctionFiles );
00077
00078 std::string fileFieldSeparator_;
00079 size_t filterScoreThreshold_;
00080 size_t filterSideLength_;
00081
00082
00084 void writeJunctionVcfHeaders(std::ostream& out) const;
00085
00089 std::string createJunctionVcfId( const JunctionRef& jref, size_t side) const;
00090
00091
00096 std::string formatPositionForVcf( reference::Location pos, const std::string& sep ) const;
00097
00098 void writeJunctionPositionToVcf( const junctions::JunctionSideSection& jss,
00099 size_t side, std::ostream& out) const;
00100
00101
00115 void writeJunctionAltFieldToVcf(const JunctionRef& jref,
00116 size_t side, std::ostream& out, bool suppressChrom=false) const;
00117
00122 std::string convertMobileElementToVcf(const std::string& med) const;
00123
00128 void writeJunctionInfoFieldToVcf(const JunctionRef& jref,
00129 size_t side, std::ostream& out) const;
00130
00136 void addFilterFlag( std::ostream& out, const std::string& flag, bool& filtered) const;
00137
00142 void writeJunctionFilterFieldToVcf( const JunctionRef& jref, std::ostream& out) const;
00143
00145 void writeJunctionComparisonField( const JunctionRef& jref, size_t side,
00146 std::ostream& out) const;
00147
00151 void writeJunctionToVcf( const JunctionRef& jref, size_t side,
00152 const JunctionCompatMapPerFile& compat,
00153 std::ostream& out) const;
00154
00155 protected:
00156
00157 JunctionVcfWriter();
00158
00160 void init();
00161
00162 boost::shared_ptr<reference::CrrFile> reference_;
00163 boost::shared_ptr<junctions::JunctionFiles> junctionFiles_;
00164 std::vector<std::string> sampleIds_;
00165 };
00166
00167 }}
00168
00169
00170 #endif //CGA_TOOLS_JUNCTION_VCF_WRITER_HPP_
00171