├── LICENSE ├── README.md └── bib2item3.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Blaine Mooers and the University of Oklahoma Board of Regents 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Version](https://img.shields.io/static/v1?label=bib2item3&message=0.2&color=brightcolor) 2 | [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) 3 | 4 | 5 | # bib2item3 6 | 7 | ## DESCRIPTION 8 | 9 | Script to reformat BibTeX reference library into bibitems for specific 10 | scientific journals. Supports only Protein Science at this time. 11 | 12 | 13 | ## BACKGROUND 14 | 15 | The ScholarOne Manuscript vendor used by Protein Science does not accept 16 | Bibtex library files. Per the authors' instructions, you are stuck 17 | with using a bibliography environment and bibitems. The bibitems are tedious 18 | and error-prone to assemble by hand. 19 | 20 | The tex Stackexchange user Ixy published online a python2 script that I 21 | repurposed for Protein Science and python3. It is not all-inclusive. Many 22 | edge cases remain unaddressed. You will still have to check all references 23 | manually. 24 | 25 | There are other solutions to this problem. You should be able to generate a 26 | *.bbl file from your lib file by running LaTeX, BibTeX, latex, and latex on 27 | your bib file. The *.bbl file contains the bibitems. I recommend using 28 | this approach whenever possible. It is superior to the solution provided by my script. However, 29 | I had no luck with this approach at 1 AM on the night of manuscript submission. 30 | 31 | There is also a Matlab solution. 32 | I did not have access to Matlab at the time that I found this solution. 33 | Perhaps this solution can be run with an octave. 34 | 35 | 36 | ## Source of original script: 37 | 38 | Author of inspiring [code](https://tex.stackexchange.com/questions/124874/converting-to-bibitem-in-latex) 39 | : Ixy, a secretive [tex StackExchange ](https://tex.stackexchange.com/) user. 40 | 41 | 42 | ## USAGE 43 | 44 | bib2item3.py refs.bib 45 | 46 | ## Notes: 47 | 48 | - The bib file should have only the citations that you want to include in your manuscript. 49 | - The names of the journals should have the proper abbreviations. 50 | - The citations in the bib file should be in alphabetical order because this script does not sort them. 51 | - You should be able to copy the output into a bibliography environment in your LaTeX file. 52 | 53 | 54 | ## To Be Done 55 | 56 | - run flake8 and edit 57 | - run pylint and edit 58 | - develop test functions 59 | - improve error handling 60 | 61 | ## Update history 62 | 63 | |Version | Changes | Date | 64 | |:-----------:|:------------------------------------------------------------------------------------------------------------------------------------------:|:--------------------:| 65 | | Version 0.2 | Added badges and update table. Corrected more typos. Merged pull request by Melodie Chen-Glasser. Her improvements are listed in the doc string in the script. | 2024 May 7 | 66 | 67 | ## Funding 68 | - NIH: R01 CA242845, R01 AI088011 69 | - NIH: P30 CA225520 (PI: R. Mannel); P20GM103640 and P30GM145423 (PI: A. West) 70 | 71 | 72 | -------------------------------------------------------------------------------- /bib2item3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import print_function 3 | import sys 4 | """ 5 | # *********************** 72 spaces *********************************** 6 | DESCRIPTION 7 | 8 | Script to reformat bibtex reference library into bibitems for specific 9 | scientific journals. 10 | 11 | 12 | BACKGROUND 13 | 14 | Tne ScholarOne Manuscript vendor used by Protein Science does not accept 15 | bibtex library files. As per the instructions to authors, you are stuck 16 | with using a bibilography environment and the bibitems. This is a tedious 17 | and error prone to do by hand. 18 | 19 | The tex stackexchange user Ixy published on-line a python2 script that I 20 | repurposed for Protein Science and python3. It is not all inclusive. Many 21 | edge cases remain unaddressed. You will still have to check all references 22 | manually. 23 | 24 | The are other solutions to this problem. You are supposed to be able to 25 | generate at *.bbl file from your lib file by running latex, bibtex, latex, 26 | and latex on your bib file. The bbl file contains the bibitems. I recommend 27 | this approach whenever possible. It is superior to this solution. However, 28 | I had no luck with this approach at 1 AM on the night of manuscript submission. 29 | 30 | There is also matlab solution. I do not have access to matlab. 31 | 32 | Source: 33 | (https://tex.stackexchange.com/questions/124874/ 34 | converting-to-bibitem-in-latex) 35 | 36 | Author of inspiring code: Ixy, a secretive tex stackexchange user. 37 | 38 | 39 | USAGE 40 | 41 | bib2item3.py refs.bib 42 | 43 | 44 | 45 | Copyright Notice 46 | ================ 47 | 48 | Copyright (c) 2019 Board of Regents for the University of Oklahoma 49 | 50 | Permission is hereby granted, free of charge, to any person 51 | obtaining a copy of this software and associated documentation file 52 | (the "Software"), to deal in the Software without restriction, 53 | including without limitation the rights to use, copy, modify, merge, 54 | publish, distribute, sublicense, and/or sell copies of the Software, 55 | and to permit persons to whom the Software is furnished to do so, 56 | subject to the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be 59 | included in all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 62 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 63 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 64 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 65 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 66 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 67 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | # *********************** 72 spaces *********************************** 69 | 70 | Blaine Mooers, PhD 71 | blaine@ouhsc.edu 72 | 975 NE 10th St, BRC 466 73 | Department of Biochemistry and Molecular Biology 74 | College of Medicine 75 | Stephenson Cancer Center 76 | University of Oklahoma Health Sciences Center, 77 | Oklahoma City, OK, USA 73104 78 | 79 | Copyright 2019 80 | Univeristy of Oklahoma Board of Regents 81 | MIT Licence 82 | 83 | 11/8/19 84 | 85 | 86 | HISTORY 87 | 88 | Initialized on November 8, 2019 by Blaine Mooers. 89 | 90 | 91 | Improved data collection by adding UTF9 compatibility, 92 | closing file after writing, allowing for supscripts and superscripts 93 | in Latex format, and corperate author instances (names without commas). 94 | Melodie Chen-Glasser 95 | mglasser@mines.edu 96 | Colorado School of Mines 97 | 2022/12/07 98 | 99 | FUTURE 100 | 101 | Make functions for other specific journals. 102 | Fix exception handling. 103 | Run flake8. 104 | Run Pep8 105 | """ 106 | 107 | 108 | def protein_science(bibtex): 109 | psUsage = """ 110 | Opens a bibtex library that contains only the citations for one 111 | manuscript. The abbreviation for the journal titles follow 112 | Chemical Abstracts Service Source Index, 1985. 113 | Note that page numbers must be inclusive. 114 | 115 | This function is configured for Protein Science. See 116 | https://onlinelibrary.wiley.com/page/journal/1469896x/homepage/\ 117 | forauthors.html#references 118 | 119 | Journal article 120 | 1. King VM, Armstrong DM, Apps R, Trott JR (1998) Numerical 121 | aspects of pontine, lateral reticular, and inferior olivary 122 | projections to two paravermal cortical zones of the cat 123 | cerebellum. J Comp Neurol 390:537-551. 124 | 125 | Book: 126 | 2. Voet D, Voet JG (1990) Biochemistry, John Wiley & Sons, New York. 127 | 128 | Book Chapter: 129 | 3. Gilmor ML, Rouse ST, Heilman CJ, Nash NR, Levey AI, 130 | Receptor fusion proteins and analysis. In: Ariano MA, Ed. 131 | (1998) Receptor localization. Wiley-Liss, New York, pp 75-90. 132 | 133 | Electronic Media: 134 | 4. Bio-Xplor, Version 1.0. New York: Biostructure Inc.; 1991. 135 | 136 | Journal article with PMID included (optional): 137 | 5. Wood CE, Appt SE, Clarkson TB, Franke AA, Lees CJ, Doerge DR, 138 | Cline JM. Effects of high-dose soy isoflavones and equol on 139 | reproductive tissues in female cynomolgus monkeys. 140 | PMID: 16723506 [Medline] 141 | """ 142 | print(psUsage) 143 | with open(home + outfilestem + '.txt', 'w', encoding='UTF8') as oitems: 144 | 145 | print() 146 | r = bibtex.split('\n') 147 | i = 0 148 | while i < len(r): 149 | line = r[i].strip() 150 | if not line: i += 1 151 | if '@' == line[0]: 152 | code = line.split('{')[-1][:-1] 153 | # Note the venue == journal 154 | title = venue = volume = number = pages = year = publisher = authors = None 155 | output_authors = [] 156 | i += 1 157 | while i < len(r) and '@' not in r[i]: 158 | line = r[i].strip() 159 | #print(line) 160 | if line.startswith("title"): 161 | title = line.split('{', 1)[-1][:-2] 162 | elif line.startswith("journal"): 163 | venue = line.split('{', 1)[-1][:-2] 164 | elif line.startswith("volume"): 165 | volume = line.split('{', 1)[-1][:-2] 166 | elif line.startswith("number"): 167 | number = line.split('{', 1)[-1][:-2] 168 | elif line.startswith("pages"): 169 | pages = line.split('{', 1)[-1][:-2] 170 | elif line.startswith("year"): 171 | year = line.split('{', 1)[-1][:-2] 172 | elif line.startswith("publisher"): 173 | publisher = line.split('{', 1)[-1][:-2] 174 | elif line.startswith("author"): 175 | authors = line[line.find("{")+1:line.rfind("}")] 176 | if authors.find(',') == -1: 177 | output_authors.append(authors) 178 | else: 179 | for LastFirst in authors.split(' and '): 180 | lf = LastFirst.replace(' ', '').split(',') 181 | assert len(lf) == 2, "Author name has more than one comma " + ",".join(lf) 182 | last, first = lf[0], lf[1] 183 | output_authors.append("{} {}".format(last, first)) 184 | i += 1 185 | 186 | oitems.write("\\bibitem{%s}" % code) 187 | oitems.write("\n") 188 | if len(output_authors) == 1: 189 | oitems.write(output_authors[0] + " ({}) ".format(year),) 190 | else: 191 | oitems.write(", ".join(_ for _ in output_authors) 192 | + " ({}) ".format(year)) 193 | if title: 194 | oitems.write("{}.".format(title)) 195 | if venue: 196 | venue2 = venue.replace('.','') 197 | oitems.write(" {}".format(" ".join([_.capitalize() for _ in venue2.split(' ')])),) 198 | if volume: 199 | oitems.write(" {}:".format(volume)) 200 | if pages: 201 | pages2 = pages.replace('--','-') 202 | oitems.write("{}.".format(pages2) if number else "{}.".format(pages2)) 203 | if publisher and not venue: 204 | oitems.write(" {}.".format(publisher)) 205 | oitems.write("\n") 206 | oitems.write("\n") 207 | return 208 | 209 | 210 | # *********************** __main__ ************ 72 spaces ************* 211 | """ In this section, select the function specific to your target 212 | journal. 213 | """ 214 | if __name__ == '__main__': 215 | # Set the name of the output file. 216 | outfilestem = 'proteinScienceBibItems' 217 | home = 'D:/projects/bib2item3/' 218 | # Set the name of the input file. 219 | try: 220 | f = open(sys.argv[1],"r") 221 | except: 222 | print('Please provide name of bib file!') 223 | print('Usage: bibtex2item.py manuscirpt.bib') 224 | bibtex = f.read() 225 | # print(bibtex) 226 | # Convert the bibtex into bibitems for Protein Science 227 | protein_science(bibtex) 228 | # iucr(bibtex) 229 | # pnas(bibtex) 230 | # jbc(bibtex) 231 | # nar(bibtex) 232 | # rna(bibtex) 233 | --------------------------------------------------------------------------------