Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/22587e0d54b6
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 08:12:03 2012
Кодировка:

# HG changeset patch
# User Andrei
# Date 1310059373 -14400
# Node ID 22587e0d54b6d2b193e748c183fc6d4c58567476
# Parent 8b03bd2f919a43dee3e69ef641ee23eb0e1f622f# Parent 55bb5aa2c92935f907f7bbdec5f2021c06e61245
Automated merge with ssh://kodomo.fbb.msu.ru/allpy

diff -r 8b03bd2f919a -r 22587e0d54b6 allpy/homology.py
--- a/allpy/homology.py Thu Jul 07 19:32:44 2011 +0400
+++ b/allpy/homology.py Thu Jul 07 21:22:53 2011 +0400
@@ -1,4 +1,6 @@
from allpy import protein
+from allpy import markups
+

class MonomerHomology(object):
""" Essentially, alignment is a set of monomer homology classes
@@ -36,8 +38,9 @@
+ .write_class(file,list_of_monomer_ids,monomer_homology_class_id)
+ .write_block(file, block)
+ .compare_with(class)
- .highest_blocks()
- .alignment_blocks(alignment)
+ + .highest_blocks()
+ + .alignment_blocks(alignment)
+ .case_homology
"""
def __init__(self, next_class_id = 1):
self.classes = {}
@@ -347,4 +350,61 @@
block = protein.Block.from_alignment(alignment, sequences = block_sequences, columns = block_columns)
blocks.append(block)

- return blocks
\ No newline at end of file
+ return blocks
+
+ @staticmethod
+ def case_homology(in_file_name,out_file_name, case):
+ """ Makes homology file from case sensitive input alignment
+ RETURN number of classes
+ """
+ try:
+ f = open(in_file_name)
+ except:
+ raise Exception("Failed to open file %s" % fasta_file_name)
+ exit()
+ try:
+ alignment = protein.Alignment().append_file(f)
+ f.close()
+ except:
+ raise Exception("Failed to cteate alignment from file %s!" % fasta_file_name)
+ exit()
+ try:
+ g = open(out_file_name, 'w')
+ except:
+ raise Exception("Failed to open output file %s!" % out_file_name)
+ exit()
+
+ # MARKUPING
+ markups.AlignmentNumberMarkup(alignment)
+
+ for sequence in alignment.sequences:
+ markups.SequenceNumberMarkup(sequence)
+ if case:
+ markups.SequenceCaseMarkup(sequence)
+
+
+ #letters = ''.join(v[0] for v in seq.markups['case'].as_list())
+
+ # WRITING CLASSES
+ next_class_id = 1
+
+ for column in alignment.columns:
+ column_number = alignment.markups['number'][column]
+ column_class = []
+
+ for sequence in column:
+ monomer = column[sequence]
+ monomer_id = (sequence.name, monomer.number)
+ if case:
+ if monomer.case == "lower":
+ MonomerHomology.write_monomer(g,monomer_id,next_class_id,column_number)
+ next_class_id += 1
+ continue
+ column_class.append(monomer_id)
+
+ if len(column_class) > 0:
+ MonomerHomology.write_class(g,column_class,next_class_id, column_number)
+ next_class_id += 1
+
+ g.close()
+ return next_class_id - 1
diff -r 8b03bd2f919a -r 22587e0d54b6 utils/make_homologies.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/make_homologies.py Thu Jul 07 21:22:53 2011 +0400
@@ -0,0 +1,72 @@
+import sys
+
+from allpy import protein
+from allpy.homology import MonomerHomology
+from allpy import markups
+
+import optparse
+import sys
+
+
+if len(sys.argv) == 1:
+ print("Makes homology files from (case sensitive by request) input alignments")
+ print("Type 'python make_homologies.py -h' for parameters")
+ exit()
+
+parser = optparse.OptionParser()
+
+parser.add_option("-c", "--case", action="store_true", help="Case sensitive interpretation of input alignment (False if -c missed)", dest="case")
+parser.add_option("-n", "--file_names", help="File with alignment fasta files names", dest="file_names")
+
+parser.add_option("-d", "--base_in", help="Name of directory with alignment files (default=\"\")", dest="base_in", default="")
+parser.add_option("-s", "--suffix", help="Suffix for out files", dest="suffix", default = "hom")
+parser.add_option("-o", "--base_out", help="Name of directory for outfiles (default=\"\")", dest="base_out", default="")
+
+# FOR ONE INPUT ALIGNMENT
+#parser.add_option("-i", "--in_file", help="File with an alignment in fasta", dest="in_file")
+#parser.add_option("-o", "--result", help="Output file with monomer homology classes (default: result.xls)", dest="out_file", default = "result.xls")
+
+options, args = parser.parse_args()
+vars().update(vars(options))
+
+
+try:
+ f = open(file_names)
+except:
+ raise Exception("File %s does not exists! Use python make_homologies.py -h for parameters" % file_names)
+
+
+
+alignment_names = []
+for line in f:
+ line = line.strip()
+ if len(line) == 0:
+ continue
+ line = line.strip().split("#")[0]
+ if len(line) == 0:
+ continue
+ alignment_names.append(line.split()[0])
+
+
+if len(base_in) > 0:
+ if base_in[-1]!= "/":
+ base_in = base_in + "/"
+
+if len(base_out) > 0:
+ if base_out[-1]!= "/":
+ base_out = base_out + "/"
+
+
+print("Wait...")
+
+for alignment_name in alignment_names:
+ in_file_name = base_in + alignment_name
+ out_file_name = base_out + alignment_name.partition(".fasta")[0] + ".xls"
+
+ classes_number = MonomerHomology.case_homology(in_file_name,out_file_name, case)
+ print ("File %s: %s monomer homology classes stored" % (out_file_name,classes_number))
+
+print("...Done")
+
+
+
diff -r 8b03bd2f919a -r 22587e0d54b6 utils/make_homology.py
--- a/utils/make_homology.py Thu Jul 07 19:32:44 2011 +0400
+++ b/utils/make_homology.py Thu Jul 07 21:22:53 2011 +0400
@@ -5,63 +5,6 @@
import optparse
import sys

-def case_homology(fasta_file_name,homology_file_name, case):
- """ Makes homology file from case sensitive input alignment
- RETURN number of classes
- """
- try:
- f = open(in_file)
- except:
- raise Exception("Failed to open file %s!" % fasta_file_name)
- exit()
- try:
- alignment = protein.Alignment().append_file(f)
- f.close()
- except:
- raise Exception("Failed to cteate alignment from file %s!" % fasta_file_name)
- exit()
- try:
- g = open(homology_file_name, 'w')
- except:
- raise Exception("Failed to open output file %s!" % homology_file_name)
- exit()
-
-# MARKUPING
- markups.AlignmentNumberMarkup(alignment)
-
- for sequence in alignment.sequences:
- markups.SequenceNumberMarkup(sequence)
- if case:
- markups.SequenceCaseMarkup(sequence)
-
-
-#letters = ''.join(v[0] for v in seq.markups['case'].as_list())
-
-# WRITING CLASSES
- next_class_id = 1
-
- for column in alignment.columns:
- column_number = alignment.markups['number'][column]
- column_class = []
-
- for sequence in column:
- monomer = column[sequence]
- monomer_id = (sequence.name, monomer.number)
- if case:
- if monomer.case == "lower":
- MonomerHomology.write_monomer(g,monomer_id,next_class_id,column_number)
- next_class_id += 1
- continue
- column_class.append(monomer_id)
-
- if len(column_class) > 0:
- MonomerHomology.write_class(g,column_class,next_class_id, column_number)
- next_class_id += 1
-
- g.close()
- return next_class_id - 1
-
-#######################################################################################
if len(sys.argv) == 1:
print("Makes homology file from case sensitive input alignment")
print("Type 'python test_homology.py -h' for parameters")
@@ -78,7 +21,7 @@

print("Wait...")

-classes_number = case_homology(in_file,out_file, case)
+classes_number = MonomerHomology.case_homology(in_file,out_file, case)

print ("%s monomer homology classes stored" % classes_number)
print("...Done")