| 1 | package Boulder::Medline; | ||
| 2 | # | ||
| 3 | use Boulder::Stream; | ||
| 4 | require Exporter; | ||
| 5 | @ISA = qw(Exporter Boulder::Stream); | ||
| 6 | @EXPORT = (); | ||
| 7 | @EXPORT_OK = (); | ||
| 8 | use Carp; | ||
| 9 | $VERSION=1.02; | ||
| 10 | use constant DEFAULT_MEDLINE_PATH => '/data/medline/medline.txt'; | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | Boulder::Medline - Fetch Medline data records as parsed Boulder Stones | ||
| 15 | |||
| 16 | =head1 SYNOPSIS | ||
| 17 | |||
| 18 | # parse a file of Medline records | ||
| 19 | $ml = new Boulder::Medline(-accessor=>'File', | ||
| 20 | -param => '/data/medline/medline.txt'); | ||
| 21 | while (my $s = $ml->get) { | ||
| 22 | print $s->Identifier; | ||
| 23 | print $s->Abstract; | ||
| 24 | } | ||
| 25 | |||
| 26 | # parse flatfile yourself | ||
| 27 | open (ML,"/data/medline/medline.txt"); | ||
| 28 | local $/ = "*RECORD*"; | ||
| 29 | while (<ML>) { | ||
| 30 | my $s = Boulder::Medline->parse($_); | ||
| 31 | # etc. | ||
| 32 | } | ||
| 33 | |||
| 34 | =head1 DESCRIPTION | ||
| 35 | |||
| 36 | Boulder::Medline provides retrieval and parsing services for Medline records | ||
| 37 | |||
| 38 | Boulder::Medline provides retrieval and parsing services for NCBI | ||
| 39 | Medline records. It returns Medline entries in L<Stone> | ||
| 40 | format, allowing easy access to the various fields and values. | ||
| 41 | Boulder::Medline is a descendent of Boulder::Stream, and provides a | ||
| 42 | stream-like interface to a series of Stone objects. | ||
| 43 | |||
| 44 | Access to Medline is provided by one I<accessors>, which | ||
| 45 | give access to local Medline database. When you | ||
| 46 | create a new Boulder::Medline stream, you provide the | ||
| 47 | accessors, along with accessor-specific parameters that control what | ||
| 48 | entries to fetch. The accessors is: | ||
| 49 | |||
| 50 | =over 2 | ||
| 51 | |||
| 52 | =item File | ||
| 53 | |||
| 54 | This provides access to local Medline entries by reading from a flat file. | ||
| 55 | The stream will return a Stone corresponding to each of the entries in | ||
| 56 | the file, starting from the top of the file and working downward. The | ||
| 57 | parameter is the path to the local file. | ||
| 58 | |||
| 59 | =back | ||
| 60 | |||
| 61 | It is also possible to parse a single Medline entry from a text string | ||
| 62 | stored in a scalar variable, returning a Stone object. | ||
| 63 | |||
| 64 | =head2 Boulder::Medline methods | ||
| 65 | |||
| 66 | This section lists the public methods that the I<Boulder::Medline> | ||
| 67 | class makes available. | ||
| 68 | |||
| 69 | =over 4 | ||
| 70 | |||
| 71 | =item new() | ||
| 72 | |||
| 73 | # Local fetch via File | ||
| 74 | $ml=new Boulder::Medline(-accessor => 'File', | ||
| 75 | -param => '/data/medline/medline.txt'); | ||
| 76 | |||
| 77 | The new() method creates a new I<Boulder::Medline> stream on the | ||
| 78 | accessor provided. The only possible accessors is B<File>. | ||
| 79 | If successful, the method returns the stream | ||
| 80 | object. Otherwise it returns undef. | ||
| 81 | |||
| 82 | new() takes the following arguments: | ||
| 83 | |||
| 84 | -accessor Name of the accessor to use | ||
| 85 | -param Parameters to pass to the accessor | ||
| 86 | |||
| 87 | Specify the accessor to use with the B<-accessor> argument. If not | ||
| 88 | specified, it defaults to B<File>. | ||
| 89 | |||
| 90 | B<-param> is an accessor-specific argument. The possibilities is: | ||
| 91 | |||
| 92 | For B<File>, the B<-param> argument must point to a string-valued | ||
| 93 | scalar, which will be interpreted as the path to the file to read | ||
| 94 | Medline entries from. | ||
| 95 | |||
| 96 | =item get() | ||
| 97 | |||
| 98 | The get() method is inherited from I<Boulder::Stream>, and simply | ||
| 99 | returns the next parsed Medline Stone, or undef if there is nothing | ||
| 100 | more to fetch. It has the same semantics as the parent class, | ||
| 101 | including the ability to restrict access to certain top-level tags. | ||
| 102 | |||
| 103 | =item put() | ||
| 104 | |||
| 105 | The put() method is inherited from the parent Boulder::Stream class, | ||
| 106 | and will write the passed Stone to standard output in Boulder format. | ||
| 107 | This means that it is currently not possible to write a | ||
| 108 | Boulder::Medline object back into Medline flatfile form. | ||
| 109 | |||
| 110 | =back | ||
| 111 | |||
| 112 | =head1 OUTPUT TAGS | ||
| 113 | |||
| 114 | The tags returned by the parsing operation are taken from the MEDLARS definition file | ||
| 115 | MEDDOC.DOC | ||
| 116 | |||
| 117 | |||
| 118 | =head2 Top-Level Tags | ||
| 119 | |||
| 120 | These are tags that appear at the top level of the parsed Medline entry. | ||
| 121 | |||
| 122 | =over 4 | ||
| 123 | |||
| 124 | ABSTRACT | ||
| 125 | ABSTRACT AUTHOR | ||
| 126 | ADDRESS | ||
| 127 | AUTHOR | ||
| 128 | CALL NUMBER | ||
| 129 | CAS REGISTRY/EC NUMBER | ||
| 130 | CLASS UPDATE DATE | ||
| 131 | COMMENTS | ||
| 132 | COUNTRY | ||
| 133 | DATE OF ENTRY | ||
| 134 | DATE OF PUBLICATION | ||
| 135 | ENGLISH ABSTRACT INDICATOR | ||
| 136 | ENTRY MONTH | ||
| 137 | GENE SYMBOL | ||
| 138 | ID NUMBER | ||
| 139 | INDEXING PRIORITY | ||
| 140 | ISSN | ||
| 141 | ISSUE/PART/SUPPLEMENT | ||
| 142 | JOURNAL SUBSET | ||
| 143 | JOURNAL TITLE CODE | ||
| 144 | LANGUAGE | ||
| 145 | LAST REVISION DATE | ||
| 146 | MACHINE-READABLE IDENTIFIER | ||
| 147 | MeSH HEADING | ||
| 148 | NO-AUTHOR INDICATOR | ||
| 149 | NOT FOR PUBLICATION | ||
| 150 | NUMBER OF REFERENCES | ||
| 151 | PAGINATION | ||
| 152 | PERSONAL NAME AS SUBJECT | ||
| 153 | PUBLICATION TYPE | ||
| 154 | RECORD ORIGINATOR | ||
| 155 | SECONDARY SOURCE ID | ||
| 156 | SPECIAL LIST INDICATOR | ||
| 157 | TITLE | ||
| 158 | TITLE ABBREVIATION | ||
| 159 | TRANSLITERATED/VERNACULAR TITLE | ||
| 160 | UNIQUE IDENTIFIER | ||
| 161 | VOLUME ISSUE | ||
| 162 | |||
| 163 | =item Identifier | ||
| 164 | |||
| 165 | The Medline identifier of this entry. Identifier is a single-value tag. | ||
| 166 | |||
| 167 | Example: | ||
| 168 | |||
| 169 | my $identifierNo = $s->Identifier; | ||
| 170 | |||
| 171 | =item Title | ||
| 172 | |||
| 173 | The Medline title for this entry. | ||
| 174 | |||
| 175 | Example: | ||
| 176 | my $titledef=$s->Title; | ||
| 177 | |||
| 178 | =back | ||
| 179 | |||
| 180 | =head1 SEE ALSO | ||
| 181 | |||
| 182 | L<Boulder>, L<Boulder::Blast>, L<Boulder::Genbank> | ||
| 183 | |||
| 184 | =head1 AUTHOR | ||
| 185 | |||
| 186 | Lincoln Stein <lstein@cshl.org>. | ||
| 187 | Luca I.G. Toldo <luca.toldo@merck.de> | ||
| 188 | |||
| 189 | Copyright (c) 1997 Lincoln D. Stein | ||
| 190 | Copyright (c) 1999 Luca I.G. Toldo | ||
| 191 | |||
| 192 | This library is free software; you can redistribute it and/or modify | ||
| 193 | it under the same terms as Perl itself. See DISCLAIMER.txt for | ||
| 194 | disclaimers of warranty. | ||
| 195 | |||
| 196 | =cut | ||
| 197 | |||
| 198 | # | ||
| 199 | # Following did not require any changes compared to Genbank.pm | ||
| 200 | # | ||
| 201 | sub new { | ||
| 202 | my($package,@parameters) = @_; | ||
| 203 | # superclass constructor | ||
| 204 | my($self) = new Boulder::Stream; | ||
| 205 | |||
| 206 | # figure out whether parameters are named. Look for | ||
| 207 | # an initial '-' | ||
| 208 | if ($parameters[0]=~/^-/) { | ||
| 209 | my(%parameters) = @parameters; | ||
| 210 | $self->{'accessor'}=$parameters{'-accessor'} || 'File'; | ||
| 211 | $self->{'param'}=$parameters{'-param'}; | ||
| 212 | $self->{'OUT'}=$parameters{'-out'} || 'main::STDOUT'; | ||
| 213 | } else { | ||
| 214 | $self->{'accessor'}='File'; | ||
| 215 | $self->{'param'}=[@parameters]; | ||
| 216 | } | ||
| 217 | |||
| 218 | croak "Require parameters" unless defined($self->{'param'}); | ||
| 219 | $self->{'accessor'} = new {$self->{'accessor'}}($self->{'param'}); | ||
| 220 | |||
| 221 | return bless $self,$package; | ||
| 222 | } | ||
| 223 | |||
| 224 | # | ||
| 225 | # Following required no changes compared to Genbank.pm | ||
| 226 | # | ||
| 227 | sub read_record { | ||
| 228 | my($self,@tags) = @_; | ||
| 229 | my($s); | ||
| 230 | |||
| 231 | if (wantarray) { | ||
| 232 | my(@result); | ||
| 233 | while (!$self->{'done'}) { | ||
| 234 | $s = $self->read_one_record(@tags); | ||
| 235 | next unless $s; | ||
| 236 | next if $query && !(&$query); | ||
| 237 | push(@result,$s); | ||
| 238 | } | ||
| 239 | return @result; | ||
| 240 | } | ||
| 241 | |||
| 242 | # we get here if in a scalar context | ||
| 243 | while (!$self->{'done'}) { | ||
| 244 | $s = $self->read_one_record(@tags); | ||
| 245 | next unless $s; | ||
| 246 | return $s unless $query; | ||
| 247 | return $s if &$query; | ||
| 248 | } | ||
| 249 | return undef; | ||
| 250 | } | ||
| 251 | |||
| 252 | #<LIGT> | ||
| 253 | # Here is everything new | ||
| 254 | #</LIGT> | ||
| 255 | sub parse { | ||
| 256 | my $self = shift; | ||
| 257 | my $record = shift; | ||
| 258 | return unless $record; | ||
| 259 | my $tags = shift; | ||
| 260 | my %ok; | ||
| 261 | %ok = map {$_ => 1} @$tags if ref($tags) eq 'ARRAY'; | ||
| 262 | my($s,@lines,$line,$accumulated,$key,$keyword,$value,$feature,@features, $label); | ||
| 263 | |||
| 264 | $s = new Stone; | ||
| 265 | #<LIGT> following this line the parsing of the record must be done | ||
| 266 | # each key-value pair is stored by the following command: | ||
| 267 | # $self->_addToStone($key,$value,$stone,\%ok); | ||
| 268 | # | ||
| 269 | # Process new record lines | ||
| 270 | # | ||
| 271 | # | ||
| 272 | (@recordlines)=split(/\n/,$record); | ||
| 273 | for ($i=0; $i<=$#recordlines; $i++) { | ||
| 274 | $line=@recordlines[$i]; | ||
| 275 | if ($line=~/^UI/) { ($junk,$ui)=split(/ \- /,$line);$label="ID"; | ||
| 276 | }elsif ($line=~/^DA/) { ($junk,$da)=split(/ \- /,$line);$label="DA"; | ||
| 277 | }elsif ($line=~/^PMID/) { ($junk,$pmid)=split(/\- /,$line);$label="PMID"; | ||
| 278 | }elsif ($line=~/^AD/) { ($junk,$ad)=split(/ \- /,$line);$label="AD"; | ||
| 279 | }elsif ($line=~/^SO/) { ($junk,$so)=split(/ \- /,$line);$label="SO"; | ||
| 280 | }elsif ($line=~/^EM/) { ($junk,$em)=split(/ \- /,$line);$label="EM"; | ||
| 281 | }elsif ($line=~/^AA/) { ($junk,$aa)=split(/ \- /,$line);$label="AA"; | ||
| 282 | }elsif ($line=~/^JC/) { ($junk,$jc)=split(/ \- /,$line);$label="JC"; | ||
| 283 | }elsif ($line=~/^VI/) { ($junk,$vi)=split(/ \- /,$line);$label="VI"; | ||
| 284 | }elsif ($line=~/^IP/) { ($junk,$ip)=split(/ \- /,$line);$label="IP"; | ||
| 285 | }elsif ($line=~/^CY/) { ($junk,$cj)=split(/ \- /,$line);$label="CY"; | ||
| 286 | }elsif ($line=~/^DP/) { ($junk,$dp)=split(/ \- /,$line);$label="DP"; | ||
| 287 | }elsif ($line=~/^IS/) { ($junk,$is)=split(/ \- /,$line);$label="IS"; | ||
| 288 | }elsif ($line=~/^TA/) { ($junk,$ta)=split(/ \- /,$line);$label="TA"; | ||
| 289 | }elsif ($line=~/^PG/) { ($junk,$pg)=split(/ \- /,$line);$label="PG"; | ||
| 290 | }elsif ($line=~/^TI/) { ($junk,$ti)=split(/ \- /,$line);$label="TI"; | ||
| 291 | }elsif ($line=~/^AB/) { ($junk,$ab)=split(/ \- /,$line);$label="AB"; | ||
| 292 | }elsif ($line=~/^CA/) { ($junk,$ca)=split(/ \- /,$line);$label="CA"; | ||
| 293 | }elsif ($line=~/^CU/) { ($junk,$cu)=split(/ \- /,$line);$label="CU"; | ||
| 294 | }elsif ($line=~/^CY/) { ($junk,$cy)=split(/ \- /,$line);$label="CY"; | ||
| 295 | }elsif ($line=~/^DP/) { ($junk,$dp)=split(/ \- /,$line);$label="DP"; | ||
| 296 | }elsif ($line=~/^EA/) { ($junk,$ea)=split(/ \- /,$line);$label="EA"; | ||
| 297 | }elsif ($line=~/^PY/) { ($junk,$py)=split(/ \- /,$line);$label="PY"; | ||
| 298 | }elsif ($line=~/^LR/) { ($junk,$lr)=split(/ \- /,$line);$label="LR"; | ||
| 299 | }elsif ($line=~/^MRI/) { ($junk,$mri)=split(/ \- /,$line);$label="MRI"; | ||
| 300 | }elsif ($line=~/^NI/) { ($junk,$ni)=split(/ \- /,$line);$label="NI"; | ||
| 301 | }elsif ($line=~/^NP/) { ($junk,$np)=split(/ \- /,$line);$label="NP"; | ||
| 302 | }elsif ($line=~/^RF/) { ($junk,$rf)=split(/ \- /,$line);$label="RF"; | ||
| 303 | }elsif ($line=~/^PG/) { ($junk,$pg)=split(/ \- /,$line);$label="PG"; | ||
| 304 | }elsif ($line=~/^LI/) { ($junk,$li)=split(/ \- /,$line);$label="LI"; | ||
| 305 | }elsif ($line=~/^TT/) { ($junk,$tt)=split(/ \- /,$line);$label="TT"; | ||
| 306 | # following are records which may appear multiple times | ||
| 307 | }elsif ($line=~/^RO/) { ($junk,$ro_tmp)=split(/ \- /,$line);$label="RO";$ro.=$ro_tmp."\n"; | ||
| 308 | }elsif ($line=~/^RN/) { ($junk,$rn_tmp)=split(/ \- /,$line);$label="RN";$rn.=$rn_tmp."\n"; | ||
| 309 | }elsif ($line=~/^LA/) { ($junk,$la_tmp)=split(/ \- /,$line);$label="LA";$la.=$la_tmp."\n"; | ||
| 310 | }elsif ($line=~/^SB/) { ($junk,$sb_tmp)=split(/ \- /,$line);$label="SB";$sb.=$sb_tmp."\n"; | ||
| 311 | }elsif ($line=~/^GS/) { ($junk,$gs_tmp)=split(/ \- /,$line);$label="GS";$gs.=$gs_tmp."\n"; | ||
| 312 | }elsif ($line=~/^MH/) { ($junk,$mh_tmp)=split(/ \- /,$line);$label="MH";$mh.=$mh_tmp."\n"; | ||
| 313 | }elsif ($line=~/^PT/) { ($junk,$pt_tmp)=split(/ \- /,$line);$label="PT";$pt.=$pt_tmp."\n"; | ||
| 314 | }elsif ($line=~/^AU/) { ($junk,$au_tmp)=split(/ \- /,$line);$label="AU"; $au.=$au_tmp."\n"; | ||
| 315 | }elsif ($line=~/^PS/) { ($junk,$ps_tmp)=split(/ \- /,$line);$label="PS";$ps.=$ps_tmp."\n"; | ||
| 316 | }elsif ($line=~/^CM/) { ($junk,$cm_tmp)=split(/ \- /,$line);$label="CM";$cm.=$cm_tmp."\n"; | ||
| 317 | }elsif ($line=~/^SI/) { ($junk,$si_tmp)=split(/ \- /,$line);$label="SI";$si.=$si_tmp."\n"; | ||
| 318 | }elsif ($line=~/^ID/) { ($junk,$id_tmp)=split(/ \- /,$line);$label="ID";$id.=$id_tmp."\n"; | ||
| 319 | } else { | ||
| 320 | # handle multiline records with empty header | ||
| 321 | if ($label=~/TI/) { | ||
| 322 | $ti.=$line; | ||
| 323 | } elsif ($label=~/AB/) { | ||
| 324 | $ab.=$line; | ||
| 325 | } else { | ||
| 326 | } | ||
| 327 | } | ||
| 328 | } | ||
| 329 | # First add the single field records | ||
| 330 | $self->_addToStone('Identifier',$ui,$s,\%ok); | ||
| 331 | $self->_addToStone('Title',$ti,$s,\%ok); | ||
| 332 | $self->_addToStone('Abstract',$ab,$s,\%ok); | ||
| 333 | $self->_addToStone('AbstractAuthor',$aa,$s,\%ok); | ||
| 334 | $self->_addToStone('Address',$ab,$s,\%ok); | ||
| 335 | $self->_addToStone('CallNumber',$ca,$s,\%ok); | ||
| 336 | $self->_addToStone('ClassUpdateDate',$cu,$s,\%ok); | ||
| 337 | $self->_addToStone('Country',$cy,$s,\%ok); | ||
| 338 | $self->_addToStone('DateOfEntry',$da,$s,\%ok); | ||
| 339 | $self->_addToStone('DateOfPublication',$dp,$s,\%ok); | ||
| 340 | $self->_addToStone('EnglishAbstractIndicator',$ea,$s,\%ok); | ||
| 341 | $self->_addToStone('EntryMonth',$em,$s,\%ok); | ||
| 342 | $self->_addToStone('IndexingPriority',$py,$s,\%ok); | ||
| 343 | $self->_addToStone('ISSN',$is,$s,\%ok); | ||
| 344 | $self->_addToStone('IssuePartSupplement',$is,$s,\%ok); | ||
| 345 | $self->_addToStone('JournalTitleCode',$jc,$s,\%ok); | ||
| 346 | $self->_addToStone('LastRevisionDate',$lr,$s,\%ok); | ||
| 347 | $self->_addToStone('MachineReadableIdentifier',$mri,$s,\%ok); | ||
| 348 | $self->_addToStone('NoAuthorIndicator',$ni,$s,\%ok); | ||
| 349 | $self->_addToStone('NotForPublication',$np,$s,\%ok); | ||
| 350 | $self->_addToStone('NumberOfReferences',$rf,$s,\%ok); | ||
| 351 | $self->_addToStone('Pagination',$pg,$s,\%ok); | ||
| 352 | $self->_addToStone('SpecialListIndicator',$li,$s,\%ok); | ||
| 353 | $self->_addToStone('TitleAbbreviation',$ta,$s,\%ok); | ||
| 354 | $self->_addToStone('TranslitteratedVernacularTitle',$tt,$s,\%ok); | ||
| 355 | $self->_addToStone('VolumeIssue',$vi,$s,\%ok); | ||
| 356 | |||
| 357 | #Then handle all other fields which may have multiple values | ||
| 358 | (@TMPs)=split(/\n/,$au); | ||
| 359 | foreach $aui (@TMPs) { | ||
| 360 | $aui=~s/\n//g; | ||
| 361 | $self->_addToStone('Author',$aui,$s,\%ok); | ||
| 362 | } | ||
| 363 | (@TMPs)=split(/\n/,$rn); | ||
| 364 | foreach $aui (@TMPs) { | ||
| 365 | $aui=~s/\n//g; | ||
| 366 | $self->_addToStone('CASRegistryECNumber',$aui,$s,\%ok); | ||
| 367 | } | ||
| 368 | (@TMPs)=split(/\n/,$cm); | ||
| 369 | foreach $aui (@TMPs) { | ||
| 370 | $aui=~s/\n//g; | ||
| 371 | $self->_addToStone('Comments',$aui,$s,\%ok); | ||
| 372 | } | ||
| 373 | (@TMPs)=split(/\n/,$gs); | ||
| 374 | foreach $aui (@TMPs) { | ||
| 375 | $aui=~s/\n//g; | ||
| 376 | $self->_addToStone('GeneSymbol',$aui,$s,\%ok); | ||
| 377 | } | ||
| 378 | (@TMPs)=split(/\n/,$id); | ||
| 379 | foreach $aui (@TMPs) { | ||
| 380 | $aui=~s/\n//g; | ||
| 381 | $self->_addToStone('IDNumber',$aui,$s,\%ok); | ||
| 382 | } | ||
| 383 | (@TMPs)=split(/\n/,$sb); | ||
| 384 | foreach $aui (@TMPs) { | ||
| 385 | $aui=~s/\n//g; | ||
| 386 | $self->_addToStone('JournalSubset',$aui,$s,\%ok); | ||
| 387 | } | ||
| 388 | (@TMPs)=split(/\n/,$la); | ||
| 389 | foreach $aui (@TMPs) { | ||
| 390 | $aui=~s/\n//g; | ||
| 391 | $self->_addToStone('Language',$aui,$s,\%ok); | ||
| 392 | } | ||
| 393 | (@TMPs)=split(/\n/,$mh); | ||
| 394 | foreach $aui (@TMPs) { | ||
| 395 | $aui=~s/\n//g; | ||
| 396 | $self->_addToStone('MeSHHeading',$aui,$s,\%ok); | ||
| 397 | } | ||
| 398 | |||
| 399 | (@TMPs)=split(/\n/,$ps); | ||
| 400 | foreach $aui (@TMPs) { | ||
| 401 | $aui=~s/\n//g; | ||
| 402 | $self->_addToStone('PersonalNameAsSubject',$aui,$s,\%ok); | ||
| 403 | } | ||
| 404 | (@TMPs)=split(/\n/,$pt); | ||
| 405 | foreach $aui (@TMPs) { | ||
| 406 | $aui=~s/\n//g; | ||
| 407 | $self->_addToStone('PublicationType',$aui,$s,\%ok); | ||
| 408 | } | ||
| 409 | (@TMPs)=split(/\n/,$ro); | ||
| 410 | foreach $aui (@TMPs) { | ||
| 411 | $aui=~s/\n//g; | ||
| 412 | $self->_addToStone('RecordOriginator',$aui,$s,\%ok); | ||
| 413 | } | ||
| 414 | (@TMPs)=split(/\n/,$si); | ||
| 415 | foreach $aui (@TMPs) { | ||
| 416 | $aui=~s/\n//g; | ||
| 417 | $self->_addToStone('SecondarySourceId',$aui,$s,\%ok); | ||
| 418 | } | ||
| 419 | #</LIGT> | ||
| 420 | return $s; | ||
| 421 | } | ||
| 422 | |||
| 423 | # | ||
| 424 | # Following is unchanged from Genbank.pm | ||
| 425 | # | ||
| 426 | sub read_one_record { | ||
| 427 | my($self,@tags) = @_; | ||
| 428 | my(%ok); | ||
| 429 | my $accessor = $self->{'accessor'}; | ||
| 430 | my $record = $accessor->fetch_next(); | ||
| 431 | unless ($record) { | ||
| 432 | $self->{'done'}++; | ||
| 433 | return undef; | ||
| 434 | } | ||
| 435 | |||
| 436 | return $self->parse($record,\@tags); | ||
| 437 | } | ||
| 438 | |||
| 439 | # | ||
| 440 | # Following is unchanged from Genbank.pm | ||
| 441 | # | ||
| 442 | sub _trim { | ||
| 443 | my($v) = @_; | ||
| 444 | $v=~s/^\s+//; | ||
| 445 | $v=~s/\s+$//; | ||
| 446 | return $v; | ||
| 447 | } | ||
| 448 | |||
| 449 | # | ||
| 450 | # Following is unchanged from Genbank.pm | ||
| 451 | # | ||
| 452 | sub _canonicalize { | ||
| 453 | my $h = shift; | ||
| 454 | substr($h,0)=~tr/a-z/A-Z/; | ||
| 455 | substr($h,1,length($h)-1)=~tr/A-Z/a-z/; | ||
| 456 | $h; | ||
| 457 | } | ||
| 458 | |||
| 459 | # | ||
| 460 | # Following is unchanged from Genbank.pm | ||
| 461 | # | ||
| 462 | sub _addToStone { | ||
| 463 | my($self,$xlabel,$value,$stone,$ok) = @_; | ||
| 464 | return unless !%{$ok} || $ok->{$xlabel}; | ||
| 465 | $stone->insert(_canonicalize($xlabel),$value); | ||
| 466 | } | ||
| 467 | |||
| 468 | #<LIGT> | ||
| 469 | # Following is entirely rewritten | ||
| 470 | #</LIGT> | ||
| 471 | sub _addFeaturesToStone { | ||
| 472 | my($self,$features,$basecount,$stone,$ok) = @_; | ||
| 473 | } | ||
| 474 | |||
| 475 | |||
| 476 | |||
| 477 | # -------------------------- DEFINITION OF ACCESSOR OBJECTS ------------------------------ | ||
| 478 | #<LIGT> | ||
| 479 | #only name changes for avoid namespace collisions | ||
| 480 | #</LIGT> | ||
| 481 | package MedlineAccessor; | ||
| 482 | use Carp; | ||
| 483 | |||
| 484 | sub new { | ||
| 485 | my($class,@parameters) = @_; | ||
| 486 | croak "MedlineAccessor::new: Abstract class\n"; | ||
| 487 | } | ||
| 488 | |||
| 489 | sub fetch_next { | ||
| 490 | my($self) = @_; | ||
| 491 | croak "MedlineAccessor::fetch_next: Abstract class\n"; | ||
| 492 | } | ||
| 493 | |||
| 494 | sub DESTROY { | ||
| 495 | } | ||
| 496 | |||
| 497 | #<LIGT> | ||
| 498 | # Following, only the File package since the only one supported. | ||
| 499 | # If other access methods must be supported, then here appropriate | ||
| 500 | # packages and methods must be implemented | ||
| 501 | #</LIGT> | ||
| 502 | package File; | ||
| 503 | use Carp; | ||
| 504 | @ISA=qw(MedlineAccessor); | ||
| 505 | $DEFAULT_PATH = Boulder::Medline::DEFAULT_MEDLINE_PATH(); | ||
| 506 | |||
| 507 | #<LIGT> | ||
| 508 | # Following, removed the search for the string locus in the file | ||
| 509 | # as validation that the input be compliant with parser | ||
| 510 | #</LIGT> | ||
| 511 | sub new { | ||
| 512 | my($package,$path) = @_; | ||
| 513 | $path = $DEFAULT_PATH unless $path; | ||
| 514 | open (ML,$path) or croak "File::new(): couldn't open $path: $!"; | ||
| 515 | # read the junk at the beginning | ||
| 516 | my $found; $found++; | ||
| 517 | croak "File::new(): $path doesn't look like a Medline flat file" | ||
| 518 | unless $found; | ||
| 519 | $_ = <ML>; | ||
| 520 | return bless {'fh'=>ML},$package; | ||
| 521 | } | ||
| 522 | |||
| 523 | #<LIGT> | ||
| 524 | # Following, changed the record separator | ||
| 525 | #</LIGT> | ||
| 526 | sub fetch_next { | ||
| 527 | my $self = shift; | ||
| 528 | return undef unless $self->{'fh'}; | ||
| 529 | local($/)="*RECORD*\n"; | ||
| 530 | my($line); | ||
| 531 | my($fh) = $self->{'fh'}; | ||
| 532 | chomp($line = <$fh>); | ||
| 533 | return $line; | ||
| 534 | } | ||
| 535 | |||
| 536 | 1; | ||
| 537 | |||
| 538 | __END__ |