"""Classes for storing matches between sequences and genomic locations built from lists of matches.""" class Match: "Track similar segments between two sequences." def __init__(self, src, dst): "src and dst are 3-tuples of (sequenceId, start, end)" self.srcSequenceId, self.srcStart, self.srcEnd = src self.dstSequenceId, self.dstStart, self.dstEnd = dst def __str__(self): return "<%s[%d..%d]=%s[%d..%d]>" % ( self.srcSequenceId, self.srcStart, self.srcEnd, self.dstSequenceId, self.dstStart, self.dstEnd ) def __repr__(self): return str(self) class GenomicLocation: "Track location of one sequence on another as a series of matches." def __init__(self, matches=None): "matches is an optional initializer list of matches" if matches is None: self.matches = [] else: # Note that we make a copy rather than using # the same list as passed in self.matches = matches[:] def addMatch(self, match): self.matches.append(match) if __name__ == "__main__": def main(): ml = [ Match(("abc", 1, 3), ("xyz", 12, 14)), Match(("abc", 4, 12), ("xyz", 70, 78)), Match(("abc", 14, 30), ("xyz", 100, 116)) ] gl = GenomicLocation(ml) print gl.matches main()