Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/usr/bin/perl -w
use strict;
my $ratio = 7; # Percentage error to apply
my $swapped_total = 0;
my $characters_seen = 0;
my $charset = "ACGT";
while(<DATA>) {
chomp;
# The line below calculates the number of characters to swap in this line
my $this_line_todo = int(($characters_seen + length($_)) * $ratio / 100)
- $swapped_total;
# Now we need to find the positions of the characters to change
my %indexes = (); # Place to store indexes
$indexes{int(rand(length))}++
while(scalar(keys %indexes) < $this_line_todo *2);
foreach my $index (keys %indexes) {
my $char = substr($_,$index,1);
my $newchar;
do {
$newchar = substr($charset, rand(4), 1);
} while ($char eq $newchar);
substr($_,$index,1) = lc $newchar;
}
$characters_seen += length;
$swapped_total += $this_line_todo;
print $_,"\n";
}
print "Total characters seen is $characters_seen\n";
print "Total characters swapped is $swapped_total\n";
__DATA__
GAATATCCCCATGATCTTTCCCTCAATCGCCCGCTGATAAGTGGGAAGACATCG
GTCGCGCCACACTCGATACCCTGCTCATGGTGGCGCTTGGTCTTCCCTTGGGAAT
GAATATCCCCATGATCTTCCCCTCAATCGACCTGGACGCTGATAAGTGGAAAGACATCG
GTCGCGCCACACTCGATACCCTGCTCACCCGCATTGGCGCTTGGTCTTCCCTTGGGAAT
GAATATCCCCATGATCTTCCCCTCAAACCTGGACGTTGATAAGTGGAAAGACATCG
GAATATCCCCATGATCTTTCCCTCAATCGACGCTGATAAGTGGGAAGACAT
GTCGCGCCACACTCGATACCCTGCTCGGCGCTTGGTCTTCCCTTGGGAATC
GGTTGGCGGTGCCGCCCTCGTGCAACCAATCAAGTTTGGTGGCGATGTTG
CACCAACGCTTAGTGTCACCTACTACATCACTAAAAAGTTGAGTTAT
GGTTGGCGGCGCCGCCCTCGTGCAACCAACAAGTTTGGTGGCGATGTTG
CACCAACGCTAAGTGTAACCTACTACATCAAGGGGCATTACTAAAAAGTT
AAAATGCAGCACAGAATACTGTCAAGTTTGGTGGCGATGTTG
GGTTGGCGGCGCTGCCCTCGTGCAACCAAAGAAAAGTTTGGTGGCGATGTTG
CACCAACGCTTAGTGTCACCTACTACATCAACGGGTATTACTAAAAAGTTGAG
AATGACCGAAATCAAGGAAGCTTTTGTCCCCCCCAGTGATTGAAGTGCTAGTCG
TTGGCGATACCGTCTCCAAGGGCCAAAGTTTCAACCATGGAAGTACCTTCGTCA
AATGACCGAAATCAAGGAAGCTTTTGTCCCCCCCAGTGATTGAAGTGCTAG
TTGGCGATACCGTCTCCAAGGGCCAAACAACCATGGAAGTACCCTCGTCA
AATGACCGAAATCAAGGAAGCTTTTGTCGTCCCAGTGATTGAAGTGCTAGTC
TTGGCGATACCGTCTCCAAGGGCCAAAGCAACCATGGAAGTACCCTCGTCA
#!/usr/bin/perl -w
use strict;
my $ratio = 7; # Percentage error to apply
my $swapped_total = 0;
my $characters_seen = 0;
my $charset = "ACGT";
while(<DATA>) {
chomp;
# The line below calculates the number of characters to swap in this line
my $this_line_todo = int(($characters_seen + length($_)) * $ratio / 100 +0.5)
- $swapped_total;
# Now we need to find the positions of the characters to change
my %indexes = (); # Place to store indexes
$indexes{int(rand(length))}++
while(scalar(keys %indexes) < $this_line_todo *2);
foreach my $index (keys %indexes) {
my $char = substr($_,$index,1);
my $newchar;
do {
$newchar = substr($charset, rand(4), 1);
} while ($char eq $newchar);
substr($_,$index,1) = lc $newchar;
}
$characters_seen += length;
$swapped_total += $this_line_todo;
print $_,"\n";
}
print "Total characters seen is $characters_seen\n";
print "Total characters swapped is $swapped_total\n";
__DATA__
GAATATCCCCATGATCTTTCCCTCAATCGCCCGCTGATAAGTGGGAAGACATCG
GTCGCGCCACACTCGATACCCTGCTCATGGTGGCGCTTGGTCTTCCCTTGGGAAT
GAATATCCCCATGATCTTCCCCTCAATCGACCTGGACGCTGATAAGTGGAAAGACATCG
GTCGCGCCACACTCGATACCCTGCTCACCCGCATTGGCGCTTGGTCTTCCCTTGGGAAT
GAATATCCCCATGATCTTCCCCTCAAACCTGGACGTTGATAAGTGGAAAGACATCG
GAATATCCCCATGATCTTTCCCTCAATCGACGCTGATAAGTGGGAAGACAT
GTCGCGCCACACTCGATACCCTGCTCGGCGCTTGGTCTTCCCTTGGGAATC
GGTTGGCGGTGCCGCCCTCGTGCAACCAATCAAGTTTGGTGGCGATGTTG
CACCAACGCTTAGTGTCACCTACTACATCACTAAAAAGTTGAGTTAT
GGTTGGCGGCGCCGCCCTCGTGCAACCAACAAGTTTGGTGGCGATGTTG
CACCAACGCTAAGTGTAACCTACTACATCAAGGGGCATTACTAAAAAGTT
AAAATGCAGCACAGAATACTGTCAAGTTTGGTGGCGATGTTG
GGTTGGCGGCGCTGCCCTCGTGCAACCAAAGAAAAGTTTGGTGGCGATGTTG
CACCAACGCTTAGTGTCACCTACTACATCAACGGGTATTACTAAAAAGTTGAG
AATGACCGAAATCAAGGAAGCTTTTGTCCCCCCCAGTGATTGAAGTGCTAGTCG
TTGGCGATACCGTCTCCAAGGGCCAAAGTTTCAACCATGGAAGTACCTTCGTCA
AATGACCGAAATCAAGGAAGCTTTTGTCCCCCCCAGTGATTGAAGTGCTAG
TTGGCGATACCGTCTCCAAGGGCCAAACAACCATGGAAGTACCCTCGTCA
AATGACCGAAATCAAGGAAGCTTTTGTCGTCCCAGTGATTGAAGTGCTAGTC
TTGGCGATACCGTCTCCAAGGGCCAAAGCAACCATGGAAGTACCCTCGTCA
#!/usr/bin/perl -w
use strict;
my $charset = "ACGT";
# Get the DNA sequence data filename
print "Please type the filename of the DNA sequence data: ";
my $dna_filename = <>;
chomp ($dna_filename);
# Validate filename
$dna_filename =~ /^\w+(?:\.\w+)$/
or die "Invalid filename format [$dna_filename]";
# Process once at 7% and once at 10%
foreach my $ratio (7,10) {
my $swapped_total = 0;
my $characters_seen = 0;
# Open file for reading
open FH, "$dna_filename"
or die "Failed to open file [$dna_filename]";
open OUT, ">${dna_filename}_${ratio}percent"
or die "Failed to create output file [${dna_filename}_${ratio}percent]";
while(<FH>) {
chomp;
# The line below calculates the number of characters to swap in this line
my $this_line_todo = int(($characters_seen + length($_)) * $ratio / 100 +0.5)
- $swapped_total;
# Now we need to find the positions of the characters to change
my %indexes = (); # Place to store indexes
$indexes{int(rand(length))}++
while(scalar(keys %indexes) < $this_line_todo *2);
foreach my $index (keys %indexes) {
my $char = substr($_,$index,1);
my $newchar;
do {
$newchar = substr($charset, rand(4), 1);
} while ($char eq $newchar);
substr($_,$index,1) = lc $newchar;
}
$characters_seen += length;
$swapped_total += $this_line_todo;
print OUT $_,"\n";
}
print "Total characters seen is $characters_seen\n";
print "Total characters swapped is $swapped_total\n";
close OUT;
close FH;
}