-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restructured File Detector and Parsing
- Loading branch information
Showing
11 changed files
with
163 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
// | ||
// Created by Richard Albin Schaefer on 11/17/24. | ||
// | ||
|
||
#ifndef GENOGROVE_BEDREADER_HPP | ||
#define GENOGROVE_BEDREADER_HPP | ||
|
||
// Standard | ||
#include <string> | ||
#include <filesystem> | ||
#include <istream> | ||
#include <algorithm> | ||
|
||
// Class | ||
#include "FileReader.hpp" | ||
#include "genogrove/Interval.hpp" | ||
#include "FileEntry.hpp" | ||
|
||
class BEDReader : public FileReader { | ||
public: | ||
BEDReader(const std::filesystem::path&, bool gzipped); | ||
bool readNext(FileEntry& entry) override; | ||
bool hasNext() override; | ||
std::string getErrorMessage() override; | ||
|
||
private: | ||
std::unique_ptr<std::istream> inputStream; | ||
std::string errorMessage; | ||
size_t lineNum; | ||
}; | ||
|
||
#endif //GENOGROVE_BEDREADER_HPP |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
// | ||
// Created by Richard Albin Schaefer on 11/17/24. | ||
// | ||
|
||
#ifndef GENOGROVE_FILEREADER_HPP | ||
#define GENOGROVE_FILEREADER_HPP | ||
|
||
// Class | ||
#include "genogrove/Interval.hpp" | ||
#include "FileEntry.hpp" | ||
|
||
class FileReader { | ||
public: | ||
virtual bool readNext(FileEntry& entry) = 0; | ||
virtual bool hasNext() = 0; | ||
virtual std::string getErrorMessage() = 0; | ||
virtual ~FileReader() = default; | ||
}; | ||
|
||
#endif //GENOGROVE_FILEREADER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
// | ||
// Created by Richard Albin Schaefer on 11/17/24. | ||
// | ||
|
||
#ifndef GENOGROVE_FILEREADERFACTORY_HPP | ||
#define GENOGROVE_FILEREADERFACTORY_HPP | ||
|
||
// Standard | ||
#include <filesystem> | ||
|
||
// Class | ||
#include "FileReader.hpp" | ||
#include "BEDReader.hpp" | ||
#include "FileTypeDetector.hpp" | ||
|
||
class FileReaderFactory { | ||
public: | ||
static std::unique_ptr<FileReader> create( | ||
const std::filesystem::path& filepath, | ||
FileType filetype, | ||
bool gzipped | ||
) { | ||
switch(filetype) { | ||
case FileType::BED: | ||
return std::make_unique<BEDReader>(filepath, gzipped); | ||
default: | ||
return nullptr; | ||
} | ||
} | ||
}; | ||
|
||
#endif //GENOGROVE_FILEREADERFACTORY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,59 @@ | ||
// | ||
// Created by Richard Albin Schaefer on 11/17/24. | ||
// | ||
#include "BEDReader.hpp" | ||
|
||
|
||
BEDReader::BEDReader(const std::filesystem::path& filepath, bool gzipped) { | ||
lineNum = 1; | ||
if(gzipped) { | ||
// open file gzipped | ||
} else { | ||
// inputStream = std::make_unique<std::ifstream>(filepath); | ||
} | ||
} | ||
|
||
bool BEDReader::readNext(FileEntry& entry) { | ||
std::string line; | ||
if(!std::getline(*inputStream, line)) { | ||
errorMessage = "Failed to read line at line " + std::to_string(lineNum); | ||
} | ||
|
||
std::stringstream ss(line); | ||
std::string chrom, start, end; | ||
|
||
try { | ||
if(!(ss >> chrom >> start >> end)) { | ||
errorMessage = "Invalid line format at line " + std::to_string(lineNum); | ||
return false; | ||
} | ||
|
||
// validate integers | ||
if(!std::all_of(start.begin(), start.end(), ::isdigit) || | ||
!std::all_of(end.begin(), end.end(), ::isdigit)) { | ||
errorMessage = "Invalid coordinate format at line " + std::to_string(lineNum); | ||
return false; | ||
} | ||
|
||
// validate and create interval object | ||
size_t startNum = std::stoul(start); | ||
size_t endNum = std::stoul(end); | ||
if(startNum >= endNum) { | ||
errorMessage = "Start coordinate must be less than end coordinate at line " + std::to_string(lineNum); | ||
return false; | ||
} | ||
FileEntry entry(chrom, genogrove::Interval{startNum, endNum}, '\0'); | ||
lineNum++; | ||
return true; | ||
|
||
} catch(std::exception& e) { | ||
errorMessage = "Failed to parse line at line " + std::to_string(lineNum) + ": " + line; | ||
return false; | ||
} | ||
} | ||
|
||
bool BEDReader::hasNext() { | ||
return inputStream && !inputStream->eof(); | ||
} | ||
|
||
std::string BEDReader::getErrorMessage() { | ||
return errorMessage; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.