annotate commons/core/writer/WriterChooser.py @ 14:c79b9ae3f65f

Deleted selected files
author m-zytnicki
date Fri, 19 Apr 2013 10:13:11 -0400
parents 769e306b7933
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.writer.TranscriptListWriter import TranscriptListWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 from commons.core.writer.SequenceListWriter import SequenceListWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 from commons.core.writer.BedWriter import BedWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 from commons.core.writer.CsvWriter import CsvWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 from commons.core.writer.EmblWriter import EmblWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 from commons.core.writer.FastaWriter import FastaWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 from commons.core.writer.FastqWriter import FastqWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 from commons.core.writer.GbWriter import GbWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 from commons.core.writer.Gff2Writer import Gff2Writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 from commons.core.writer.SamWriter import SamWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 from commons.core.writer.UcscWriter import UcscWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 from commons.core.writer.WigWriter import WigWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 from commons.core.writer.Gff3Writer import Gff3Writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 from commons.core.writer.GtfWriter import GtfWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 from commons.core.writer.MapWriter import MapWriter
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 class WriterChooser(object):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 A class that finds the correct writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 @ivar type: transcript / sequence writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 @ivar format: the format of the writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 @ivar writerClass: the class of the writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 @type writerClass: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 @ivar extension: default extension of the file
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 @type extension: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 @ivar verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 def __init__(self, verbosity = 0):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 Constructor
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 @param verbosity: verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 @type verbosity: int
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 self.type = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 self.format = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 self.writerClass = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 self.extension = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 self.verbosity = verbosity
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 def findFormat(self, format, type = None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 Find the correct parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 @ivar format: the format
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 @type format: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 @ivar type: transcript sequence parser (None is all)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 @type type: string
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 @return: a parser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 classes = {}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 if (type == "transcript"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 classes = {TranscriptListWriter: "transcript"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 elif (type == "sequence"):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 classes = {SequenceListWriter: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 elif (type == None):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 classes = {TranscriptListWriter: "transcript", SequenceListWriter: "sequence"}
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 sys.exit("Do not understand format type '%s'" % (type))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 for classType in classes:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 for writerClass in classType.__subclasses__():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 if format in writerClass.getFileFormats():
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 self.writerClass = writerClass
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 self.extension = writerClass.getExtension()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 self.type = classes[classType]
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 return
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102 sys.exit("Cannot get writer for format '%s'" % (format))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 def getWriter(self, fileName):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 Get the writer previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 @return: the writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 return self.writerClass(fileName, self.verbosity)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 def getType(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 Get the type of writer previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 @return: the type of writer
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118 return self.type
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 def getExtension(self):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 Get the default extension of writer previously found
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 @return: the extension
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 """
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 return self.extension
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127