Skip to content

Commit

Permalink
source files: update dot begin and end to non-member functions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdavidsmith committed Nov 29, 2023
1 parent 7b0b499 commit 6e9c8b7
Show file tree
Hide file tree
Showing 30 changed files with 606 additions and 586 deletions.
38 changes: 19 additions & 19 deletions src/common/Alphabet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ void
get_base_comp(const vector<string>& sequences, float *base_comp) {
std::fill(base_comp, base_comp + alphabet_size, 0.0);
float total = 0;
for (vector<string>::const_iterator i = sequences.begin();
i != sequences.end(); ++i)
for (string::const_iterator j = i->begin(); j != i->end(); ++j)
for (vector<string>::const_iterator i = begin(sequences);
i != end(sequences); ++i)
for (string::const_iterator j = begin(*i); j != end(*i); ++j)
if (valid_base(*j)) {
base_comp[base2int(*j)]++;
total++;
Expand All @@ -119,63 +119,63 @@ get_base_comp(const vector<string>& sequences, float *base_comp) {
void
get_base_comp(const vector<string>& sequences, vector<float>& base_comp) {
vector<size_t> count(alphabet_size, 0);
for (vector<string>::const_iterator i = sequences.begin();
i != sequences.end(); ++i)
for (string::const_iterator j = i->begin(); j != i->end(); ++j)
for (vector<string>::const_iterator i = begin(sequences);
i != end(sequences); ++i)
for (string::const_iterator j = begin(*i); j != end(*i); ++j)
if (valid_base(*j)) {
count[base2int(*j)]++;
}
const float total = std::accumulate(count.begin(), count.end(), 0.0);
const float total = std::accumulate(begin(count), end(count), 0.0);
base_comp.clear();
transform(count.begin(), count.end(), back_inserter(base_comp),
transform(begin(count), end(count), back_inserter(base_comp),
std::bind(std::divides<float>(), std::placeholders::_1, total));
}


void
get_base_comp(const vector<string>& sequences, vector<double>& base_comp) {
vector<size_t> count(alphabet_size, 0);
for (vector<string>::const_iterator i = sequences.begin();
i != sequences.end(); ++i)
for (string::const_iterator j = i->begin(); j != i->end(); ++j)
for (vector<string>::const_iterator i = begin(sequences);
i != end(sequences); ++i)
for (string::const_iterator j = begin(*i); j != end(*i); ++j)
if (valid_base(*j)) {
count[base2int(*j)]++;
}
const double total = std::accumulate(count.begin(), count.end(), 0.0);
const double total = std::accumulate(begin(count), end(count), 0.0);
base_comp.clear();
transform(count.begin(), count.end(), back_inserter(base_comp),
transform(begin(count), end(count), back_inserter(base_comp),
std::bind(std::divides<double>(), std::placeholders::_1, total));
}


string
reverse_complement(const string& s) {
string r;
transform(s.begin(), s.end(), back_inserter(r), complement);
reverse(r.begin(), r.end());
transform(begin(s), end(s), back_inserter(r), complement);
reverse(begin(r), end(r));
return r;
}


/*string commented out
revcomp(const string& s) {
string r;
transform(s.begin(), s.end(), back_inserter(r), complement);
reverse(r.begin(), r.end());
transform(begin(s), end(s), back_inserter(r), complement);
reverse(begin(r), end(r));
return r;
}*/


size_t
count_valid_bases(const string& s) {
return count_if(s.begin(), s.end(), &valid_base);
return count_if(begin(s), end(s), &valid_base);
}


size_t
count_valid_bases(const vector<string>& s) {
size_t n_valid = 0;
for (vector<string>::const_iterator i = s.begin(); i != s.end(); ++i)
for (vector<string>::const_iterator i = begin(s); i != end(s); ++i)
n_valid += count_valid_bases(*i);
return n_valid;
}
Expand Down
16 changes: 8 additions & 8 deletions src/common/BEDFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ string
UCSCGenomeBrowserHeader::tostring() const {
ostringstream s;
if (!header_lines.empty()) {
copy(header_lines.begin(), header_lines.end() - 1,
copy(begin(header_lines), end(header_lines) - 1,
std::ostream_iterator<string>(s, "\n"));
s << header_lines.back();
}
Expand All @@ -78,7 +78,7 @@ UCSCGenomeBrowserHeader::set_position(const GenomicRegion& region) {
ostringstream ss;
ss << position << "\t"
<< region.get_chrom() << "\t"
<< region.get_start() << "\t" << region.get_end();
<< region.get_start() << "\t" << region.end(get);
header_lines.push_back(ss.str());
}

Expand Down Expand Up @@ -106,7 +106,7 @@ UCSCGenomeBrowserTrack::valid_attributes[] = {

string
UCSCGenomeBrowserTrack::get_attribute(string label) const {
if (attributes.find(label) != attributes.end())
if (attributes.find(label) != end(attributes))
return attributes.find(label)->second;
else return "";
}
Expand Down Expand Up @@ -154,7 +154,7 @@ UCSCGenomeBrowserTrack::tostring() const {
if (!name.empty())
s << " name=" << name;
typedef map<string, string>::const_iterator attr_itr;
for (attr_itr i = attributes.begin(); i != attributes.end(); ++i) {
for (attr_itr i = begin(attributes); i != end(attributes); ++i) {
s << " " << i->first << "=";
const bool print_quotes = (i->second.find(' ') != string::npos ||
i->second.find('\t') != string::npos);
Expand Down Expand Up @@ -353,8 +353,8 @@ ReadBEDTrack(string filename,
the_track = the_tracks.front();

vector<vector<GenomicRegion> >::const_iterator i;
for (i = the_region_sets.begin(); i != the_region_sets.end(); ++i)
the_regions.insert(the_regions.end(), i->begin(), i->end());
for (i = begin(the_region_sets); i != end(the_region_sets); ++i)
the_regions.insert(end(the_regions), begin(*i), end(*i));
}


Expand All @@ -380,8 +380,8 @@ ReadBEDTrack(string filename,
the_track = the_tracks.front();

vector<vector<SimpleGenomicRegion> >::const_iterator i;
for (i = the_region_sets.begin(); i != the_region_sets.end(); ++i)
the_regions.insert(the_regions.end(), i->begin(), i->end());
for (i = begin(the_region_sets); i != end(the_region_sets); ++i)
the_regions.insert(end(the_regions), begin(*i), end(*i));
}


Expand Down
20 changes: 10 additions & 10 deletions src/common/FastaFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ size_t
BigFastaFile::SequenceInfo::count_newlines(size_t range_start,
size_t range_end) const {
vector<size_t>::const_iterator lower =
lower_bound(newlines.begin(), newlines.end(), range_start - start);
lower_bound(cbegin(newlines), cend(newlines), range_start - start);
vector<size_t>::const_iterator upper =
lower_bound(newlines.begin(), newlines.end(), range_end - start);
lower_bound(cbegin(newlines), cend(newlines), range_end - start);
return upper - lower;
}

Expand Down Expand Up @@ -115,7 +115,7 @@ BigFastaFile::make_index(string filename) {

BigFastaFile::SeqInfoIter
BigFastaFile::find_containing_sequence(size_t position) const {
return lower_bound(SequenceTable.begin(), SequenceTable.end(), position);
return lower_bound(begin(SequenceTable), end(SequenceTable), position);
}


Expand All @@ -125,12 +125,12 @@ BigFastaFile::get_names(const size_t chunk_start,
SeqInfoIter start_index = find_containing_sequence(chunk_start);
// SeqInfoIter end_index = (chunk_start + chunk_size < filesize) ?
// find_containing_sequence(chunk_start + chunk_size) + 1 :
// SequenceTable.end();
// end(SequenceTable);

SeqInfoIter end_index = find_containing_sequence(chunk_start + chunk_size);
// This check is needed because the end could be between sequences:
// in the name part
if (end_index != SequenceTable.end() &&
if (end_index != end(SequenceTable) &&
chunk_start + chunk_size > end_index->start)
++end_index;

Expand Down Expand Up @@ -174,12 +174,12 @@ BigFastaFile::get_sequences(const size_t chunk_start,
// chunk
// SeqInfoIter end_index = (chunk_start + chunk_size < filesize) ?
// find_containing_sequence(chunk_start + chunk_size) + 1 :
// SequenceTable.end();
// end(SequenceTable);

SeqInfoIter end_index = find_containing_sequence(chunk_start + chunk_size);
// This check is needed because the end could be between sequences:
// in the name part
if (end_index != SequenceTable.end() &&
if (end_index != end(SequenceTable) &&
chunk_start + chunk_size > end_index->start)
++end_index;

Expand Down Expand Up @@ -293,7 +293,7 @@ vector<string>
FastaFile::get_ids() const {
if (names.empty()) read();
vector<string> ids;
for (vector<string>::iterator i = names.begin(); i != names.end(); ++i)
for (vector<string>::iterator i = begin(names); i != end(names); ++i)
ids.push_back(i->substr(0, i->find_first_of(" \t")));
return ids;
}
Expand All @@ -303,7 +303,7 @@ vector<string>
FastaFile::get_descriptions() const {
if (names.empty()) read();
vector<string> descriptions;
for (vector<string>::iterator i = names.begin(); i != names.end(); ++i) {
for (vector<string>::iterator i = begin(names); i != end(names); ++i) {
const size_t desc_offset = i->find_first_of(" \t");
if (desc_offset != string::npos)
descriptions.push_back(i->substr(desc_offset));
Expand Down Expand Up @@ -418,7 +418,7 @@ FastaFile::base_comp_from_files(const vector<string>& fns,
delete[] buffer;

// get the total number of valid bases
const double total = std::accumulate(count.begin(), count.end(), 0.0);
const double total = std::accumulate(begin(count), end(count), 0.0);
base_comp.clear();
transform(cbegin(count), cend(count), back_inserter(base_comp),
[&](const char x) {return x/total;});
Expand Down
Loading

0 comments on commit 6e9c8b7

Please sign in to comment.