-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathget_pseudo_circle.pl
33 lines (32 loc) · 1.19 KB
/
get_pseudo_circle.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
#!/usr/bin/perl -w
use strict;
# concatenate the first N-bases to the end of the sequence, thus creating a pseudo-circle
die "Usage: $0 \"input_fasta\" \"output\" \"\(optional\) extend_N_bases\" \"\(optional\)only_junction==0 or 1\"" if (@ARGV < 2);
my $filein=$ARGV[0];
my $fileout=$ARGV[1];
my $extend=150;
if (scalar(@ARGV) > 2) { $extend=$ARGV[2]; }
if ($extend < 0) { die "extend_N_bases must be larger than 0 and optimal to be the sequencing length"; }
my $OJ=0;
if (scalar(@ARGV) > 3) { $OJ=$ARGV[3]; }
if (($OJ ne 0) and ($OJ ne 1)) { die "only_junction must be either 0 (output full sequence with first N_bases appended) or 1 (only junction of length <= 2*entend_N_bases)"; }
open(IN, $filein) or die "Cannot open input_fasta : $filein";
open(OUT, ">".$fileout) or die "Cannot open output file : $fileout";
while(<IN>){
chomp;
my $id=$_;
my $seq=<IN>;
chomp $seq;
print OUT $id,"\n";
if ($OJ eq 0) {
print OUT $seq.substr($seq,0,$extend),"\n";
}
elsif ($OJ eq 1) {
if (length($seq) > $extend) {
print OUT substr($seq,(0-$extend)).substr($seq,0,$extend),"\n";
}
else {
print OUT $seq.$seq,"\n";
}
}
}