Skip to content

Commit

Permalink
Merge pull request #14 from vdanjean/master
Browse files Browse the repository at this point in the history
Fix a deadlock with multi threads and various improvement proposed
  • Loading branch information
sfchen authored Feb 6, 2022
2 parents 3c3d851 + 281c5ea commit 26684b3
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 896 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ mutscan
*.o
*.obj

# Dependency files
*.d

# Precompiled Headers
*.gch
*.pch
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ TARGET = mutscan
BIN_TARGET = ${TARGET}

CC = g++
CPPFLAGS = -Wall
CFLAGS = -std=c++11 -g -I${DIR_INC}

${BIN_TARGET}:${OBJ}
$(CC) $(OBJ) -lz -lpthread -o $@

${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp make_obj_dir
$(CC) $(CFLAGS) -O3 -c $< -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp
@mkdir -p "${DIR_OBJ}"
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -O3 -c $< -o $@

-include $(wildcard ${DIR_OBJ}/*.d)

.PHONY:clean
clean:
rm obj/*.o
rm obj/*.d
rm mutscan

make_obj_dir:
@if test ! -d $(DIR_OBJ) ; \
then \
mkdir $(DIR_OBJ) ; \
fi

install:
install $(TARGET) $(BINDIR)/$(TARGET)
@echo "Installed."
install $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
@echo "Installed."
12 changes: 6 additions & 6 deletions src/editdistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ unsigned int edit_distance_bpv(T &cmap, char const *vec, size_t const &vecsize,
for(size_t i = 0; i < tlen; ++i) VP[tmax] |= (1L << i);
for(size_t i = 0; i < vecsize; ++i) {
TVALUE &PM = cmap[vec[i]];
for(int r = 0; r <= tmax; ++r) {
for(unsigned int r = 0; r <= tmax; ++r) {
uint64_t X = PM[r];
if(r > 0 && (HN[r - 1] & lmb)) X |= 1L;
D0[r] = (((X & VP[r]) + VP[r]) ^ VP[r]) | X | VN[r];
Expand All @@ -65,10 +65,10 @@ unsigned int edit_distance_bpv(T &cmap, char const *vec, size_t const &vecsize,
template<typename T>
unsigned int edit_distance_dp(T const *str1, size_t const size1, T const *str2, size_t const size2) {
vector< vector<uint32_t> > d(size1 + 1, vector<uint32_t>(size2 + 1));
for (int i = 0; i < size1 + 1; i++) d[i][0] = i;
for (int i = 0; i < size2 + 1; i++) d[0][i] = i;
for (int i = 1; i < size1 + 1; i++) {
for (int j = 1; j < size2 + 1; j++) {
for (size_t i = 0; i < size1 + 1; i++) d[i][0] = i;
for (size_t i = 0; i < size2 + 1; i++) d[0][i] = i;
for (size_t i = 1; i < size1 + 1; i++) {
for (size_t j = 1; j < size2 + 1; j++) {
d[i][j] = min(min(d[i-1][j], d[i][j-1]) + 1, d[i-1][j-1] + (str1[i-1] == str2[j-1] ? 0 : 1));
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ unsigned int edit_distance(string a, string b) {

unsigned int hamming_distance(const char *a, const unsigned int asize, const char *b, const unsigned int bsize) {
int dis = 0;
for(int i=0; i<min(asize, bsize); i++) {
for(unsigned int i=0; i<min(asize, bsize); i++) {
if(a[i]!=b[i])
dis++;
}
Expand Down
22 changes: 11 additions & 11 deletions src/htmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void HtmlReporter::printHelper() {
void HtmlReporter::printMutations() {
// calculate the found mutation
int found = 0;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
vector<Match*> matches = mMutationMatches[i];
if(matches.size()>=GlobalSettings::minReadSupport){
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport){
found++;
}
}
Expand All @@ -56,9 +56,9 @@ void HtmlReporter::printMutations() {
if(found>1)
mFile<<"s";
mFile<<":</p><ul>";
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
vector<Match*> matches = mMutationMatches[i];
if(matches.size()>=GlobalSettings::minReadSupport){
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport){
id++;
mFile<<"<li class='menu_item'><a href='#"<<mMutationList[i].mName<<"'> " << id << ", " << mMutationList[i].mName;
mFile<< " (" << matches.size() << " reads support, " << Match::countUnique(matches) << " unique)" << "</a></li>";
Expand All @@ -67,9 +67,9 @@ void HtmlReporter::printMutations() {
mFile<<"</ul></div>";
}
id=0;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
vector<Match*> matches = mMutationMatches[i];
if(matches.size()>=GlobalSettings::minReadSupport){
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport){
id++;
printMutation(id, mMutationList[i], matches);
}
Expand All @@ -80,11 +80,11 @@ void HtmlReporter::printMutationsJS() {
mFile << "\n<script type=\"text/javascript\">" << endl;
mFile << "var data_break = [";
int id=0;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
vector<Match*> matches = mMutationMatches[i];
if(matches.size()>=GlobalSettings::minReadSupport){
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport){
mFile << "\n[";
for(int m=0; m<matches.size(); m++){
for(size_t m=0; m<matches.size(); m++){
mFile << "\n[";
matches[m]->printJS(mFile, mMutationList[i].mLeft.length(), mMutationList[i].mCenter.length(), mMutationList[i].mRight.length());
mFile << "],";
Expand Down Expand Up @@ -140,7 +140,7 @@ void HtmlReporter::printMutation(int id, Mutation& mutation, vector<Match*>& mat
mFile << "<td>" << mutation.mRight << "</td>";
mFile << "<td>" << "" << "</td>";
mFile << "</tr>";
for(int m=0; m<matches.size(); m++){
for(size_t m=0; m<matches.size(); m++){
long rowid = id*100000 + m;
if(!GlobalSettings::simplifiedMode)
mFile << "<tr onclick='toggle(" << rowid << ");'>";
Expand Down Expand Up @@ -266,7 +266,7 @@ void HtmlReporter::printScanTargets(){
mFile << "<p> scanned " << mMutationList.size() << " mutation spots...<input type='button' id='target_view_btn', onclick=toggle_target_list('target_list'); value='show'></input></p>";
mFile << "<ul id='target_list' style='display:none'>";
int id=0;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
id++;
mFile<<"<li> " << id << ", " << mMutationList[i].mName << "</li>";
}
Expand Down
6 changes: 3 additions & 3 deletions src/jsonreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ void JsonReporter::run() {
mFile << "\t\"mutations\":{";

bool isFirstMut = true;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
Mutation mut = mMutationList[i];
vector<Match*> matches = mMutationMatches[i];
if(matches.size()>=GlobalSettings::minReadSupport){
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport){
if(isFirstMut) {
mFile << endl;
isFirstMut = false;
Expand All @@ -40,7 +40,7 @@ void JsonReporter::run() {
mFile << "\t\t\t\"" << "chr" << "\":" << "\"" << mut.mChr << "\"," << endl;
mFile << "\t\t\t\"" << "ref" << "\":[" << "\"" << mut.mLeft << "\"," << "\"" << mut.mCenter << "\"," << "\"" << mut.mRight << "\"]," << endl;
mFile << "\t\t\t\"" << "reads" << "\":[" << endl;
for(int m=0; m<matches.size(); m++){
for(size_t m=0; m<matches.size(); m++){
mFile << "\t\t\t\t{" << endl;
mFile << "\t\t\t\t\t\"breaks\":";
matches[m]->printBreaksToJson(mFile, mut.mLeft.length(), mut.mCenter.length(), mut.mRight.length());
Expand Down
8 changes: 4 additions & 4 deletions src/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Match::~Match(){
// we don't delete mRead or mSequence here since they are shared by different objects
// and will be deleted in other places
if(mOriginalReads) {
for(int i=0;i<mOriginalReads->size();i++){
for(size_t i=0;i<mOriginalReads->size();i++){
delete (*mOriginalReads)[i];
(*mOriginalReads)[i] = NULL;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ void Match::printBreaksToJson(ofstream& file, int leftlen, int centerlen, int ri
breaks.push_back( mPos+centerlen );
breaks.push_back( min(mPos+centerlen+rightlen, mReadLen));
file << "[";
for(int i=0; i<breaks.size(); i++) {
for(size_t i=0; i<breaks.size(); i++) {
file << breaks[i];
if(i!=breaks.size() - 1)
file << ",";
Expand Down Expand Up @@ -149,7 +149,7 @@ void Match::printJS(ofstream& file, int leftlen, int centerlen, int rightlen) {
void Match::printReadsToFile(ofstream& file){
if(!mOriginalReads)
return;
for(int i=0;i<mOriginalReads->size();i++){
for(size_t i=0;i<mOriginalReads->size();i++){
(*mOriginalReads)[i]->printFile(file);
}
}
Expand All @@ -163,7 +163,7 @@ int Match::countUnique(vector<Match*>& matches) {
return 0;
int count = 1;
Match* cur = matches[0];
for(int i=1;i<matches.size();i++){
for(size_t i=1;i<matches.size();i++){
Match* m = matches[i];
if( *m > *cur || *m < *cur) {
cur = m;
Expand Down
12 changes: 11 additions & 1 deletion src/match.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Match{
void setReversed(bool flag);
void addOriginalRead(Read* r);
void addOriginalPair(ReadPair* pair);
template <class ReadData> void addOriginalReadData(ReadData* r);
int readlength() const;

inline bool operator <(const Match& other) const
Expand Down Expand Up @@ -62,5 +63,14 @@ class Match{
char mMeanQual;
};

template <>
inline void Match::addOriginalReadData<Read> (Read* r) {
addOriginalRead(r);
}

#endif
template <>
inline void Match::addOriginalReadData<ReadPair> (ReadPair* pair) {
addOriginalPair(pair);
}

#endif
18 changes: 9 additions & 9 deletions src/multihtmlreporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ MultiHtmlReporter::~MultiHtmlReporter(){

void MultiHtmlReporter::stat(){
mTotalCount = 0;
for(int m=0; m<mMutationList.size(); m++) {
for(size_t m=0; m<mMutationList.size(); m++) {
vector<Match*> matches = mMutationMatches[m];
if(matches.size()>=GlobalSettings::minReadSupport) {
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport) {
mTotalCount++;
string chr = mMutationList[m].mChr;
if(mChrCount.count(chr)==0)
Expand Down Expand Up @@ -69,9 +69,9 @@ void MultiHtmlReporter::printAllChromosomeLink(ofstream& file) {
map<string, int>::iterator iter;
file << "<ul id='menu'>";
file << "<div style='font-size:12px;padding-top:20px;text-align:left;color:#aaaaaa'>Mutations found of all chromosomes:</div>";
for(int m=0; m<mMutationList.size(); m++) {
for(size_t m=0; m<mMutationList.size(); m++) {
vector<Match*> matches = mMutationMatches[m];
if(matches.size()>=GlobalSettings::minReadSupport) {
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport) {
found = true;
string chr = mMutationList[m].mChr;
string filename = chr + "/" + to_string(m) + ".html";
Expand All @@ -88,9 +88,9 @@ void MultiHtmlReporter::printAllChromosomeLink(ofstream& file) {

void MultiHtmlReporter::printChrLink(ofstream& file, string chr) {
bool found = false;
for(int m=0; m<mMutationList.size(); m++) {
for(size_t m=0; m<mMutationList.size(); m++) {
vector<Match*> matches = mMutationMatches[m];
if(matches.size()>=GlobalSettings::minReadSupport) {
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport) {
found = true;
if(chr == mMutationList[m].mChr) {
string filename = chr + "/" + to_string(m) + ".html";
Expand All @@ -106,9 +106,9 @@ void MultiHtmlReporter::printChrLink(ofstream& file, string chr) {
}

void MultiHtmlReporter::printMutationHtml() {
for(int m=0; m<mMutationList.size(); m++) {
for(size_t m=0; m<mMutationList.size(); m++) {
vector<Match*> matches = mMutationMatches[m];
if(matches.size()>=GlobalSettings::minReadSupport) {
if((ssize_t)matches.size()>=GlobalSettings::minReadSupport) {
string chr = mMutationList[m].mChr;
string folder = mFolderPath + "/" + chr;
string filename = folder + "/" + to_string(m) + ".html";
Expand Down Expand Up @@ -262,7 +262,7 @@ void MultiHtmlReporter::printScanTargets(ofstream& file){
file << "<p> scanned " << mMutationList.size() << " mutation spots...<input type='button' id='target_view_btn', onclick=toggle_target_list('target_list'); value='show'></input></p>";
file << "<ul id='target_list' style='display:none'>";
int id=0;
for(int i=0;i<mMutationList.size();i++){
for(size_t i=0;i<mMutationList.size();i++){
id++;
file<<"<li> " << id << ", " << mMutationList[i].mName << "</li>";
}
Expand Down
6 changes: 3 additions & 3 deletions src/mutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ vector<Mutation> Mutation::parseBuiltIn() {
vector<Mutation> mutations;
vector<string> lines;
split(BUILT_IN_MUTATIONS, lines, "\n");
for(int i=0;i<lines.size();i++){
for(size_t i=0;i<lines.size();i++){
string linestr = lines[i];
vector<string> splitted;
split(linestr, splitted, ",");
Expand Down Expand Up @@ -228,7 +228,7 @@ vector<Mutation> Mutation::parseVcf(string vcfFile, string refFile) {
fr.readAll();
map<string, string> ref = fr.contigs();

for(int i=0;i<variants.size();i++) {
for(size_t i=0;i<variants.size();i++) {
Variant& v = variants[i];
// skip the unmasked if markedOnly flag is set true
if(markedOnly && (v.filter!="m" && v.filter!="M"))
Expand All @@ -248,7 +248,7 @@ vector<Mutation> Mutation::parseVcf(string vcfFile, string refFile) {
}
// the variant is out of this contig, or in the front or tail
// note that VCF is 1-based, and string is 0-based
if(v.pos > ref[chrom].length() + 25 + v.ref.length() || v.pos < 25 + v.ref.length())
if((size_t)v.pos > ref[chrom].length() + 25 + v.ref.length() || (size_t)v.pos < 25 + v.ref.length())
continue;

string gene = v.gene();
Expand Down
Loading

0 comments on commit 26684b3

Please sign in to comment.