#!/usr/bin/perl use strict; use subs; use Data::Dumper; require XML::Simple; my %args = getParams(); my $probe_file = new XML::Simple(); my $db_file = new XML::Simple(); my $all_probes = $probe_file->XMLin($args{probefile}, keyattr => {}); my $db_probes = $db_file->XMLin($args{dbfile}, keyattr => {}); open (OUTFILE, ">".$args{outfile}); writeXMLheader( *OUTFILE ); for (my $i=0; $i<@{$all_probes->{probe}}; $i++) { my $probe1 = $all_probes->{probe}->[$i]->{species}->[0]->{sequence}; print "Validate Generic Probe [$probe1]\n" if ($args{verbose}); for(my $j=0; $j<@{$db_probes->{parent_alignment}}; $j++) { my $probe2 = $db_probes->{parent_alignment}->[$j]->{probe}->{sequence}; print " ... [$probe2]\n" if ($args{verbose}); if ( $probe1 eq $probe2 ) { print "Matching DB probe found, write generic probe to file\n\n" if ($args{verbose}); writeProbe (*OUTFILE, $all_probes->{probe}->[$i]); last; } } } writeXMLfooter( *OUTFILE ); sub writeProbe { local *OUTFILE = shift; my $probe = shift; printf OUTFILE " \n"; printf OUTFILE " \n", $probe->{time}; printf OUTFILE " %s\n",$probe->{date}; printf OUTFILE " \n"; printf OUTFILE " %d\n",$probe->{length}; printf OUTFILE " %d\n",$probe->{alignment_identity}; printf OUTFILE " %d\n",$probe->{probe_identity}; printf OUTFILE " %d\n", $probe->{transversions}; printf OUTFILE " %d\n",$probe->{transitions}; printf OUTFILE " %d\n", $probe->{gaps}; printf OUTFILE " %s\n", $probe->{probe_alignment}; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " %d\n",$probe->{species}->[0]->{alignment_start}; printf OUTFILE " %d\n",$probe->{species}->[0]->{alignment_end}; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " %d\n", $probe->{species}->[0]->{probe_start}; printf OUTFILE " %d\n", $probe->{species}->[0]->{probe_end}; printf OUTFILE " %s\n", $probe->{species}->[0]->{sequence}; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " %d\n",$probe->{species}->[1]->{alignment_start}; printf OUTFILE " %d\n", $probe->{species}->[1]->{alignment_end}; printf OUTFILE " \n"; printf OUTFILE " \n"; printf OUTFILE " %d\n",$probe->{species}->[1]->{probe_start}; printf OUTFILE " %d\n",$probe->{species}->[1]->{probe_end}; printf OUTFILE " %s\n", $probe->{species}->[1]->{sequence}; printf OUTFILE " \n"; printf OUTFILE " \n\n\n"; } sub writeXMLheader { local *OUTFILE = shift; print OUTFILE "\n"; print OUTFILE "\n\n"; } sub writeXMLfooter { local *OUTFILE = shift; print OUTFILE "\n\n\n"; } ################################################# # getParams - This gets command line parameters ################################################# sub getParams { my %opts; my $errstr = ""; use Getopt::Long; GetOptions(\%opts, 'dbfile=s', 'probefile=s', 'verbose', 'outfile=s', 'help'); if (defined($opts{help})) { $errstr = "\n"; } else { if (!defined($opts{dbfile})) { $errstr .= "ERROR : File containing database probes not set\n"; } elsif ( ! -f $opts{dbfile} ) { $errstr .= "ERROR : Database file doesn't exist\n"; } if (!defined($opts{probefile})) { $errstr .= "ERROR : Probe File not set\n"; } elsif ( ! -f $opts{probefile} ) { $errstr .= "ERROR : Probe file doesn't exist\n"; } } if ($errstr) { print <<"END_USAGE"; Description: This script will take a database generated file (dbfile in xml v1 format) and a probe file (xml v2 format) and will create a xml file that contains only the probes from the database. The xml file will be in v2 format, and will contain all the information from the probe file. Usage: select_db_probes.pl -dbfile -probefile [-outfile ] [-help] [-verbose] Probe Sources: -dbfile Name of file that contains the probes that were generated from the DB (xml v1 format) -probefile Name of file that contains all probes (xml v2 format) -outfile Name of the output file, data will be in xml v1 format (default name : select_db_probes.xml) -help Display help for command -verbose Display all debug messages during execution. END_USAGE print "\n$errstr" if ($errstr); die("\n"); } return (dbfile => $opts{dbfile}, probefile => $opts{probefile}, outfile => $opts{outfile} || "select_db_probes.xml", verbose => $opts{verbose} || 0) }