-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmergeWrapper.pl
More file actions
executable file
·138 lines (130 loc) · 3.85 KB
/
Copy pathmergeWrapper.pl
File metadata and controls
executable file
·138 lines (130 loc) · 3.85 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env perl
use warnings;
use strict;
use FAlite;
use File::Temp qw/tempdir/;
my $in = $ARGV[0];
my $tmpdir = tempdir( CLEANUP => 1 );
my $basename = `basename $ARGV[0]`;
chomp $basename;
my $iterateCount = 0;
my $THREADS = $ARGV[1];
my $outStrict = "";
if ($ARGV[2]) {
$outStrict = $ARGV[2];
}
my $outCount = 0;
while (1) {
my $outBefore = {};
my $outAfter = {};
print STDERR "Outer iteration $outCount.$iterateCount of merge\n";
open IN, "$in";
my $fasta_file = new FAlite(\*IN);
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
$outBefore->{$def} = 1;
}
close IN;
my $strict = "";
if ($outCount == 0 and $outStrict eq "init") {
$strict = "init";
}
if ($outStrict eq "init" and $outCount > 0) {
$strict = "strict";
}
if ($outStrict eq "strict") {
$strict = "strict";
}
while (1) {
my $before = {};
my $after = {};
if ($outStrict eq "strict" and $outCount > 0) {
system("cat $in > $tmpdir/$basename.final.fa");
$in = "$tmpdir/$basename.final.fa";
}
print STDERR "Iteration $outCount.$iterateCount of merge\n";
open IN, "$in";
$fasta_file = new FAlite(\*IN); # or any other filehandle
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
$before->{$def} = 1;
}
my $oldIn = $in;
close IN;
system("doubleReverse.pl $in > $tmpdir/$basename.prepped.iterationMerge.$outCount.$iterateCount.fa");
print STDERR "Called merge with $strict\n";
system("easyMerge.pl $tmpdir/$basename.prepped.iterationMerge.$outCount.$iterateCount.fa $THREADS $strict > $tmpdir/$basename.iterationMerge.$outCount.$iterateCount.fa");
$in = "$tmpdir/$basename.iterationMerge.$outCount.$iterateCount.fa";
open IN, "$in";
$fasta_file = new FAlite(\*IN);
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
$after->{$def} = 1;
}
close IN;
print STDERR "END Inner iteration $outCount.$iterateCount of merge\n";
my $beforeCount = scalar(keys %$before);
my $afterCount = scalar(keys %$after);
print STDERR "inner before after merge: $beforeCount\n";
print STDERR "inner after after mege count: $afterCount\n";
if ($beforeCount == $afterCount) {
print STDERR "Finished inner loop after $outCount.$iterateCount iterations\n";
print STDERR "in was $in\n";
last;
} elsif ($afterCount > $beforeCount) {
$iterateCount++;
print STDERR "ERROR: After cannot be greater than before\n";
foreach my $def (keys %$after) {
$def =~ s/;noChange=1//g;
unless (exists $before->{$def}) {
print STDERR "$def is not in before\n";
}
}
die;
}
$iterateCount++;
}
print STDERR "\n";
print STDERR "BACK to outer loop\n";
open IN, "$in";
$fasta_file = new FAlite(\*IN);
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
$outAfter->{$def} = 1;
}
close IN;
print STDERR "END Outer iteration $outCount.$iterateCount of merge\n";
my $outBeforeCount = scalar(keys %$outBefore);
my $outAfterCount = scalar(keys %$outAfter);
print STDERR "before count $outBeforeCount\n";
print STDERR "out after count $outAfterCount\n";
if (scalar(keys %$outBefore) == scalar(keys %$outAfter)) {
print STDERR "Finished merging after $iterateCount iterations\n";
print STDERR "printing infile $in\n";
open IN, "$in";
$fasta_file = new FAlite(\*IN);
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
my $seq = $entry->seq;
$def =~ s/;noChange=1//g;
print "$def\n";
print "$seq\n";
}
last;
} else {
$outCount++;
open IN, "$in";
$fasta_file = new FAlite(\*IN);
open OUT, ">$tmpdir/$basename.iterationMerge.$outCount.$iterateCount.fa";
while (my $entry = $fasta_file->nextEntry) {
my $def = $entry->def;
my $seq = $entry->seq;
$def =~ s/;noChange=1//g;
print OUT "$def\n";
print OUT "$seq\n";
}
close OUT;
close IN;
$in = "$tmpdir/$basename.iterationMerge.$outCount.$iterateCount.fa";
}
}