Commit da1ae29f authored by Benoit Valot's avatar Benoit Valot
Browse files

Initial import.

git-svn-id: https://subversion.renater.fr/masschroq/quanti/trunk@760 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 853c983f
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>quantification</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.epic.perleditor.perlbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.epic.perleditor.perlnature</nature>
</natures>
</projectDescription>
#!/usr/bin/perl -w
#Filtre le raw transform en .txt
#Ne fonctionne pas avec des zoom??
use strict;
use File::Basename;
use Wx;
use Wx qw(:filedialog wxID_CANCEL);
my $mass;
my @masses;
my $line;
my @elementline;
my $error;
my $attente = '0';
my $timemedian = '1';
my $scanlimite = '40';
my $timeminimun = '0.5';
my $massmax = '1.5';
my $massmin = '0.5';
my $endtreshold = '200000';
my $treshold = '300000';
my $files;
my $dirin;
my $temp;
my $scantime;
my $intensity;
my %data = ();
my %datatemp = ();
my %quant = ();
my @scantimes;
eval {
print STDOUT "Detection de peak\n\n";
#### Aller chercher des fichiers######################
my ($this) = shift;
my $opendialog = Wx::FileDialog->new(
$this, # Parent du Dialog, ici la Frame
"Slectionn les fichiers raw tranform en txt", # Titre du Dialog
'', '',
"txt files (*.txt)|*.txt|All files (*.*)|*.*",
wxOPEN | wxMULTIPLE
);
( $opendialog->ShowModal != wxID_CANCEL ) || die("Analyse abandonnee");
my @filestxt = $opendialog->GetPaths;
my ( $filename, $dirname ) =
&File::Basename::fileparse( $opendialog->GetPath );
$dirin = $dirname;
$opendialog->Destroy;
#### Aller chercher un dossier de sortie ######################
my $opendirdialog = Wx::DirDialog->new(
$this, # Parent du Dialog, ici la Frame
"Slectionn le dossier dans lequel les rsultats seront enregistrs"
, # Titre du Dialog
$dirin,
wxOPEN
); # Flags de style
( $opendirdialog->ShowModal != wxID_CANCEL ) || die("Analyse abandonnee");
my $dirout = $opendirdialog->GetPath;
$dirout .= "/";
$opendirdialog->Destroy;
###########################
print STDOUT "Les fichiers qui suis vont etre analyses :\n";
foreach $files (@filestxt) {
( -e $files ) || die( "on ne peut ouvrir le fichier " . $files );
print STDOUT $files . "\n";
}
print STDOUT " \nles resultats seront enregistres dans :\n" . $dirout
. "\n\n";
$error = '0';
print STDOUT "Masses a detecter \n";
while ( $error == 0 ) {
$mass = <STDIN>;
chomp $mass;
if ( $mass and $mass =~ m/^\d+\.?\d*$/ ) {
push( @masses, $mass );
}
else {
$error += 1;
}
}
print STDOUT "Analyse demarre\n\n";
####Fichier resultats combinant l'ensemble des peak dtecter et des fichiers
open QUANFILE,
">" . $dirout . "Quantification_peak_" . join( '_', @masses ) . ".txt"
|| die "impossible d'ouvrir "
. "Quantification_peak_"
. join( '', @masses ) . ".txt";
###Parsage du fichier pour obtenir les donnes##########
foreach $files (@filestxt) {
%quant = ();
%data = ();
%datatemp = ();
@scantimes = ();
open INFILE, "<" . $files
|| die "impossible d'ouvrir " . $files;
while ( $attente == 0 ) {
$line = <INFILE>;
chomp $line;
if ( !$line ) {
$attente += 1;
}
}
while ( defined( $line = <INFILE> ) ) {
@elementline = &parse($line);
if ( @elementline gt 3
and $elementline[0] =~ m/^Scan/
and $elementline[3] =~ m/^\d+\.\d+\,$/ )
{
$scantime = $elementline[3];
$scantime =~ s/\,//;
if ( $scantime <= $scanlimite ) {
push( @scantimes, $scantime );
}
$line = <INFILE>;
#Rajouter test sur ZOOM
$line = <INFILE>;
$line = <INFILE>;
$line = <INFILE>;
$line = <INFILE>;
$attente = '0';
$intensity = '0';
while ( $attente == 0 ) {
$line = <INFILE>;
@elementline = &parsetabule($line);
if ( @elementline gt 1 ) {
foreach $mass (@masses) {
if ( $elementline[1] >= ( $mass - $massmin )
and $elementline[1] <= ( $mass + $massmax ) )
{
$datatemp{$mass}{$scantime}{'intensite'} +=
$elementline[2];
}
}
}
else {
foreach $mass (@masses) {
$datatemp{$mass}{$scantime}{'intensite'} +=
$intensity;
}
$attente += 1;
}
}
}
}
my $tmp = $scanlimite + 0.1;
push (@scantimes, $tmp);
foreach $mass (@masses) {
$datatemp{$mass}{$tmp}{'intensite'} = '0';
}
close INFILE;
print STDOUT "partage terminer de " . basename($files) . "\n";
#####Parsage termin############
####Calcule des medians, des minimun, des noises
###et de la valeur final soustraite du noise#######
my @datas = ();
my @temps = @scantimes;
my $key;
foreach $mass (@masses) {
foreach $scantime (@scantimes) {
@datas = ();
foreach $key (@temps) {
if ( ( $key <= ( $scantime + $timemedian ) )
and ( $key >= ( $scantime - $timemedian ) ) )
{
push( @datas, $datatemp{$mass}{$key}{'intensite'} );
}
}
$temp = &median(@datas);
$datatemp{$mass}{$scantime}{'median'} = $temp;
}
}
foreach $mass (@masses) {
foreach $scantime (@scantimes) {
@datas = ();
foreach $key (@temps) {
if ( ( $key <= ( $scantime + $timeminimun ) )
and ( $key >= ( $scantime - $timeminimun ) ) )
{
push( @datas, $datatemp{$mass}{$key}{'median'} );
}
}
$temp = &min(@datas);
$datatemp{$mass}{$scantime}{'min'} = $temp;
}
}
foreach $mass (@masses) {
foreach $scantime (@scantimes) {
@datas = ();
foreach $key (@temps) {
if ( ( $key <= ( $scantime + $timeminimun ) )
and ( $key >= ( $scantime - $timeminimun ) ) )
{
push( @datas, $datatemp{$mass}{$key}{'min'} );
}
}
$temp = &max(@datas);
$datatemp{$mass}{$scantime}{'noise'} = $temp;
}
}
foreach $mass (@masses) {
foreach $scantime (@scantimes) {
$temp = $datatemp{$mass}{$scantime}{'intensite'} -
$datatemp{$mass}{$scantime}{'noise'};
$data{$mass}{$scantime}{'intensite'} = $temp;
$data{$mass}{$scantime}{'originvalue'} =
$datatemp{$mass}{$scantime}{'intensite'};
}
}
###Vidage de la table de hache temporaire###
%datatemp = ();
############################
########Recherche des peaks##########
foreach $mass (@masses) {
my $aire = '0';
my $timemax = '';
@temps = @scantimes;
my $keyback = shift(@temps);
while ( $key = shift(@temps) ) {
if ( $data{$mass}{$key}{'intensite'} >= $treshold ) {
$aire += (
( $key - $keyback ) * (
$data{$mass}{$key}{'intensite'} +
$data{$mass}{$keyback}{'intensite'}
)
) / 2;
$timemax = $key;
$keyback = $key;
$key = shift(@temps);
if ( $key and $data{$mass}{$key}{'intensite'} >= $treshold )
{
$aire += (
( $key - $keyback ) * (
$data{$mass}{$key}{'intensite'} +
$data{$mass}{$keyback}{'intensite'}
)
) / 2;
if ( $key
and $data{$mass}{$key}{'intensite'} >=
$data{$mass}{$timemax}{'intensite'} )
{
$timemax = $key;
}
$attente = '0';
while ( $attente == 0 ) {
$keyback = $key;
$key = shift(@temps);
$aire += (
( $key - $keyback ) * (
$data{$mass}{$key}{'intensite'} +
$data{$mass}{$keyback}{'intensite'}
)
) / 2;
if ( $data{$mass}{$key}{'intensite'} >=
$data{$mass}{$timemax}{'intensite'} )
{
$timemax = $key;
}
if ( $data{$mass}{$key}{'intensite'} <=
$endtreshold )
{
$attente += 1;
my $tmp = $aire * 60;
$_ = sprintf( "%.0f", $tmp );
$data{$mass}{$timemax}{'peak'} = $_;
$quant{$timemax}{$mass} = $_;
$aire = '0';
$timemax = '';
}
}
}
else {
$keyback = $key;
$aire = '0';
$timemax = '';
}
}
else {
$keyback = $key;
}
}
}
####Impression des data brutes de dtection, un par fichier#####
open OUTFILE,
'>' . $dirout . substr( basename($files), 0, -4 ) . "_data.txt"
|| die "impossible d'crire le fichier data";
foreach $mass (@masses) {
print OUTFILE "\t" . $mass . "\t\t";
}
print OUTFILE "\n";
foreach $scantime (@scantimes) {
print OUTFILE $scantime . "\t";
# . $datatemp{$mass}{$scantime}{'intensite'} . "\t"
# . $datatemp{$mass}{$scantime}{'median'} . "\t"
# . $datatemp{$mass}{$scantime}{'min'} . "\t"
# . $datatemp{$mass}{$scantime}{'noise'} . "\t"
foreach $mass (@masses) {
print OUTFILE $data{$mass}{$scantime}{'originvalue'} . "\t";
print OUTFILE $data{$mass}{$scantime}{'intensite'} . "\t";
if ( $data{$mass}{$scantime}{'peak'} ) {
print OUTFILE $data{$mass}{$scantime}{'peak'} . "\t";
}
else {
print OUTFILE "\t";
}
}
print OUTFILE "\n";
}
close OUTFILE;
##Ecriture des donnes combinant tout les Lc-MS/MS et les dtections####
print QUANFILE basename($files) . "\n";
print QUANFILE "\t";
foreach $mass (@masses) {
print QUANFILE "\t" . $mass;
}
print QUANFILE "\n";
@temps = sort { $a <=> $b } keys(%quant);
foreach $scantime (@temps) {
print QUANFILE "\t" . $scantime;
foreach $mass (@masses) {
if ( $quant{$scantime}{$mass} ) {
print QUANFILE "\t" . $quant{$scantime}{$mass};
}
else {
print QUANFILE "\t";
}
}
print QUANFILE "\n";
}
print STDOUT "Calcule terminer de " . basename($files);
print STDOUT "\n\n";
}
close QUANFILE;
print STDOUT "Analyse terminee";
<STDIN>;
};
if ($@) {
my $error = $@;
# $error =~ s/at .*\.$//s;
print STDOUT $error;
<STDIN>;
}
############################################
#sous-routine qui parse un fichier txt tabule
sub parse() {
my ($string) = @_;
my @strings;
if ($string) {
chomp $string;
@strings = split( / /, $string, -1 );
}
else {
@strings = ();
}
return (@strings);
}
#sous-routine qui parse un fichier txt tabule
sub parsetabule() {
my ($string) = @_;
my @strings;
if ($string) {
chomp $string;
$string =~ s/ //g;
@strings = split( /\t/, $string, -1 );
}
else {
@strings = ();
}
return (@strings);
}
##Renvoie la valeur mediane
sub median() {
my @string = @_;
my $nombremedian = "";
my $median = "";
my $min = "";
my $max = "";
my @medians = sort { $a <=> $b } @string;
my $nombre = @medians;
if ( $nombre =~ m/[1,3,5,7,9]$/ ) {
$nombremedian = $nombre / 2;
$nombremedian += 0.5;
my $error = '1';
while ( $error <= $nombremedian ) {
$median = shift(@medians);
$error += 1;
}
}
else {
$nombremedian = $nombre / 2;
my $error = '1';
while ( $error <= $nombremedian ) {
$min = shift(@medians);
$error += 1;
}
$max = shift(@medians);
$median = ( $min + $max ) / 2;
}
return ($median);
}
#renvoie la valeur min
sub min() {
my @string = @_;
my @mins = sort { $a <=> $b } @string;
my $min = shift(@mins);
return ($min);
}
#renvoie la valeur max=noise
sub max() {
my @string = @_;
my @maxs = sort { $b <=> $a } @string;
my $max = shift(@maxs);
return ($max);
}
#!/usr/bin/perl -w -I ../
#
#
#Benoit Valot, 2007
#Bioinformatique, INRA Le Moulon
#
# parses the Sashimi mzXML file for quantification
#
package ms1_creation_lmata;
BEGIN {
use Exporter ();
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
$VERSION = 1.00;
# if using RCS/CVS, this may be preferred
#$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
@ISA = qw(Exporter);
@EXPORT = qw(parsing_ok);
%EXPORT_TAGS = (); # eg: TAG => [ qw!name1 name2! ],
# your exported package globals go here,
# as well as any optionally exported functions
@EXPORT_OK = qw();
}
use strict;
use MIME::Base64;
my $_data;
my $_mslevel;
my $_lowMz;
my $_highMz;
my $_basepeak;
my $_scantype; #Full ou Zoom
my $_RT; #Temp de retention extrait de : 'PT300.03S'
my $_peakscount;
my $_mass_start;
my $_mass_end;
my $_filemata;
my @_scantimes;
my @_massesdata;
my $_basepeakmin;
my $_scanlimite;
#initialize the handler
sub new () {
my $type = shift;
#Récupere les variables envoyer au parser
( $_mass_start, $_mass_end, $_scanlimite, $_basepeakmin, $_filemata ) = @_;
@_scantimes = ();
return bless {}, $type;
}
#handle a start-of-element event
sub start_element {
my ( $self, $element ) = @_;
$_data = "";
if ( $element->{Name} eq 'scan' ) {
$_mslevel = $element->{Attributes}->{'{}msLevel'}->{Value};
if ( $_mslevel eq '1' ) {
my $RTtmp = $element->{Attributes}->{'{}retentionTime'}->{Value};
$RTtmp =~ s/^PT//; #Transformation du temps
$RTtmp =~ s/S$//;
( $RTtmp =~ m/^\d+\.?\d*$/ )
|| die "Probleme de transformation du temps de rentention : "
. $RTtmp;
$_RT = $RTtmp; #Conservation en seconde
#$_RT = sprintf( "%.2f", $RTtmp / 60 ); #transformation en minute!
#recherche du type de scan full ou zoom
if ( defined( $element->{Attributes}->{'{}scanType'} ) ) {
$_scantype = $element->{Attributes}->{'{}scanType'}->{Value};
}
else {
$_lowMz = $element->{Attributes}->{'{}lowMz'}->{Value};
$_highMz = $element->{Attributes}->{'{}highMz'}->{Value};
if ( ( $_highMz - $_lowMz ) > 100 ) {
$_scantype = 'Full';
}
else {
$_scantype = 'Zoom';
}
}
$_basepeak =
$element->{Attributes}->{'{}basePeakIntensity'}->{Value};
$_peakscount = $element->{Attributes}->{'{}peaksCount'}->{Value};
}
}
}
#handle a end-of-element event
sub end_element {
my ( $self, $element ) = @_;
if ( $element->{Name} eq 'peaks'
and $_mslevel eq '1'
and $_basepeak >= $_basepeakmin
and $_RT <= $_scanlimite
and $_scantype eq 'Full' )
{
&decodebase64_dataprint($_data);
}
}
#handle a data between event start and end
sub characters {
my ( $self, $characters ) = @_;
$_data .= $characters->{Data};
}
#handle a start-of-document event
sub start_document {
my ($self) = @_;
@_massesdata = ();
my $mass = $_mass_start;
while ( $mass < $_mass_end ) {
push( @_massesdata, $mass );
$mass += 1;
}
}
#handle a end-of-document event
sub end_document {
my ($self) = @_;
}
sub get_scan() {
return (@_scantimes);
}
sub get_massesdata() {
return (@_massesdata);
}
sub decodebase64_dataprint () {
my ($base64) = @_;
#decodage du spectre