view bih4maconda.pl @ 1:2744d20c830a draft default tip

" master branch Updating with tag :CI_COMMIT_TAG - - Fxx"
author fgiacomoni
date Fri, 27 Nov 2020 11:21:58 +0000
parents de13e2c45971
children
line wrap: on
line source

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

=head1 NAME

bih4maconda.pl - Utility to detect potential contaminants in your peak list based on MaConDa database

=head1 USAGE


=head1 SYNOPSIS

=head1 DESCRIPTION

=over 4

=item B<function01>

=item B<function02>

=back

=head1 AUTHOR

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

=head1 SUPPORT

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

 perldoc bih4maconda.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 1 : 2019/07/24

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::MaConDa 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, $instruments, $instrumentTypes) = (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)
				"filterInstrument=s"	=> \$instruments,	# instruments listing to apply filter
				"filterInstrumentType=s"	=> \$instrumentTypes,	# instrumentTypes listing to apply filter
				"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 "--filterInstrument $instruments " if (defined $instruments) ;
	print "--filterInstrumentType $instrumentTypes " if (defined $instrumentTypes) ;
#	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::MaConDa->new() ;
	
	# get contaminants bank
	my ($oFilteredContaminants, $totalEntryNum, $fiteredEntryNum) = (undef, 0, 0) ;
	
	$oBank->getContaminantsExtensiveFromSource() ;
	
	# Applying filters
	
	## Instrument #Filter01 (ALL|...)
	if ( defined $instruments ) {
		my @instruments = split(/,/, $instruments) ;
		($oFilteredContaminants, $totalEntryNum, $fiteredEntryNum) = $oBank->filterContaminantInstruments(\@instruments) ;
		print "Only few instruments were selected: $fiteredEntryNum/$totalEntryNum entries were filtered.\n" ;
	}
	## Instrument type #Filter02 (ALL|...)
	if ( defined $instrumentTypes ) {
		
		my @instrumentTypes = split(/,/, $instrumentTypes) ;
		if (!defined $oFilteredContaminants){	($oFilteredContaminants, $totalEntryNum, $fiteredEntryNum) = $oBank->filterContaminantInstrumentTypes(\@instrumentTypes) ; 		}
		else 								{	($oFilteredContaminants, $totalEntryNum, $fiteredEntryNum) = $oFilteredContaminants->filterContaminantInstrumentTypes(\@instrumentTypes) ; }
		
		print "Only few instrument types were selected: $fiteredEntryNum/$totalEntryNum entries were filtered.\n" ;
	}
	## Ion mode #Filter03 (POS|NEG|BOTH)
	if ( defined $mode) {
		
		print "Mode selected is $mode..." ;
		
		if (!defined $oFilteredContaminants){	$oFilteredContaminants = $oBank->filterContaminantIonMode($mode) ; 	}
		else 								{	$oFilteredContaminants = $oFilteredContaminants->filterContaminantIonMode($mode) ; }
		
		if ( ($mode eq 'POSITIVE') or ($mode eq 'NEGATIVE') or ($mode eq 'BOTH') ) {
			$QueryMode = 'ION' ;
		}
		elsif ($mode eq 'NEUTRAL') {
			$QueryMode = 'NEUTRAL' ;
		}
		else {
			croak "[ERROR] mode $mode is not recognize...Please defined a acceptable one\n" ;
		}
		print "and detected query mode is $QueryMode...\n" ;
	}
	# in case no filter is defined beforr
	if ( ( !defined $mode) and ( !defined $instruments) and ( !defined $instrumentTypes)  ) {
		$oFilteredContaminants = $oBank ;
	}

	# build the query object
	$oFilteredContaminants->buildTheoPeakBankFromContaminants($QueryMode) ;
	
	# get experimental masses
	if ( (defined $mzCol) and (defined $asHeader) ) {
		$oFilteredContaminants->parsingMsFragments($inputFile, $asHeader, $mzCol) ;
	}
	
	## Analysis :
	my $oAnalysis = Metabolomics::Fragment::Annotation->new($oFilteredContaminants) ;
	
	
	# 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 contaminants from ms analysis depending some filters as instruments, ionisation mode from MaConDa 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__