forked from liangclab/HERA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-Split_Scaffold_To_Contigs.pl
executable file
·50 lines (48 loc) · 1.2 KB
/
02-Split_Scaffold_To_Contigs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
#Author: huilong du
#Note: splicing the scaffolds into contigs by name count++
use warnings;
use strict;
sub reverse_complement{
my $input_seq=shift;
my $reverse=reverse $input_seq;
$reverse=~tr/ACGT/TGCA/;
$reverse=~tr/acgt/tgca/;
return $reverse;
}
my $infile=shift;
my $outfile=shift;
my $Enzyme=shift;
if(!defined $infile || !defined $outfile || !defined $Enzyme ){
print "Usage: perl $0 infile outfile Enzyme\n";
exit;
}
my $Reverse=reverse_complement($Enzyme);
$Reverse="N".$Reverse."N";
$Enzyme="N".$Enzyme."N";
open IN,"<$infile" or die $!;
open OUT,">$outfile" or die $!;
my $contigs;
my $count=0;
while(<IN>){
chomp;
my $line=$_;
if($line=~/^>(\S+)/){
$contigs=$1;
$count=1;
}
else{
$line=~ s/$Enzyme/N/g;
$line=~ s/$Reverse/N/g;
$line =~ s/N*N/N/g;
$line =~ s/n/N/g;
my @splitline = split(/N/,$line);
for(my $i=0;$i<@splitline;$i++){
print OUT ">$contigs.$count\n";
print OUT "$splitline[$i]\n";
$count++;
}
}
}
close(OUT);
close(IN);