Skip to content

Commit

Permalink
Merge pull request #137 from Nesvilab/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Felipe Leprevost committed Jun 4, 2020
2 parents c523573 + 9454a59 commit 50a08ee
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 57 deletions.
4 changes: 3 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
### Changed

### Fixed
- Pipeline functions were restored.
- Pipeline functions were restored.
- Ion Purity calculation was fixed, and now supports msconvert 3.20
- Fixed file discovery for filtering on Windows
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BINARY = philosopher
VERSION = $(shell date +%Y%m%d)
BUILD = $(shell date +%Y%m%d%H%M)

TAG = v3.2.5
TAG = v3.2.6

LDFLAGS = -ldflags "-w -s -X main.version=${TAG} -X main.build=${BUILD}"

Expand Down
2 changes: 0 additions & 2 deletions cmd/labelquant.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ var labelquantCmd = &cobra.Command{
msg.InputNotFound(errors.New("You need to specify the experiment Plex"), "fatal")
}

// hardcoded tmt for now
msg.Executing("Isobaric-label quantification ", Version)
//m.Quantify.Brand = "tmt"

if strings.EqualFold(strings.ToLower(m.Quantify.Format), "mzml") {
m.Quantify.Format = "mzML"
Expand Down
31 changes: 20 additions & 11 deletions lib/aba/pep.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,36 @@ func peptideLevelAbacus(m met.Data, args []string) {
var labels DataSetLabelNames
labels.LabelName = make(map[string]string)

// collect interact full file names
files, _ := ioutil.ReadDir(i)

// collect interact full file names
for _, f := range files {
if strings.Contains(f.Name(), "pep.xml") {
interactFile := fmt.Sprintf("%s%s%s", i, string(filepath.Separator), f.Name())
absPath, _ := filepath.Abs(interactFile)
xmlFiles = append(xmlFiles, absPath)
}
}
if strings.Contains(f.Name(), "annotation") {
var annot = fmt.Sprintf("%s%s%s", i, string(filepath.Separator), f.Name())
labels.Name = annot

var annot = fmt.Sprintf("%s%sannotation.txt", i, string(filepath.Separator))
if strings.Contains(i, string(filepath.Separator)) {
i = strings.Replace(i, string(filepath.Separator), "", -1)
labels.Name = i
} else {
labels.Name = i
if len(m.Quantify.Annot) > 0 {
labels.LabelName = getLabelNames(annot)
}
}
}

if len(m.Quantify.Annot) > 0 {
labels.LabelName = getLabelNames(annot)
}
// var annot = fmt.Sprintf("%s%sannotation.txt", i, string(filepath.Separator))
// if strings.Contains(i, string(filepath.Separator)) {
// i = strings.Replace(i, string(filepath.Separator), "", -1)
// labels.Name = i
// } else {
// labels.Name = i
// }

// if len(m.Quantify.Annot) > 0 {
// labels.LabelName = getLabelNames(annot)
// }

// collect project names
prjName := i
Expand Down
28 changes: 18 additions & 10 deletions lib/aba/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,27 @@ func proteinLevelAbacus(m met.Data, args []string) {
absPath, _ := filepath.Abs(interactFile)
xmlFiles = append(xmlFiles, absPath)
}
}
if strings.Contains(f.Name(), "annotation") {
var annot = fmt.Sprintf("%s%s%s", i, string(filepath.Separator), f.Name())
labels.Name = annot

var annot = fmt.Sprintf("%s%sannotation.txt", i, string(filepath.Separator))
if strings.Contains(i, string(filepath.Separator)) {
i = strings.Replace(i, string(filepath.Separator), "", -1)
labels.Name = i
} else {
labels.Name = i
if len(m.Quantify.Annot) > 0 {
labels.LabelName = getLabelNames(annot)
}
}
}

if len(m.Quantify.Annot) > 0 {
labels.LabelName = getLabelNames(annot)
}
// var annot = fmt.Sprintf("%s%sannotation.txt", i, string(filepath.Separator))
// if strings.Contains(i, string(filepath.Separator)) {
// i = strings.Replace(i, string(filepath.Separator), "", -1)
// labels.Name = i
// } else {
// labels.Name = i
// }

// if len(m.Quantify.Annot) > 0 {
// labels.LabelName = getLabelNames(annot)
// }

// collect project names
prjName := i
Expand Down
2 changes: 1 addition & 1 deletion lib/fil/fil.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func readPepXMLInput(xmlFile, decoyTag, temp string, models bool, calibratedMass
fileCheckList = append(fileCheckList, xmlFile)
files[xmlFile] = 0
} else {
glob := fmt.Sprintf("%s/*pep.xml", xmlFile)
glob := fmt.Sprintf("%s%s*pep.xml", xmlFile, string(filepath.Separator))
list, _ := filepath.Glob(glob)

if len(list) == 0 {
Expand Down
8 changes: 5 additions & 3 deletions lib/mzn/mzn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (

"philosopher/lib/msg"

"github.com/sirupsen/logrus"
"philosopher/lib/psi"

"github.com/sirupsen/logrus"
)

// MsData top struct
Expand Down Expand Up @@ -46,8 +47,9 @@ type Precursor struct {
ParentScan string
ChargeState int
SelectedIon float64
SelectedIonIntensity float64
TargetIon float64
PeakIntensity float64
TargetIonIntensity float64
IsolationWindowLowerOffset float64
IsolationWindowUpperOffset float64
}
Expand Down Expand Up @@ -228,7 +230,7 @@ func processSpectrum(mzSpec psi.Spectrum) Spectrum {
if e != nil {
msg.CastFloatToString(e, "fatal")
}
spec.Precursor.PeakIntensity = val
spec.Precursor.SelectedIonIntensity = val
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/mzn/mzn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func TestMS2Spectra(t *testing.T) {
t.Errorf("Spectrum target ion is incorrect, got %f, want %f", spec.Precursor.TargetIon, 391.2)
}

if spec.Precursor.PeakIntensity != 3.58558525e+06 {
t.Errorf("Spectrum precursor intensity is incorrect, got %f, want %f", spec.Precursor.PeakIntensity, 3.58558525e+06)
if spec.Precursor.SelectedIonIntensity != 3.58558525e+06 {
t.Errorf("Spectrum precursor intensity is incorrect, got %f, want %f", spec.Precursor.SelectedIonIntensity, 3.58558525e+06)
}

if spec.Precursor.IsolationWindowLowerOffset != 0.34999999404 {
Expand Down
31 changes: 21 additions & 10 deletions lib/qua/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func calculateIonPurity(d, f string, mz mzn.MsData, evi []rep.PSMEvidence) []rep
var indexedMS1 = make(map[string]mzn.Spectrum)
var indexedMS2 = make(map[string]mzn.Spectrum)

var MS1Peaks = make(map[string][]float64)
var MS1Int = make(map[string][]float64)

for i := range mz.Spectra {

if mz.Spectra[i].Level == "1" {
Expand All @@ -39,6 +42,9 @@ func calculateIonPurity(d, f string, mz mzn.MsData, evi []rep.PSMEvidence) []rep

indexedMS1[paddedScan] = mz.Spectra[i]

MS1Peaks[paddedScan] = mz.Spectra[i].Mz.DecodedStream
MS1Int[paddedScan] = mz.Spectra[i].Intensity.DecodedStream

} else if mz.Spectra[i].Level == "2" {

if mz.Spectra[i].Precursor.IsolationWindowLowerOffset == 0 && mz.Spectra[i].Precursor.IsolationWindowUpperOffset == 0 {
Expand All @@ -63,10 +69,17 @@ func calculateIonPurity(d, f string, mz mzn.MsData, evi []rep.PSMEvidence) []rep
mz.Spectra[i].Precursor.ParentIndex = paddedPI
mz.Spectra[i].Precursor.ParentScan = paddedPS

indexedMS2[paddedScan] = mz.Spectra[i]
stream := MS1Peaks[paddedPS]

}
for j := range stream {
if stream[j] >= (mz.Spectra[i].Precursor.TargetIon-mz.Spectra[i].Precursor.IsolationWindowLowerOffset) && stream[j] <= (mz.Spectra[i].Precursor.TargetIon+mz.Spectra[i].Precursor.IsolationWindowUpperOffset) {
mz.Spectra[i].Precursor.TargetIonIntensity = MS1Int[mz.Spectra[i].Precursor.ParentScan][j]
break
}
}

indexedMS2[paddedScan] = mz.Spectra[i]
}
}

for i := range evi {
Expand Down Expand Up @@ -98,14 +111,16 @@ func calculateIonPurity(d, f string, mz mzn.MsData, evi []rep.PSMEvidence) []rep

var isotopePackage = make(map[float64]float64)

isotopePackage[v2.Precursor.TargetIon] = v2.Precursor.PeakIntensity
isotopesInt := v2.Precursor.PeakIntensity
isotopePackage[v2.Precursor.TargetIon] = v2.Precursor.TargetIonIntensity
isotopesInt := v2.Precursor.TargetIonIntensity

for k, v := range ions {
for _, m := range mzRatio {
if math.Abs(v2.Precursor.TargetIon-k) <= (m+0.02) && math.Abs(v2.Precursor.TargetIon-k) >= (m-0.02) {
isotopePackage[k] = v
isotopesInt += v
if v != v2.Precursor.TargetIonIntensity {
isotopePackage[k] = v
isotopesInt += v
}
break
}
}
Expand All @@ -117,11 +132,7 @@ func calculateIonPurity(d, f string, mz mzn.MsData, evi []rep.PSMEvidence) []rep
evi[i].Purity = uti.Round((isotopesInt / isolationWindowSummedInt), 5, 2)
}

if evi[i].Purity > 1 {
evi[i].Purity = 1
}
}

}

return evi
Expand Down
32 changes: 23 additions & 9 deletions lib/qua/lfq.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"sort"
"strings"

"philosopher/lib/bio"
"philosopher/lib/msg"
"philosopher/lib/uti"

"philosopher/lib/bio"
"philosopher/lib/mzn"
"philosopher/lib/rep"

"github.com/sirupsen/logrus"
)

// // peakIntensity collects PSM intensities from the apex peak
func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float64, isIso bool) rep.Evidence {

logrus.Info("Indexing PSM information")
Expand All @@ -31,8 +31,10 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float
var retentionTime = make(map[string]float64)
var intensity = make(map[string]float64)

for _, i := range evi.PSM {
var charges = make(map[string]int)

// collect attributes from PSM
for _, i := range evi.PSM {
partName := strings.Split(i.Spectrum, ".")
sourceMap[partName[0]] = 0
spectra[partName[0]] = append(spectra[partName[0]], i.Spectrum)
Expand All @@ -42,13 +44,15 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float
minRT[i.Spectrum] = (i.RetentionTime / 60) - rTWin
maxRT[i.Spectrum] = (i.RetentionTime / 60) + rTWin
retentionTime[i.Spectrum] = i.RetentionTime

charges[i.Spectrum] = int(i.AssumedCharge)
}

// get a sorted list of spectrum names
var sourceMapList []string
for source := range sourceMap {
sourceMapList = append(sourceMapList, source)
}

sort.Strings(sourceMapList)

logrus.Info("Reading spectra and tracing peaks")
Expand All @@ -59,7 +63,8 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float

fileName := fmt.Sprintf("%s%s%s.mzML", dir, string(filepath.Separator), s)

mz.Read(fileName, false, true, true)
// load MS1, ignore MS2 and MS3
mz.Read(fileName, false, false, true)

for i := range mz.Spectra {
if mz.Spectra[i].Level == "1" {
Expand All @@ -68,6 +73,7 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float
spectrum := fmt.Sprintf("%s.%05s.%05s.%d", s, mz.Spectra[i].Scan, mz.Spectra[i].Scan, mz.Spectra[i].Precursor.ChargeState)
_, ok := mzMap[spectrum]
if ok {
// update the MZ with the desired Precursor value from mzML
if isIso == true {
mzMap[spectrum] = mz.Spectra[i].Precursor.TargetIon
} else {
Expand All @@ -81,12 +87,21 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float
if ok {
for _, j := range v {

//var measured = make(map[float64]float64)
//var retrieved bool

measured, retrieved := xic(mz.Spectra, minRT[j], maxRT[j], ppmPrecision[j], mzMap[j])

// if j == "20180209_03_TP_1A.03130.03130.2#interact.pep.xml" {
// fmt.Println(measured)
// }

if retrieved == true {

// create the list of mz differences for each peak
var mzRatio []float64
for k := 1; k <= 6; k++ {
r := float64(k) * (float64(1) / float64(charges[j]))
mzRatio = append(mzRatio, uti.ToFixed(r, 2))
}

var timeW = retentionTime[j] / 60
var topI = 0.0

Expand All @@ -102,7 +117,6 @@ func peakIntensity(evi rep.Evidence, dir, format string, rTWin, pTWin, tol float
}
}
}

}

for i := range evi.PSM {
Expand Down
2 changes: 0 additions & 2 deletions lib/qua/qua.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func RunIsobaricLabelQuantification(p met.Quantify, mods bool) met.Quantify {
psmMap[j.Spectrum] = psm
}
}
//mappedPurity = nil

for _, j := range mappedPSM {
v, ok := psmMap[j.Spectrum]
Expand All @@ -132,7 +131,6 @@ func RunIsobaricLabelQuantification(p met.Quantify, mods bool) met.Quantify {
psmMap[j.Spectrum] = psm
}
}
//mappedPSM = nil

}

Expand Down
8 changes: 3 additions & 5 deletions lib/rep/rep.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,9 @@ func Run(m met.Data) {

// get the labels from the annotation file
if len(m.Quantify.Annot) > 0 {
if len(m.Quantify.Annot) > 0 {
annotfile := fmt.Sprintf(".%sannotation.txt", string(filepath.Separator))
annotfile, _ = filepath.Abs(annotfile)
labels = uti.GetLabelNames(annotfile)
}
annotfile := fmt.Sprintf(".%sannotation.txt", string(filepath.Separator))
annotfile, _ = filepath.Abs(annotfile)
labels = uti.GetLabelNames(annotfile)
}

logrus.Info("Creating reports")
Expand Down
14 changes: 14 additions & 0 deletions lib/uti/uti.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package uti

import (
"bufio"
"fmt"
"math"
"os"
"path/filepath"
"philosopher/lib/msg"
"regexp"
"strconv"
Expand Down Expand Up @@ -110,3 +112,15 @@ func GetLabelNames(annot string) map[string]string {

return labels
}

// FindFile locates a file based on a name pattern
func FindFile(targetDir string, pattern string) string {

match, e := filepath.Glob(targetDir + string(filepath.Separator) + pattern)

if e != nil {
fmt.Println(e)
}

return match[0]
}

0 comments on commit 50a08ee

Please sign in to comment.