allpy
view allpy/homology.py @ 1168:b556c96c6719
blocks3d/www Makefile: never check certificates of github, they are too confusing for wget
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Mon, 26 May 2014 17:20:29 +0400 |
parents | 922712705968 |
children | 83167a09a19d |
line source
8 """ Essentially, alignment is a set of monomer homology classes.
9 Object of type MonomerHomology desribes an alignment in terms of monomer homology.
10 Each monomer of any sequence from an alignment must be contained in a homology class
12 Homology of nonequal monomers of the same sequence is allowed (formally) in attributes,
13 but there is no implemented methods to deal with
15 DATA:
16 monomer_ids = {monomer_id:class_id}
17 monomer_id = (sequence_name, monomer_number)
18 monomer_number is a number of the monomer in the sequence
19 class_id = string
20 classes = {class_id:[monomer_id1, monomer_id2,...], ...}
21 columns = {class_id:column_number}
22 blocks_data = [block_data, ...]
23 block_data = (sequence_names,class_ids)
24 sequence_names = set( [sequence_1_name,...] )
25 class_ids = = set( [class_1_id, ...] )
27 block_data contain identifiers of objects only, alignment object is not needed.
28 block_data may be converted to bloks of an alignment by appropriate method
30 METHODS:
31 + .read(file_name, columns = True)
32 Reads file of monomer homology format into MonomerHomology object.
33 + .write_monomer(file,monomer_id,monomer_homology_class_id, column_number = column_number) STATIC
34 + .write_class(file,list_of_monomer_ids,monomer_homology_class_id,column_number = column_number) STATIC
35 + .write_block(file, alignment, block)
36 + .add_monomer(monomer_id,class_id,column_number)
37 + .add_class(monomer_ids,class_id, column_number)
38 + .add_block(alignment, block)
39 + .compare_with(class)
40 + .two_vs_one(classes_one, classes_two) STATIC
41 + .highest_blocks()
42 + .alignment_blocks(alignment)
43 + .case_homology(in_file_name,out_file_name, case) STATIC
44 """
52 ################################################################
55 """
56 Monomer_homology file format is as follows
57 One line corresponds to one monomer.
58 Thus, number of lines with information is equal to the sum of all sequences lengths
59 Three obligatory fields are in each line:
60 - homology_class_id (string) arbitrary
61 - sequence_id (string) sequence.name is used as sequence id
62 - monomer_number (integer) number in the sequence, 1, 2, ...
63 If columns:
64 - column_number
65 Everything from "#" to the line end is ignored
66 Fields are delimited by white spaces
67 Empty lines (only white speces in the line) are skipped
69 RETURN total number of monomers
70 """
82 continue
85 continue
96 continue
113 ################################################################
115 @staticmethod
117 """ Computes weighted average number of mistakes of classes_two with respect to classes_one
118 May be used as external function
119 See compare_with help for more details
120 Actually, sizes of intersections are computed and store in class_one_splits but not used
121 """
161 """Compares two monomer homology classes made on the same set of sequences: self and other
162 Both sets of classes MUST contain isomorfic sets of monomer_ids
164 RETURN two weighted averege number of mistakes: other vs self and self vs other
165 Number of mistakes other vs self in a homology class of self is
166 number of classes of other intersecting with the class of self minus one
167 In other words, one mistake of other is splitting a class of self
168 (believed to be true monomer homology class) into two classes
169 Wieght of a class of self is size of the class divided by total number of monomeres.
171 Different mesures and outputs may be implemented later.
172 """
174 mistakes_two_vs_one = MonomerHomology.two_vs_one(self, other) # mistakes are splitting self by intersections with other
175 mistakes_one_vs_two = MonomerHomology.two_vs_one(other, self) # mistakes are splitting other by intersections with self
179 ################################################################
181 @staticmethod
183 """ Writes list of monomer_ids forming one homology_class
184 """
190 """ Adds list of monomer_ids forming one homology_class
191 """
198 #################################################################
201 """ Add one monomer to Homology
202 """
204 raise Exception("wrong parameters given for Monomer_homology.write_monomer: len(monomer_id) is not 2!")
215 @staticmethod
217 """ Write a line "class_id sequence_id monome number \n" into file
218 """
220 raise Exception("wrong parameters given for Monomer_homology.write_monomer: len(monomer_id) is not 2!")
233 #################################################################
236 """ Add classes of plus-block to Homology
237 """
240 continue
245 raise Exception("Alignment column has no number! Alignment must be marked up by numbers before .add_block")
254 raise Exception("Monomer has no number! Sequences must be marked up by numbers before .writ_block")
266 """ Writes each block column into as one homology class
267 WARRNINGS:
268 (1) method works in object of class MonomerHomology
269 (2) all sequences MUST BE MARKED UP with resudue NUMBERS!
270 (3) automatic class ids (actually, numbers) are assigned to homology classes
271 (4) if markedup, then block MUST be marked up by column numbers
273 Block may contain "gaps"
274 """
278 continue
292 raise Exception("Monomer has no number! Sequences must be marked up by numbers before .writ_block")
294 MonomerHomology.write_monomer(file,monomer_id,self.next_class_id, column_number = column_number)
298 #################################################################
301 """ RETURN set of sequences from a list of monomer_ids
302 """
310 """ Makes blocks of maximal possible heights from monomer homology classes
311 block = set of homology classes with the same set of sequences
312 block MUST BE marked up by column numbers
314 blocks_data = [block_data, ...]
315 block_data = (sequence_names,class_ids)
316 sequence_names = set( [sequence_1_name,...] )
317 class_ids = = set( [class_1_id, ...] )
320 RETURN: self.blocks_data
322 """
332 continue
338 raise Exception("Fail to get column_number! Homology classes must be marked to creats highest blocks")
340 # NEW BLOCK
347 # ADD classes to BLOCK
352 continue
360 raise Exception("Fail to get column_number! Homology classes must be marked to creats hiest blocks")
366 ################################################################
369 """ From homology.blocks creates a list of alignment blocks (accessible for visualization)
371 blocks_data = [block_data, ...]
372 block_data = (sequence_names,class_ids)
373 sequence_names = set( [sequence_1_name,...] )
374 class_ids = = set( [class_1_id, ...] )
375 RETURN blocks, list of blocks in alignment
377 """
388 raise Exception("alignment columns are not marked up by numbers! Can't creat block from blocks data")
403 raise Exception("Sequence name %s from block data is not in alignment sequences!" % sequence_name)
412 raise Exception("Column number %s from block data is not in alignment columns numbers!" % column_number)
415 block = protein.Block.from_alignment(alignment, sequences = block_sequences, columns = block_columns)
419 #################################################################
420 @staticmethod
422 """ Makes homology file from input alignment
423 case = True => Upper letters in a column are in one class, each lower letter in separate class
424 case = False => all letter in a column are in one class
426 RETURN number of classes
427 """
445 # MARKUPING
454 #letters = ''.join(v[0] for v in seq.markups['case'].as_list())
456 # WRITING CLASSES
470 continue
480 ################################################################