Mercurial > repos > yufei-luo > s_mart
comparison commons/core/writer/TranscriptListWriter.py @ 6:769e306b7933
Change the repository level.
author | yufei-luo |
---|---|
date | Fri, 18 Jan 2013 04:54:14 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:ea3082881bf8 | 6:769e306b7933 |
---|---|
1 # | |
2 # Copyright INRA-URGI 2009-2010 | |
3 # | |
4 # This software is governed by the CeCILL license under French law and | |
5 # abiding by the rules of distribution of free software. You can use, | |
6 # modify and/ or redistribute the software under the terms of the CeCILL | |
7 # license as circulated by CEA, CNRS and INRIA at the following URL | |
8 # "http://www.cecill.info". | |
9 # | |
10 # As a counterpart to the access to the source code and rights to copy, | |
11 # modify and redistribute granted by the license, users are provided only | |
12 # with a limited warranty and the software's author, the holder of the | |
13 # economic rights, and the successive licensors have only limited | |
14 # liability. | |
15 # | |
16 # In this respect, the user's attention is drawn to the risks associated | |
17 # with loading, using, modifying and/or developing or reproducing the | |
18 # software by the user in light of its specific status of free software, | |
19 # that may mean that it is complicated to manipulate, and that also | |
20 # therefore means that it is reserved for developers and experienced | |
21 # professionals having in-depth computer knowledge. Users are therefore | |
22 # encouraged to load and test the software's suitability as regards their | |
23 # requirements in conditions enabling the security of their systems and/or | |
24 # data to be ensured and, more generally, to use and operate it in the | |
25 # same conditions as regards security. | |
26 # | |
27 # The fact that you are presently reading this means that you have had | |
28 # knowledge of the CeCILL license and that you accept its terms. | |
29 # | |
30 from SMART.Java.Python.misc.Progress import Progress | |
31 | |
32 class TranscriptListWriter(object): | |
33 """ | |
34 An interface that writes a transcript list into a file | |
35 @ivar fileName: name of the file | |
36 @type fileName: string | |
37 @ivar handle: handle to the file | |
38 @type handle: file handle | |
39 @ivar header: first lines of the file | |
40 @type header: string | |
41 @ivar started: whether some transcripts have already been writted | |
42 @type started: boolean | |
43 @ivar lastChromosome: the chromosome on which the transcript which was inserted last | |
44 @type lastChromosome: string | |
45 """ | |
46 | |
47 | |
48 def __init__(self, fileName, verbosity = 0): | |
49 """ | |
50 Constructor | |
51 @param fileName: name of the file | |
52 @type fileName: string | |
53 @param verbosity: verbosity | |
54 @type verbosity: int | |
55 """ | |
56 self.fileName = fileName | |
57 self.verbosity = verbosity | |
58 self.handle = open(self.fileName, "w") | |
59 self.started = False | |
60 self.lastChromosome = None | |
61 self.header = "" | |
62 self.sequenceFileName = None | |
63 | |
64 | |
65 def __del__(self): | |
66 """ | |
67 Destructor | |
68 """ | |
69 self.close() | |
70 | |
71 | |
72 def close(self): | |
73 """ | |
74 Close writer | |
75 """ | |
76 if self.handle != None and not self.handle.closed: | |
77 self.handle.close() | |
78 self.handle = None | |
79 | |
80 | |
81 def addTranscript(self, transcript): | |
82 """ | |
83 Add a transcript to the list of transcripts to be written | |
84 @param transcript: transcript to be written | |
85 @type transcript: class L{Transcript<Transcript>} | |
86 """ | |
87 if not self.started: | |
88 self.handle.write(self.header) | |
89 self.started = True | |
90 | |
91 self.handle.write(self.printTranscript(transcript)) | |
92 self.lastChromosome = transcript.getChromosome() | |
93 | |
94 | |
95 def addElement(self, element): | |
96 """ | |
97 Same as "addTranscript" | |
98 @param element: transcript to be written | |
99 @type element: class L{Transcript<Transcript>} | |
100 """ | |
101 self.addTranscript(element) | |
102 | |
103 | |
104 def addTranscriptList(self, transcriptList): | |
105 """ | |
106 Add a list of transcripts to the transcripts to be written | |
107 @param transcriptList: transcripts to be written | |
108 @type transcriptList: class L{TranscriptList<TranscriptList>} | |
109 """ | |
110 progress = Progress(transcriptList.getNbTranscripts(), "Writing transcripts", self.verbosity) | |
111 for transcript in transcriptList.getIterator(): | |
112 self.addTranscript(transcript) | |
113 progress.inc() | |
114 progress.done() | |
115 | |
116 | |
117 def addTranscriptTable(self, transcriptTable): | |
118 """ | |
119 Add a list of transcripts in a mySQL table to the transcripts to be written | |
120 @param transcriptTable: transcripts to be written | |
121 @type transcriptTable: class L{MySqlTranscriptTable<MySqlTranscriptTable>} | |
122 """ | |
123 for transcript in transcriptTable.getIterator(): | |
124 self.addTranscript(transcript) | |
125 | |
126 | |
127 def setTitle(self, title): | |
128 """ | |
129 Possibly write a title for the list (by default, do nothing) | |
130 @param title: a title for the list | |
131 @type title: string | |
132 """ | |
133 pass | |
134 | |
135 def setFeature(self, feature): | |
136 """ | |
137 Set the name of the feature | |
138 @param title: the title of the feature | |
139 @type feature: string | |
140 """ | |
141 pass | |
142 | |
143 def setFeaturePart(self, featurePart): | |
144 """ | |
145 Set the name of the feature part | |
146 @param title: the title of the feature part | |
147 @type featurePart: string | |
148 """ | |
149 pass | |
150 | |
151 | |
152 def addSequenceFile(self, fileName): | |
153 """ | |
154 Get the multi-fasta file of the sequences | |
155 """ | |
156 self.sequenceFileName = fileName | |
157 | |
158 | |
159 def write(self): | |
160 """ | |
161 No-op | |
162 """ | |
163 pass |