Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
add -offset argument to CLI for isolation offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kovalchik committed Jul 9, 2018
1 parent 6d00b64 commit 9dd61c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
31 changes: 13 additions & 18 deletions RawQuant/RawQuant.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class RawQuant:

def __init__(self, RawFile, order='auto', disable_bar=False):
def __init__(self, RawFile, order='auto', disable_bar=False, boxcar=False, isolationOffset=None):

self.disable_bar = disable_bar

Expand Down Expand Up @@ -141,23 +141,12 @@ def __init__(self, RawFile, order='auto', disable_bar=False):
if 'Master Scan Number:' in labels:
self.flags['MasterScanNumber'] = True

# get the isolation window offset, if there is one
# if the system is linux, this seems to fail, so for now we will check that and skip if it is so

if (sys.platform is 'linux') | (sys.platform is 'darwin'):

offset = 0.0

if isolationOffset is not None:
self.MetaData['Offset'] = float(isolationOffset)
else:
self.MetaData['Offset'] = 0.0

method = self.raw.GetInstrumentMethod(1)

offset = findall(r'Isolation[ m/z ]*Offset\s*=*\s*(\S+)', method, flags=IGNORECASE)[0]

if (offset.lower() == 'off') | (offset.lower() == 'false') :
offset = 0.0

self.MetaData['Offset'] = float(offset)
self.flags['BoxCar'] = boxcar

self.Initialized = True

Expand Down Expand Up @@ -275,6 +264,8 @@ def ExtractTriggerMass(self):

scans = self.info.loc[(self.info['MSOrder'] == 2), 'ScanNum']

print(self.RawFile + ': Extracting parent peak masses')

self.data['TriggerMass'] = OD((str(x), self.raw.GetScanEventForScanNumber(x).Reactions[0].PrecursorMass -
self.MetaData['Offset']) for x in scans)

Expand Down Expand Up @@ -424,8 +415,12 @@ def get_out(scan):

keys = ['MassRange[' + str(x.LowMass) + '-' + str(x.HighMass) + ']FillTime' for x in ranges]

print(keys)

fill_times = self.data['MS1TrailerExtra'][str(scan)]['Multi Inject Info'][3:].split(',')

print(fill_times)

return OD((keys[x], fill_times[x]) for x in range(len(keys)))

print(self.RawFile + ': Extracting boxcar mass ranges and fill times')
Expand Down Expand Up @@ -2026,9 +2021,9 @@ def __del__(self):


# define a function to be used in parallelism
def func(msFile, reagents, mgf, interference, impurities, metrics, boxcar):
def func(msFile, reagents, mgf, interference, impurities, metrics, boxcar, isolationOffset=None):
filename = msFile[:-4] + '_QuantData.txt'
data = RawQuant(msFile, disable_bar=True)
data = RawQuant(msFile, disable_bar=True, isolationOffset=isolationOffset)

if boxcar:
data.SetAsBoxcar()
Expand Down
21 changes: 15 additions & 6 deletions RawQuant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
'Number of CPU cores to be used when processing multiple files.\n'+
'If left blank a single core will be used.\n ')

quant.add_argument('-b', '--boxcar', help=
quant.add_argument('-b', '--boxcar', action='store_true', help=
'Indicates that the rawfile is from a boxcar experiment and the program'
'should look for multi-injection data.')

Expand Down Expand Up @@ -201,6 +201,9 @@
'>python -m RawQuant quant -f rawFile.raw -r TMT0 -mgf -mco 128\n' +
'cuts off all MS2 ions < m/z 128 when making the mgf file.')

quant.add_argument('-offset', '--isolation_window_offset', help=
'Specify the offset of the isolation window, if there was one.')

### Examples subparser section ###

examples.add_argument('-m','--multiple', action='store_true', help =
Expand Down Expand Up @@ -267,6 +270,9 @@
'>python -m RawQuant parse -f rawFile.raw -o 0 -mgf -mco 128\n' +
'cuts off all MS2 ions < m/z 128 when making the mgf file.')

parse.add_argument('-offset', '--isolation_window_offset', help=
'Specify the offset of the isolation window, if there was one.')

args = parser.parse_args()

else:
Expand Down Expand Up @@ -712,7 +718,8 @@ def __init__(self):
for msFile in files:

filename = msFile[:-4]+'_ParseData.txt'
data = RawQuant(msFile,disable_bar=suppress_bar)
data = RawQuant(msFile, disable_bar=suppress_bar, isolationOffset=args.isolation_window_offset,
boxcar=args.boxcar)

if args.boxcar:

Expand Down Expand Up @@ -758,7 +765,7 @@ def __init__(self):

elif args.multiple is not None:

files = np.loadtxt(args.multiple,dtype=str).tolist()
files = np.loadtxt(args.multiple, dtype=str).tolist()

elif args.directory is not None:

Expand Down Expand Up @@ -822,7 +829,8 @@ def __init__(self):
for msFile in files:

filename = msFile[:-4]+'_QuantData.txt'
data = RawQuant(msFile,order=order,disable_bar=suppress_bar)
data = RawQuant(msFile, order=order, disable_bar=suppress_bar, boxcar=args.boxcar,
isolationOffset=args.isolation_window_offset)

if args.boxcar:
data.SetAsBoxcar()
Expand All @@ -841,7 +849,7 @@ def __init__(self):
data.GenerateCorrectionMatrix()
data.CorrectImpurities()

data.SaveData(filename = filename)
data.SaveData(filename=filename)

if args.generate_mgf:

Expand Down Expand Up @@ -869,4 +877,5 @@ def __init__(self):

Parallel(n_jobs=num_cores)(delayed(func)(msFile=msFile, reagents=reagents, mgf=args.generate_mgf,
interference=args.quantify_interference, impurities=impurities,
metrics=args.metrics, boxcar=args.boxcar) for msFile in files)
metrics=args.metrics, boxcar=args.boxcar,
isolationOffset=args.isolation_window_offset) for msFile in files)

0 comments on commit 9dd61c1

Please sign in to comment.