Mercurial > repos > dereeper > ragoo
comparison RaGOO/ragoo_utilities/PAFReader.py @ 13:b9a3aeb162ab draft default tip
Uploaded
| author | dereeper |
|---|---|
| date | Mon, 26 Jul 2021 18:22:37 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 12:68a9ec9ce51e | 13:b9a3aeb162ab |
|---|---|
| 1 class PAFLine: | |
| 2 """ Object to represent a single alignment in a minimap PAF file. """ | |
| 3 | |
| 4 def __init__(self, in_line): | |
| 5 """ | |
| 6 start positions should be before end positions for both query and target | |
| 7 """ | |
| 8 self.line = in_line.rstrip().split('\t') | |
| 9 self.contig = self.line[0] | |
| 10 self.query_len = int(self.line[1]) | |
| 11 self.query_start = int(self.line[2]) | |
| 12 self.query_end = int(self.line[3]) | |
| 13 self.strand = self.line[4] | |
| 14 self.ref_header = self.line[5] | |
| 15 self.ref_len = int(self.line[6]) | |
| 16 self.ref_start = int(self.line[7]) | |
| 17 self.ref_end = int(self.line[8]) | |
| 18 self.num_match = int(self.line[9]) | |
| 19 self.aln_len = int(self.line[10]) | |
| 20 self.mapq = int(self.line[11]) | |
| 21 | |
| 22 assert self.query_start <= self.query_end | |
| 23 assert self.ref_start <= self.ref_end | |
| 24 | |
| 25 def __str__(self): | |
| 26 return '\t'.join(self.line) | |
| 27 | |
| 28 def __eq__(self, other): | |
| 29 return self.line == other.line | |
| 30 | |
| 31 | |
| 32 class PAFReader: | |
| 33 | |
| 34 def __init__(self, paf_file): | |
| 35 self.paf_file = paf_file | |
| 36 | |
| 37 def parse_paf(self): | |
| 38 with open(self.paf_file) as f: | |
| 39 for line in f: | |
| 40 yield PAFLine(line) |
