generated from greenelab/lab-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_citation_dbase.pl
182 lines (162 loc) · 3.89 KB
/
mk_citation_dbase.pl
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
#!/usr/bin/perl -w
if (scalar(@ARGV) == 1) {
$citeyaml = shift(@ARGV);
} else {
print "usage: mk_citation.dbase.pl citation.yaml >my_sources.yaml\n";
exit();
}
open IN, "<$citeyaml" or die "can't open: $citeyaml!\n";
$entry = 0;
while ($rl = <IN>) {
chomp($rl);
NEW:
if ($rl =~ / id:/) {
# sleep 1;
# get the doi
@e = split '\s+', $rl;
$doi = $e[2];
# print "New entry: $doi\n";
$entry++;
$data{$entry}{"doi"} = $doi;
$data{$entry}{"title"} = "NA";
$data{$entry}{"pubmed"} = "NA";
# print/get the title
$gotit = 0;
$title = "";
while ($gotit == 0) {
$rl = <IN>;
chomp($rl);
if ($rl =~ /authors:/) {
$gotit = 1;
} else {
$title .= $rl;
# print "$rl\n";
}
}
$data{$entry}{"title"} = $title;
#get date
$gotit = 0;
$year = ".";
while ($gotit == 0) {
$rl = <IN>;
chomp($rl);
if ($rl =~ / id:/) {
goto NEW;
} else {
if ($rl =~ / date:/) {
$rl =~ /'([0-9]+)-([0-9]+)-([0-9]+)'/;
$year = $1;
$data{$entry}{year} = $year;
$gotit = 1;
}
}
}
#get buttons, then pubmed
$gotit = 0;
$pubmed = "NA";
while ($gotit == 0) {
$rl = <IN>;
chomp($rl);
if ($rl =~ / id:/) { # new entry, start at the top, output current
# print ">>ENTRY $entry<<\n";
# print "doi: $data{$entry}{doi}\n";
# print "title: $data{$entry}{title}\n";
# print "pmid: $data{$entry}{pubmed}\n";
# if (!defined($data{$entry}{tags}[0])) {
# print "tags: none\n";
# } else {
# for ($j=0; $j<scalar(@{$data{$entry}{tags}}); $j++) {
# if ($j==0) {
# print "tags: $data{$entry}{tags}[$j]";
# } else {
# print " -- $data{$entry}{tags}[$j]";
# }
# }
# print "\n";
# }
goto NEW;
} else {
if ($rl =~ /type: pubmed/) {
$rl = <IN>;
chomp($rl);
$rl =~ /https:\/\/pubmed.ncbi.nlm.nih.gov\/([0-9]+)\//;
$pubmed = $1;
$data{$entry}{"pubmed"} = $pubmed;
$rl = <IN>; #get the residual
} elsif ($rl =~ / tags:/) { #stop reading buttons when you hit tags
$gotit = 1;
}
}
}
#get tags
$gotit = 0;
while ($gotit == 0) {
$rl = <IN>;
if (eof(IN)) {
goto END;
}
chomp($rl);
if ($rl =~ / id:/) { # new entry, start at the top, output current
# print ">>ENTRY $entry<<\n";
# print "doi: $data{$entry}{doi}\n";
# print "title: $data{$entry}{title}\n";
# print "pmid: $data{$entry}{pubmed}\n";
# if (!defined($data{$entry}{tags}[0])) {
# print "tags: none\n";
# } else {
# for ($j=0; $j<scalar(@{$data{$entry}{tags}}); $j++) {
# if ($j==0) {
# print "tags: $data{$entry}{tags}[$j]";
# } else {
# print " -- $data{$entry}{tags}[$j]";
# }
# }
# print "\n";
# }
goto NEW;
}
$rl =~ / - ([\w\d\s\/\-]+)/;
$tag = $1;
#print "tag>> $tag\n";
if (!defined($data{$entry}{tags}[0])) {
$data{$entry}{"tags"}[0] = $tag;
} else {
push @{$data{$entry}{"tags"}}, $tag;
}
}
END:
#print this shit
# print ">>ENTRY $entry<<\n";
# print "doi: $data{$entry}{doi}\n";
# print "title: $data{$entry}{title}\n";
# print "pmid: $data{$entry}{pubmed}\n";
# if (!defined($data{$entry}{tags}[0])) {
# print "tags: none\n";
# } else {
# for ($j=0; $j<scalar(@{$data{$entry}{tags}}); $j++) {
# if ($j==0) {
# print "tags: $data{$entry}{tags}[$j]";
# } else {
# print " -- $data{$entry}{tags}[$j]";
# }
# }
# print "\n";
# }
}
}
## ok database from citations loaded. Now, print a sources.yaml file
foreach $entry (sort {$a <=> $b} keys %data) {
print "$entry,$data{$entry}{doi},$data{$entry}{title},$data{$entry}{year},$data{$entry}{pubmed},";
if (!defined($data{$entry}{tags}[0])) {
print ".\n";
} else {
for ($j=0; $j<scalar(@{$data{$entry}{tags}}); $j++) {
if ($j==0) {
print "$data{$entry}{tags}[$j]";
} else {
print ",$data{$entry}{tags}[$j]";
}
}
print "\n";
}
}