Hi,
I have the data file. txt (3.96 MB) and I want to make each 50 Character on the one line.
For EX:
In put data :
GTGAGCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGATCTC........
out put with 50 character on one line:
GTGAGCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCC
TGAGCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCG
GAGCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGA
AGCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGAT
GCCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGATC
CCAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGATCT
CAGAACTCATCTTCTTTGCTCGAAACCTGGCGCCAAGTTGTTGCCGATCTC
Below is my script but it take me along time to do that. Could you show me the fast way to solve this problem.
use bigint;
print "Insert the file:";
$file = <STDIN>;
if (!open (IN,"$file")){
print "false.\n";
pause;
}
if (!open (OUTB, ">mode.txt")){
print "false.\n";
pause;
}
if (!open (OUTC, ">mode1.txt")){
print "false.\n";
pause;
}
$data = "";
while (<IN>){
if ($_ =~ />/){
next;
}
$_ =~ s/\r//;
$_ =~ s/\n//;
$data = $data.$_;
}
$num = length($data);
for ($i = 0; $i < $num; $i++){
$tag = substr($data, 0 + $i, 50);
print (OUTB "$i\t$tag\n");
}
print (OUTB "\n");
$data = reverse($data);
$count = 0;
$pos = 0;
$tag = "";
for ($i = 0; $i < $num + 49; $i++){
$change = substr($data, 0 + $i, 1);
if ($change eq "A") {
$change =~ s/A/T/;
}
elsif ($change eq "T"){
$change =~ s/T/A/;
}
elsif ($change eq "G"){
$change =~ s/G/C/;
}
elsif ($change eq "C"){
$change =~ s/C/G/;
}
$tag = $tag.$change;
$count++;
if($count == 50){
print (OUTC "\t$tag\n");
$count = 0;
$tag = "";
$pos++;
$i = $pos;
}
}
print "\ndata finished.\ncheck 「Model and model.txt.\n";
close (IN);
close (OUTB);
close (OUTC);