-
Notifications
You must be signed in to change notification settings - Fork 2
/
reorder_scaffolds.pl
executable file
·120 lines (91 loc) · 2.9 KB
/
reorder_scaffolds.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
=head1
reorder_scaffolds.pl
=head1 SYNOPSIS
reorder_scaffolds.pl -t [TPF file] -l [file with order and orientation]
=head1 COMMAND-LINE OPTIONS
-t TPF file
-l Tab-delimited file containing tab-delimited lines of scaffolds orientation as + or - listed in the desired new order.
-h Help
=cut
use strict;
use Bio::GenomeUpdate::TPF::TPFSequenceLine;
use Bio::GenomeUpdate::TPF::TPFGapLine;
use Bio::GenomeUpdate::TPF;
use File::Slurp;
use Getopt::Std;
use Getopt::Std;
our ( $opt_t, $opt_l, $opt_h );
getopts('t:l:h');
if ($opt_h) {
help();
exit;
}
if ( !$opt_t || !$opt_l ) {
print "\nTPF and order/orientation filenames are required.\n\n\n";
help();
}
#get input files
my $tpf_input_file = $opt_t;
my $input_tpf = read_file($tpf_input_file)
or die "Could not open TPF input file: $tpf_input_file\n";
my $order_input_file = $opt_l;
my $input_order = read_file($order_input_file)
or die
"Could not open scaffold order and orientation file: $order_input_file\n";
#new TPF object
my $tpf = Bio::GenomeUpdate::TPF->new();
my $out_tpf;
my @order_lines;
my @ordered_and_oriented_scaffolds;
my $ordered_tpf;
#get info from input TPF file and populate $tpf
$tpf->parse_tpf($input_tpf);
#create a TPF for output by copying the original and clearing the lines. This preserves the other TPF info.
#$out_tpf = $tpf;
#$out_tpf->clear_tpf_lines();
#read in order lines into array
#SL2.40sc04133 +
#SL2.40sc04191 +
#SL2.40sc03666 -
@order_lines = split( /\n/, $input_order );
foreach my $line (@order_lines) {
chomp($line);
my @scaffold_and_orientation = split( /\t/, $line );
my $scaffold_name = $scaffold_and_orientation[0];
my $orientation = $scaffold_and_orientation[1];
if ( ( $orientation eq "+" ) || ( $orientation eq "-" ) ) {
my @scaffold_and_orientation_array = ( $scaffold_name, $orientation );
# making 2D array
push( @ordered_and_oriented_scaffolds,
\@scaffold_and_orientation_array );
}
else {
die "Orientation must be specified as + or -\n";
}
}
#reorient the scaffolds
$ordered_tpf =
$tpf->get_tpf_in_new_scaffold_order( \@ordered_and_oriented_scaffolds );
my $out_str_from_tpf_ordered = $ordered_tpf->get_formatted_tpf();
print $out_str_from_tpf_ordered. "\n";
###write_file('processed_tpf.txt',$out_str_from_tpf_parsed);
sub help {
print STDERR <<EOF;
$0:
Description:
This script changes the order and orientation of scaffolds in a Tiling Path File (TPF).
Usage:
reorder_scaffolds.pl -t [TPF file] -l [file with order and orientation]
Flags:
-t <TPF_file> Original TPF file (mandatory)
-l <order_and_orientation_file> Tab-delimited file containing tab-delimited lines of scaffolds orientation as + or - listed in the desired new order.
-h <help> Help
EOF
exit(1);
}
=head1 LICENSE
Same as Perl.
=head1 AUTHORS
Jeremy D. Edwards <[email protected]>
=cut