NCBI C++ Toolkit Cross Reference

  C++/src/objtools/format/qualifiers.cpp


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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815
/* $Id: qualifiers.cpp 81277 2018-02-21 01:50:09Z kans $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Aaron Ucko, NCBI * * File Description: * new (early 2003) flat-file generator -- qualifier types * (mainly of interest to implementors) * * =========================================================================== */ #include <ncbi_pch.hpp> #include <corelib/ncbistd.hpp> #include <util/sgml_entity.hpp> #include <serial/enumvalues.hpp> #include <objects/general/Dbtag.hpp> #include <objects/general/Object_id.hpp> #include <objects/pub/Pub.hpp> #include <objects/pub/Pub_set.hpp> #include <objects/seqfeat/Seq_feat.hpp> #include <objects/seqfeat/Cdregion.hpp> #include <objects/seqfeat/BioSource.hpp> #include <objects/seqfeat/Code_break.hpp> #include <objects/seqfeat/Genetic_code_table.hpp> //#include <objects/seqfeat/Gb_qual.hpp> #include <objects/seqfeat/OrgMod.hpp> #include <objects/seqfeat/SubSource.hpp> #include <objects/seq/Seq_inst.hpp> #include <objects/seq/MolInfo.hpp> #include <objects/seq/seqport_util.hpp> #include <objmgr/seq_vector.hpp> #include <objmgr/util/seq_loc_util.hpp> #include <objtools/format/items/qualifiers.hpp> #include <objtools/format/context.hpp> #include <objmgr/util/objutil.hpp> BEGIN_NCBI_SCOPE BEGIN_SCOPE(objects) const string IFlatQVal::kSpace = " "; const string IFlatQVal::kSemicolon = ";"; const string IFlatQVal::kSemicolonEOL = ";\n"; const string IFlatQVal::kComma = ","; const string IFlatQVal::kEOL = "\n"; static bool s_IsNote(IFlatQVal::TFlags flags, CBioseqContext& ctx) { return (flags & IFlatQVal::fIsNote) && !ctx.Config().IsModeDump(); } static bool s_StringIsJustQuotes(const string& str) { ITERATE(string, it, str) { if ( (*it != '"') && (*it != '\'') ) { return false; } } return true; } static string s_GetGOText( const CUser_field& field, const bool is_ftable, const bool is_html) { const string* text_string = NULL, * evidence = NULL, * go_id = NULL, * go_ref = NULL; string temp; int pmid = 0; ITERATE (CUser_field::C_Data::TFields, it, field.GetData().GetFields()) { if ( !(*it)->IsSetLabel() || !(*it)->GetLabel().IsStr() ) { continue; } const string& label = (*it)->GetLabel().GetStr(); const CUser_field::C_Data& data = (*it)->GetData(); if (data.IsStr()) { if (label == "text string") { text_string = &data.GetStr(); } else if (label == "go id") { go_id = &data.GetStr(); } else if (label == "evidence") { evidence = &data.GetStr(); } else if (label == "go ref") { go_ref = &data.GetStr(); } } else if (data.IsInt()) { if (label == "go id") { NStr::IntToString(temp, data.GetInt()); go_id = &temp; } else if (label == "pubmed id") { pmid = data.GetInt(); } } } string go_text; if (text_string != NULL) { go_text = *text_string; } if ( is_ftable ) { go_text += '|'; if (go_id != NULL) { go_text += *go_id; } go_text += '|'; if ( pmid != 0 ) { go_text += NStr::IntToString(pmid); } if (evidence != NULL) { go_text += '|'; go_text += *evidence; } } else { bool add_dash = false; if (go_id != NULL) { go_text = string( "GO:" ); if( is_html ) { go_text += "<a href=\""; go_text += strLinkBaseGeneOntology + *go_id + "\">"; } go_text += *go_id; if( is_html ) { go_text += "</a>"; } add_dash = true; } else { go_text.clear(); } if ( text_string != 0 && text_string->length() > 0 ) { if (add_dash) { go_text += string( " - " ); } if( is_html && go_id != NULL ) { go_text += "<a href=\""; go_text += strLinkBaseGeneOntology + *go_id + "\">"; } // NO, we NO LONGER have the dash here even if there's no go_id (RETAIN compatibility with CHANGE in C) go_text += *text_string; if( is_html && go_id != NULL ) { go_text += "</a>"; } } if ( evidence != 0 ) { go_text += string( " [Evidence " ) + *evidence + string( "]" ); } if ( pmid != 0 ) { string pmid_str = NStr::IntToString(pmid); go_text += " [PMID "; if( is_html && go_id != NULL ) { go_text += "<a href=\""; go_text += strLinkBasePubmed + pmid_str + "\">"; } go_text += pmid_str; if( is_html && go_id != NULL ) { go_text += "</a>"; } go_text += "]"; } if ( go_ref != 0 ) { go_text += " [GO Ref "; if( is_html ) { go_text += "<a href=\""; go_text += strLinkBaseGeneOntologyRef + *go_ref + "\">"; } go_text += *go_ref; if( is_html ) { go_text += "</a>"; } go_text += "]"; } } CleanAndCompress(go_text, go_text.c_str()); NStr::TruncateSpacesInPlace(go_text); return go_text; } static void s_ReplaceUforT(string& codon) { NON_CONST_ITERATE (string, base, codon) { if (*base == 'T') { *base = 'U'; } } } static char s_MakeDegenerateBase(const string &str1, const string& str2) { static const char kIdxToSymbol[] = "?ACMGRSVUWYHKDBN"; vector<char> symbol_to_idx(256, '\0'); for (size_t i = 0; i < sizeof(kIdxToSymbol) - 1; ++i) { symbol_to_idx[kIdxToSymbol[i]] = i; } size_t idx = symbol_to_idx[str1[2]] | symbol_to_idx[str2[2]]; return kIdxToSymbol[idx]; } static size_t s_ComposeCodonRecognizedStr(const CTrna_ext& trna, string& recognized) { recognized.erase(); if (!trna.IsSetCodon()) { return 0; } list<string> codons; ITERATE (CTrna_ext::TCodon, it, trna.GetCodon()) { string codon = CGen_code_table::IndexToCodon(*it); s_ReplaceUforT(codon); if (!codon.empty()) { codons.push_back(codon); } } if (codons.empty()) { return 0; } size_t size = codons.size(); if (size > 1) { codons.sort(); list<string>::iterator it = codons.begin(); list<string>::iterator prev = it++; while (it != codons.end()) { string& codon1 = *prev; string& codon2 = *it; if (codon1[0] == codon2[0] && codon1[1] == codon2[1]) { codon1[2] = s_MakeDegenerateBase(codon1, codon2); it = codons.erase(it); } else { prev = it; ++it; } } } recognized = NStr::Join(codons, ", "); return size; } static bool s_AltitudeIsValid(const string & str ) { // this is the regex we're validating, but for speed and library dependency // reasons, we're using a more raw approach: // // ^[+-]?[0-9]+(\.[0-9]+)?[ ]m\.$ // we use c-style strings so we don't have to worry about constantly // checking if we're out of bounds: we get a '\0' which lets us be cleaner const char *pch = str.c_str(); // optional sign at start if( *pch == '+' || *pch == '-' ) { ++pch; } // then a number, maybe with one decimal point if( ! isdigit(*pch) ) { return false; } while( isdigit(*pch) ) { ++pch; } if( *pch == '.' ) { ++pch; if( ! isdigit(*pch) ) { return false; } while( isdigit(*pch) ) { ++pch; } } // should end with " m" return NStr::Equal(pch, " m"); } ///////////////////////////////////////////////////////////////////////////// // CFormatQual - low-level formatted qualifier CFormatQual::CFormatQual (const CTempString& name, const CTempString& value, const CTempString& prefix, const CTempString& suffix, TStyle style, TFlags flags, ETrim trim ) : m_Name(name), m_Prefix(prefix), m_Suffix(suffix), m_Style(style), m_Flags(flags), m_Trim(trim), m_AddPeriod(false) { CleanAndCompress(m_Value, value); } CFormatQual::CFormatQual(const CTempString& name, const CTempString& value, TStyle style, TFlags flags, ETrim trim) : m_Name(name), m_Prefix(" "), m_Suffix(kEmptyStr), m_Style(style), m_Flags(flags), m_Trim(trim), m_AddPeriod(false) { CleanAndCompress(m_Value, value); } // === CFlatStringQVal ====================================================== CFlatStringQVal::CFlatStringQVal(const CTempString& value, TStyle style, ETrim trim) : IFlatQVal(&kSpace, &kSemicolon), m_Style(style), m_Trim(trim), m_AddPeriod(0) { CleanAndCompress(m_Value, value); } CFlatStringQVal::CFlatStringQVal (const CTempString& value, const string& pfx, const string& sfx, TStyle style, ETrim trim) : IFlatQVal(&pfx, &sfx), m_Style(style), m_Trim(trim), m_AddPeriod(0) { CleanAndCompress(m_Value, value); } CFlatStringQVal::CFlatStringQVal(const CTempString& value, ETrim trim ) : IFlatQVal(&kSpace, &kSemicolon), m_Style(CFormatQual::eQuoted), m_Trim(trim), m_AddPeriod(0) { CleanAndCompress(m_Value, value); } typedef SStaticPair<const char*, ETildeStyle> TNameTildeStylePair; typedef CStaticPairArrayMap<const char*, ETildeStyle, PCase_CStr > TNameTildeStyleMap; static const TNameTildeStylePair kNameTildeStyleMap[] = { { "function", eTilde_tilde }, { "prot_desc", eTilde_note }, { "prot_note", eTilde_note }, { "seqfeat_note", eTilde_note } }; DEFINE_STATIC_ARRAY_MAP(TNameTildeStyleMap, sc_NameTildeStyleMap, kNameTildeStyleMap); // a few kinds don't use the default tilde style ETildeStyle s_TildeStyleFromName( const string &name ) { TNameTildeStyleMap::const_iterator result = sc_NameTildeStyleMap.find( name.c_str() ); if( sc_NameTildeStyleMap.end() == result ) { return eTilde_space; } else { return result->second; } } void CFlatStringQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { bool bHtml = ctx.Config().DoHTML(); if ( bHtml && name == "EC_number" ) { string strLink = "<a href=\""; strLink += strLinkBaseExpasy; strLink += m_Value; strLink += "\">"; strLink += m_Value; strLink += "</a>"; x_AddFQ(q, name, strLink, m_Style, 0, m_Trim); return; } flags |= m_AddPeriod; ETildeStyle tilde_style = s_TildeStyleFromName( name ); ExpandTildes(m_Value, tilde_style); const bool is_note = s_IsNote(flags, ctx); // e.g. CP001398 // if( ! is_note ) { // e.g. NP_008173 if( m_Style != CFormatQual::eUnquoted ) { ConvertQuotesNotInHTMLTags( m_Value ); } // } // eventually, the last part will be replaced with a hash-table // or something, but this is fine while we're only checking for // one type. // This prevents quals like /metagenomic="metagenomic" (e.g. EP508672) const bool forceNoValue = ( ! ctx.Config().SrcQualsToNote() && name == m_Value && name == "metagenomic" ); const bool prependNewline = (flags & fPrependNewline) && ! q.empty(); TFlatQual qual = x_AddFQ( q, (is_note ? "note" : name), ( prependNewline ? CTempString("\n" + m_Value) : CTempString(m_Value) ), ( forceNoValue ? CFormatQual::eEmpty : m_Style ), 0, m_Trim ); if ((flags & fAddPeriod) && qual) { qual->SetAddPeriod(); } } // === CFlatNumberQVal ====================================================== void CFlatNumberQVal::Format (TFlatQuals& quals, const CTempString& name, CBioseqContext& ctx, TFlags flags) const { if (ctx.Config().CheckQualSyntax()) { if (NStr::IsBlank(m_Value)) { return; } bool has_space = false; ITERATE (string, it, m_Value) { if (isspace((unsigned char)(*it))) { has_space = true; } else if (has_space) { // non-space after space return; } } } CFlatStringQVal::Format(quals, name, ctx, flags); } // === CFlatBondQVal ======================================================== void CFlatBondQVal::Format (TFlatQuals& quals, const CTempString& name, CBioseqContext& ctx, TFlags flags) const { string value = m_Value; if (s_IsNote(flags, ctx)) { value += " bond"; } x_AddFQ(quals, (s_IsNote(flags, ctx) ? "note" : name), value, m_Style); } // === CFlatGeneQVal ======================================================== void CFlatGeneQVal::Format (TFlatQuals& quals, const CTempString& name, CBioseqContext& ctx, TFlags flags) const { CFlatStringQVal::Format(quals, name, ctx, flags); } // === CFlatSiteQVal ======================================================== void CFlatSiteQVal::Format (TFlatQuals& quals, const CTempString& name, CBioseqContext& ctx, TFlags flags) const { if ( m_Value == "transmembrane-region" ) { m_Value = "transmembrane region"; } if ( m_Value == "signal-peptide" ) { m_Value = "signal peptide"; } if ( m_Value == "transit-peptide" ) { m_Value = "transit peptide"; } if (m_Value != "transit peptide" && m_Value != "signal peptide" && m_Value != "transmembrane region" && s_IsNote(flags, ctx)) { const static char *pchSiteSuffix = " site"; if( ! NStr::EndsWith(m_Value, pchSiteSuffix) ) { m_Value += pchSiteSuffix; } } CFlatStringQVal::Format(quals, name, ctx, flags); } // === CFlatStringListQVal ================================================== void CFlatStringListQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { if (m_Value.empty()) { return; } if ( s_IsNote(flags, ctx) ) { m_Suffix = &kSemicolon; } x_AddFQ(q, (s_IsNote(flags, ctx) ? "note" : name), JoinString(m_Value, "; "), m_Style); } // === CFlatGeneSynonymsQVal ================================================ class CLessThanNoCaseViaUpper { public: bool operator()( const string &str1, const string &str2 ) { // C++'s built-in stuff compares via "tolower" which gets a different ordering // in some subtle cases than C's no-case comparison which uses "toupper" SIZE_TYPE pos = 0; const SIZE_TYPE min_length = min( str1.length(), str2.length() ); for( ; pos < min_length; ++pos ) { const char textComparison = toupper( str1[pos] ) - toupper( str2[pos] ); if( textComparison != 0 ) { return textComparison < 0; } } // if we reached the end, compare via length (shorter first) return ( str1.length() < str2.length() ); } }; void CFlatGeneSynonymsQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { if (GetValue().empty()) { return; } string qual = "gene_synonym"; const list<string> &synonyms = GetValue(); vector<string> sub; std::copy(synonyms.begin(), synonyms.end(), back_inserter(sub)); // For compatibility with C, we use a slightly different sorting algo // In the future, we might go back to the other one for simplicity // std::sort(sub.begin(), sub.end(), PNocase()); stable_sort(sub.begin(), sub.end(), CLessThanNoCaseViaUpper() ); if (ctx.IsRefSeq() && !ctx.Config().IsModeDump()) { x_AddFQ( q, qual, NStr::Join(sub, "; "), m_Style, 0, CFormatQual::eTrim_WhitespaceOnly ); } else { ITERATE (vector<string>, it, sub) { x_AddFQ( q, qual, *it, m_Style, 0, CFormatQual::eTrim_WhitespaceOnly ); } } } // === CFlatCodeBreakQVal =================================================== void CFlatCodeBreakQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags) const { static const char* kOTHER = "OTHER"; ITERATE (CCdregion::TCode_break, it, m_Value) { const char* aa = kOTHER; switch ((*it)->GetAa().Which()) { case CCode_break::C_Aa::e_Ncbieaa: aa = GetAAName((*it)->GetAa().GetNcbieaa(), true); break; case CCode_break::C_Aa::e_Ncbi8aa: aa = GetAAName((*it)->GetAa().GetNcbi8aa(), false); break; case CCode_break::C_Aa::e_Ncbistdaa: aa = GetAAName((*it)->GetAa().GetNcbistdaa(), false); break; default: return; } string pos = CFlatSeqLoc( (*it)->GetLoc(), ctx).GetString(); x_AddFQ(q, name, "(pos:" + pos + ",aa:" + aa + ')', CFormatQual::eUnquoted); } } void CFlatNomenclatureQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags) const { if( m_Value.IsNull() ) { return; } if( ! m_Value->CanGetStatus() || ! m_Value->CanGetSymbol() || m_Value->GetSymbol().empty() ) { return; } // we build up the final result in this variable string nomenclature; // add the status part switch( m_Value->GetStatus() ) { case CGene_nomenclature::eStatus_official: nomenclature += "Official "; break; case CGene_nomenclature::eStatus_interim: nomenclature += "Interim "; break; default: nomenclature += "Unclassified "; break; } nomenclature += "Symbol: "; // add the symbol part nomenclature += m_Value->GetSymbol(); // add the name part, if any if( m_Value->CanGetName() && ! m_Value->GetName().empty() ) { nomenclature += " | Name: " + m_Value->GetName(); } // add the source part, if any if( m_Value->CanGetSource() ) { const CGene_nomenclature_Base::TSource& source = m_Value->GetSource(); if( source.CanGetDb() && ! source.GetDb().empty() && source.CanGetTag() ) { if( source.GetTag().IsId() || ( source.GetTag().IsStr() && ! source.GetTag().GetStr().empty() ) ) { nomenclature += " | Provided by: " + source.GetDb() + ":"; if( source.GetTag().IsStr() ) { nomenclature += source.GetTag().GetStr(); } else { nomenclature += NStr::IntToString( source.GetTag().GetId() ); } } } } x_AddFQ(q, name, nomenclature, CFormatQual::eQuoted ); } CFlatCodonQVal::CFlatCodonQVal(unsigned int codon, unsigned char aa, bool is_ascii) : m_Codon(CGen_code_table::IndexToCodon(codon)), m_AA(GetAAName(aa, is_ascii)), m_Checked(true) { } void CFlatCodonQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags) const { if ( !m_Checked ) { // ... } x_AddFQ(q, name, "(seq:\"" + m_Codon + "\",aa:" + m_AA + ')'); } CFlatExperimentQVal::CFlatExperimentQVal( const string& value ) : m_str( value ) { if ( m_str.empty() ) { m_str = "experimental evidence, no additional details recorded"; } } void CFlatExperimentQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext&, IFlatQVal::TFlags) const { x_AddFQ(q, name, m_str.c_str(), CFormatQual::eQuoted); } CFlatInferenceQVal::CFlatInferenceQVal( const string& gbValue ) : m_str( "non-experimental evidence, no additional details recorded" ) { // // the initial "non-experimental ..." is just a default value which may be // overridden through an additional "inference" Gb-qual in the ASN.1. // However, it can't be overriden to be just anything, only certain strings // are allowed. // The following code will change m_str from its default if gbValue is a // legal replacement for "non-experimental ...", and leave it alone // otherwise. // string prefix = ""; string remainder = ""; CInferencePrefixList::GetPrefixAndRemainder (gbValue, prefix, remainder); if (!NStr::IsBlank(prefix)) { m_str = gbValue; } } void CFlatInferenceQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext&, IFlatQVal::TFlags) const { x_AddFQ(q, name, m_str, CFormatQual::eQuoted); } void CFlatIllegalQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext &ctx, IFlatQVal::TFlags) const { // XXX - return if too strict // special case: in sequin mode, orig_protein_id and orig_transcript_id removed, // even though we usually keep illegal quals in sequin mode if( m_Value->GetQual() == "orig_protein_id" || m_Value->GetQual() == "orig_transcript_id" ) { return; } x_AddFQ(q, m_Value->GetQual(), m_Value->GetVal()); } void CFlatMolTypeQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { const char* s = 0; switch ( m_Biomol ) { default: break; case CMolInfo::eBiomol_unknown: switch ( m_Mol ) { case CSeq_inst::eMol_dna: s = "unassigned DNA"; break; case CSeq_inst::eMol_rna: s = "unassigned RNA"; break; default: break; } break; case CMolInfo::eBiomol_genomic: switch ( m_Mol ) { case CSeq_inst::eMol_dna: s = "genomic DNA"; break; case CSeq_inst::eMol_rna: s = "genomic RNA"; break; default: break; } break; case CMolInfo::eBiomol_mRNA: s = "mRNA"; break; case CMolInfo::eBiomol_rRNA: s = "rRNA"; break; case CMolInfo::eBiomol_tRNA: s = "tRNA"; break; case CMolInfo::eBiomol_pre_RNA: case CMolInfo::eBiomol_snRNA: case CMolInfo::eBiomol_scRNA: case CMolInfo::eBiomol_snoRNA: case CMolInfo::eBiomol_ncRNA: case CMolInfo::eBiomol_tmRNA: case CMolInfo::eBiomol_transcribed_RNA: s = "transcribed RNA"; break; case CMolInfo::eBiomol_other_genetic: case CMolInfo::eBiomol_other: switch ( m_Mol ) { case CSeq_inst::eMol_dna: s = "other DNA"; break; case CSeq_inst::eMol_rna: s = "other RNA"; break; default: break; } break; case CMolInfo::eBiomol_cRNA: s = "viral cRNA"; break; } if ( s == 0 ) { switch ( m_Mol ) { case CSeq_inst::eMol_rna: s = "unassigned RNA"; break; case CSeq_inst::eMol_aa: s = 0; break; case CSeq_inst::eMol_dna: default: s = "unassigned DNA"; break; } } if ( s != 0 ) { x_AddFQ(q, name, s); } } void CFlatOrgModQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { TFlatQual qual; string subname = m_Value->GetSubname(); if ( s_StringIsJustQuotes(subname) ) { subname = kEmptyStr; } ConvertQuotesNotInHTMLTags(subname); CleanAndCompress(subname, subname.c_str()); NStr::TruncateSpacesInPlace(subname); ExpandTildes(subname, ( (flags & IFlatQVal::fIsNote) != 0 ? eTilde_tilde : eTilde_space ) ); if (s_IsNote(flags, ctx)) { bool add_period = RemovePeriodFromEnd(subname, true); if (!subname.empty() || add_period ) { bool is_src_orgmod_note = (flags & IFlatQVal::fIsSource) && (name == "orgmod_note"); if (is_src_orgmod_note) { if (add_period) { AddPeriod(subname); } m_Prefix = &kEOL; m_Suffix = ( add_period ? &kEOL : &kSemicolonEOL ); qual = x_AddFQ(q, "note", subname); } else { qual = x_AddFQ(q, "note", string(name) + ": " + subname, CFormatQual::eQuoted, CFormatQual::fFlags_showEvenIfRedund ); } if (add_period && qual) { qual->SetAddPeriod(); } } } else { // TODO: consider adding this back when we switch to just C++ // x_AddFQ(q, name, s_GetSpecimenVoucherText(ctx, subname) ); x_AddFQ(q, name, subname ); } } void CFlatOrganelleQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext&, IFlatQVal::TFlags) const { const string& organelle = CBioSource::GetTypeInfo_enum_EGenome()->FindName(m_Value, true); switch (m_Value) { case CBioSource::eGenome_chloroplast: case CBioSource::eGenome_chromoplast: case CBioSource::eGenome_cyanelle: case CBioSource::eGenome_apicoplast: case CBioSource::eGenome_leucoplast: case CBioSource::eGenome_proplastid: x_AddFQ(q, name, "plastid:" + organelle); break; case CBioSource::eGenome_kinetoplast: x_AddFQ(q, name, "mitochondrion:kinetoplast"); break; case CBioSource::eGenome_mitochondrion: case CBioSource::eGenome_plastid: case CBioSource::eGenome_nucleomorph: case CBioSource::eGenome_hydrogenosome: case CBioSource::eGenome_chromatophore: x_AddFQ(q, name, organelle); break; case CBioSource::eGenome_macronuclear: case CBioSource::eGenome_proviral: x_AddFQ(q, organelle, kEmptyStr, CFormatQual::eEmpty); break; case CBioSource::eGenome_virion: // x_AddFQ(q, organelle, kEmptyStr, CFormatQual::eEmpty); break; case CBioSource::eGenome_plasmid: case CBioSource::eGenome_transposon: x_AddFQ(q, organelle, kEmptyStr); break; case CBioSource::eGenome_insertion_seq: x_AddFQ(q, "insertion_seq", kEmptyStr); break; default: break; } } void CFlatPubSetQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags) const { const bool bHtml = ctx.Config().DoHTML(); if( ! m_Value->IsPub() ) { return; // TODO: is this right? } // copy the list list< CRef< CPub > > unusedPubs = m_Value->GetPub(); if( ctx.GetReferences().empty() ) { // Yes, this even skips creating "/citation=[PUBMED ...]" items return; } ITERATE (vector< CRef<CReferenceItem> >, ref_iter, ctx.GetReferences()) { CPub_set_Base::TPub::iterator pub_iter = unusedPubs.begin(); for( ; pub_iter != unusedPubs.end() ; ++pub_iter ) { if( (*ref_iter)->Matches( **pub_iter ) ) { // We have a match, so create the qual string value; string pub_id_str; int serial = (*ref_iter)->GetSerial(); int pmid = (*ref_iter)->GetPMID(); if (serial) { pub_id_str = NStr::IntToString(serial); } else if (pmid) { pub_id_str = NStr::IntToString(pmid); } /* string pub_id_str = ((*ref_iter)->GetPMID() ? NStr::IntToString((*ref_iter)->GetPMID()) : NStr::IntToString((*ref_iter)->GetSerial())); */ if(bHtml && pmid) { // create a link value = "[<a href=\""; value += strLinkBasePubmed + NStr::IntToString(pmid) + "\">" + pub_id_str + "</a>]"; } else { value = '[' + pub_id_str + ']'; } x_AddFQ(q, name, value, CFormatQual::eUnquoted); pub_iter = unusedPubs.erase( pub_iter ); // only one citation should be created per reference break; // break so we don't show the same ref more than once } } } // out of the pubs which are still unused, we may still be able to salvage some // under certain conditions. string pubmed; if (ctx.IsRefSeq() && !ctx.Config().IsModeRelease()) { CPub_set_Base::TPub::iterator pub_iter = unusedPubs.begin(); for (; pub_iter != unusedPubs.end(); ++pub_iter) { if ((*pub_iter)->IsPmid()) { const int pmid = (*pub_iter)->GetPmid().Get(); string pmid_str = NStr::NumericToString(pmid); pubmed = "[PUBMED "; if (bHtml) { pubmed += "<a href=\""; pubmed += strLinkBasePubmed; pubmed += pmid_str; pubmed += "\">"; } pubmed += pmid_str; if (bHtml) { pubmed += "</a>"; } pubmed += ']'; x_AddFQ(q, name, pubmed, CFormatQual::eUnquoted); } } } } void CFlatIntQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, TFlags) const { bool bHtml = ctx.Config().DoHTML(); string value = NStr::IntToString(m_Value); if ( bHtml && name == "transl_table" ) { string link = "<a href=\""; link += strLinkBaseTransTable; link += value; link += "\">"; link += value; link += "</a>"; value = link; } x_AddFQ( q, name, value, CFormatQual::eUnquoted); } void CFlatSeqIdQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags) const { bool bHtml = ctx.Config().DoHTML(); string id_str; if ( m_Value->IsGi() ) { if ( m_GiPrefix ) { id_str = "GI:"; if (ctx.Config().HideGI() && name == "db_xref") return; } m_Value->GetLabel(&id_str, CSeq_id::eContent); } else { id_str = m_Value->GetSeqIdString(true); } #ifdef NEW_HTML_FMT if (name == "protein_id") { ctx.Config().GetHTMLFormatter().FormatProteinId(id_str, *m_Value, string(id_str)); } if (name == "transcript_id") { ctx.Config().GetHTMLFormatter().FormatTranscriptId(id_str, *m_Value, string(id_str)); } #else if (bHtml && name == "protein_id") { string raw_id_str = id_str; string raw_link_str = id_str; CBioseq_Handle bsh = ctx.GetScope().GetBioseqHandle( *m_Value ); vector< CSeq_id_Handle > ids = bsh.GetId(); ITERATE( vector< CSeq_id_Handle >, it, ids ) { CSeq_id_Handle hid = *it; if ( hid.IsGi() ) { raw_link_str = NStr::NumericToString(hid.GetGi()); break; } } id_str = "<a href=\""; id_str += strLinkBaseProt; id_str += raw_link_str; id_str += "\">"; id_str += raw_id_str; id_str += "</a>"; } #endif x_AddFQ(q, name, id_str); } void s_ConvertGtLt(string& subname) { SIZE_TYPE pos; for (pos = subname.find('<'); pos != NPOS; pos = subname.find('<', pos)) { subname.replace(pos, 1, "&lt;"); } for (pos = subname.find('>'); pos != NPOS; pos = subname.find('>', pos)) { subname.replace(pos, 1, "&gt;"); } } void s_HtmlizeLatLon( string &subname ) { string lat; string north_or_south; string lon; string east_or_west; // extract the pieces CNcbiIstrstream lat_lon_stream( subname.c_str() ); lat_lon_stream >> lat; lat_lon_stream >> north_or_south; lat_lon_stream >> lon; lat_lon_stream >> east_or_west; if( lat_lon_stream.bad() ) { return; } if( north_or_south != "N" && north_or_south != "S" ) { return; } if( east_or_west != "E" && east_or_west != "W" ) { return; } // see if lat and lon make numerical sense try { double lat_num = NStr::StringToDouble( lat ); double lon_num = NStr::StringToDouble( lon ); // cap ranges if( lon_num < -180.0 ) { lon = "-180"; } else if( lon_num > 180.0 ) { lon = "180"; } if( lat_num < -90.0 ) { lat = "-90"; } else if( lat_num > 90.0 ) { lat = "90"; } } catch( CStringException & ) { // error parsing numbers return; } // negate the numbers if we're west of prime meridian or south of equator if( east_or_west == "W" && ! NStr::StartsWith(lon, "-") ) { lon = "-" + lon; } if( north_or_south == "S" && ! NStr::StartsWith(lat, "-")) { lat = "-" + lat; } // now we can form the HTML CNcbiOstrstream result; /* result << "<a href=\"" << strLinkBaseLatLon << "?lat=" << lat << "&amp;lon=" << lon << "\">" << subname << "</a>"; */ result << "<a href=\"" << "https://www.google.com/maps/place/" << lat << "+" << lon << "\">" << subname << "</a>"; subname = CNcbiOstrstreamToString(result); } void CFlatSubSourcePrimer::Format( TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { vector< string > fwd_names; if ( ! m_fwd_name.empty() ) { string fwd_name = m_fwd_name; if ( NStr::StartsWith( m_fwd_name, "(" ) && NStr::EndsWith( m_fwd_name, ")" ) ) { fwd_name = m_fwd_name.substr( 1, m_fwd_name.size() - 2 ); } NStr::Split( fwd_name, ",", fwd_names ); } vector< string > rev_names; if ( ! m_rev_name.empty() ) { string rev_name = m_rev_name; if ( NStr::StartsWith( m_rev_name, "(" ) && NStr::EndsWith( m_rev_name, ")" ) ) { rev_name = m_rev_name.substr( 1, m_rev_name.size() - 2 ); } NStr::Split( rev_name, ",", rev_names ); } vector< string > fwd_seqs; if ( ! m_fwd_seq.empty() ) { string fwd_seq = NStr::Replace( m_fwd_seq, "(", "" ); NStr::ReplaceInPlace( fwd_seq, ")", "" ); NStr::Split( fwd_seq, ",", fwd_seqs ); } if ( fwd_seqs.empty() ) { return; } vector< string > rev_seqs; if ( ! m_rev_seq.empty() ) { string rev_seq = NStr::Replace( m_rev_seq, "(", "" ); NStr::ReplaceInPlace( rev_seq, ")", "" ); NStr::Split( rev_seq, ",", rev_seqs ); } for ( size_t i=0; i < fwd_seqs.size(); ++i ) { string value; string sep = ""; if ( i < fwd_names.size() ) { value += sep + "fwd_name: "; value += fwd_names[i]; sep = ", "; } if( i < fwd_seqs.size() ) { value += sep + "fwd_seq: "; value += fwd_seqs[i]; sep = ", "; } if ( i < rev_names.size() ) { value += sep + "rev_name: "; value += rev_names[i]; sep = ", "; } if( i < rev_seqs.size() ) { value += sep + "rev_seq: "; value += rev_seqs[i]; sep = ", "; } x_AddFQ( q, "PCR_primers", value ); } } void CFlatSubSourceQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { TFlatQual qual; string subname = m_Value->CanGetName() ? m_Value->GetName() : kEmptyStr; if ( s_StringIsJustQuotes(subname) ) { subname = kEmptyStr; } ConvertQuotes(subname); CleanAndCompress(subname, subname.c_str()); NStr::TruncateSpacesInPlace(subname); if (ctx.Config().DoHTML()) { s_ConvertGtLt(subname); } if ( s_IsNote(flags, ctx) ) { bool add_period = RemovePeriodFromEnd(subname, true); if (!subname.empty()) { bool is_subsource_note = m_Value->GetSubtype() == CSubSource::eSubtype_other; if (is_subsource_note) { if (add_period) { AddPeriod(subname); } m_Suffix = ( add_period ? &kEOL : &kSemicolonEOL ); qual = x_AddFQ(q, "note", subname); } else { qual = x_AddFQ(q, "note", string(name) + ": " + subname); } if (add_period && qual) { qual->SetAddPeriod(); } } } else { CSubSource::TSubtype subtype = m_Value->GetSubtype(); switch( subtype ) { case CSubSource::eSubtype_germline: case CSubSource::eSubtype_rearranged: case CSubSource::eSubtype_transgenic: case CSubSource::eSubtype_environmental_sample: case CSubSource::eSubtype_metagenomic: x_AddFQ(q, name, kEmptyStr, CFormatQual::eEmpty); break; case CSubSource::eSubtype_plasmid_name: ExpandTildes(subname, eTilde_space); x_AddFQ(q, name, subname); break; case CSubSource::eSubtype_lat_lon: if( ctx.Config().DoHTML() ) { s_HtmlizeLatLon(subname); } ExpandTildes(subname, eTilde_space); x_AddFQ(q, name, subname); break; case CSubSource::eSubtype_altitude: // skip invalid /altitudes if( s_AltitudeIsValid(subname) || ( ! ctx.Config().IsModeRelease() && ! ctx.Config().IsModeEntrez() ) ) { x_AddFQ(q, name, subname); } break; default: if ( ! subname.empty() ) { ExpandTildes(subname, eTilde_space); x_AddFQ(q, name, subname); } break; } } } struct SSortReferenceByName { bool operator()(const CDbtag* dbt1, const CDbtag* dbt2) { return (dbt1->Compare(*dbt2)<0); } }; void CFlatXrefQVal::Format(TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { // to avoid duplicates, keep track of ones we've already done set<string> quals_already_done; TXref temp(m_Value); sort(temp.begin(), temp.end(), SSortReferenceByName()); string id; string db_xref; db_xref.reserve(100); ITERATE(TXref, it, temp) { const CDbtag& dbt = **it; if (!m_Quals.Empty() && x_XrefInGeneXref(dbt)) { continue; } CTempString db = dbt.GetDb(); if (db == "PID" || db == "GI") { continue; } if( db == "taxon" && (flags & fIsSource) == 0 ) { continue; } if (db == "cdd") { db = "CDD"; // canonicalize } if (ctx.Config().DropBadDbxref()) { // Special case for EST or GSS: we don't filter the dbtags as toughly CDbtag::EIsEstOrGss is_est_or_gss = CDbtag::eIsEstOrGss_No; const CMolInfo* mol_info = ctx.GetMolinfo(); if( NULL != mol_info && mol_info->CanGetTech() ) { if( mol_info->GetTech() == CMolInfo::eTech_est || mol_info->GetTech() == CMolInfo::eTech_survey ) { is_est_or_gss = CDbtag::eIsEstOrGss_Yes; } } const CDbtag::EIsRefseq is_refseq = ( ctx.IsRefSeq() ? CDbtag::eIsRefseq_Yes : CDbtag::eIsRefseq_No ); const CDbtag::EIsSource is_source = ( (flags & IFlatQVal::fIsSource) ? CDbtag::eIsSource_Yes : CDbtag::eIsSource_No ); if (!dbt.IsApproved( is_refseq, is_source, is_est_or_gss )) { continue; } } const CDbtag::TTag& tag = (*it)->GetTag(); id.clear(); if (tag.IsId()) { id = NStr::IntToString(tag.GetId()); } else if (tag.IsStr()) { id = tag.GetStr(); if (NStr::EqualNocase(db, "MGI") || NStr::EqualNocase(db, "MGD")) { if (NStr::StartsWith(id, "MGI:", NStr::eNocase) || NStr::StartsWith(id, "MGD:", NStr::eNocase)) { db = "MGI"; id.erase(0, 4); } } // trim TrimSpacesAndJunkFromEnds( id, true ); } if (NStr::IsBlank(id)) { continue; } if (NStr::EqualNocase(db, "HGNC")) { if (!NStr::StartsWith(id, "HGNC:", NStr::eNocase)) { id = "HGNC:" + id; } } else if (NStr::EqualNocase(db, "VGNC")) { if (!NStr::StartsWith(id, "VGNC:", NStr::eNocase)) { id = "VGNC:" + id; } } else if (NStr::EqualNocase(db, "MGI")) { if (!NStr::StartsWith(id, "MGI:", NStr::eNocase)) { id = "MGI:" + id; } } if (NStr::EqualNocase(db, "GO")) { if (!id.empty()){ while (id.size() < SIZE_TYPE(7)){ id = '0' + id; } } } db_xref.clear(); db_xref.append(db.data(), db.length()).push_back(':'); if (ctx.Config().DoHTML()) { string url = dbt.GetUrl( ctx.GetTaxname() ); if (!NStr::IsBlank(url)) { db_xref.append("<a href=\"").append(url).append("\">").append(id).append("</a>"); } else { db_xref.append(id); } } else { db_xref.append(id); } // add quals not already done if (quals_already_done.find(db_xref) == quals_already_done.end()) { quals_already_done.insert(db_xref); x_AddFQ(q, name, db_xref); } } } bool CFlatXrefQVal::x_XrefInGeneXref(const CDbtag& dbtag) const { if ( !m_Quals->HasQual(eFQ_gene_xref) ) { return false; } typedef TQuals::const_iterator TQCI; TQCI gxref = m_Quals->LowerBound(eFQ_gene_xref); TQCI end = m_Quals->end(); while (gxref != end && gxref->first == eFQ_gene_xref) { const CFlatXrefQVal* xrefqv = dynamic_cast<const CFlatXrefQVal*>(gxref->second.GetPointerOrNull()); if (xrefqv != NULL) { ITERATE (TXref, dbt, xrefqv->m_Value) { if (dbtag.Match(**dbt)) { return true; } } } ++gxref; } /*pair<TQCI, TQCI> gxrefs = m_Quals->GetQuals(eFQ_gene_xref); for ( TQCI it = gxrefs.first; it != gxrefs.second; ++it ) { const CFlatXrefQVal* xrefqv = dynamic_cast<const CFlatXrefQVal*>(it->second.GetPointerOrNull()); if ( xrefqv != 0 ) { ITERATE (TXref, dbt, xrefqv->m_Value) { if ( dbtag.Match(**dbt) ) { return true; } } } }*/ return false; } static size_t s_CountAccessions(const CUser_field& field) { size_t count = 0; if (!field.IsSetData() || !field.GetData().IsFields()) { return 0; } // // Each accession consists of yet another block of "Fields" one of which carries // a label named "accession": // ITERATE (CUser_field::TData::TFields, it, field.GetData().GetFields()) { const CUser_field& uf = **it; if ( uf.CanGetData() && uf.GetData().IsFields() ) { ITERATE( CUser_field::TData::TFields, it2, uf.GetData().GetFields() ) { const CUser_field& inner = **it2; if ( inner.IsSetLabel() && inner.GetLabel().IsStr() ) { if ( inner.GetLabel().GetStr() == "accession" ) { ++count; } } } } } return count; } void CFlatModelEvQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { size_t num_mrna = 0, num_prot = 0, num_est = 0, num_long_sra = 0; size_t rnaseq_base_coverage = 0, rnaseq_biosamples_introns_full = 0; const string* method = 0; ITERATE (CUser_object::TData, it, m_Value->GetData()) { const CUser_field& field = **it; if (! field.IsSetLabel() || ! field.GetLabel().IsStr()) { continue; } const string& label = field.GetLabel().GetStr(); if (label == "Method") { method = &label; if ( field.CanGetData() && field.GetData().IsStr() ) { method = &( field.GetData().GetStr() ); } } else if (label == "Counts") { ITERATE (CUser_field::TData::TFields, i, field.GetData().GetFields()) { if (!(*i)->IsSetLabel() && (*i)->GetLabel().IsStr()) { continue; } const string& label = (*i)->GetLabel().GetStr(); if (label == "mRNA") { num_mrna = (*i)->GetData().GetInt(); } else if (label == "EST") { num_est = (*i)->GetData().GetInt(); } else if (label == "Protein") { num_prot = (*i)->GetData().GetInt(); } else if (label == "long SRA read") { num_long_sra = (*i)->GetData().GetInt(); } } } else if (label == "mRNA") { num_mrna = s_CountAccessions(field); } else if (label == "EST") { num_est = s_CountAccessions(field); } else if (label == "Protein") { num_prot = s_CountAccessions(field); } else if (label == "long SRA read") { num_long_sra = s_CountAccessions(field); } else if (label == "rnaseq_base_coverage" ) { if ( field.CanGetData() && field.GetData().IsInt() ) { rnaseq_base_coverage = field.GetData().GetInt(); } } else if (label == "rnaseq_biosamples_introns_full" ) { if ( field.CanGetData() && field.GetData().IsInt() ) { rnaseq_biosamples_introns_full = field.GetData().GetInt(); } } } CNcbiOstrstream text; text << "Derived by automated computational analysis"; if (method != NULL && !NStr::IsBlank(*method)) { text << " using gene prediction method: " << *method; } text << "."; if (num_mrna > 0 || num_est > 0 || num_prot > 0 || num_long_sra > 0 || rnaseq_base_coverage > 0 ) { text << " Supporting evidence includes similarity to:"; } string section_prefix = " "; // The countable section if( num_mrna > 0 || num_est > 0 || num_prot > 0 || num_long_sra > 0 ) { text << section_prefix; string prefix = ""; if (num_mrna > 0) { text << prefix << num_mrna << " mRNA"; if (num_mrna > 1) { text << 's'; } prefix = ", "; } if (num_est > 0) { text << prefix << num_est << " EST"; if (num_est > 1) { text << 's'; } prefix = ", "; } if (num_long_sra > 0) { text << prefix << num_long_sra << " long SRA read"; if (num_long_sra > 1) { text << 's'; } prefix = ", "; } if (num_prot > 0) { text << prefix << num_prot << " Protein"; if (num_prot > 1) { text << 's'; } prefix = ", "; } section_prefix = ", and "; } // The RNASeq section if( rnaseq_base_coverage > 0 ) { text << section_prefix; text << rnaseq_base_coverage << "% coverage of the annotated genomic feature by RNAseq alignments"; if( rnaseq_biosamples_introns_full > 0 ) { text << ", including " << rnaseq_biosamples_introns_full; text << " sample"; if( rnaseq_biosamples_introns_full > 1 ) { text << 's'; } text << " with support for all annotated introns"; } section_prefix = ", and "; } x_AddFQ(q, name, CNcbiOstrstreamToString(text).operator std::string()); } void CFlatGoQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { _ASSERT(m_Value->GetData().IsFields()); const bool is_ftable = ctx.Config().IsFormatFTable(); const bool is_html = ctx.Config().DoHTML(); if ( s_IsNote(flags, ctx) ) { static const string sfx = ";"; m_Prefix = &kEOL; m_Suffix = &sfx; x_AddFQ(q, "note", string(name) + ": " + s_GetGOText(*m_Value, is_ftable, is_html)); } else { x_AddFQ(q, name, s_GetGOText(*m_Value, is_ftable, is_html)); } } bool CFlatGoQVal::Equals( const CFlatGoQVal &rhs ) const { return m_Value->Equals( *rhs.m_Value ); } const string & CFlatGoQVal::GetTextString(void) const { if( m_Value.IsNull() ) { return kEmptyStr; } CConstRef<CUser_field> textStringField = m_Value->GetFieldRef("text string"); if( textStringField.IsNull() ) { return kEmptyStr; } const CUser_field_Base::TData & textStringData = textStringField->GetData(); if( ! textStringData.IsStr() ) { return kEmptyStr; } return textStringData.GetStr(); } int CFlatGoQVal::GetPubmedId(void) const { if( m_Value.IsNull() ) { return 0; } CConstRef<CUser_field> pmidField = m_Value->GetFieldRef("pubmed id"); if( pmidField.IsNull() ) { return 0; } const CUser_field_Base::TData & pmidData = pmidField->GetData(); if( ! pmidData.IsInt() ) { return 0; } return pmidData.GetInt(); } void CFlatAnticodonQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { if ( m_Aa.empty() ) { return; } const CSeq_loc& slp = *m_Anticodon; CRef<CSeq_loc> loc2(new CSeq_loc); loc2->Assign(slp); loc2->SetId(*ctx.GetPrimaryId()); string locationString = CFlatSeqLoc(*loc2, ctx).GetString(); string text; text = "(pos:"; text += locationString; text += ",aa:"; text += m_Aa; CScope & scope = ctx.GetScope(); if (sequence::GetLength(*m_Anticodon, &scope) == 3) { // "3" because 3 nucleotides to an amino acid (and thus anticodon sequence) try { CSeqVector seq_vector(*m_Anticodon, scope, CBioseq_Handle::eCoding_Iupac); if (seq_vector.size() == 3) { string seq("---"); seq_vector.GetSeqData(0, 3, seq); NStr::ToLower(seq); text += ",seq:"; text += seq; } } catch (...) { // ignore any sort of error that occurs in this process } } text += ')'; x_AddFQ(q, name, text, CFormatQual::eUnquoted); } void CFlatTrnaCodonsQVal::Format (TFlatQuals& q, const CTempString& name, CBioseqContext& ctx, IFlatQVal::TFlags flags) const { if (!m_Value || !m_Value->IsSetCodon()) { return; } string recognized; size_t num = s_ComposeCodonRecognizedStr(*m_Value, recognized); if ( 0 == num ) { return; } if ( ctx.Config().CodonRecognizedToNote() ) { if (num == 1) { string str = "codon recognized: " + recognized; if (NStr::Find(m_Seqfeat_note, str) == NPOS) { x_AddFQ(q, name, str); } } else { x_AddFQ(q, name, "codons recognized: " + recognized); } } else { x_AddFQ(q, "codon_recognized", recognized); } } void CFlatProductNamesQVal::Format (TFlatQuals& quals, const CTempString& name, CBioseqContext& ctx, TFlags flags) const { if (m_Value.size() < 2) { return; } bool note = s_IsNote(flags, ctx); CProt_ref::TName::const_iterator it = m_Value.begin(); ++it; // first is used for /product while (it != m_Value.end() && !NStr::IsBlank(*it)) { if (*it != m_Gene) { x_AddFQ(quals, (note ? "note" : name), *it); } ++it; } } END_SCOPE(objects) END_NCBI_SCOPE

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.