bivy 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +21 -0
  2. data/History +16 -0
  3. data/LICENSE +29 -0
  4. data/README.rdoc +37 -0
  5. data/Rakefile +43 -0
  6. data/TODO +12 -0
  7. data/VERSION +1 -0
  8. data/bin/bivy.rb +56 -0
  9. data/bin/pubmed_to_bivy.rb +78 -0
  10. data/doc/config.yaml +13 -0
  11. data/doc/src/default.css +126 -0
  12. data/doc/src/default.template +38 -0
  13. data/doc/src/tutorial/basic_flow.page +71 -0
  14. data/doc/src/tutorial/index.page +8 -0
  15. data/doc/src/tutorial/new_formats_and_media.page +83 -0
  16. data/jrn_abbrev/abbr_html.tgz +0 -0
  17. data/jrn_abbrev/abbr_to_journal.yaml +676 -0
  18. data/jrn_abbrev/download_abbrevs.rb +20 -0
  19. data/jrn_abbrev/for_ruby_class.rb +686 -0
  20. data/jrn_abbrev/html_to_yaml.rb +50 -0
  21. data/lib/bibliography.rb +144 -0
  22. data/lib/bivy.rb +4 -0
  23. data/lib/citation.rb +194 -0
  24. data/lib/format.rb +120 -0
  25. data/lib/format/acs.rb +88 -0
  26. data/lib/format/bioinformatics.rb +33 -0
  27. data/lib/format/bmc.rb +38 -0
  28. data/lib/format/jtp.rb +30 -0
  29. data/lib/format/mla.rb +50 -0
  30. data/lib/formatter.rb +276 -0
  31. data/lib/journal.rb +6 -0
  32. data/lib/journal/iso_to_full.yaml +1320 -0
  33. data/lib/journal/medline_to_full.yaml +7 -0
  34. data/lib/journal/medline_to_iso.yaml +45 -0
  35. data/lib/media.rb +88 -0
  36. data/lib/media/html.rb +65 -0
  37. data/lib/ooffice.rb +39 -0
  38. data/lib/pubmed.rb +209 -0
  39. data/lib/rtf.rb +217 -0
  40. data/old_stuff/old_list2refs.rb +103 -0
  41. data/old_stuff/pubmed2html.rb +119 -0
  42. data/old_stuff/pubmed_bib_write.rb +92 -0
  43. data/old_stuff/xml.tmp.xml +115 -0
  44. data/scripts/merge_bibs.rb +70 -0
  45. data/spec/bibliography_spec.rb +127 -0
  46. data/spec/citation_positions.odt +0 -0
  47. data/spec/formatter_spec.rb +14 -0
  48. data/spec/formatter_spec/cits_after.xml +2 -0
  49. data/spec/formatter_spec/cits_before.xml +2 -0
  50. data/spec/formatter_spec/content.xml +2 -0
  51. data/spec/ooffice_spec.rb +27 -0
  52. data/spec/pubmed_spec.rb +26 -0
  53. data/spec/spec_helper.rb +7 -0
  54. data/spec/testfiles/doc1.odt +0 -0
  55. metadata +136 -0
data/lib/rtf.rb ADDED
@@ -0,0 +1,217 @@
1
+ module RTF
2
+
3
+ def rtf_num_list(items, num_spacer_lines=0)
4
+ with_number = items.collect do |item|
5
+ '\par \pard\plain {\listtext\pard\plain \li283\ri0\lin283\rin0\fi-283\f2\f2\f4 2.}\ilvl0 \ltrpar\s1\ls0\li283\ri0\lin283\rin0\fi-283\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f2\fs24\lang1033{\loch\f2\fs24\lang1033\i0\b0\*\cs8\cf0\rtlch\ltrch\dbch\loch\f1\fs24\lang1033 ' + item.to_s + '}'
6
+ end
7
+
8
+ ## Add spacers
9
+ spacing = ""
10
+ rtf_list_spacer = '\par \pard\plain \ltrpar\s1\li283\ri0\lin283\rin0\fi0\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f2\fs24\lang1033'
11
+ spacer_lines = []
12
+ num_spacer_lines.times do
13
+ spacer_lines.push(rtf_list_spacer)
14
+ end
15
+ if spacer_lines.size > 0
16
+ spacing = spacer_lines.join("\n")
17
+ else
18
+ spacing = ""
19
+ end
20
+ with_number.join(spacing)
21
+ end
22
+
23
+ def in_text_citation(string, font_size=7, citation_height=5)
24
+ rtf_fontsize = font_size * 2
25
+ return '{\fs' + rtf_fontsize.to_s + '{\*\updnprop10000}\up'+ citation_height.to_s + ' ' + string.to_s + '}'
26
+ end
27
+
28
+
29
+ def rtf_stylesheet_insert_for_list
30
+ '{\*\cs7\cf0\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 Numbering Symbols;}'
31
+ end
32
+
33
+ def rtf_list_header
34
+ # NOTE THE triple quotes are necessary to end up with: \'
35
+ string = '
36
+ {\*\listtable{\list\listtemplateid1
37
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'00.;}{\levelnumbers\\\'01;}\fi-283\li283}
38
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'01.;}{\levelnumbers\\\'01;}\fi-283\li567}
39
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'02.;}{\levelnumbers\\\'01;}\fi-283\li850}
40
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'03.;}{\levelnumbers\\\'01;}\fi-283\li1134}
41
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'04.;}{\levelnumbers\\\'01;}\fi-283\li1417}
42
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'05.;}{\levelnumbers\\\'01;}\fi-283\li1701}
43
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'06.;}{\levelnumbers\\\'01;}\fi-283\li1984}
44
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'07.;}{\levelnumbers\\\'01;}\fi-283\li2268}
45
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'08.;}{\levelnumbers\\\'01;}\fi-283\li2551}
46
+ {\*\soutlvl{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'09.;}{\levelnumbers\\\'01;}\fi-283\li2835}}\listid1}
47
+ }{\listoverridetable{\listoverride\listid1\listoverridecount0\ls0}}
48
+
49
+ '
50
+ end
51
+
52
+ # returns an rtf header string
53
+ def footer
54
+ '}'
55
+ end
56
+ # italicized text
57
+ def i(string)
58
+ if string
59
+ return '{\i\insrsid6900457 ' + string + '}'
60
+ else
61
+ return ""
62
+ end
63
+ end
64
+ # underlined text
65
+ def u(string)
66
+ if string
67
+ '{\ul\insrsid6900457\charrsid6900457 '+string+'}'
68
+ else
69
+ return ""
70
+ end
71
+ end
72
+ # bold text
73
+ def b(string)
74
+ if string
75
+ '{\b\insrsid6900457\charrsid6900457 '+string+'}'
76
+ else
77
+ return ""
78
+ end
79
+ end
80
+ # Normal text
81
+ def n(string)
82
+ if string
83
+ '{\insrsid6900457 '+string+'}'
84
+ else
85
+ return ""
86
+ end
87
+ end
88
+ # returns a normal '.'
89
+ def dot
90
+ '{\insrsid6900457 '+ '.' +'}'
91
+ end
92
+
93
+ # returns a normal '. '
94
+ def ds
95
+ '{\insrsid6900457 '+ '. ' +'}'
96
+ end
97
+ # returns a normal ' .'
98
+ def sd
99
+ '{\insrsid6900457 '+ ' .' +'}'
100
+ end
101
+ # parenthesized: adds () around the non nil strings
102
+ # NOTE: will not parenthesize nil or empty ("") string!
103
+ def para(string)
104
+ if string && string != ""
105
+ return '(' + string + ')'
106
+ else
107
+ return ""
108
+ end
109
+ end
110
+ # space of normal text
111
+ def s
112
+ '{\insrsid6900457 '+ ' ' +'}'
113
+ end
114
+ def newline(number)
115
+ string = '{\insrsid13852479' + "\n"
116
+ pars = []
117
+ number.times {pars << '\par'}
118
+ string << pars.join("\n")
119
+ string << '}'
120
+ string
121
+ end
122
+
123
+ # returns a new string with the list info embedded
124
+ def insert_list_to_header(rtf_string)
125
+ search_string = '{\stylesheet'
126
+ #puts "RTF_string: " + rtf_string + "**********"
127
+ not_interested, header = rtf_string.split(search_string)
128
+ return rtf_string unless header
129
+ new_string = ""
130
+ brack_cnt = 0
131
+ # {stuff}{stuff}{insert my stuff}}insert list stuff
132
+ nothing_left_to_do = false
133
+ header.scan(/.|\n/) do |letter|
134
+ if nothing_left_to_do
135
+ new_string << letter
136
+ next
137
+ end
138
+ if letter == "{"
139
+ brack_cnt += 1
140
+ elsif letter == '}'
141
+ brack_cnt -= 1
142
+ end
143
+ if brack_cnt < 0
144
+ new_string << rtf_stylesheet_insert_for_list
145
+ new_string << '}'
146
+ new_string << rtf_list_header
147
+ nothing_left_to_do = true
148
+ else
149
+ new_string << letter
150
+ end
151
+ end
152
+ new_rtf = [not_interested,new_string].join(search_string)
153
+ return new_rtf
154
+ end
155
+ end
156
+
157
+
158
+
159
+ =begin
160
+
161
+ # this is the microsoft rtf header
162
+
163
+ return '{\rtf1\ansi\ansicpg1252\uc1\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f119\froman\fcharset238\fprq2 Times New Roman CE;}
164
+ {\f120\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f122\froman\fcharset161\fprq2 Times New Roman Greek;}{\f123\froman\fcharset162\fprq2 Times New Roman Tur;}{\f124\froman\fcharset177\fprq2 Times New Roman (Hebrew);}
165
+ {\f125\froman\fcharset178\fprq2 Times New Roman (Arabic);}{\f126\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f127\froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
166
+ \red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
167
+ \red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive \ssemihidden
168
+ Default Paragraph Font;}{\*\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv
169
+ \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs20\lang1024\langfe1024\cgrid\langnp1024\langfenp1024 \snext11 \ssemihidden Normal Table;}}{\*\rsidtbl \rsid6900457}{\*\generator Microsoft Word 10.0.2627;}{\info
170
+ {\title This part normal}{\author john}{\operator john}{\creatim\yr2003\mo3\dy19\hr17\min13}{\revtim\yr2003\mo3\dy19\hr17\min14}{\version1}{\edmins1}{\nofpages1}{\nofwords14}{\nofchars83}{\*\company UT Austin}{\nofcharsws96}{\vern16437}}
171
+ \widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1
172
+ \jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct\asianbrkrule\rsidroot6900457 \fet0\sectd
173
+ \linex0\endnhere\sectlinegrid360\sectdefaultcl\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4
174
+ \pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}
175
+ {\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}\pard\plain \ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0
176
+ \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033'
177
+
178
+
179
+ # the oofice header
180
+ # includes formatting for lists!
181
+ def header
182
+ return '{\rtf1\ansi\deff0\adeflang1025
183
+ {\fonttbl{\f0\froman\fprq2\fcharset0 Nimbus Roman No9 L;}{\f1\froman\fprq2\fcharset0 Nimbus Roman No9 L;}{\f2\fnil\fprq2\fcharset0 Bitstream Vera Sans;}{\f3\fnil\fprq2\fcharset0 Lucidasans;}{\f4\fnil\fprq0\fcharset0 Lucidasans;}}
184
+ {\colortbl;\red0\green0\blue0;\red128\green128\blue128;}
185
+ {\stylesheet{\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033\snext1 Default;}
186
+ {\s2\sa120\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033\sbasedon1\snext2 Text body;}
187
+ {\s3\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033\sbasedon2\snext3 List;}
188
+ {\s4\sb120\sa120\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs20\lang255\ai\ltrch\dbch\af2\afs20\langfe255\ai\loch\f0\fs20\lang1033\i\sbasedon1\snext4 Caption;}
189
+ {\s5\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033\sbasedon1\snext5 Index;}
190
+ {\*\cs7\cf0\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 Numbering Symbols;}
191
+ }{\*\listtable{\list\listtemplateid1
192
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'00.;}{\levelnumbers\'01;}\fi-283\li283}
193
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'01.;}{\levelnumbers\'01;}\fi-283\li567}
194
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'02.;}{\levelnumbers\'01;}\fi-283\li850}
195
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'03.;}{\levelnumbers\'01;}\fi-283\li1134}
196
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'04.;}{\levelnumbers\'01;}\fi-283\li1417}
197
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'05.;}{\levelnumbers\'01;}\fi-283\li1701}
198
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'06.;}{\levelnumbers\'01;}\fi-283\li1984}
199
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'07.;}{\levelnumbers\'01;}\fi-283\li2268}
200
+ {\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'08.;}{\levelnumbers\'01;}\fi-283\li2551}
201
+ {\*\soutlvl{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \'02\'09.;}{\levelnumbers\'01;}\fi-283\li2835}}\listid1}
202
+ }{\listoverridetable{\listoverride\listid1\listoverridecount0\ls0}}
203
+
204
+ {\info{\creatim\yr2005\mo10\dy28\hr8\min49}{\revtim\yr2005\mo10\dy28\hr8\min49}{\printim\yr1601\mo1\dy1\hr0\min0}{\comment StarWriter}{\vern6450}}\deftab709
205
+ {\*\pgdsctbl
206
+ {\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgdscnxt0 Default;}}
207
+ \paperh15840\paperw12240\margl1800\margr1800\margt1440\margb1440\sectd\sbknone\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc
208
+ \pard\plain {\listtext\pard\plain \li283\ri0\lin283\rin0\fi-283 1.}\ilvl0 \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ls0\li283\ri0\lin283\rin0\fi-283\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 {\loch\f0\fs24\lang1033\i0\b0 First item}
209
+ \par \pard\plain {\listtext\pard\plain \li283\ri0\lin283\rin0\fi-283 2.}\ilvl0 \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ls0\li283\ri0\lin283\rin0\fi-283\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 {\loch\f0\fs24\lang1033\i0\b0 Second}
210
+ \par \pard\plain {\listtext\pard\plain \li283\ri0\lin283\rin0\fi-283 3.}\ilvl0 \ltrpar\s1\cf0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\ls0\li283\ri0\lin283\rin0\fi-283\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 {\loch\f0\fs24\lang1033\i0\b0 Third}
211
+ \par }'
212
+
213
+ end
214
+
215
+ =end
216
+
217
+
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+
4
+ require 'ostruct'
5
+ require 'pubmed2html'
6
+
7
+ if ARGV.size < 2
8
+ puts "usage: #{File.basename($0)} cits.txt ref_list.txt"
9
+ exit
10
+ end
11
+
12
+ cits = ARGV[0]
13
+ reflist = ARGV[1]
14
+
15
+ outf = cits.gsub(/\.txt$/, ".html")
16
+
17
+ def read_reflist(reflist)
18
+ hashes = {}
19
+ reading = false
20
+ key = nil
21
+ File.open(reflist).each do |line|
22
+ if line !~ /[\w\d]/
23
+ reading = false
24
+ elsif reading
25
+ if line =~ /(.*) = (.*)/
26
+ ikey = $1.dup; ival = $2.dup
27
+ if ikey == "authors"
28
+ auths = ival.split(", ")
29
+ ival = []
30
+ auths.each do |auth|
31
+ last, first = auth.split(/\s+/)
32
+ ival << Author.new(last, first)
33
+ end
34
+ end
35
+ hashes[key][ikey] = ival
36
+ end
37
+ elsif line =~ /^\d+\.\s+(.*)/
38
+ key = $1.chomp
39
+ hashes[key] = {}
40
+ reading = true
41
+ end
42
+ end
43
+ hashes
44
+ end
45
+
46
+ def cithash2html(hash)
47
+ #puts "HASH GIVIN: " + hash.to_s
48
+ ob = OpenStruct.new(hash)
49
+ #puts "OBJ: "; p ob
50
+ ob2html(ob)
51
+ end
52
+
53
+ reflist_hash = read_reflist(reflist)
54
+
55
+ #reflist_hash.each do |k,v|
56
+ # puts "****************************************"
57
+ # puts "KEY: #{k}"
58
+ # puts "****************************************"
59
+ # v.each do |kk,vv|
60
+ # puts "#{kk}: #{vv}"
61
+ # end
62
+ #end
63
+
64
+ def html_header
65
+ "<html><body><ol>"
66
+ end
67
+
68
+ def html_tail
69
+ "</ol></body></html>"
70
+ end
71
+
72
+
73
+ html_lines = []
74
+ File.open(cits).each do |line|
75
+ if line =~ /[\w\d]/ && line !~ /^[#]/
76
+ #puts "LINE: " + line
77
+ arr = line.chomp.split
78
+ # is this a pmid?
79
+ if arr[1] =~ /[^\d]/ && arr[1] != "NULL"
80
+ #puts "ARR[1]: " + arr[1]
81
+ # not a pmid
82
+ call_key = arr[1..-1].join(" ")
83
+ #puts "CALLING KEY: " + call_key
84
+ if !reflist_hash.key?(call_key)
85
+ puts "NO RESPONSE FOR #{call_key}"
86
+ exit
87
+ end
88
+ cit_hash = reflist_hash[call_key]
89
+ #p cit_hash
90
+ html_lines << cithash2html(cit_hash)
91
+ else
92
+ #pmid
93
+ html_lines << `ruby pubmed2html.rb #{arr[1]}`
94
+ end
95
+ end
96
+ end
97
+
98
+ File.open(outf, "w") do |fh|
99
+ fh.print html_header + "\n"
100
+ fh.print html_lines.join("\n")
101
+ fh.print html_tail + "\n"
102
+ end
103
+
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+
4
+ $jrn = {
5
+ "Anal. Chem." => "Anal. Chem.",
6
+ "Anal Chem" => "Anal. Chem.",
7
+ "Nature Methods" => "Nature Methods",
8
+ "Analytica Chimica Acta" => "Anal. Chim. Acta",
9
+ "Bioinformatics" => "Bioinformatics",
10
+ "Biomed. Mass Spectrom." => "Biomed. Mass Spectrom.",
11
+ "Biomed Mass Spectrom" => "Biomed. Mass Spectrom.",
12
+ "Environ Sci Technol" => "Environ. Sci. Technol.",
13
+ "Eur. Food Res. Technol." => "Eur. Food Res. Technol.",
14
+ "Genome Res" => "Genome Res.",
15
+ "IEEE ASSP" => "IEEE ASSP",
16
+ "J. Chemom." => "J. Chemom.",
17
+ "J Chemom" => "J. Chemom.",
18
+ "J. Mol. Biol." => "J. Mol. Biol.",
19
+ "J Mol Biol" => "J. Mol. Biol.",
20
+ "J. Am. Soc. Mass Spectrom." => "J. Am. Soc. Mass Spectrom.",
21
+ "J. Chromatogr., A" => "J. Chromatogr., A",
22
+ "J Chromatogr B Analyt Technol Biomed Life Sci" => "J. Chromatogr., B",
23
+ "J Proteome Res" => "J. Proteome Res.",
24
+ "J. Proteome Res." => "J. Proteome Res.",
25
+ "J Chromatogr A" => "J. Chromatogr., A",
26
+ "KDD Workshop on Mining Temporal and Sequential Data" => "KDD Workshop MTSD",
27
+ "Mol Cell Proteomics" => "Mol. Cell. Proteomics",
28
+ "Nat Biotechnol" => "Nat. Biotechnol.",
29
+ "Nature" => "Nature",
30
+ "Nat Chem Biol" => "Nat. Chem. Biol.",
31
+ "Nucleic Acids Res" => "Nucleic Acids Res.",
32
+ "Proteomics" => "Proteomics",
33
+ "SIAM J. Num. Anal." => "SIAM J. Num. Anal.",
34
+ "Rapid Commun Mass Spectrom" => "Rapid Commun. Mass Spectrom.",
35
+ }
36
+
37
+ $LOAD_PATH << "lib"
38
+ require 'pub_med'
39
+ require 'citation'
40
+
41
+
42
+ # takes author objects
43
+ def authors_to_list(authors)
44
+ auths = []
45
+ authors.each do |auth|
46
+ a_init = ""
47
+ if auth.initials =~ /\./
48
+ a_init = auth.initials
49
+ else
50
+ a_init = auth.initials.split("").join(".") + '.'
51
+ end
52
+ auths << auth.last + ', ' + a_init
53
+ end
54
+ auths.join("; ")
55
+ end
56
+
57
+ # ob needs to respond to authors, journal, etc
58
+ def ob2html(ob)
59
+ string = ""
60
+ if ob.respond_to?(:btype) && ob.btype != "article"
61
+ ## Type specific
62
+ #puts "NON ARTICLE!"
63
+ if ob.btype == "workshop"
64
+ string = "<li>#{authors_to_list(ob.authors)} <span style=\"font-style:italic;\">#{format_journal(ob.name)}</span>. <span style=\"font-weight:bold\">#{ob.year}</span>.</li>"
65
+
66
+ else
67
+ puts "don't recognize type: #{ob.btype}"
68
+ exit
69
+ end
70
+ # Ho, M.; Pemberton, J. E. Anal. Chem.1998, 70, 4915�4920.
71
+ # (2) Bard, A. J.; Faulker, L. R. Electrochemical Methods, 2nd ed.; Wiley:
72
+ # New York; 2001.
73
+ # (3) Francesconi, K. A.; Kuehnelt, D. In Environmental Chemistry of Arsenic;
74
+ # Frankenberger, W. T., Jr., Ed.; Marcel Dekker: New York, 2002;
75
+ # pp 51�94.
76
+
77
+ else
78
+ #p ob
79
+ string = "<li>#{authors_to_list(ob.authors)} <span style=\"font-style:italic;\">#{format_journal(ob.journal)}</span>. <span style=\"font-weight:bold\">#{ob.year}</span>, <span style=\"font-style:italic;\">#{ob.vol}</span>, #{ob.pages}.</li>"
80
+ end
81
+ string
82
+ end
83
+
84
+
85
+ # journal from pubmed
86
+ def format_journal(journal)
87
+ if $jrn.key?(journal)
88
+ $jrn[journal].gsub(/(\.\.$)|(\.$)/, "")
89
+ else
90
+ puts "NO KEY FOR: #{journal}"
91
+ nil
92
+ end
93
+ end
94
+
95
+
96
+ if $0 == __FILE__
97
+ if ARGV.size < 1
98
+ puts "usage: #{File.basename($0)} pmid ..."
99
+ puts "outputs <li> item of the citation based on internal formatting"
100
+ exit
101
+ end
102
+
103
+ ids = ARGV.to_a
104
+ ids.each do |id|
105
+ ob = PubMed.new(id)
106
+ ## FORMAT THE RESULT:
107
+
108
+ #ob.attr_as_hash.each do |k,v| puts k.to_s + " : " + v.to_s end
109
+
110
+
111
+ # Last, F.M.; Last, F.M. <i>Journ.</i> <b>YEAR</b>, <i>VOL</i>, pages-pages.
112
+
113
+ # analytical chemistry
114
+ puts ob2html(ob)
115
+ end
116
+ end
117
+
118
+
119
+
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $LOAD_PATH.push File.join( File.dirname(__FILE__), "lib" )
4
+
5
+ ###############################################################################
6
+ # John Prince
7
+ # pubmed_bib_write.rb
8
+ # Takes a list of pubmed id's, queries pubmed to get the citation,
9
+ # and outputs a rich text format (rtf) document based on the below $TEMPLATE
10
+ ###############################################################################
11
+
12
+ ###########################################################################
13
+ ###########################################################################
14
+ # Choose the style of bibliography here:
15
+ ##### Four Formatting tags:
16
+ # n = normal text
17
+ # b = bold
18
+ # i = italics
19
+ # u = underline
20
+
21
+ ##### Helper tags (shouldn't go inside other tags)
22
+ # s = space (normal text)
23
+ # dot = '.'
24
+ # ds = '. '
25
+ # sd = ' .'
26
+
27
+ ##### Lightweight tags (must be format still)
28
+ # para = parenthesized eg ()
29
+
30
+ # NOTE: Author list is guaranteed to end in a period!
31
+ $styles = {
32
+ 'article' => 'n(author_list) + s + para(@year) + ds + b(@title) + ds + i(@journal) + ds + n(@vol + para(@issue) + ":" + @pages) + dot',
33
+ 'article_to_be_submitted' => 'n(author_list) + s + b(@title) + ds + i(@journal) + ds + i("to be submitted") + dot',
34
+ 'book' => 'n(author_list) + s + para(@pub_year) + ds + b(@title) + ds + i(@publisher) + dot',
35
+ 'webpage' => 'b(@title) + ds + u(@href)'
36
+ }
37
+
38
+ # CITATION VARIABLES:
39
+ # the font size of the in-text citation marker
40
+ # 7 is default
41
+ CIT_FONTSIZE = 7
42
+ # the height of the in-text citation marker (range at least -7 to 7)
43
+ # 5 is probably a good height
44
+ CIT_HEIGHT = 6
45
+ # Replaces the brackets in the paper with numbered footnotes
46
+ REPLACE_CITATIONS = true
47
+
48
+ $FILE_TRAILER = "_PRETTY.rtf"
49
+
50
+ ###########################################################################
51
+ ###########################################################################
52
+
53
+ def usage
54
+ string =<<HERE
55
+ ***************************************************************
56
+ * usage: #{File.basename($0)} file.rtf ref_file.txt *
57
+ * - change templates in the program for different formats *
58
+ ***************************************************************
59
+ HERE
60
+ end
61
+
62
+
63
+ ## This is a hack to fix author names with strange characters:
64
+ def correct_author_lists(citation_hash)
65
+ citation_hash[:authors].each do |auth|
66
+ auth.last.gsub!(/Pasa-Toli.*/, 'Pasa-Tolic')
67
+ auth.last.gsub!(/G.rg/, 'Gorg') # can't get this one working...
68
+ end
69
+ end
70
+
71
+
72
+ require 'bib_writer'
73
+
74
+ # citations will look like this:
75
+ # [pmid 123456] or [ref 23]
76
+
77
+ unless ARGV.length == 2
78
+ puts usage()
79
+ exit
80
+ end
81
+
82
+ file = ARGV[0]
83
+ ref_file = ARGV[1]
84
+
85
+ bib = BibWriter.new(file, ref_file)
86
+ bib.read_citations(REPLACE_CITATIONS, CIT_FONTSIZE, CIT_HEIGHT)
87
+ string = bib.create_bib($styles)
88
+ out = file.gsub(/\.\w+$/, $FILE_TRAILER)
89
+ File.open(out, "w") do |file|
90
+ file.print string
91
+ end
92
+