Permalink
Browse files

Change indents

  • Loading branch information...
Giles Miclotte
Giles Miclotte committed Mar 2, 2016
1 parent d9df760 commit 7a38f5323bedfafc967a2cd575254dadb94a3f49
View
@@ -4,7 +4,7 @@ project (Jabba)
# project version
set (${PROJECT_NAME}_MAJOR_VERSION 1)
set (${PROJECT_NAME}_MINOR_VERSION 1)
set (${PROJECT_NAME}_MINOR_VERSION 0)
set (${PROJECT_NAME}_PATCH_LEVEL 0)
add_definitions("-DJABBA_MAJOR_VERSION=${${PROJECT_NAME}_MAJOR_VERSION}")
add_definitions("-DJABBA_MINOR_VERSION=${${PROJECT_NAME}_MINOR_VERSION}")
View
@@ -26,151 +26,144 @@
#include "Graph.hpp"
AlignedRead::AlignedRead(Read &read, OutputMode output_mode)
: read_(read),
output_mode_(output_mode)
: read_(read),
output_mode_(output_mode)
{}
std::vector<std::pair<int, int>> AlignedRead::not_corrected() {
sortAlongRead();
std::vector<std::pair<int, int>> nc;
int curr_pos = 0;
int curr_al = 0;
while (curr_pos < read_.size()) {
int next_pos;
if (curr_al < local_alignments_.size()) {
next_pos = local_alignments_[curr_al].get_read_start();
} else {
next_pos = read_.size();
}
if (curr_pos < next_pos) {
nc.push_back(std::pair<int, int> (curr_pos, next_pos));
curr_pos = next_pos;
}
if (curr_al < local_alignments_.size()) {
curr_pos = local_alignments_[curr_al].get_read_end();
}
++curr_al;
}
return nc;
sortAlongRead();
std::vector<std::pair<int, int>> nc;
int curr_pos = 0;
int curr_al = 0;
while (curr_pos < read_.size()) {
int next_pos;
if (curr_al < local_alignments_.size()) {
next_pos = local_alignments_[curr_al].get_read_start();
} else {
next_pos = read_.size();
}
if (curr_pos < next_pos) {
nc.push_back(std::pair<int, int> (curr_pos, next_pos));
curr_pos = next_pos;
}
if (curr_al < local_alignments_.size()) {
curr_pos = local_alignments_[curr_al].get_read_end();
}
++curr_al;
}
return nc;
}
void AlignedRead::correct(std::vector<LocalAlignment> const &als) {
for (int i = 0; i < als.size(); ++i) {
correct(als[i]);
}
for (int i = 0; i < als.size(); ++i) {
correct(als[i]);
}
}
void AlignedRead::correct(LocalAlignment const &al) {
local_alignments_.push_back(al);
local_alignments_.push_back(al);
}
void AlignedRead::sortAlongRead() {
auto sort_alignments =
[&](LocalAlignment a, LocalAlignment b)-> bool
{
return a.get_read_start() < b.get_read_start();
};
std::sort(local_alignments_.begin(), local_alignments_.end(), sort_alignments);
auto sort_alignments =
[&](LocalAlignment a, LocalAlignment b)-> bool
{
return a.get_read_start() < b.get_read_start();
};
std::sort(local_alignments_.begin(), local_alignments_.end(), sort_alignments);
}
void AlignedRead::sortReadCov() {
auto sort_alignments =
[&](LocalAlignment a, LocalAlignment b)-> bool
{
return a.get_read_end() - a.get_read_start() < b.get_read_end() - b.get_read_start();
};
std::sort(local_alignments_.begin(), local_alignments_.end(), sort_alignments);
auto sort_alignments =
[&](LocalAlignment a, LocalAlignment b)-> bool
{
return a.get_read_end() - a.get_read_start() < b.get_read_end() - b.get_read_start();
};
std::sort(local_alignments_.begin(), local_alignments_.end(), sort_alignments);
}
bool AlignedRead::fit(std::vector<int>::iterator const &index,
std::vector<int> const &lai, std::vector<int> const & laj)
std::vector<int> const &lai, std::vector<int> const & laj)
{
if (index != laj.end()) {
int d = index - laj.begin() + 1;
d = d < lai.size() ? d : lai.size();
for (int k = 1; k < d + 1; ++k) {
if (lai[lai.size() - k] != laj[d - k]) {
return false;
}
}
return true;
} else {
return false;
}
if (index != laj.end()) {
int d = index - laj.begin() + 1;
d = d < lai.size() ? d : lai.size();
for (int k = 1; k < d + 1; ++k) {
if (lai[lai.size() - k] != laj[d - k]) {
return false;
}
}
return true;
} else {
return false;
}
}
bool AlignedRead::merge() {
sortAlongRead();
for (int i = 0; i < local_alignments_.size(); ++i) {
std::vector<int> lai = local_alignments_[i].get_path();
for (int j = 0; j < local_alignments_.size(); ++j) {
if (i == j) {
continue;
}
std::vector<int> laj = local_alignments_[j].get_path();
std::vector<int>::iterator index;
index = std::find(laj.begin(), laj.end(), lai.back());
if (fit(index, lai, laj)) {
lai.insert(lai.end(), index + 1, laj.end());
local_alignments_[i].set_path(lai);
int read_start = local_alignments_[i].get_read_start();
int read_end = local_alignments_[j].get_read_end();
int ref_start = local_alignments_[i].get_ref_start();
int ref_size = read_end - read_start;
if (ref_size < 0) {
break;
}
//std::cout << "Merged: " << read_start << " " << read_end << " " << ref_start << " " << ref_size << std::endl;
local_alignments_[i].set_read_end(read_end);
local_alignments_[i].set_ref_end(ref_start + ref_size);
local_alignments_.erase(local_alignments_.begin() + j);
return true;
}
}
}
return false;
sortAlongRead();
for (int i = 0; i < local_alignments_.size(); ++i) {
std::vector<int> lai = local_alignments_[i].get_path();
for (int j = 0; j < local_alignments_.size(); ++j) {
if (i == j) {
continue;
}
std::vector<int> laj = local_alignments_[j].get_path();
std::vector<int>::iterator index;
index = std::find(laj.begin(), laj.end(), lai.back());
if (fit(index, lai, laj)) {
lai.insert(lai.end(), index + 1, laj.end());
local_alignments_[i].set_path(lai);
int read_start = local_alignments_[i].get_read_start();
int read_end = local_alignments_[j].get_read_end();
int ref_start = local_alignments_[i].get_ref_start();
int ref_size = read_end - read_start;
if (ref_size < 0) {
break;
}
local_alignments_[i].set_read_end(read_end);
local_alignments_[i].set_ref_end(ref_start + ref_size);
local_alignments_.erase(local_alignments_.begin() + j);
return true;
}
}
}
return false;
}
void AlignedRead::print() {
for (const auto &la : local_alignments_) {
std::cout << la.to_string(read_.get_id()) << std::endl;
}
for (const auto &la : local_alignments_) {
std::cout << la.to_string(read_.get_id()) << std::endl;
}
}
void AlignedRead::getCorrectedRead(Graph const &graph, std::vector<std::string> &corrections) {
//std::cout << "Local Alignments before merging: " << std::endl;
//print();
while(merge());
//std::cout << "Local Alignments after merging: " << std::endl;
//print();
std::string corrected_read = "";
if (local_alignments_.size() == 0) {
return;//read_.get_sequence();
}
int max_cov = 0;
sortReadCov();
std::vector<LocalAlignment> corrs;
for (const LocalAlignment &la : local_alignments_) {
bool overlaps = false;
for (const LocalAlignment &c : corrs) {
if(la.overlapsOnRead(c)) {
overlaps = true;
continue;
}
}
if(!overlaps) {
corrs.push_back(la);
}
}
for (const LocalAlignment &la : corrs) {
std::string result = graph.concatenateNodes(la.get_path());
if (output_mode_ == LONG) {
corrections.push_back(result);
} else if (output_mode_ == SHORT){
result = result.substr(la.get_ref_start(), la.get_ref_end() - la.get_ref_start());
corrections.push_back(result);
}
}
while(merge());
std::string corrected_read = "";
if (local_alignments_.size() == 0) {
return;
}
int max_cov = 0;
sortReadCov();
std::vector<LocalAlignment> corrs;
for (const LocalAlignment &la : local_alignments_) {
bool overlaps = false;
for (const LocalAlignment &c : corrs) {
if(la.overlapsOnRead(c)) {
overlaps = true;
continue;
}
}
if(!overlaps) {
corrs.push_back(la);
}
}
for (const LocalAlignment &la : corrs) {
std::string result = graph.concatenateNodes(la.get_path());
if (output_mode_ == LONG) {
corrections.push_back(result);
} else if (output_mode_ == SHORT){
result = result.substr(la.get_ref_start(), la.get_ref_end() - la.get_ref_start());
corrections.push_back(result);
}
}
}
View
@@ -32,41 +32,41 @@ class Graph;
struct AlignedRead {
Read &read_; //reference to the read
std::vector<LocalAlignment> local_alignments_; //list of alignments
OutputMode output_mode_;
Read &read_; //reference to the read
std::vector<LocalAlignment> local_alignments_; //list of alignments
OutputMode output_mode_;
public:
/*
* ctors
*/
AlignedRead(Read &read, OutputMode output_mode);
/*
* methods
*/
//getters
std::vector<LocalAlignment> get_local_alignments() {return local_alignments_;}
//setters
void set_local_alignments(std::vector<LocalAlignment> local_alignments) {local_alignments_ = local_alignments;}
//get a list of all regions that have not been corrected
std::vector<std::pair<int, int>> not_corrected();
//add a list of local alignments
void correct(std::vector<LocalAlignment> const &als);
//add a local alignment
void correct(LocalAlignment const &al);
//correct the read based on the longest local alignment
void getCorrectedRead(Graph const &graph,
std::vector<std::string> &corrections);
//sort local_alignments_
void sortAlongRead();
void sortReadCov();
//checks if laj extends lai, overlap ends at index
bool fit(std::vector<int>::iterator const &index,
std::vector<int> const &lai, std::vector<int> const & laj);
//merge local alignments
bool merge();
//print all local alignments
void print();
/*
* ctors
*/
AlignedRead(Read &read, OutputMode output_mode);
/*
* methods
*/
//getters
std::vector<LocalAlignment> get_local_alignments() {return local_alignments_;}
//setters
void set_local_alignments(std::vector<LocalAlignment> local_alignments) {local_alignments_ = local_alignments;}
//get a list of all regions that have not been corrected
std::vector<std::pair<int, int>> not_corrected();
//add a list of local alignments
void correct(std::vector<LocalAlignment> const &als);
//add a local alignment
void correct(LocalAlignment const &al);
//correct the read based on the longest local alignment
void getCorrectedRead(Graph const &graph,
std::vector<std::string> &corrections);
//sort local_alignments_
void sortAlongRead();
void sortReadCov();
//checks if laj extends lai, overlap ends at index
bool fit(std::vector<int>::iterator const &index,
std::vector<int> const &lai, std::vector<int> const & laj);
//merge local alignments
bool merge();
//print all local alignments
void print();
};
#endif
View
@@ -1,6 +1,5 @@
/***************************************************************************
* Copyright (C) 2014, 2015 Jan Fostier (jan.fostier@intec.ugent.be) *
* Copyright (C) 2014, 2015 Mahdi Heydari (mahdi.heydari@intec.ugent.be) *
* This file is part of Brownie *
* *
* This program is free software; you can redistribute it and/or modify *
Oops, something went wrong.

0 comments on commit 7a38f53

Please sign in to comment.