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
|
"""Martel based parser to read LocusLink flat files.
This is a huge regular expression for LocusLink,
built using the 'regular expressions on steroids' capabilities of
Martel.
A description of the format can be found in the 'ligand.doc' file
from the Ligand distribution, available from:
http://www.ncbi.nih.gov/LocusLink
"""
# Martel
from Martel import Str
from Martel import Str1
from Martel import Alt
from Martel import Rep
from Martel import Group
from Martel import ToEol
from Martel import AnyEol
from Martel import Any
from Martel import Word
from Martel import Opt
from Martel import AssertNot
from Martel import RecordReader
# --- First set up some helper constants and functions
INDENT = 12
blank_spaces = Rep(Str1(" "))
point = Str1(".")
white_space = Rep( Any( " " ) )
locus_keys = [ \
'LOCUSID', \
'LOCUS_CONFIRMED', \
'LOCUS_TYPE', \
'ORGANISM', \
'STATUS', \
'NM', \
'NP', \
'CDD', \
'PRODUCT', \
'ASSEMBLY', \
'CONTIG', \
'EVID', \
'XM', \
'XP', \
'ACCNUM', \
'TYPE', \
'PROT', \
'OFFICIAL_SYMBOL', \
'OFFICIAL_GENE_NAME', \
'PREFERRED_PRODUCT', \
'ALIAS_SYMBOL', \
'SUMMARY', \
'CHR', \
'STS', \
'COMP', \
'ALIAS_PROT', \
'UNIGENE', \
'BUTTON', \
'LINK', \
'OMIM', \
'MAP', \
'MAPLINK', \
'ECNUM', \
'PROTOTYPE', \
'DB_DESCR', \
'DB_LINK', \
'PMID', \
'GRIF', \
'SUBFUNC', \
'GO', \
'EXTANNOT'
]
accnum_block_keys = [ \
'ACCNUM', \
'TYPE', \
'PROT' \
]
phenotype = Str1( 'PHENOTYPE' )
db = Str1( 'DB' )
accnum_block_key = Str( *accnum_block_keys )
valid_locus_key = Str( *locus_keys )
def define_locus_line( entry_tag ):
return( white_space + \
Str1(entry_tag ) + \
white_space + \
Str1( ":" ) + \
white_space + \
ToEol() )
def define_locus_group( entry_name, entry_tag ):
return Group( entry_name, \
define_locus_line( entry_tag ))
accnum_block = Group( 'accnum_block', \
define_locus_line( 'ACCNUM' ) + \
define_locus_line( 'TYPE' ) + \
Opt(define_locus_line( 'PROT' ) ) )
phenotype_block = Group( 'phenotype_block', \
define_locus_line( 'PHENOTYPE' ) + \
Opt( define_locus_line( 'PHENOTYPE_ID' ) ) )
db_block = Group( 'db_block', \
define_locus_line( 'DB_DESCR' ) + \
define_locus_line( 'DB_LINK' ) )
begin_record_line = Str1( '>>' ) + ToEol()
locus_line = Group( 'locus_line', \
white_space + AssertNot( accnum_block_key ) + AssertNot( phenotype ) + AssertNot( db ) + Word() + white_space + Str1( ':' ) + ToEol() )
locus_record = begin_record_line + Rep( Alt( locus_line, accnum_block, phenotype_block, db_block ) )
#locus_record = Rep( locus_line )
|