def make_xml(start_pos, stop_pos, nsamples): """ @return: location of xml file, location of log file """ out = StringIO() print >> out, g_xml_pre_alignment print >> out, """ <!-- The sequence alignment (each sequence refers to a taxon above). --> <alignment id="alignment" dataType="nucleotide"> """ lines = g_fasta_string.splitlines() for header, seq in Fasta.gen_header_sequence_pairs(lines): print >> out, '<sequence>' print >> out, '<taxon idref="%s"/>' % header print >> out, seq print >> out, '</sequence>' print >> out, '</alignment>' print >> out, """ <patterns id="firsthalf.patterns" from="%d" to="%d"> <alignment idref="alignment"/> </patterns> """ % (start_pos, stop_pos) print >> out, get_xml_post_alignment(nsamples) log_loc = Util.get_tmp_filename(prefix='beast', suffix='.log') print >> out, get_log_xml(log_loc) xml_loc = Util.create_tmp_file(out.getvalue(), prefix='beast', suffix='.xml') return xml_loc, log_loc
def make_xml(start_pos, stop_pos, nsamples): """ @return: location of xml file, location of log file """ out = StringIO() print >> out, g_xml_pre_alignment print >> out, """ <!-- The sequence alignment (each sequence refers to a taxon above). --> <alignment id="alignment" dataType="nucleotide"> """ lines = g_fasta_string.splitlines() for header, seq in Fasta.gen_header_sequence_pairs(lines): print >> out, '<sequence>' print >> out, '<taxon idref="%s"/>' % header print >> out, seq print >> out, '</sequence>' print >> out, '</alignment>' print >> out, """ <patterns id="firsthalf.patterns" from="%d" to="%d"> <alignment idref="alignment"/> </patterns> """ % (start_pos, stop_pos) print >> out, get_xml_post_alignment(nsamples) log_loc = Util.get_tmp_filename(prefix='beast', suffix='.log') print >> out, get_log_xml(log_loc) xml_loc = Util.create_tmp_file( out.getvalue(), prefix='beast', suffix='.xml') return xml_loc, log_loc
def get_response_content(fs): out = StringIO() try: alignment = Fasta.Alignment(fs.fasta.splitlines()) print >> out, 'This is a valid alignment.' except Fasta.AlignmentError as e: alignment = None print >> out, 'This is not a valid alignment:', e if alignment: try: old_column_count = len(alignment.columns) alignment.force_nucleotide() removed_column_count = old_column_count - len(alignment.columns) if removed_column_count: print >> out, ('After removing %d' % removed_column_count), print >> out, 'columns this is a valid nucleotide alignment.' else: print >> out, 'This is a valid nucleotide alignment.' except Fasta.AlignmentError as e: print >> out, 'This is not a valid nucleotide alignment:', e for header, seq in Fasta.gen_header_sequence_pairs(StringIO(fs.fasta)): print >> out, '%s: %d' % (header, len(seq)) return out.getvalue()
def get_header_seq_pairs(): lines = g_fasta_string.splitlines() return list(Fasta.gen_header_sequence_pairs(lines))