Skip to content

Commit

Permalink
reading sequence-region tag from gff
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolmogorov committed Sep 15, 2021
1 parent b8d5ddc commit 607a68b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/maf_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ PermVec parseGff(const std::string& filename, int minBlockLen)
std::cerr << "\tReading GFF file" << std::endl;

std::unordered_map<std::string, Permutation> permBySeqId;
std::unordered_map<std::string, int> sequenceLengths;
//std::unordered_map<std::string, std::vector<Block>> newBlocks;

std::ifstream fin(filename);
Expand All @@ -134,6 +135,16 @@ PermVec parseGff(const std::string& filename, int minBlockLen)
{
std::getline(fin, line);
if (line.empty()) continue;

//reading sequence lengths
if (line.substr(0, 17) == "##sequence-region")
{
auto tokens = split(line, " ");
if (tokens.size() != 4) continue;
int length = atoi(tokens[3].c_str()) - atoi(tokens[2].c_str()) + 1;
sequenceLengths[tokens[1]] = length;
}

if (line[0] == '#') continue;

auto tokens = split(line, "\t");
Expand All @@ -160,6 +171,14 @@ PermVec parseGff(const std::string& filename, int minBlockLen)
permBySeqId[seqName].seqName = seqName;
}

for (auto permIt : permBySeqId)
{
if (sequenceLengths.count(permIt.first))
{
permIt.second.nucLength = sequenceLengths[permIt.first];
}
}

std::vector<Permutation> permutations;
int seqId = 1;
auto cmp = [](const Block& a, const Block& b) {return a.start < b.start;};
Expand Down

0 comments on commit 607a68b

Please sign in to comment.