-
Notifications
You must be signed in to change notification settings - Fork 10
/
strip-mzml.rb
executable file
·84 lines (70 loc) · 2.99 KB
/
strip-mzml.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env ruby
require './include/ruby/proteomatic'
require './include/ruby/evaluate-omssa-helper'
require 'fileutils'
require 'set'
class StripMs1Scans < ProteomaticScript
def run()
# scanIds: # in certain mzml files
# MT_CP_blabla_01: Set([113, 100])
# allScanIds: Set([113, 100]) # in all mzml files
scanIds = Hash.new
allScanIds = Set.new
@input[:scanIds].each do |path|
File::open(path) do |f|
f.each_line do |line|
line.strip!
next if line.empty?
id = line.to_i
allScanIds << id
end
end
end
@input[:psmList].each do |path|
results = loadPsm(path)
results[:scanHash].each_key do |scanKey|
scanKeyList = scanKey.split('.')
filename = scanKeyList[0, scanKeyList.size - 3].join('.')
scanId = scanKeyList[-3]
filename.chomp!('-no-ms1')
filename.chomp!('-stripped')
scanIds[filename] ||= Set.new
scanIds[filename] << scanId
end
end
@output.each do |ls_InPath, ls_OutPath|
filename = File::basename(ls_InPath).split('.').first
filename.chomp!('-no-ms1')
filename.chomp!('-stripped')
thisScanIds = scanIds[filename]
thisScanIds ||= Set.new
thisScanIds |= allScanIds
ls_TempOutPath = tempFilename('strip-mzml', File.dirname(ls_OutPath))
FileUtils::mkpath(ls_TempOutPath)
ls_ScanIdsPath = File::join(ls_TempOutPath, 'scan-ids.txt')
ls_StrippedMzMlPath = File::join(ls_TempOutPath, 'stripped.mzml')
unless ls_ScanIdsPath.empty?
File::open(ls_ScanIdsPath, 'w') do |f|
f.puts thisScanIds.to_a.join("\n")
end
end
puts "Stripping #{File.basename(ls_InPath)}..."
$stdout.flush
# call stripscans
scanIdOption = "--#{@param[:scanIdAction]}ScanIds \"#{ls_ScanIdsPath}\""
scanIdOption = '' if thisScanIds.empty?
ls_Command = "#{ExternalTools::binaryPath('ptb.stripscans')} --quiet --outputPath \"#{ls_StrippedMzMlPath}\" --stripMsLevels \"#{@param[:stripMsLevels]}\" #{scanIdOption} \"#{ls_InPath}\""
runCommand(ls_Command)
unless (@param[:compression].empty?)
ls_7ZipPath = ExternalTools::binaryPath('7zip.7zip')
ls_Command = "\"#{ls_7ZipPath}\" a -t#{@param[:compression] == '.gz' ? 'gzip' : 'bzip2'} \"#{ls_OutPath}\" \"#{ls_StrippedMzMlPath}\" -mx5"
runCommand(ls_Command)
else
FileUtils::mv(ls_StrippedMzMlPath, ls_OutPath)
end
FileUtils::mv(ls_OutPath, ls_OutPath.sub('.proteomatic.part', ''))
FileUtils::rm_rf(ls_TempOutPath)
end
end
end
script = StripMs1Scans.new