#!/usr/bin/perl
Hide Show 36 lines of Pod
my
(
$help
,
$tol
,
$imposedCharge
,
$numPeaks
,
$relNumPeaks
);
my
$unit
=
'ppm'
;
if
(!GetOptions(
'help'
=> \
$help
,
'h'
=> \
$help
,
'tol=f'
=> \
$tol
,
'numpeaks=i'
=> \
$numPeaks
,
'relnumpeaks=f'
=> \
$relNumPeaks
,
'imposedcharge=i'
=> \
$imposedCharge
,
'unit=s'
=> \
$unit
) ||
defined
(
$help
) || (!
defined
(
$tol
) && !
defined
(
$imposedCharge
) && !
defined
(
$numPeaks
) && !
defined
(
$relNumPeaks
))){
print
STDERR "Usage: filterPeptSpectra.pl [options] peptSpectra.xml
\t-h
\t-help
\t--imposedcharge=
int
\t--tol=float [mass tolerance]
\t--unit=string [
'ppm'
or
'Da'
,
default
is
'$unit'
]
\t--numPeaks=
int
[minimum number of peaks in an experimental spectrum]
\t--relnumpeaks=float [minimum relative number of peaks, divide the parent mass by 100 and multiply by this number to obtain the minimum number of peaks required]\n";
exit
(0);
}
$unit
=
uc
(
$unit
);
InSilicoSpectro::init();
open
(F,
$ARGV
[0]) || CORE::
die
(
"Cannot open [$ARGV[0]]: $!"
);
while
(<F>){
print
;
last
if
(/<idi:Identifications>/);
}
my
(
$oneIdentification
,
$peptide
,
$modif
,
$charge
,
$moz
,
$numMoz
);
while
(<F>){
last
if
(/<\/idi:Identifications>/);
$oneIdentification
.=
$_
;
if
(/<idi:sequence>(.+)<\/idi:sequence>/){
$peptide
= $1;
}
elsif
(/<idi:modif>(.+)<\/idi:modif>/){
$modif
= $1;
}
elsif
(/<idi:charge>(.+)<\/idi:charge>/){
$charge
= $1+0;
}
elsif
(/<ple:ParentMass><!\[CDATA\[(.+)\]\]><\/ple:ParentMass>/){
$moz
= (
split
(/\s+/, $1))[0];
}
elsif
(/<ple:peaks><!\[CDATA\[/){
$numMoz
= 0;
while
(<F>){
$oneIdentification
.=
$_
;
last
if
(/\]\]><\/ple:peaks>/);
$numMoz
++;
}
}
elsif
(/<\/idi:OneIdentification>/){
if
(
defined
(
$imposedCharge
) && (
$charge
!=
$imposedCharge
)){
print
STDERR
"$charge != $imposedCharge\n"
;
undef
(
$oneIdentification
);
next
;
}
if
(
defined
(
$tol
)){
my
@modif
=
split
(/:/,
$modif
);
my
$theoMass
= getPeptideMass(
pept
=>
$peptide
,
modif
=>\
@modif
);
my
(
$charge
,
$moz2
) = getCorrectCharge(
$theoMass
,
$moz
);
my
$expMass
= (
$moz
-getMass(
'el_H+'
))
*$charge
;
my
$err
= (
$unit
eq
'PPM'
) ? (
$expMass
-
$theoMass
)/(
$expMass
+
$theoMass
)*2.e+6 :
$expMass
-
$theoMass
;
if
(
abs
(
$err
) >
$tol
){
print
STDERR
"$err > $tol\n"
;
undef
(
$oneIdentification
);
next
;
}
}
if
(
defined
(
$numPeaks
) && (
$numMoz
<
$numPeaks
)){
print
STDERR
"$numMoz < $numPeaks\n"
;
undef
(
$oneIdentification
);
next
;
}
if
(
defined
(
$relNumPeaks
)){
my
@modif
=
split
(/:/,
$modif
);
my
$theoMass
= getPeptideMass(
pept
=>
$peptide
,
modif
=>\
@modif
);
my
(
$charge
,
$moz2
) = getCorrectCharge(
$theoMass
,
$moz
);
my
$expMass
= (
$moz
-getMass(
'el_H+'
))
*$charge
;
my
$n
=
$expMass
/100.0;
if
(
$numMoz
<
$n
*$relNumPeaks
){
print
STDERR
"$numMoz < $n*$relNumPeaks\n"
;
undef
(
$oneIdentification
);
next
;
}
}
print
$oneIdentification
;
undef
(
$oneIdentification
);
}
}
print
;
while
(<F>){
print
;
}
close
(F);