annotate commons/core/parsing/ParserChooser.py @ 27:4e7ee5683ef1

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:30:11 -0400
parents 94ab73e8a190
children
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
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
56 from commons.core.parsing.WigParser import WigParser
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 from commons.core.parsing.NCListParser import NCListParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 from commons.core.parsing.PklParser import PklParser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 #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
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 class ParserChooser(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 A class that finds the correct parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 @ivar format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 @ivar type: transcript / mapping / sequence parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 @ivar parser: the parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 @type parser: object
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 @ivar verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 def __init__(self, verbosity = 0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 @param verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 self.type = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 self.parserClass = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 def findFormat(self, format, type = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 Find the correct parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 @ivar format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 @ivar type: transcript / mapping / sequence parser (None is all)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 @return: a parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 classes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 if (type == "transcript"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 classes = {TranscriptListParser: "transcript"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 elif (type == "mapping"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 classes = {MapperParser: "mapping"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 elif (type == "sequence"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 classes = {SequenceListParser: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 elif (type == None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 classes = {TranscriptListParser: "transcript", MapperParser: "mapping", SequenceListParser: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 raise Exception("Do not understand format type '%s'" % (type))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 for classType in classes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 for parserClass in classType.__subclasses__():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 if format in parserClass.getFileFormats():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 self.parserClass = parserClass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 self.type = classes[classType]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 raise Exception("Cannot get parser for format '%s'" % (format))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 def getParser(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 Get the parser previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 @return: the parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 return self.parserClass(fileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 def getType(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 Get the type of parser previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 @return: the type of parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 return self.type