Página 1 de 1

Pasar sencillo programa en Python a Perl

NotaPublicado: 2015-12-23 11:41 @528
por Hamtaro
Hola, gente. Estoy aprendiendo bioinformática con Perl.

Estoy haciendo un programa en Python pero mi profesor me lo pide en Perl y todavía no lo domino mucho. ¿Alguien me podría ayudar?

Aquí tenéis el código: https://gist.github.com/anonymous/5138c61c41fb985c7837
Sintáxis: [ Descargar ] [ Ocultar ]
Using python Syntax Highlighting
  1. sequence = 'TAAAGACTGCCGAGAGGCCAACACGAGTGCTAGAACGAGGGGCGTAAACGCGGGTCCGAT'
  2.  
  3. def skew(sequence):
  4.         c = 0
  5.         g = 0
  6.         min_skew = 0
  7.         skew_list = []
  8.         index = 0
  9.         for i in sequence:
  10.                 index += 1
  11.                 if i == 'C':
  12.                         c += 1
  13.                 if i == 'G':
  14.                         g += 1
  15.                 skew = g-c
  16.                 if skew < min_skew:
  17.                         skew_list = [index]
  18.                         min_skew = skew
  19.                 if skew == min_skew and index not in skew_list:
  20.                         skew_list.append(index)
  21.         print(skew_list)
  22.        
  23. #with open('data.txt', 'r') as in_file:
  24.         #sequence = in_file.readline() 
  25.         #skew(sequence)
  26. skew(sequence)
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4

Re: Pasar sencillo programa en Python a Perl

NotaPublicado: 2015-12-23 16:42 @738
por explorer
Bienvenido a los foros de Perl en Español, Hamtaro.

El problema es sencillo. Puedes hacer una traducción literal (o casi):
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/env perl
  2. use v5.22;
  3. use feature 'signatures';
  4. no warnings "experimental::signatures";
  5. no strict;
  6.  
  7. my $sequence = 'TAAAGACTGCCGAGAGGCCAACACGCCAGCTAGAACGAGGGGCGTAAACGCGGGTCCGAT';
  8.  
  9. sub skew($sequence) {
  10.     $c = 0;
  11.     $g = 0;
  12.     $min_skew = 0;
  13.     %skew_list;
  14.     $index = 0;
  15.     for $i (split //, $sequence) {
  16.         $index++;
  17.         $c++ if $i eq 'C';
  18.         $g++ if $i eq 'G';
  19.         $skew = $g - $c;
  20.         if ($skew < $min_skew) {
  21.             %skew_list = ( $index => 1 );
  22.             $min_skew = $skew;
  23.         }
  24.         if ($skew == $min_skew) {
  25.             $skew_list{$index} = 1;
  26.         }
  27.     }
  28.     say join ', ', sort {$a <=> $b} keys %skew_list;
  29. }
  30.  
  31. skew($sequence);
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4