Página 1 de 1

Interpretación de resultados múltiples

NotaPublicado: 2013-03-04 09:03 @419
por Alfumao
Hola a todos,

Necesito ayuda con la interpretación de unos resultados complejos.

Tengo encadenados los resultados de un programa y he de extraer solo dos datos de cada informe individual que se repite modularmente miles de veces (os pongo un ejemplo del formato):

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
########################################
# Program: predicter
# Rundate: Wed 27 Feb 2013 23:42:03
# Commandline: predicter
#    -sequence ../Genes/NM_001163474.txt
#    -minrepeat 5
#    -maxrepeat 100
#    -outfile NM_001163474.out
# Report_format: table
# Report_file: NM_001163474.out
########################################

#=======================================
#
# Sequence: NM_001146075.1     from: 1   to: 3585
# HitCount: 1
#
# Threshold: 20
# Minrepeat: 5
# Maxrepeat: 100
# Mismatch: No
# Uniform: No
#
#=======================================

  Start     End  Strand   Score   Size  Count Identity Consensus            
     22      87       +      20     22      3     81.8 gcggggctgagcgtgagtcact

#---------------------------------------
#---------------------------------------
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


De cada uno de estos módulos he de extraer los valores de los campos "Sequence:" y "HitCount:".

He hecho analizadores otras veces antes (gracias a lo aprendido en este foro, todo hay que decirlo), pero en éste me he atascado en los bucles y no consigo pasar los valores de los campos que busco a un array (que luego imprimiré si se cumple una condición).

Aquí os pongo el código (que se explicará mejor por sí mismo).

Seguro que es una tontería muy básica, pero yo llevo un rato laaaaargo con ello y ya no sé que más probar...

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. use strict;
  3. use Getopt::Long;
  4. use Spreadsheet::WriteExcel;
  5.  
  6. #usage: perl script.pl -i [infile] -h [cutoff value]
  7.  
  8. my ( $file, $cutoff );
  9. GetOptions(
  10.     'infile=s' => \$file,
  11.     'hits=i'   => \$cutoff,
  12. );
  13.  
  14. open( INFILE, "$file" ) or die("ERROR: $!\n");
  15. chomp( my @data = <INFILE> );
  16.  
  17. #print "Enter your cut-off e-value\n";
  18. #chomp(my $evalue = <STDIN>);
  19. open SALIDA, ">Parsed_results.txt" or die("ERROR: $!\n");
  20.  
  21. # Create a new workbook and add a worksheet
  22. my $tabla     = "$^T" . "Results_parsed";
  23. my $workbook  = Spreadsheet::WriteExcel->new( "$tabla" . ".xls" );
  24. my $worksheet = $workbook->add_worksheet();
  25. my $fila      = 1;
  26. my @header    = ( "Query Seq.", "hits", "evalue" );
  27. &ex_print( $worksheet, @header );
  28.  
  29. my @TM = ();
  30.  
  31. for (@data) {
  32.  
  33.     if ( /^\#\sProgram/ .. /^\#\sUniform/ ) {
  34.  
  35.         my ( $sequence, $hitcount );
  36.  
  37.         if (/^\#\sSequence\:\s(\w+)/)
  38.         {                              #->"sequence", la regex lo captura lo pasa al array, pero luego es reemplazado por $hitcount
  39.  
  40.             $sequence = $1;
  41.             print "Sequence: $sequence\n";
  42.             push @TM, $sequence;
  43.  
  44.             #print SALIDA "$sequence\t";
  45.  
  46.             if (/HitCount\:\s(\d+)/) { #->hitcount, la regex lo captura pero no lo pasa al array
  47.  
  48.                 $hitcount = $1;
  49.                 print "Hitcount: $hitcount\n";
  50.                 push @TM, $hitcount;
  51.  
  52.                 #print SALIDA "$hitcount\n";
  53.                 print "@TM\n";
  54.                 if ( $TM[1] >= $cutoff ) {
  55.                     push @TM, $sequence;
  56.                     push @TM, $hitcount;
  57.  
  58.                     #print SALIDA "$sequence\t$hitcount\n";
  59.                     #print "$sequence\t$hitcount\n";
  60.                     print SALIDA "@TM\n";    #####->No me escribe nada
  61.                     &ex_print( $worksheet, @TM );
  62.  
  63.                 }
  64.             }
  65.         }
  66.         @TM = ();                      #reinicialización
  67.     }
  68. }
  69.  
  70. close INFILE;
  71. close SALIDA;
  72.  
  73. ####################Subroutines####################
  74.  
  75. sub ex_print {
  76.  
  77.     my ( $worksheet, @TM ) = @_;
  78.  
  79.     $worksheet->write_row( "A" . "$fila", \@TM );
  80.     $fila++;
  81.  
  82. }
  83.  
Coloreado en 0.004 segundos, usando GeSHi 1.0.8.4


Muchas gracias por adelantado ;)

Re: Interpretación de resultados múltiples

NotaPublicado: 2013-03-04 11:45 @531
por Alfumao
Lo he conseguido resolver, aquí va el código ;)

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. use strict;
  3. use Getopt::Long;
  4. use Spreadsheet::WriteExcel;
  5.  
  6. #usage: perl script.pl -i [infile] -h [cutoff value]
  7.  
  8. my ( $file, $cutoff );
  9. GetOptions(
  10.     'infile=s' => \$file,
  11.     'hits=i'   => \$cutoff,
  12. );
  13.  
  14. open( INFILE, "$file" ) or die("ERROR: $!\n");
  15. chomp( my @data = <INFILE> );
  16. open SALIDA, ">Parsed_results.txt" or die("ERROR: $!\n");
  17.  
  18. # Create a new workbook and add a worksheet
  19. my $tabla     = "$^T" . "Results_parsed";
  20. my $workbook  = Spreadsheet::WriteExcel->new( "$tabla" . ".xls" );
  21. my $worksheet = $workbook->add_worksheet();
  22. my $fila      = 1;
  23. my @header    = ( "Query Seq.", "etandem hits", "evalue" );
  24. &ex_print( $worksheet, @header );
  25.  
  26. my @TM = ();
  27. my $sequence;
  28. my $hitcount;
  29.  
  30. for (@data) {
  31.  
  32.     if ( /^\#\sProgram/ .. /^\#\sUniform/ ) {
  33.  
  34.         if (/^\#\sSequence\:\s(\w+)/) {
  35.             $sequence = $1;
  36.             print "Sequence: $sequence\n";
  37.  
  38.         }
  39.         if (/HitCount\:\s(\d+)/) {
  40.             $hitcount = $1;
  41.             print "Hitcount: $hitcount\n";
  42.  
  43.             if ( $hitcount >= $cutoff ) {
  44.                 push @TM, $sequence;
  45.                 push @TM, $hitcount;
  46.                 print "@TM\n";
  47.                 print SALIDA "@TM\n";
  48.                 &ex_print( $worksheet, @TM );
  49.             }
  50.         }
  51.  
  52.         @TM = ();                      #reinicializacion
  53.     }
  54. }
  55.  
  56. close INFILE;
  57. close SALIDA;
  58.  
  59. ####################Subroutines####################
  60.  
  61. sub ex_print {
  62.  
  63.     my ( $worksheet, @TM ) = @_;
  64.  
  65.     $worksheet->write_row( "A" . "$fila", \@TM );
  66.     $fila++;
  67. }
  68.  
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

Re: Interpretación de resultados múltiples

NotaPublicado: 2013-03-04 14:40 @653
por explorer
Un poco más abreviado:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use autodie;
  5. use feature 'say';
  6.  
  7. use Getopt::Long;
  8. use Spreadsheet::WriteExcel;
  9.  
  10. # usage: perl script.pl -i [infile] -h [cutoff value]
  11.  
  12. my($file, $cutoff);
  13.  
  14. GetOptions(
  15.     'infile=s' => \$file,
  16.     'hits=i'   => \$cutoff,
  17. );
  18.  
  19. # Create a new workbook and add a worksheet
  20. my $tabla     = $^T . '_Results_parsed.xls';
  21. my $workbook  = Spreadsheet::WriteExcel->new($tabla);
  22. my $worksheet = $workbook->add_worksheet();
  23. my $fila      = 1;
  24. my @header    = ( 'Query Seq.', 'etandem hits', 'evalue' );
  25.  
  26. excel_print($worksheet, @header);
  27.  
  28.  
  29. # Process
  30. my($sequence, $hitcount);
  31.  
  32. open my $INFILE, $file;
  33. open my $SALIDA, '>Parsed_results.txt';
  34.  
  35. while (<$INFILE>) {
  36.  
  37.     if (/^#\sSequence:\s(\w+)/) {
  38.         $sequence = $1;
  39. #       say "Sequence: $sequence";
  40.     }
  41.  
  42.     if (/^#\sHitCount:\s(\d+)/) {
  43.         $hitcount = $1;
  44. #       say "Hitcount: $hitcount";
  45.  
  46.         if ( $hitcount >= $cutoff ) {
  47. #           say         "$sequence $hitcount";
  48.             say $SALIDA "$sequence $hitcount";
  49.            
  50.             excel_print($worksheet, $sequence, $hitcount);
  51.         }
  52.     }
  53. }
  54.  
  55. close $INFILE;
  56. close $SALIDA;
  57.  
  58. #################### Subroutines ####################
  59.  
  60. sub excel_print {
  61.     my ($worksheet, @TM) = @_;
  62.  
  63.     $worksheet->write_row( "A$fila", \@TM );
  64.  
  65.     $fila++;
  66. }
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

Re: Interpretación de resultados múltiples

NotaPublicado: 2013-03-05 06:30 @312
por Alfumao
Gracias una vez más, explorer :wink: