Hi all, I got an error message when running the code at the end of this post. It said that "Use of uninitialized value in join or string at make_file2.pl line 51."
Although I doubt the error message, I would appreciate if you can find something I really missed.
Thank you!
Alex
#!/usr/bin/perl
use strict;
use warnings;
my @fullset =
qw(GTAC CGAG GTAA CGAA AAAT CGAC AGTG AGTA AGTC AAAA CGAT AAAC GTAT GGTT AGTT AACA GTAG GAAT TTAG ATAT TTAC TTAA GAAC GAAA GAAG GAGA TTAT ACTT GCTC GGAC GCTA ATAA ATAC CCAT ATAG GCTT CCAA ATTT CCAC GTGG TTGC CCAG TAAC TAAG GTCT TAAA TGTC TGTA TCTT TGTG TAAT ACAT TCTG CTCA CTCC TCTC TATG TCTA TGTT AAGG GCCG CGGA AAGC ACGT AAGA CTAA GTGA GTGC GGCT ACGA ACGC AAGT ACGG CGGT GGCC GGCA GGCG TTCT AGGG AGGA AGGC AATC GATT AAAG CCCT GACT ATCA AGGT TTCG CTGG TTCA TTCC CACT GACA GACC GATG GATA GACG AATG TAGT AGAC ATCT GCCC GCCA CCGG TACT TCAG CCGC CAGT CCTT CACG ATCG TAGG TAGA TATT CAGA CCTC CAGC CCGT CCTG CAGG TGGG ACTC TGGC TGGA TCGC TCGA TCGG TGGT GCCT CCCG ACTG GATC TCGT ATCC ACAG CGGC ACAC ATGT ACAA CTAG CTTC TAGC GTCG TCAC CGGG CTAC GGAA AGAA CCTA AGAG GGAG ATTG CTCT ATTC GGAT ATTA AGAT TACG CTTG TGCG TGAT TTTA TTTC TTTG CAAG AACG GCAG GCAA CAAA TGAG TTTT TGAA TGAC GCAT CAAT CTGT GGGG TCAT AATT CGTT CTCG TATA CTAT TATC TCAA AATA CTGA CTGC CGTG CGTC CGTA GTTA GTTC GGGT GTCA GTTG GTCC AACC ACCG ACCA ACCC ACTA GGGC GTTT GGGA CTTT ACCT AACT GAGT GGTA GGTG AGCA GTGT AGCC TTGT AGCG GAGG CCGA GAGC TTGA CTTA AGCT TTGG ATGC ATGA ATGG TGCT GGTC GCGC CAAC GCGA GCGG CCCC TGCC CCCA TGCA CACA GCAC CACC TACA TACC GCGT CATA CATC CATG TCCT CGCT CATT GCTG CGCG TCCG CGCC TCCC CGCA TCCA);
my (@major, @minor,$y, @combinations);
my ($prob, $records) = (55, 100); # Probably of major pair, #num records to generate
# This is a basic ceiling function for $num_major
for ($y=0; $y<=99; $y++) {
my $num_major = ($prob / 100) * $records;
if ($num_major != int($num_major)) { $num_major = int($num_major++); }
my $num_minor = $records - $num_major;
{ my @temp = @fullset;
foreach (0..1) {
my $r_pair = splice(@temp, int(rand($#temp+1)), 1);
$major[$_] = $r_pair;
}}
foreach my $pos (0..$#major) {
my @list;
foreach (1..$num_major) { push(@list, $major[$pos]); }
my $pair = $major[$pos]; # because array indices don't #work in
# a pattern match.
my @minor_list = grep { not /[$pair]/ } @fullset;
foreach (1..$num_minor) {
push(@list,$minor_list[int(rand($#minor_list+1))]);
}
foreach (0..$records-1) {
$combinations[$_][$pos] = splice(@list, int(rand($#list+1)),
}
}
open OUTPUT, "> outfile9_55_$y.txt" or die "Cannot open output file.\n";
foreach (@combinations) {
print OUTPUT join('', @{$_}), "\n";
}
close OUTPUT;
replace();
}
exit();
sub replace {
my (@short, @long,$x,$r,$output_norm);
open (SHORT, "< outfile9_55_$y.txt");
chomp (@short = <SHORT>);
close SHORT;
open (LONG, "< long_sequences.txt");
chomp (@long = <LONG>);
close LONG;
open (OUT_HTML, "> output9_55_$y.html");
print OUT_HTML "<pre>";
open (OUT_NORM, "> output9_55_$y.txt");
for ($x=0; $x<=$#short; $x++) {
$r=2;
$output_norm = substr($long[$x], $r, length $short[$x]);
substr($long[$x], $r, length $short[$x]) = "<font color=red><b>$short[$x]</b></font>";
print OUT_HTML "$long[$x]\n";
$long[$x] =~ s/<[^>]+>//g;
print OUT_NORM ">SeqName$x\n$long[$x]\n";
}
print OUT_NORM ">SeqName$x\n$long[$x]\n";
}
close OUT_HTML;
close OUT_NORM;
}
Although I doubt the error message, I would appreciate if you can find something I really missed.
Thank you!
Alex
#!/usr/bin/perl
use strict;
use warnings;
my @fullset =
qw(GTAC CGAG GTAA CGAA AAAT CGAC AGTG AGTA AGTC AAAA CGAT AAAC GTAT GGTT AGTT AACA GTAG GAAT TTAG ATAT TTAC TTAA GAAC GAAA GAAG GAGA TTAT ACTT GCTC GGAC GCTA ATAA ATAC CCAT ATAG GCTT CCAA ATTT CCAC GTGG TTGC CCAG TAAC TAAG GTCT TAAA TGTC TGTA TCTT TGTG TAAT ACAT TCTG CTCA CTCC TCTC TATG TCTA TGTT AAGG GCCG CGGA AAGC ACGT AAGA CTAA GTGA GTGC GGCT ACGA ACGC AAGT ACGG CGGT GGCC GGCA GGCG TTCT AGGG AGGA AGGC AATC GATT AAAG CCCT GACT ATCA AGGT TTCG CTGG TTCA TTCC CACT GACA GACC GATG GATA GACG AATG TAGT AGAC ATCT GCCC GCCA CCGG TACT TCAG CCGC CAGT CCTT CACG ATCG TAGG TAGA TATT CAGA CCTC CAGC CCGT CCTG CAGG TGGG ACTC TGGC TGGA TCGC TCGA TCGG TGGT GCCT CCCG ACTG GATC TCGT ATCC ACAG CGGC ACAC ATGT ACAA CTAG CTTC TAGC GTCG TCAC CGGG CTAC GGAA AGAA CCTA AGAG GGAG ATTG CTCT ATTC GGAT ATTA AGAT TACG CTTG TGCG TGAT TTTA TTTC TTTG CAAG AACG GCAG GCAA CAAA TGAG TTTT TGAA TGAC GCAT CAAT CTGT GGGG TCAT AATT CGTT CTCG TATA CTAT TATC TCAA AATA CTGA CTGC CGTG CGTC CGTA GTTA GTTC GGGT GTCA GTTG GTCC AACC ACCG ACCA ACCC ACTA GGGC GTTT GGGA CTTT ACCT AACT GAGT GGTA GGTG AGCA GTGT AGCC TTGT AGCG GAGG CCGA GAGC TTGA CTTA AGCT TTGG ATGC ATGA ATGG TGCT GGTC GCGC CAAC GCGA GCGG CCCC TGCC CCCA TGCA CACA GCAC CACC TACA TACC GCGT CATA CATC CATG TCCT CGCT CATT GCTG CGCG TCCG CGCC TCCC CGCA TCCA);
my (@major, @minor,$y, @combinations);
my ($prob, $records) = (55, 100); # Probably of major pair, #num records to generate
# This is a basic ceiling function for $num_major
for ($y=0; $y<=99; $y++) {
my $num_major = ($prob / 100) * $records;
if ($num_major != int($num_major)) { $num_major = int($num_major++); }
my $num_minor = $records - $num_major;
{ my @temp = @fullset;
foreach (0..1) {
my $r_pair = splice(@temp, int(rand($#temp+1)), 1);
$major[$_] = $r_pair;
}}
foreach my $pos (0..$#major) {
my @list;
foreach (1..$num_major) { push(@list, $major[$pos]); }
my $pair = $major[$pos]; # because array indices don't #work in
# a pattern match.
my @minor_list = grep { not /[$pair]/ } @fullset;
foreach (1..$num_minor) {
push(@list,$minor_list[int(rand($#minor_list+1))]);
}
foreach (0..$records-1) {
$combinations[$_][$pos] = splice(@list, int(rand($#list+1)),
}
}
open OUTPUT, "> outfile9_55_$y.txt" or die "Cannot open output file.\n";
foreach (@combinations) {
print OUTPUT join('', @{$_}), "\n";
}
close OUTPUT;
replace();
}
exit();
sub replace {
my (@short, @long,$x,$r,$output_norm);
open (SHORT, "< outfile9_55_$y.txt");
chomp (@short = <SHORT>);
close SHORT;
open (LONG, "< long_sequences.txt");
chomp (@long = <LONG>);
close LONG;
open (OUT_HTML, "> output9_55_$y.html");
print OUT_HTML "<pre>";
open (OUT_NORM, "> output9_55_$y.txt");
for ($x=0; $x<=$#short; $x++) {
$r=2;
$output_norm = substr($long[$x], $r, length $short[$x]);
substr($long[$x], $r, length $short[$x]) = "<font color=red><b>$short[$x]</b></font>";
print OUT_HTML "$long[$x]\n";
$long[$x] =~ s/<[^>]+>//g;
print OUT_NORM ">SeqName$x\n$long[$x]\n";
}
print OUT_NORM ">SeqName$x\n$long[$x]\n";
}
close OUT_HTML;
close OUT_NORM;
}