# Path: nanopore/mappers/blasr.py
# class Blasr(AbstractMapper):
#     def run(self, args=""):
#         tempSamFile = os.path.join(self.getLocalTempDir(), "temp.sam")
#         system("blasr %s %s -sam -clipping hard %s > %s" % (self.readFastqFile, self.referenceFastaFile, args, tempSamFile))
#         #Blasr seems to corrupt the names of read sequences, so lets correct them.
#         sam = pysam.Samfile(tempSamFile, "r" )
#         outputSam = pysam.Samfile(self.outputSamFile, "wh", template=sam)
#         readSequences = getFastqDictionary(self.readFastqFile) #Hash of names to sequences
#         for aR in sam: #Iterate on the sam lines and put into buckets by read
#             if aR.qname not in readSequences:
#                 newName = '/'.join(aR.qname.split('/')[:-1])
#                 if newName not in readSequences:
#                     raise RuntimeError("Tried to deduce correct read name: %s, %s" % (newName, readSequences.keys()))
#                 aR.qname = newName
#             outputSam.write(aR)
#         outputSam.close()


from nanopore.mappers.blasr import Blasr
from sonLib.bioio import system
import os

class BlasrParams(Blasr):
    def run(self):
        Blasr.run(self, args="-sdpTupleSize 8 -bestn 1 -m 0")
        #system("blasr %s %s -sdpTupleSize 8 -bestn 1 -clipping hard -nproc 8 -sam -out %s -m 0" % (self.readFastqFile, self.referenceFastaFile, self.outputSamFile))

class BlasrParamsChain(BlasrParams):
    def run(self):
        BlasrParams.run(self)
        self.chainSamFile()

class BlasrParamsRealign(BlasrParams):
    def run(self):
        BlasrParams.run(self)

# Path: nanopore/mappers/blasr.py
# class Blasr(AbstractMapper):
#     def run(self, args=""):
#         tempSamFile = os.path.join(self.getLocalTempDir(), "temp.sam")
#         system("blasr %s %s -sam -clipping hard %s > %s" % (self.readFastqFile, self.referenceFastaFile, args, tempSamFile))
#         #Blasr seems to corrupt the names of read sequences, so lets correct them.
#         sam = pysam.Samfile(tempSamFile, "r" )
#         outputSam = pysam.Samfile(self.outputSamFile, "wh", template=sam)
#         readSequences = getFastqDictionary(self.readFastqFile) #Hash of names to sequences
#         for aR in sam: #Iterate on the sam lines and put into buckets by read
#             if aR.qname not in readSequences:
#                 newName = '/'.join(aR.qname.split('/')[:-1])
#                 if newName not in readSequences:
#                     raise RuntimeError("Tried to deduce correct read name: %s, %s" % (newName, readSequences.keys()))
#                 aR.qname = newName
#             outputSam.write(aR)
#         outputSam.close()


# Path: nanopore/mappers/blasr_params.py
from nanopore.mappers.blasr import Blasr
from sonLib.bioio import system
import os


class BlasrParams(Blasr):
    def run(self):
        Blasr.run(self, args="-sdpTupleSize 8 -bestn 1 -m 0")
        #system("blasr %s %s -sdpTupleSize 8 -bestn 1 -clipping hard -nproc 8 -sam -out %s -m 0" % (self.readFastqFile, self.referenceFastaFile, self.outputSamFile))

class BlasrParamsChain(BlasrParams):
    def run(self):
        BlasrParams.run(self)
        self.chainSamFile()

class BlasrParamsRealign(BlasrParams):
    def run(self):
        BlasrParams.run(self)

        self.realignSamFile()