Skip to content

Commit

Permalink
#279; @Miserlou; output read files as a list in lib_format_counts.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Patro committed Aug 26, 2018
1 parent ef41a8c commit 1380e2b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/ReadExperiment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class ReadExperiment {
errstr.clear();
}

oa(cereal::make_nvp("read_files", rl.readFilesAsString()));
oa(cereal::make_nvp("read_files", rl.readFilesAsVector()));
std::string expectedFormat = rl.format().toString();
oa(cereal::make_nvp("expected_format", expectedFormat));

Expand Down
41 changes: 39 additions & 2 deletions include/ReadLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,39 @@ class ReadLibrary {
return true;
}

std::vector<std::string> readFilesAsVector() {
std::stringstream sstr;
std::vector<std::string> fnames;
if (isPairedEnd()) {
size_t n1 = mateOneFilenames_.size();
size_t n2 = mateTwoFilenames_.size();
if (n1 == 0 or n2 == 0 or n1 != n2) {
sstr << "LIBRARY INVALID --- You must provide #1 and #2 mated read "
"files with a paired-end library type";
fnames.push_back(sstr.str());
} else {
fnames.reserve(n1+n2);
for (size_t i = 0; i < n1; ++i) {
fnames.push_back(mateOneFilenames_[i]);
fnames.push_back(mateTwoFilenames_[i]);
}
}
} else {
size_t n = unmatedFilenames_.size();
if (n == 0) {
sstr << "LIBRARY INVALID --- You must provide unmated read files with "
"a single-end library type";
fnames.push_back(sstr.str());
} else {
for (size_t i = 0; i < n; ++i) {
fnames.push_back(unmatedFilenames_[i]);
}
}
}

return fnames;
}

std::string readFilesAsString() {
std::stringstream sstr;
if (isPairedEnd()) {
Expand All @@ -191,26 +224,30 @@ class ReadLibrary {
sstr << "LIBRARY INVALID --- You must provide #1 and #2 mated read "
"files with a paired-end library type";
} else {
if (n1 > 1) { sstr << "[ "; }
for (size_t i = 0; i < n1; ++i) {
sstr << "( " << mateOneFilenames_[i] << ", " << mateTwoFilenames_[i]
<< " )";
sstr << "[ " << mateOneFilenames_[i] << ", " << mateTwoFilenames_[i]
<< "]";
if (i != n1 - 1) {
sstr << ", ";
}
}
if (n1 > 1) { sstr << " ]"; }
}
} else { // single end
size_t n = unmatedFilenames_.size();
if (n == 0) {
sstr << "LIBRARY INVALID --- You must provide unmated read files with "
"a single-end library type";
} else {
sstr << "[ ";
for (size_t i = 0; i < n; ++i) {
sstr << unmatedFilenames_[i];
if (i != n - 1) {
sstr << ", ";
}
}
sstr << " ]";
}
} // end else
return sstr.str();
Expand Down

0 comments on commit 1380e2b

Please sign in to comment.