Package Bio :: Package Medline
[hide private]
[frames] | no frames]

Source Code for Package Bio.Medline

  1  # Copyright 1999 by Jeffrey Chang.  All rights reserved. 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package. 
  5   
  6  """ 
  7  This module provides code to work with Medline. 
  8   
  9  Classes: 
 10  Record           A dictionary holding Medline data. 
 11   
 12  Functions: 
 13  read             Reads one Medline record 
 14  parse            Allows you to iterate over a bunch of Medline records 
 15  """ 
 16   
17 -class Record(dict):
18 """A dictionary holding information from a Medline record. 19 All data are stored under the mnemonic appearing in the Medline 20 file. These mnemonics have the following interpretations: 21 22 Mnemonic Description 23 AB Abstract 24 CI Copyright Information 25 AD Affiliation 26 IRAD Investigator Affiliation 27 AID Article Identifier 28 AU Author 29 FAU Full Author 30 CN Corporate Author 31 DCOM Date Completed 32 DA Date Created 33 LR Date Last Revised 34 DEP Date of Electronic Publication 35 DP Date of Publication 36 EDAT Entrez Date 37 GS Gene Symbol 38 GN General Note 39 GR Grant Number 40 IR Investigator Name 41 FIR Full Investigator Name 42 IS ISSN 43 IP Issue 44 TA Journal Title Abbreviation 45 JT Journal Title 46 LA Language 47 LID Location Identifier 48 MID Manuscript Identifier 49 MHDA MeSH Date 50 MH MeSH Terms 51 JID NLM Unique ID 52 RF Number of References 53 OAB Other Abstract 54 OCI Other Copyright Information 55 OID Other ID 56 OT Other Term 57 OTO Other Term Owner 58 OWN Owner 59 PG Pagination 60 PS Personal Name as Subject 61 FPS Full Personal Name as Subject 62 PL Place of Publication 63 PHST Publication History Status 64 PST Publication Status 65 PT Publication Type 66 PUBM Publishing Model 67 PMC PubMed Central Identifier 68 PMID PubMed Unique Identifier 69 RN Registry Number/EC Number 70 NM Substance Name 71 SI Secondary Source ID 72 SO Source 73 SFM Space Flight Mission 74 STAT Status 75 SB Subset 76 TI Title 77 TT Transliterated Title 78 VI Volume 79 CON Comment on 80 CIN Comment in 81 EIN Erratum in 82 EFR Erratum for 83 CRI Corrected and Republished in 84 CRF Corrected and Republished from 85 PRIN Partial retraction in 86 PROF Partial retraction of 87 RPI Republished in 88 RPF Republished from 89 RIN Retraction in 90 ROF Retraction of 91 UIN Update in 92 UOF Update of 93 SPIN Summary for patients in 94 ORI Original report in 95 """
96 97
98 -def parse(handle):
99 """Read Medline records one by one from the handle. 100 101 The handle is either is a Medline file, a file-like object, or a list 102 of lines describing one or more Medline records. 103 104 Typical usage: 105 106 from Bio import Medline 107 handle = open("mymedlinefile") 108 records = Medline.parse(handle) 109 for record in record: 110 print record['TI'] 111 112 """ 113 # These keys point to string values 114 textkeys = ("ID", "PMID", "SO", "RF", "NI", "JC", "TA", "IS", "CY", "TT", 115 "CA", "IP", "VI", "DP", "YR", "PG", "LID", "DA", "LR", "OWN", 116 "STAT", "DCOM", "PUBM", "DEP", "PL", "JID", "SB", "PMC", 117 "EDAT", "MHDA", "PST", "AB", "AD", "EA", "TI", "JT") 118 handle = iter(handle) 119 # First skip blank lines 120 for line in handle: 121 line = line.rstrip() 122 if line: 123 break 124 else: 125 return 126 record = Record() 127 finished = False 128 while not finished: 129 if line[:6]==" ": # continuation line 130 record[key].append(line[6:]) 131 elif line: 132 key = line[:4].rstrip() 133 if not key in record: 134 record[key] = [] 135 record[key].append(line[6:]) 136 try: 137 line = handle.next() 138 except StopIteration: 139 finished = True 140 else: 141 line = line.rstrip() 142 if line: 143 continue 144 # Join each list of strings into one string. 145 for key in textkeys: 146 if key in record: 147 record[key] = " ".join(record[key]) 148 if record: 149 yield record 150 record = Record()
151
152 -def read(handle):
153 """Read a single Medline records from the handle. 154 155 The handle is either is a Medline file, a file-like object, or a list 156 of lines describing a Medline record. 157 158 Typical usage: 159 160 from Bio import Medline 161 handle = open("mymedlinefile") 162 record = Medline.read(handle) 163 print record['TI'] 164 165 """ 166 records = parse(handle) 167 return records.next()
168