GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lambda/src/mkindex_misc.hpp at lambda3 · seqan/lambda

Expand file tree

/

mkindex_misc.hpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
146 lines (123 loc) · 5.21 KB
/

mkindex_misc.hpp

Copy path

File metadata and controls

146 lines (123 loc) · 5.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ==========================================================================
// lambda
// ==========================================================================
// Copyright (c) 2013-2024, Hannes Hauswedell <h2 @ fsfe.org>
// Copyright (c) 2016-2020, Knut Reinert and Freie Universität Berlin
// All rights reserved.
//
// This file is part of Lambda.
//
// Lambda is Free Software: you can redistribute it and/or modify it
// under the terms found in the LICENSE[.md|.rst] file distributed
// together with this file.
//
// Lambda is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// ==========================================================================
// mkindex_misc.hpp: misc stuff for indexer
// ==========================================================================
#pragma once
#include <charconv>
#include <filesystem>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <bio/io/txt/reader.hpp>
#include <bio/ranges/to.hpp>
bool setEnv(std::string const & key, std::string const & value)
{
#ifdef PLATFORM_WINDOWS
return !_putenv_s(key.c_str(), value.c_str());
#else
return !setenv(key.c_str(), value.c_str(), true);
#endif
}
// ----------------------------------------------------------------------------
// hashmap type
// ----------------------------------------------------------------------------
struct hash_string
{
using is_transparent = void;
std::size_t operator()(std::string const & v) const { return std::hash<std::string>{}(v); }
std::size_t operator()(char const * v) const { return std::hash<std::string_view>{}(v); }
std::size_t operator()(std::string_view const & v) const { return std::hash<std::string_view>{}(v); }
};
using TaccToIdRank = std::unordered_map<std::string, uint64_t, hash_string, std::equal_to<void>>;
// ----------------------------------------------------------------------------
// function _readMappingFileNCBI
// ----------------------------------------------------------------------------
#if defined(__GNUC__) && __GNUC__ < 11
# define LAMBDA_TO_STR(x) static_cast<std::string>(x)
#else
# define LAMBDA_TO_STR(x) x
#endif
inline void _readMappingFileUniProt(std::filesystem::path const & fileName,
TaccToIdRank const & accToIdRank,
std::vector<std::vector<uint32_t>> & sTaxIds,
std::vector<bool> & taxIdIsPresent)
{
bio::io::txt::reader reader{fileName, '\t'};
for (auto & r : reader)
{
assert(r.fields.size() == 3);
std::string_view acc = r.fields[0];
std::string_view category = r.fields[1];
std::string_view tId = r.fields[2];
if (category == "NCBI_TaxID")
{
if (auto it = accToIdRank.find(LAMBDA_TO_STR(acc)); it != accToIdRank.end())
{
std::vector<uint32_t> & sTaxIdV = sTaxIds[it->second];
uint32_t idNum = 0;
auto [p, ec] = std::from_chars(tId.data(), tId.data() + tId.size(), idNum);
if (ec != std::errc{})
{
std::string msg = "Error: Expected taxonomical ID, but got something I couldn't read: ";
msg += tId;
msg += '\n';
throw std::runtime_error(msg);
}
sTaxIdV.push_back(idNum);
if (taxIdIsPresent.size() < idNum + 1)
taxIdIsPresent.resize(idNum + 1);
taxIdIsPresent[idNum] = true;
}
}
}
}
inline void _readMappingFileNCBI(std::filesystem::path const & fileName,
TaccToIdRank const & accToIdRank,
std::vector<std::vector<uint32_t>> & sTaxIds,
std::vector<bool> & taxIdIsPresent)
{
bio::io::txt::reader reader{fileName, '\t', bio::io::txt::header_kind::first_line};
if (reader.header() != "accession\taccession.version\ttaxid\tgi")
throw std::runtime_error{"Unexpected first line in NCBI taxid file."};
for (auto & r : reader)
{
assert(r.fields.size() == 4);
std::string_view acc = r.fields[0];
std::string_view tId = r.fields[2];
if (auto it = accToIdRank.find(LAMBDA_TO_STR(acc)); it != accToIdRank.end())
{
std::vector<uint32_t> & sTaxIdV = sTaxIds[it->second];
uint32_t idNum = 0;
auto [p, ec] = std::from_chars(tId.data(), tId.data() + tId.size(), idNum);
if (ec != std::errc{})
{
std::string msg = "Error: Expected taxonomical ID, but got something I couldn't read: ";
msg += tId;
msg += '\n';
throw std::runtime_error(msg);
}
sTaxIdV.push_back(idNum);
if (taxIdIsPresent.size() < idNum + 1)
taxIdIsPresent.resize(idNum + 1);
taxIdIsPresent[idNum] = true;
}
}
}
#undef LAMBDA_TO_STR
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.