Skip to content

Commit

Permalink
Save the number of reads and the average read length per library in a…
Browse files Browse the repository at this point in the history
… metadata file
  • Loading branch information
jfostier committed Feb 23, 2016
1 parent 8a4e52b commit aebc8b1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/brownie.cpp
Expand Up @@ -145,6 +145,10 @@ void Brownie::stageOne()
cout << "done (" << Util::stopChronoStr() << ")" << endl;

delete readParser;

// write metadata for all libraries
libraries.writeMetadata(settings.getTempDirectory());

cout << "Stage 1 finished.\n" << endl;
}

Expand Down
33 changes: 33 additions & 0 deletions src/library.cpp
Expand Up @@ -71,6 +71,27 @@ std::ostream &operator<<(std::ostream &out, const FileType &fileType) {
return out;
}

void ReadLibrary::readMetadata(const string& path)
{
ifstream ifs((path + inputFilename + ".met").c_str());
if (!ifs.good())
return;
string line, tmp;
getline(ifs, line);
stringstream(line) >> tmp >> tmp >> tmp >> numReads;
getline(ifs, line);
stringstream(line) >> tmp >> tmp >> tmp >> avgReadLength;
ifs.close();
}

void ReadLibrary::writeMetadata(const string& path) const
{
ofstream ofs((path + inputFilename + ".met").c_str());
ofs << "Number of reads: " << numReads << "\n"
<< "Average read length: " << avgReadLength << endl;
ofs.close();
}

// ============================================================================
// READLIBRARY CLASS
// ============================================================================
Expand Down Expand Up @@ -584,3 +605,15 @@ void LibraryContainer::joinIOThreads()
workBlocks.clear(); // contains only a termination msg
outputBlocks.clear(); // contains only a termination msg
}

void LibraryContainer::readMetadata(const string& path)
{
for (auto& it : container)
it.readMetadata(path);
}

void LibraryContainer::writeMetadata(const string& path) const
{
for (const auto& it : container)
it.writeMetadata(path);
}
24 changes: 24 additions & 0 deletions src/library.h
Expand Up @@ -127,6 +127,18 @@ class ReadLibrary
double getAvgReadLength() const {
return avgReadLength;
}

/**
* Read the metadata to disk
* @param path Path to dir where the metadata should be read
*/
void readMetadata(const std::string& path);

/**
* Write the metadata to disk
* @param path Path to dir where the metadata should be written
*/
void writeMetadata(const std::string& path) const;
};

// ============================================================================
Expand Down Expand Up @@ -387,6 +399,18 @@ class LibraryContainer
* routine is called will result in undefined behavior
*/
void joinIOThreads();

/**
* Read the metadata to disk
* @param path Path to dir where the metadata should be read
*/
void readMetadata(const std::string& path);

/**
* Write the metadata to disk
* @param path Path to dir where the metadata should be written
*/
void writeMetadata(const std::string& path) const;
};

#endif
3 changes: 3 additions & 0 deletions src/settings.cpp
Expand Up @@ -215,4 +215,7 @@ void Settings::parseCommandLineArguments(int argc, char** args,
ofs << args[argc-1] << endl;

ofs.close();

// try to read the metadata for each library
libCont.readMetadata(getTempDirectory());
}

0 comments on commit aebc8b1

Please sign in to comment.