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