def constructe_aln_graph_from_fasta(read_fasta_fn, backbone_fasta_fn, max_num_reads = None, remove_in_del = False, ref_group = None, min_length = None): import os os.system("blasr %s %s -m 5 -nproc 8 -out %s" % (read_fasta_fn, backbone_fasta_fn, read_fasta_fn+".aln_unsorted")) os.system("cat %s | sort > %s" % (read_fasta_fn+".aln_unsorted", read_fasta_fn+".aln" )) aln_hit_iterator = simple_align_hit_iterator(read_fasta_fn+".aln", ref_group = ref_group) alns = get_aln_array(aln_hit_iterator, max_num_reads = max_num_reads, remove_in_del = remove_in_del, min_length = min_length) backboneSeq = open(backbone_fasta_fn).read() backboneSeq = "".join(backboneSeq.split()[1:]) g = AlnGraph(backboneSeq) i = 0 for aln in alns: rId = aln[2] rId = rId.split("/")[0] aln = aln[0:2] g.add_alignment( aln, "%s" % rId) return g
def constructe_aln_graph_from_cmph5(cmpH5_fn, backbone_fasta_fn, max_num_reads = None, remove_in_del = False, ref_group = None, min_length = None): from pbcore.io import cmph5 from pbcore.io.cmph5 import CmpH5 cmpType = CmpH5.SFCmpH5 cmph5f = cmph5.factory.create( cmpH5_fn, "r", cmpType=cmpType ) aln_hit_iterator = None if ref_group != None: aln_hit_iterator = cmph5f["/%s" % ref_group].alnHitIterator() else: aln_hit_iterator = cmph5f.alnHitIterator() alns = get_aln_array(aln_hit_iterator, max_num_reads = max_num_reads, remove_in_del = remove_in_del, min_length = min_length) backboneSeq = open(backbone_fasta_fn).read() backboneSeq = "".join(backboneSeq.split()[1:]) g = AlnGraph(backboneSeq) i = 0 for aln in alns: rId = aln[2] aln = aln[0:2] g.add_alignment( aln, "%s" % rId) cmph5.factory.close(cmph5f) return g