• Publicidad

Últimas dudas

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Últimas dudas

Notapor Ponciano » 2009-04-06 08:36 @400

Hola a todos.

Antes quiero agradecerles la ayuda, pues he ido concluyendo mi primer script que lee archivos de alineamientos (.pir), les hace algo a las secuencias y luego las imprime nuevamente.

La duda ahora es la siguiente:
Mi script me arroja algo así como:
Código: Seleccionar todo
aaaadigupaaaaapdduthhhhhhqrt98yyyyyyyyyyyyyyyyy9puhoqhghggaoihggggggggggggggggggqo
ioquuuyhhhhhhhhuirphgfjvnaaapi9uig (aquí termina la secuencia)
nbugqiprrryhpuiiiiiiiiiiiiiiiiiinfaddddjhgggggggggagoqhrihgoqhrrrrrhqioogqnrogqhjhgajkdddddyhgfuirrius
ndpppppppppppppppppppppqhg4gir (aquí termina la secuencia)
jniophgirhqqhhgklngaingauinroggggghqerrrrrrrrrrrrrrrrrrrrrrrhguoqkjagbsduuuuhgggggggggggggggg
nnioqhreeeeeeeqqqqqqqqqqiheqqio (aquí termina la secuencia)
.
.
.
.
etc.


Necesito darle formato fasta a esta cadenas y que quede más o menos así,

Código: Seleccionar todo
añhdjhaohhhhhabpphañuoahsqrrrgggqqqqqqtggfa
nalhhhhhhhhhhhhhhhhiohgdaiqaahrrqehqehhhhdf
akjhauhuidhsqiuhhughuuuiiihqafdhqe4yttqfhhwhfd
akjhgaupppqha (aquí termina la primera secuencia; líneas de no más de 40 elementos)
kjqhguiiiiihrrrjgnbudfhggfkañjhhhhu9hp8rjkkhquhg
gnqrehhhguqhkjjjjbvuiihauhgfffqjanbgjjnnbuafihgfa
nnbauiheenrgo9brhbnfffffffuahhuhgjlfkjgoijfjnbvfub
jkabfigggggaba (aquí termina la segunda secuencia; líneas de no más de 40 elementos)
.
.
.
etc.


El script es el siguiente y, como he indicado anteriormente, me interesa modificar la última parte para que se vea en la pantalla algo así como les he comentado.
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
#!/usr/bin/perl
if (@ARGV<1){die "Usar pir8.pl y fichero.pir\n";};
open (PIR,$ARGV[0]) || die "Error, no puede leerse el archivo: '$ARGV[0]'\n";

use strict;
use warnings;

my @nombres;
my $head;
my $fichero;

while (<PIR>) {
    if(/^>/) {
        $head=substr($_,1);
        {
            push (@nombres,$_);
        }
    }
    chomp $_;
    $fichero.=$_;
}
close PIR;

#print $nombres[0];
#print "$fichero\n";

my @seqs;
my $sec;

while ($fichero=~ m/ \.FASTAC (.*?)\*/simogx) {
    $sec= $1;
    my @residues = split("",$sec);
    push(@seqs,\@residues);
}

for(my $j=0; $j<scalar(@seqs); $j++) {
    for(my $i=0; $i<scalar@{$seqs[$j]};$i++) {      
             if(${$seqs[0]}[$i] ne "-") {
                 if(($i%$longitud)=0)
                 print ${$seqs[$j]}[$i];  
             }                                          
     }
     print"\n";
}
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4

Adicionalmente, he guardado los head de cada secuencia en el array nombres y deseo ponerle, en la salida su head a cada secuencia nuevamente.

Otra vez, cualquier ayuda será importante.
Ponciano
Perlero nuevo
Perlero nuevo
 
Mensajes: 13
Registrado: 2009-03-31 10:08 @463

Publicidad

Notapor explorer » 2009-04-06 10:22 @474

La variable $head no la estás usando en ningún sitio...
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Variable $head

Notapor Ponciano » 2009-04-06 10:51 @494

Tienes razón, la he declarado sin ningún uso real.

También la línea 47, me parece, donde se lee if(($i%$longitud)=0), tampoco tiene un uso en el script. Ésta era un intento por empezar a darle formato al texto de salida.
Ponciano
Perlero nuevo
Perlero nuevo
 
Mensajes: 13
Registrado: 2009-03-31 10:08 @463

Notapor explorer » 2009-04-06 18:17 @803

Yo creo que lo complicas un poco.

Yo lo que haría sería meter toda la secuencia en un escalar, y luego presentarlo en recortes de 40 caracteres.

Algo así (no probado):
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
for (my $i=0, $i<length $secuencia; $i+=40) {
    print substr($secuencia, $i, 40), "\n";
}
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 48 invitados

cron