annotate commons/pyRepetUnit/fastaTranslation/allFrames/TranslateInAllFramesAndReplaceStopByX.py @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 94ab73e8a190
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
1 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 from commons.core.seq.BioseqUtils import BioseqUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 class TranslateInAllFramesAndReplaceStopByX(object):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 def __init__(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7 self._inputFile = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 self._outputFile = ""
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 def setInputFile(self, input):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 self._inputFile = input
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 def setOutputFile(self, output):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 self._outputFile = output
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 def run(self):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 """
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 read a fasta file with nucleotide sequences and translate all sequences in all frames, write the result in a file
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 """
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 if not FileUtils.isRessourceExists(self._inputFile):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 raise Exception("Warning your input file %s does not exist!\n" % self._inputFile)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22 bioseqList = BioseqUtils.extractBioseqListFromFastaFile(self._inputFile)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 bioseqListInAllFrames = BioseqUtils.translateBioseqListInAllFrames(bioseqList)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24 bioseqListTranslatedAndStopsReplace = BioseqUtils.replaceStopCodonsByXInBioseqList(bioseqListInAllFrames)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 BioseqUtils.writeBioseqListIntoFastaFile(bioseqListTranslatedAndStopsReplace, self._outputFile)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26