<commit_before>#!/usr/bin/env python3
'''
Created on Monday, May 15 2017
Last Updated Friday, Oct 20 2017

Computes molecule size and stdev (for error bounds of molecule size)

Columns: BX, MI, RefName, Start, End, Length_stdev, Reads
Optional Columns: Mapq_median, AS_median, NM_median

Version 0.0.1

@author: cjustin
'''

from optparse import OptionParser
import pysam

class Molecule:
    def __init__(self, rname, start, end, newMolecID, barcode, interArrivals, totalBases, alignScore, count):
        self.rname = rname
        self.start = start
        self.end = end
        self.barcode = barcode
        self.newMolecID = newMolecID
        self.interArrivals = interArrivals
        self.totalBases = totalBases
        self.alignScore = alignScore
        self.count = count
    
    def asTSV(self):
        return(self.barcode + "\t" + str(self.newMolecID) + "\t" \
                 + str(self.rname) + "\t" + str(self.start) + "\t" + str(self.end) \
                 + "\t" + str(len(self.interArrivals)))
        
    def getLength(self):
        return self.end-self.start
        
class MolecIdentifier:
    
    def setDist(self, dist):
        self._maxDist = dist
        
    def setMin(self, min):
        self._min = min
    
    def setMAPQ(self, mapq):
        self._mapq = mapq
    
    def setNewBam(self, filename):
        self._newBamFilename = filename
    
    def setOutput(self, filename):
        self._tsvFilename = filename
        
    def setMAPQ(self, mapq):
        self._mapq = mapq
        
    def printTSV(self, molec):
        if self._tsvFilename:
            self._newMolecFH.write(molec.asTSV() + "\n")
        else:
            print(molec.asTSV())
    
    def __init__(self, filename):
        """
        Constructor, identifies molecules based on inter-arrival time threshold
        """
        self._min = 4
        self._maxDist = 50000
        self._mapq = 1
        self._filename = filename;
        self._newBamFilename = ""
        self._tsvFilename = ""
        
    def run(self):
        samfile = pysam.AlignmentFile(self._filename, "rb")
        if self._newBamFilename:
            self._outfilebam = pysam.AlignmentFile(self._newBamFilename, "wb", template=samfile)
        else:
            self._outfilebam = None
        
        header = "BX\tMI\tRname\tStart\tEnd\tReads"
        if self._tsvFilename:
            self._newMolecFH = open(self._tsvFilename, "w");
            self._newMolecFH.write(header + "\n")
        else:
            self._newMolecFH = None
            print(header)
            
        prevBarcode = ""
        prevChr = ""
        curReads = []<commit_msg>MolecEst/MolecLenEst.py: Reorder the columns<commit_after>#!/usr/bin/env python3
'''
Created on Monday, May 15 2017
Last Updated Friday, Oct 20 2017

Computes molecule size and stdev (for error bounds of molecule size)

Columns: BX, MI, RefName, Start, End, Length_stdev, Reads
Optional Columns: Mapq_median, AS_median, NM_median

Version 0.0.1

@author: cjustin
'''

from optparse import OptionParser
import pysam

class Molecule:
    def __init__(self, rname, start, end, newMolecID, barcode, interArrivals, totalBases, alignScore, count):
        self.rname = rname
        self.start = start
        self.end = end
        self.barcode = barcode
        self.newMolecID = newMolecID
        self.interArrivals = interArrivals
        self.totalBases = totalBases
        self.alignScore = alignScore
        self.count = count

    def asTSV(self):
        return self.rname + "\t" + str(self.start) + "\t" + str(self.end) \
            + "\t" + self.barcode + "\t" + str(self.count) + "\t" + str(self.newMolecID)

    def getLength(self):
        return self.end-self.start
        
class MolecIdentifier:
    
    def setDist(self, dist):
        self._maxDist = dist
        
    def setMin(self, min):
        self._min = min
    
    def setMAPQ(self, mapq):
        self._mapq = mapq
    
    def setNewBam(self, filename):
        self._newBamFilename = filename
    
    def setOutput(self, filename):
        self._tsvFilename = filename
        
    def setMAPQ(self, mapq):
        self._mapq = mapq
        
    def printTSV(self, molec):
        if self._tsvFilename:
            self._newMolecFH.write(molec.asTSV() + "\n")
        else:
            print(molec.asTSV())
    
    def __init__(self, filename):
        """
        Constructor, identifies molecules based on inter-arrival time threshold
        """
        self._min = 4
        self._maxDist = 50000
        self._mapq = 1
        self._filename = filename;
        self._newBamFilename = ""
        self._tsvFilename = ""
        
    def run(self):
        samfile = pysam.AlignmentFile(self._filename, "rb")
        if self._newBamFilename:
            self._outfilebam = pysam.AlignmentFile(self._newBamFilename, "wb", template=samfile)
        else:
            self._outfilebam = None
        
        header = "Rname\tStart\tEnd\tBX\tReads\tMI"
        if self._tsvFilename:
            self._newMolecFH = open(self._tsvFilename, "w");
            self._newMolecFH.write(header + "\n")
        else:
            self._newMolecFH = None
            print(header)
            
        prevBarcode = ""
        prevChr = ""
        curReads = []
{'fraction_non_alphanumeric': 0.10359168241965974, 'fraction_numerical': 0.008695652173913044, 'mean_word_length': 2.007959067652075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '775740', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1700, 'n_words': 380}