view bih4bloodexposome.pl @ 0:94eeed7f737f draft default tip

planemo upload commit 399d2714dd85043f2ed8bdeff05bb1ccd4c5dd29
author fgiacomoni
date Fri, 27 Nov 2020 10:06:35 +0000
parents
children
line wrap: on
line source

#!c:\Perl\bin\perl.exe -w

=head1 NAME

bih4bloodexposome.pl - Utility to detect potential contaminants in your peak list based on BloodExposome database

=head1 USAGE


=head1 SYNOPSIS

=head1 DESCRIPTION

=over 4

=item B<function01>

=item B<function02>

=back

=head1 AUTHOR

Prenom Nom E<lt>franck.giacomoni@inrae.frE<gt>

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

 perldoc bih4bloodexposome.pl

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=head1 VERSION

version 0.1.0 : 2020/01/21

version 2 : ??

=cut
#=============================================================================
#                              Included modules and versions
#=============================================================================
## Perl modules
use strict ;
use warnings ;
use diagnostics ;
use Carp qw (cluck croak carp) ;

use Data::Dumper ;
use Getopt::Long ;
use File::Basename ;
use FindBin ; ## Allows you to locate the directory of original perl script

## Specific Perl Modules (PFEM)
use lib $FindBin::Bin ;
my $binPath = $FindBin::Bin ;

## Dedicate Perl Modules (Home made...)
use Metabolomics::Fragment::Annotation qw( :all ) ;
use Metabolomics::Banks qw( :all ) ;
use Metabolomics::Banks::BloodExposome qw( :all ) ;
use Metabolomics::Utils qw( :all ) ;

## Initialized values
my $ProgramName = basename($0) ;
my $OptionHelp = undef ;
my $VERBOSE = undef ;

my ($inputFile, $mzCol, $asHeader, $ppmError, $mode ) = (undef, undef, undef, undef, undef, undef, undef ) ;
my ($outputTabular, $outputXls, $outputHTML, $outputFull) = (undef, undef, undef, undef) ;

my $QueryMode = undef ; # depending of the input data the query mode can be ION|NEUTRAL

#=============================================================================
#                                Manage EXCEPTIONS
#=============================================================================
&GetOptions ( 	"h|help"     => \$OptionHelp,       # HELP
				"v|verbose=i"	=> \$VERBOSE,		# Level of verbose (0 to 2)
				"i|input=s"		=> \$inputFile, 		# Input file containing a peak list (mz)
				"mzCol=i"		=> \$mzCol,				# Column in CSV file for MZ
				"header=i"		=> \$asHeader,				# CSV file as header (1=true, 0=false)
				"ppmError=f"	=> \$ppmError,				# ppm error
				"m|mode=s"		=> \$mode,				# indicate the ionisation mode (POS|NEG|NEUTRAL)
				"outputTab=s"		=> \$outputTabular,			# output file in tabular format
				"outputXls=s"		=> \$outputXls,			# output file in Xls format
				"outputHtml=s"		=> \$outputHTML,			# output file in html format
				"outputFull=s"		=> \$outputFull,			# output file in full format
				
            ) ;
         
## if you put the option -help or -h function help is started
if ( defined($OptionHelp) ){ &help ; }

#=============================================================================
#                                MAIN SCRIPT
#=============================================================================

if ($VERBOSE == 3) {
	print "The $ProgramName program is launched as:\n";
	print "./$ProgramName " ;
	print "--h "  if (defined $OptionHelp) ;
	print "--input $inputFile " if (defined $inputFile) ;
	print "--mzCol $mzCol " if (defined $mzCol) ;
	print "--header $asHeader " if (defined $asHeader) ;
	print "--ppmError $ppmError " if (defined $ppmError) ;
	print "--mode $mode " if (defined $mode) ;
#	print "--outputXls $outputXls " if (defined $outputXls) ;
	print "--outputTab $outputTabular " if (defined $outputTabular) ;
#	print "--outputHtml $outputHTML " if (defined $outputHTML) ;
	print "--outputFull $outputFull " if (defined $outputFull) ;
	print "with verbose $VERBOSE" ;
	print "\n" ;	
}

## Get conf
my ( $oCONF, $oTEMPLATE) = ( undef, undef ) ;
foreach my $conf ( <$binPath/*.cfg> ) { $oCONF = Metabolomics::Utils->utilsAsConf($conf) ; }

foreach my $template ( <$binPath/_template.tabular> ) { $oTEMPLATE = $template ; }

#print Dumper $oCONF ;


if ( ( defined $inputFile ) and ( $inputFile ne "" ) and ( -e $inputFile ) ) {
	
	# create a empty bank object
	my $oBank = Metabolomics::Banks::BloodExposome->new() ;
	
	# get contaminants bank
	my ($validedMode, $totalEntryNum) = (undef, 0, 0) ;
	
	$oBank->getMetabolitesFromSource() ;
	
	if ( ( defined $mode ) and  ( ( $mode eq 'POSITIVE' ) | ( $mode eq 'NEGATIVE' ) | ( $mode eq 'NEUTRAL' ) ) ) {
		$validedMode = $mode ;
	}
	else {
		croak "[ERROR] Your ionisation mode is not defined or is different to POSITIVE or NEGATIVE\n"
	}

	# build the query object
	$totalEntryNum = $oBank->buildTheoPeakBankFromEntries($validedMode) ;
	
	# get experimental masses
	if ( (defined $mzCol) and (defined $asHeader) ) {
		$oBank->parsingMsFragments($inputFile, $asHeader, $mzCol) ;
	}
	
	## Analysis :
	my $oAnalysis = Metabolomics::Fragment::Annotation->new($oBank) ;
	
#	print Dumper $oAnalysis ;

	# Compare peaklists:
	$oAnalysis->compareExpMzToTheoMzList('PPM', $ppmError) ;
	
#	print Dumper $oBank ;
	
	
	
	# complete initial input tabular file
	if ( (defined $outputFull) and (defined $inputFile) ) {
		my $tabularfile = $oAnalysis->writeFullTabularWithPeakBankObject($inputFile, $oTEMPLATE, $outputFull)
	}
	# write a simple tabular output
	if ( (defined $outputTabular) and (defined $inputFile) ) {
		my $tabularfile = $oAnalysis->writeTabularWithPeakBankObject($oTEMPLATE, $outputTabular) ;
	}
}
else {
	croak "Input file is not defined or is not exist.\n" ;
}





#====================================================================================
# Help subroutine called with -h option
# number of arguments : 0
# Argument(s)        :
# Return           : 1
#====================================================================================
sub help {


print STDERR <<EOF ;
### $ProgramName ###
#
# AUTHOR:     Franck Giacomoni
# VERSION:    1.0
# CREATED:    2019/08/21
# LAST MODIF: 
# PURPOSE: This program annotates any known or hypothetical metabolites (peak matching) from ms analysis with BloodExposome database 
# USAGE: $ProgramName or $ProgramName --input *.tabular --mzCol INT --header INT --ppmError 5 --mode POSITIVE|NEGATIVE|NEUTRAL --outputTab outTab.tabular --outputFull outFull.tabular --verbose 3 
EOF
exit(1) ;
}

## END of script - F Giacomoni 

__END__