get_spec_dict(filename,
delimiter=' : ' ,
pat_replace={ } ,
ignore_case=True)
|
|
Reads the file, tokenizes the each line with delimiter, and returns the
dict.
It ignores the lines which start with '#'.
@type filename: string
@param filename: The name of the input file.
@type delimiter: string
@param delimiter: line is divided from delimiter to create the
<key,value> of dict.
@type pat_replace: dict
@param pat_replace: this dict can be used to replace pattern, if specified.
For example: pat_replace={'#.*':'', '\s+':' '} would do...
- replace all characters starting from '#' to end of the line
with '' and
- replace multiple spaces with one space.
@type ignore_case: bool
@param ignore_case: it is used to create the lowercase keys to make case
insensitive search
-------------
Illustration:
-------------
A call to get_spec_dict(filename, pat_replace={'#.*':'', '\s+':' '})
with following file..
file content = "
#CombGen input file
#Core molecule
Core: cg_singledock_run1_tproj38171a23586-core.mae
#Attachment AcCl
Chain: AcCl 1 1 1f 1t
Frag: AcCl 1 cg_acid_chlorides_Acid_Cl_C_C
#Attachment Hyd
Chain: Hyd 1 1 2f 2t
Frag: Hyd 1 cg_hydrazines_Hydrazine_C_N
#Attachment NCO
Chain: NCO 1 1 3f 3t
Frag: NCO 1 cg_isocyanates_Isocyanate_C_N
"
would return spec_dict as follow...
{'frag': ['AcCl', '1', 'cg_acid_chlorides_Acid_Cl_C_C',
'Hyd', '1', 'cg_hydrazines_Hydrazine_C_N',
'NCO', '1', 'cg_isocyanates_Isocyanate_C_N'],
'core': ['cg_singledock_run1_tproj38171a23586-core.mae'],
'chain': ['AcCl', '1', '1', '1f', '1t',
'Hyd', '1', '1', '2f', '2t',
'NCO', '1', '1', '3f', '3t']}
|