84 const string &url_prefix,
const string &alt_prefix,
const bool is_html )
86 const char * pchPrefix =
"";
90 const string &
id = *str_iter;
95 if( is_html && ! url_prefix.empty() ) {
96 string url = url_prefix;
100 url =
"https://www.ncbi.nlm.nih.gov/Traces/sra/sra.cgi?analysis=";
102 result <<
"<a href=\"" << url <<
id <<
"\">";
105 if( is_html && ! url_prefix.empty() ) {
117 const char * pchPrefix =
"";
121 if( *int_iter == 0 ) {
126 pchPrefix = separator.c_str();
132 struct SDBLinkLineLessThan {
133 bool operator()(
const string &
line1,
const string &
line2 ) {
134 const int line1_prefix_order = x_GetPrefixOrder(
line1);
135 const int line2_prefix_order = x_GetPrefixOrder(
line2);
136 if( line1_prefix_order != line2_prefix_order ) {
137 return (line1_prefix_order < line2_prefix_order);
146 int x_GetPrefixOrder(
const string & line)
149 const static int kDefaultPrefixOrder =
kMax_Int;
152 string::size_type colon_pos = line.find(
':');
153 if( colon_pos == string::npos ) {
154 return kDefaultPrefixOrder;
157 const string sPrefix = line.substr(0, colon_pos);
161 static const TPrefixElem sc_prefix_map[] = {
166 {
"BioProject", 10 },
169 {
"Sequence Read Archive", 40 },
170 {
"Trace Assembly Archive", 60 }
175 TPrefixMap::const_iterator find_iter = sc_PrefixMap.find(sPrefix.c_str());
176 if( find_iter == sc_PrefixMap.end() ) {
178 return kDefaultPrefixOrder;
181 return find_iter->second;
185 struct SDbLinkLabelInfo {
194 const bool bHtml =
ctx.Config().DoHTML();
208 if (! genome_projects_user_obje) {
209 genome_projects_user_obje = &uo;
213 if (! dblink_user_obj) {
214 dblink_user_obj = &uo;
221 if( genome_projects_user_obje !=
NULL ) {
234 static const TDbLinkLabelToInfo kDbLinkLabelToInfo[] = {
235 {
"Assembly", {
true,
false,
"https://www.ncbi.nlm.nih.gov/assembly/" } },
236 {
"BioProject", {
true,
false,
"https://www.ncbi.nlm.nih.gov/bioproject/" } },
237 {
"BioSample", {
true,
false,
"https://www.ncbi.nlm.nih.gov/biosample/" } },
238 {
"ProbeDB", {
true,
false,
"" } },
239 {
"Sequence Read Archive", {
true,
false,
"https://www.ncbi.nlm.nih.gov/sra/" } },
240 {
"Trace Assembly Archive", {
false,
true,
"" } }
248 vector<string> dblinkLines;
249 if( dblink_user_obj !=
NULL ) {
255 TDbLinkLabelToInfoMap::const_iterator find_iter =
256 kDbLinkLabelToInfoMap.find(
label.c_str());
257 if( find_iter == kDbLinkLabelToInfoMap.end() ) {
261 const char * pchNormalizedDbLinkLabel = find_iter->first;
262 const SDbLinkLabelInfo & dbLinkLabelInfo = find_iter->second;
265 const TFieldData & field_data = field.
GetData();
267 if( dbLinkLabelInfo.allow_text &&
268 (field_data.IsStrs() || field_data.IsStr()) )
270 const TFieldData::TStrs * pStrs =
NULL;
274 unique_ptr<TFieldData::TStrs> pStrsDestroyer;
276 if( field_data.IsStrs() ) {
277 pStrs = & field_data.GetStrs();
280 pStrsDestroyer.reset(
new TFieldData::TStrs );
281 pStrsDestroyer->push_back( field_data.GetStr() );
282 pStrs = pStrsDestroyer.get();
287 alt_url =
"https://www.ncbi.nlm.nih.gov/Traces/sra/sra.cgi?analysis=";
290 *pStrs, dbLinkLabelInfo.url, alt_url, bHtml );
291 if( ! dblinkValue.empty() ) {
292 dblinkLines.push_back(
293 pchNormalizedDbLinkLabel +
string(
": ") + dblinkValue );
299 }
else if( dbLinkLabelInfo.allow_numeric &&
300 (field_data.IsInts() || field_data.IsInt()) )
303 const TFieldData::TInts * pInts =
NULL;
305 unique_ptr<TFieldData::TInts> pIntsDestroyer;
307 if( field_data.IsInts() ) {
308 pInts = & field_data.GetInts();
309 }
else if( field_data.IsInt() ) {
310 pIntsDestroyer.reset(
new TFieldData::TInts );
311 pIntsDestroyer->push_back( field_data.GetInt() );
312 pInts = pIntsDestroyer.get();
316 if( ! dblinkValue.empty() ) {
317 dblinkLines.push_back(
318 pchNormalizedDbLinkLabel +
string(
": ") +
325 sort( dblinkLines.begin(), dblinkLines.end(), SDBLinkLineLessThan() );
void x_SetObject(const CSerialObject &obj)
EItem GetItemType() const override
void Format(IFormatter &formatter, IFlatTextOStream &text_os) const override
vector< int > m_ProjectNumbers
TDBLinkLineVec m_DBLinkLines
const TDBLinkLineVec & GetDBLinkLines(void) const
vector< TDBLinkLine > TDBLinkLineVec
const vector< int > & GetProjectNumbers(void) const
void x_GatherInfo(CBioseqContext &ctx) override
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
class CStaticArrayMap<> provides access to a static array in much the same way as CStaticArraySet<>,...
class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined a...
Include a standard set of the NCBI C++ Toolkit most basic headers.
static string s_JoinNumbers(const CUser_field_Base::C_Data::TInts &ints, const string &separator)
static string s_JoinLinkableStrs(const CUser_field_Base::C_Data::TStrs &strs, const string &url_prefix, const string &alt_prefix, const bool is_html)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
static const char label[]
bool IsStr(void) const
Check if variant Str is selected.
const TData & GetData(void) const
Get the Data member data.
bool CanGetData(void) const
Check if it is safe to call GetData method.
bool IsSetLabel(void) const
field label Check if a value has been assigned to Label data member.
const TStr & GetStr(void) const
Get the variant data.
TInt GetInt(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
const TLabel & GetLabel(void) const
Get the Label member data.
const TType & GetType(void) const
Get the Type member data.
vector< CStringUTF8 > TStrs
vector< CRef< CUser_field > > TData
@ e_User
user defined object
constexpr auto sort(_Init &&init)
constexpr bool empty(list< Ts... >) noexcept
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
void TryToSanitizeHtml(std::string &str)
#define DEFINE_STATIC_ARRAY_MAP(Type, Var, Array)
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
static char line1[1024 *16]
static char line2[1024 *16]