Skip to content

Commit

Permalink
added fractions code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremiah Wala committed Aug 19, 2015
1 parent c278f67 commit 180f755
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 7 deletions.
80 changes: 80 additions & 0 deletions src/Fractions.cpp
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



}

}
6 changes: 6 additions & 0 deletions src/GenomicRegionCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ const T& GenomicRegionCollection<T>::at(size_t i) const
GenomicRegionCollection<GenomicRegion> GenomicRegionCollection<T>::findOverlaps(GenomicRegionCollection<K>& subject, std::vector<int32_t>& query_id, std::vector<int32_t>& subject_id, bool ignore_strand) const
{

#ifdef DEBUG_OVERLAPS
std::cerr << "OVERLAP SUBJECT: " << std::endl;
for (auto& i : subject)
std::cerr << i << std::endl;
#endif

GenomicRegionCollection<GenomicRegion> output;

// loop through the query GRanges (this) and overlap with subject
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ libsnowtools_a_SOURCES = GenomicRegion.cpp Histogram.cpp \
BamWalker.cpp BamStats.cpp MiniRules.cpp gzstream.C SnowUtils.cpp \
gChain.cpp BamRead.cpp gzstream.C BWAWrapper.cpp BamRead.cpp \
AlignedContig.cpp STCoverage.cpp DBSnpFilter.cpp \
BreakPoint.cpp DiscordantCluster.cpp \
BreakPoint.cpp DiscordantCluster.cpp Fractions.cpp \
../bwa/is.c ../bwa/bwtindex.c \
../bwa/bwt_gen.c ../bwa/QSufSort.c \
../bwa/bwt.c ../bwa/bwamem_extra.c \
Expand Down
28 changes: 22 additions & 6 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
top_builddir = ../..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
Expand All @@ -34,7 +34,7 @@ POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
subdir = src
subdir = SnowTools/src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
Expand Down Expand Up @@ -65,7 +65,8 @@ am_libsnowtools_a_OBJECTS = libsnowtools_a-GenomicRegion.$(OBJEXT) \
libsnowtools_a-DBSnpFilter.$(OBJEXT) \
libsnowtools_a-BreakPoint.$(OBJEXT) \
libsnowtools_a-DiscordantCluster.$(OBJEXT) \
libsnowtools_a-is.$(OBJEXT) libsnowtools_a-bwtindex.$(OBJEXT) \
libsnowtools_a-Fractions.$(OBJEXT) libsnowtools_a-is.$(OBJEXT) \
libsnowtools_a-bwtindex.$(OBJEXT) \
libsnowtools_a-bwt_gen.$(OBJEXT) \
libsnowtools_a-QSufSort.$(OBJEXT) libsnowtools_a-bwt.$(OBJEXT) \
libsnowtools_a-bwamem_extra.$(OBJEXT) \
Expand Down Expand Up @@ -183,7 +184,7 @@ libsnowtools_a_SOURCES = GenomicRegion.cpp Histogram.cpp \
BamWalker.cpp BamStats.cpp MiniRules.cpp gzstream.C SnowUtils.cpp \
gChain.cpp BamRead.cpp gzstream.C BWAWrapper.cpp BamRead.cpp \
AlignedContig.cpp STCoverage.cpp DBSnpFilter.cpp \
BreakPoint.cpp DiscordantCluster.cpp \
BreakPoint.cpp DiscordantCluster.cpp Fractions.cpp \
../bwa/is.c ../bwa/bwtindex.c \
../bwa/bwt_gen.c ../bwa/QSufSort.c \
../bwa/bwt.c ../bwa/bwamem_extra.c \
Expand All @@ -203,9 +204,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign SnowTools/src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --foreign src/Makefile
$(AUTOMAKE) --foreign SnowTools/src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
Expand Down Expand Up @@ -245,6 +246,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-BreakPoint.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-DBSnpFilter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-DiscordantCluster.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-Fractions.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-GenomicRegion.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-Histogram.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsnowtools_a-MiniRules.Po@am__quote@
Expand Down Expand Up @@ -485,6 +487,20 @@ libsnowtools_a-DiscordantCluster.obj: DiscordantCluster.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsnowtools_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsnowtools_a-DiscordantCluster.obj `if test -f 'DiscordantCluster.cpp'; then $(CYGPATH_W) 'DiscordantCluster.cpp'; else $(CYGPATH_W) '$(srcdir)/DiscordantCluster.cpp'; fi`

libsnowtools_a-Fractions.o: Fractions.cpp
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsnowtools_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsnowtools_a-Fractions.o -MD -MP -MF "$(DEPDIR)/libsnowtools_a-Fractions.Tpo" -c -o libsnowtools_a-Fractions.o `test -f 'Fractions.cpp' || echo '$(srcdir)/'`Fractions.cpp; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libsnowtools_a-Fractions.Tpo" "$(DEPDIR)/libsnowtools_a-Fractions.Po"; else rm -f "$(DEPDIR)/libsnowtools_a-Fractions.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Fractions.cpp' object='libsnowtools_a-Fractions.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsnowtools_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsnowtools_a-Fractions.o `test -f 'Fractions.cpp' || echo '$(srcdir)/'`Fractions.cpp

libsnowtools_a-Fractions.obj: Fractions.cpp
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsnowtools_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libsnowtools_a-Fractions.obj -MD -MP -MF "$(DEPDIR)/libsnowtools_a-Fractions.Tpo" -c -o libsnowtools_a-Fractions.obj `if test -f 'Fractions.cpp'; then $(CYGPATH_W) 'Fractions.cpp'; else $(CYGPATH_W) '$(srcdir)/Fractions.cpp'; fi`; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libsnowtools_a-Fractions.Tpo" "$(DEPDIR)/libsnowtools_a-Fractions.Po"; else rm -f "$(DEPDIR)/libsnowtools_a-Fractions.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='Fractions.cpp' object='libsnowtools_a-Fractions.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsnowtools_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libsnowtools_a-Fractions.obj `if test -f 'Fractions.cpp'; then $(CYGPATH_W) 'Fractions.cpp'; else $(CYGPATH_W) '$(srcdir)/Fractions.cpp'; fi`

.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
Expand Down
40 changes: 40 additions & 0 deletions src/SnowTools/Fractions.h
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

0 comments on commit 180f755

Please sign in to comment.