Package biana :: Package utilities :: Module FormattedFileProcessor
[hide private]
[frames] | no frames]

Source Code for Module biana.utilities.FormattedFileProcessor

 1  import sets 
 2   
3 -class FormattedFileProcessor(object):
4 """ 5 Wrapper around reading/processing various formatted input streams 6 """ 7 allowed_formats = sets.Set(["sif", "fasta", "tsv"])
8 - def __init__(self, input_file_name, input_type):
9 """ 10 Initialize an object of this class storing 11 input_file_name: file name to be read/processed 12 input_type: could be sif, tsv, fasta, etc.. 13 """ 14 self.input_file_name = input_file_name 15 self.input_type = input_type 16 if not self.input_type in self.allowed_formats: 17 raise Exception("Unrecognized input type") 18 return
19
20 - def read(self, fields_to_include=None):
21 """ 22 Read the file into a dictionary and return cloumns names and value dictionary 23 """ 24 #raise Exception("Call method of FormattedInputProcesor abstract class") 25 return self.process(out_method = None, fields_to_include = fields_to_include)
26
27 - def process(self, out_method, fields_to_include):
28 """ 29 Read and process an input file line by line. If out_method is None a dictionary storing read lines are returned. 30 out_method: method to output columns in current line on the fly in the input_type format 31 fields_to_include: columns that would be included in the dictionary or processed with the function 32 """ 33 raise Exception("Call method of FormattedInputProcesor abstract class") 34 return
35