annotate commons/core/parsing/ParserChooser.py @ 14:c79b9ae3f65f

Deleted selected files
author m-zytnicki
date Fri, 19 Apr 2013 10:13:11 -0400
parents 769e306b7933
children 94ab73e8a190
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 # Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 # This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 # abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 # modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 # license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 # "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 # As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 # modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 # with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 # economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 # liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 # In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 # with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 # software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 # that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 # therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 # professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 # encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 # requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 # data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 # same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 # The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 # knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 #
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 from commons.core.parsing.TranscriptListParser import TranscriptListParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.parsing.MapperParser import MapperParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.parsing.SequenceListParser import SequenceListParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.parsing.BedParser import BedParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.parsing.GffParser import GffParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.parsing.MapperParser import MapperParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.parsing.CoordsParser import CoordsParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from commons.core.parsing.SeqmapParser import SeqmapParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from commons.core.parsing.SoapParser import SoapParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 from commons.core.parsing.Soap2Parser import Soap2Parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 from commons.core.parsing.BlastParser import BlastParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 from commons.core.parsing.PslParser import PslParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 from commons.core.parsing.RmapParser import RmapParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 from commons.core.parsing.ShrimpParser import ShrimpParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 from commons.core.parsing.AxtParser import AxtParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 from commons.core.parsing.ExoParser import ExoParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 from commons.core.parsing.MaqParser import MaqParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 from commons.core.parsing.SamParser import SamParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 from commons.core.parsing.BamParser import BamParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 from commons.core.parsing.BowtieParser import BowtieParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 from commons.core.parsing.ElandParser import ElandParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 from commons.core.parsing.GtfParser import GtfParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 from commons.core.parsing.FastaParser import FastaParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 from commons.core.parsing.FastqParser import FastqParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 from commons.core.parsing.MapParser import MapParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 from commons.core.parsing.NCListParser import NCListParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 from commons.core.parsing.PklParser import PklParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 #Attention!! Do not delete the imports!! They are used to know the type of file format!!!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 class ParserChooser(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 A class that finds the correct parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 @ivar format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 @ivar type: transcript / mapping / sequence parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 @ivar parser: the parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 @type parser: object
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 @ivar verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 def __init__(self, verbosity = 0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 @param verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 self.type = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 self.parserClass = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 def findFormat(self, format, type = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 Find the correct parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 @ivar format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 @ivar type: transcript / mapping / sequence parser (None is all)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 @return: a parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 classes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 if (type == "transcript"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 classes = {TranscriptListParser: "transcript"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 elif (type == "mapping"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 classes = {MapperParser: "mapping"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 elif (type == "sequence"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 classes = {SequenceListParser: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 elif (type == None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 classes = {TranscriptListParser: "transcript", MapperParser: "mapping", SequenceListParser: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 raise Exception("Do not understand format type '%s'" % (type))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 for classType in classes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 for parserClass in classType.__subclasses__():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 if format in parserClass.getFileFormats():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 self.parserClass = parserClass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 self.type = classes[classType]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 raise Exception("Cannot get parser for format '%s'" % (format))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 def getParser(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 Get the parser previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 @return: the parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 return self.parserClass(fileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 def getType(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 Get the type of parser previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 @return: the type of parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 return self.type