annotate commons/pyRepetUnit/align/AlignListUtils.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 import os
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
2 import commons.core.coord.Align
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
3 import commons.pyRepetUnit.align.AlignList
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
4 from commons.core.utils.FileUtils import FileUtils
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
5
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
6 class AlignListUtils:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
7
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
8 ##read a file in align format and return a AlignList
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
9 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
10 # @param inFileName string name of file
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
11 # @return listAlignInstance list list of align instance
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
12 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
13 def read( inFileName ):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
14 alignInstance = commons.core.coord.Align.Align()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
15 listAlignInstance = commons.pyRepetUnit.align.AlignList.AlignList()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
16 f = open( inFileName , "r")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
17 while alignInstance.read( f ):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
18 listAlignInstance.append(alignInstance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
19 alignInstance = commons.core.coord.Align.Align()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
20 f.close
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
21 return (listAlignInstance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
22
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
23 read = staticmethod( read )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
24
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
25 ## write a file in align format from an AlignList
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
26 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
27 # @param alignListInstance list list of align instance object
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
28 # @param inFileName string name of file
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
29 def write( alignListInstance, inFileName ):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
30 f = open( inFileName , "w")
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
31 for alignInstance in alignListInstance.getList():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
32 alignInstance.write( f )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
33 f.close
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
34
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
35 write = staticmethod( write )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
36
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
37 ## Filter an AlignList by removing all is <= minScore
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
38 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
39 # @param listAlignInstance list list of align instance object
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
40 # @param minScore integer minimum score to keep in result
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
41 #
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
42 def filterOnAMinimalScore( listAlignInstance, minScore ):
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
43 listAlignInstanceOld = commons.pyRepetUnit.align.AlignList.AlignList()
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
44 for alignInstance in listAlignInstance.getList():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
45 listAlignInstanceOld.append(alignInstance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
46 for alignInstance in listAlignInstanceOld.getList():
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
47 if alignInstance.score <= minScore:
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
48 listAlignInstance.remove(alignInstance)
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
49
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
50 filterOnAMinimalScore = staticmethod( filterOnAMinimalScore )
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
51
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
52 if __name__ == "__main__":
94ab73e8a190 Uploaded
m-zytnicki
parents:
diff changeset
53 main()