Exemplo n.º 1
0
    def LabelMe(self):
        Handle = open(self.InputFilePath, "rb")
        Dymo = Label.LabelClass()
        Count = 0
        GoodScoreCount = 0
        WrongChargeCount = 0
        ScoredWorseCount = 0
        for Line in Handle.xreadlines():
            if Line[0] == "#":
                self.Columns.initializeHeaders(Line)
                continue
            if not Line.strip():
                continue
            Bits = list(Line.strip().split("\t"))
            #Charge = int (Bits[self.Columns.Charge])  I don't thin I need this anymore
            Count += 1
            Annotation = Bits[self.Columns.getIndex("Annotation")]
            #print "Annotation :%s:"%Annotation
            FileName = Bits[self.Columns.getIndex("SpectrumFile")]
            Scan = int(Bits[self.Columns.getIndex("Scan#")])
            if not self.InspectFormat:
                FileNameMinusPath = os.path.split(FileName)[1]
                (FullPathDummy,
                 ByteOffset) = self.ScanOffset[(FileNameMinusPath, Scan)]
                #print (FullPathDummy, ByteOffset)
                #continue
            else:
                ByteOffset = int(Bits[self.Columns.getIndex("SpecFilePos")])
            (Path, File) = os.path.split(FileName)
            FileName = os.path.join(self.MZXMLDir, File)
            VerboseFileName = "%s.%s.%s.verbose.txt" % (File, Scan,
                                                        Annotation[2:-2])
            ImageFileName = "%s.%s.%s.png" % (File, Scan, Annotation[2:-2])
            VerboseFilePath = os.path.join(self.LabeledAnnotationsDir,
                                           VerboseFileName)
            ImageFilePath = os.path.join(self.LabeledAnnotationsDir,
                                         ImageFileName)
            ## as we've got a single Dymo object, we must be passing in full args list
            ## -p to suppress the image popup, and -P for the PLS score
            Args = " -r %s -b %d -a %s -v %s -w %s -p -P" % (
                FileName, ByteOffset, Annotation, VerboseFilePath,
                ImageFilePath)
            ArgsList = Args.split()
            #print "Parsing Results for %s, scan %s, charge %s"%(FileName, Scan, Charge)
            #print "Args: %s"%Args
            Dymo.ParseCommandLine(ArgsList)
            Dymo.Main()

        Handle.close()
Exemplo n.º 2
0
    def WritePeptideLine(self, File, IntervalStr, ProteinID, SpectrumIndex,
                         Peptide, TotalHitCount):
        Dir = os.path.split(self.SummaryPagePath)[0]
        Annotation = Peptide.GetModdedName()
        SpecFileName = Peptide.SpectrumFilePath.replace("/",
                                                        "\\").split("\\")[-1]
        if self.GenerateSpectrumImagesFlag:
            ImageFileName = "%s.%s.png" % (Annotation, SpectrumIndex)
            ImageFilePath = os.path.join(Dir, ImageFileName)
            Maker = MakeImage.MSImageMaker()
            MSpectrum = MSSpectrum.SpectrumClass()
            Path = self.GetSpectrumPath(Peptide.SpectrumFilePath,
                                        self.MZXMLPath)
            FileName = "%s:%s" % (Path, Peptide.SpectrumFilePos)
            try:
                #SpectrumFile = Label.OpenAndSeekFile(FileName)
                #print FileName
                #MSpectrum.ReadPeaksFromFile(SpectrumFile, FileName)
                #MSpectrum.RankPeaksByIntensity()
                #SpectrumFile.close()
                #Label.LabelSpectrum(MSpectrum, Peptide)
                #Maker.ConvertSpectrumToImage(MSpectrum, ImageFilePath, Peptide, Width = 500, Height = 380)
                Args = " -r %s -b %d -a %s -w %s -p" % (
                    Path, int(
                        Peptide.SpectrumFilePos), Annotation, ImageFilePath)
                ArgsList = Args.split()
                #print "Parsing Results for %s, scan %s"%(FileName, Scan)
                Dymo = Label.LabelClass()
                Dymo.ParseCommandLine(ArgsList)
                #Dymo.LoadModel(0, Dymo.PeptideHasPhosphorylation)
                Dymo.Main()

            except:
                traceback.print_exc()
            File.write(
                "<tr><td>%s</td><td>%s</td><td><a href=\"%s\">%s</td><td>%s</td><td>%s</td>"
                %
                (IntervalStr, TotalHitCount, ImageFileName,
                 Peptide.GetFullModdedName(), Peptide.PValue, Peptide.MQScore))
            File.write("<td>%s</td><td>%s</td></tr>\n" %
                       (SpecFileName, Peptide.ScanNumber))
        else:
            File.write(
                "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" %
                (IntervalStr, TotalHitCount, Peptide.GetFullModdedName(),
                 Peptide.PValue, Peptide.MQScore))
            File.write("<td>%s</td><td>%s</td></tr>\n" %
                       (SpecFileName, Peptide.ScanNumber))