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