def _new_rec(self, name: str, chrom: str, start: int, attrs: Optional[Dict[str, Any]]) -> AlignedSegment: """Generates a new AlignedSegment. Sets the segment up with the correct header and adds the RG attribute if not contained in attrs. Args: name: the name of the read/template chrom: the chromosome to which the read is mapped start: the start position of the read on the chromosome attrs: an optional dictionary of SAM attributes with two-char keys Returns: AlignedSegment: an aligned segment with name, chrom, pos, attributes the read group, and the unmapped flag all set appropriately. """ if chrom is not sam.NO_REF_NAME and chrom not in self._seq_lookup: raise ValueError( f"{chrom} is not a valid chromosome name in this builder.") rec = AlignedSegment(header=self._samheader) rec.query_name = name rec.reference_name = chrom rec.reference_start = start rec.mapping_quality = self.mapping_quality if chrom == sam.NO_REF_NAME or start == sam.NO_REF_POS: rec.is_unmapped = True attrs = attrs if attrs else dict() if "RG" not in attrs: attrs["RG"] = self.rg_id() rec.set_tags(list(attrs.items())) return rec
def _make_read_unmapped(rec: AlignedSegment) -> None: """Removes mapping information from a read.""" if rec.is_reverse: quals = rec.query_qualities quals.reverse() rec.query_sequence = dnautils.reverse_complement(rec.query_sequence) rec.query_qualities = quals rec.is_reverse = False rec.reference_id = sam.NO_REF_INDEX rec.reference_start = sam.NO_REF_POS rec.cigar = None rec.mapping_quality = 0 rec.template_length = 0 rec.is_duplicate = False rec.is_secondary = False rec.is_supplementary = False rec.is_proper_pair = False rec.is_unmapped = True
AEQ(BZ.insertRegions, VZ.insertRegions) def testRead(self): BZR = self.BZ.read() VZR = self.VZ.read() EQ(BZR.basecalls(), VZR.basecalls()) # Mockup some bam records reflecting the internal "pulse BAM" spec from mock import Mock from pysam import AlignedSegment from pbcore.io import BamAlignment from PRmm.io.ZmwReadStitcherIO import StitchedZmw, FeatureDesc pulsePeer = AlignedSegment() pulsePeer.is_unmapped=True pulsePeer.seq = "GATTACAGATTACA" pulsePeer.qname = "FakePulseRead" tags = dict( RG="00000000", np=1, qs=0, qe=14, rq=0.80, sn=[2.0, 3.0, 5.0, 6.0], ip=[15]*14, pw=[16]*14, zm=42, cx=2, # Now, the pulse stuff pc = " GAgggTTACAcccGATaaaTACA",
AEQ(BZ.insertRegions, VZ.insertRegions) def testRead(self): BZR = self.BZ.read() VZR = self.VZ.read() EQ(BZR.basecalls(), VZR.basecalls()) # Mockup some bam records reflecting the internal "pulse BAM" spec from mock import Mock from pysam import AlignedSegment from pbcore.io import BamAlignment from PRmm.io.ZmwReadStitcherIO import StitchedZmw, FeatureDesc pulsePeer = AlignedSegment() pulsePeer.is_unmapped = True pulsePeer.seq = "GATTACAGATTACA" pulsePeer.qname = "FakePulseRead" tags = dict( RG="00000000", np=1, qs=0, qe=14, rq=0.80, sn=[2.0, 3.0, 5.0, 6.0], ip=[15] * 14, pw=[16] * 14, zm=42, cx=2, # Now, the pulse stuff pc=" GAgggTTACAcccGATaaaTACA",