Thread Hilfe zu Mustererkennung + if (27 answers)
Opened by Anonymus at 2013-06-13 11:02

topeg
 2013-06-14 17:42
#168270 #168270
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Hast du den Zweischenschritt mit "#" aus einem bestimmten Grund gemacht?
Code (perl): (dl )
1
2
3
4
my $big_dna = 'TGAACCCGGGATTTGAGATTCCGGGGTTAAAAACGATTGAACCCGGGATTTGAGATTCCGGGGTTAAAAA';
my $cutter = 'GATT';

my @cutted_parts = split /\Q$cutter\E/,$big_dna;


Oder wenn es schnell sein soll mit index/substr:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use warnings;

my $big_dna = 'TGAACCCGGGATTTGAGATTCCGGGGTTAAAAACGATTGAACCCGGGATTTGAGATTCCGGGGTTAAAAA';
my $cutter = 'GATT';

my @cutted_parts;
my $cutter_length=length($cutter);
my $pos=0;
while( (my $p=index($big_dna,$cutter,$pos)) > -1 )
{
  push(@cutted_parts, substr($big_dna,$pos,$p-$pos) );
  $pos=$p+$cutter_length;
}
push(@cutted_parts,substr($big_dna,$pos)) if($pos<length($big_dna));

print "$_\n" for(@cutted_parts);



EDIT:
Ist mir doch glatt noch eine "perlige" Variante eingefallen:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use warnings;

my $big_dna = 'TGAACCCGGGATTTGAGATTCCGGGGTTAAAAACGATTGAACCCGGGATTTGAGATTCCGGGGTTAAAAA';
my $cutter = 'GATT';

my @cutted_parts;

{
  open(my $vh, '<', \$big_dna);
  local $/=$cutter;
  @cutted_parts=<$vh>;
  chomp(@cutted_parts);
  close($vh);
}

print "$_\n" for(@cutted_parts);

Hier benutze ich ein virtuelles Filehandle zum Zerlegen. Das sollte sehr schnell sein.
Last edited: 2013-06-14 17:51:18 +0200 (CEST)

View full thread Hilfe zu Mustererkennung + if