Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.47 KB | None | 0 0
  1. #Miguel Román Sánchez
  2. #IMPORTANTE: ESTE PROGRAMA TOMA DATOS DE LA MATRIZ @ARGV, SUS ARGUMENTOS SON:
  3. #   NOMBRE_DE_FICHERO LONGITUD_DE_VENTANA PASO_DE_VENTANA
  4.  
  5. open (INPUT, $ARGV[0]);
  6.     @input = <INPUT>;   #recogida de datos del fichero
  7.     chomp (@input);
  8. close INPUT;
  9.  
  10. #---------------------------------------------------------------------------------------------------------|
  11.     #FRAGMENTO NECESARIO PARA ARCHIVOS CON SECUENCIAS PARTIDAS EN LÍNEAS
  12. for (my $i = 0; $i < @input; $i++) {
  13.    
  14.     if ($input[$i] =~ /^>/) {   #Si encontramos una cabecera:
  15.         if (defined($line)) {       #Si además teníamos previamente una secuencia:
  16.             push (@format, $line);      #Guardamos la secuencia
  17.             undef $line;                #Reiniciamos la variable temporal que recoge la secuencia
  18.         }
  19.         push (@format, $input[$i]);
  20.  
  21.     }else{
  22.         $line .= $input[$i];   
  23.     }
  24. }
  25. push (@format, $line);
  26. #---------------------------------------------------------------------------------------------------------|
  27.  
  28.  
  29. #-------------------------------------------------------------|
  30.     #ESTE BLOQUE SELECCIONA LA ID Y SECUENCIA CON MAYOR %GC
  31. for (my $i = 1; $i < @format; $i+=2) {
  32.     if (gcratio($format[$i]) >= gcratio($winnerSeq)) {
  33.             $winnerSeq = $format[$i];
  34.             $winnerID = $format[$i-1];
  35.             $winnerID =~ s/>//;
  36.         }
  37. }
  38. #-------------------------------------------------------------|
  39. print $winnerID."\n";   # Ahora winnerID tiene la ID de la secuencia con mayor %GC
  40. print ((gcratio($winnerSeq)*100)."\n"."\n");
  41.  
  42.  
  43. #-----------------------------------------------------------------------------------------------------------------------------|
  44.     #ESTE BLOQUE MUESTRA LOS PORCENTAJES TRAS PASAR VENTANAS
  45. if (defined($ARGV[1])) {
  46.     $windowL = $ARGV[1];
  47.     }else{
  48.     $windowL = 100;
  49. } #Definición de la longitud de la ventana (default = 100)
  50.  
  51. if (defined($ARGV[2])) {
  52.     $offset = $ARGV[2];
  53.     }else{
  54.     $offset = 100;
  55. } #Definición del paso de las ventanas (default = 100)
  56.  
  57. $LNG = length($winnerSeq);
  58. for (my $i = 0; $i < $LNG-$windowL; $i+=$offset) {
  59.     print(gcratio(substr($winnerSeq, $i, $windowL))."\n"); #imprime los porcentajes de GC que va encontrando en cada ventana.
  60. }
  61. #-----------------------------------------------------------------------------------------------------------------------------|
  62.  
  63. #DEFINICIÓN DE LA FUNCIÓN QUE DEVUELVE EL %GC DE UNA STRING
  64. sub gcratio () {
  65.     my ($seq) = @_;
  66.     my $gcCounter;
  67.     $gcCounter = () = $seq =~ /[CG]/gi;
  68.  
  69.     if (length($seq) != 0) {
  70.         return ($gcCounter/length($seq));
  71.     }else{
  72.         return 0;
  73.     }  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement