-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathevaluateTePavALignmentNoreasone.pl
118 lines (105 loc) · 3.14 KB
/
evaluateTePavALignmentNoreasone.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
#!perl -w
use strict;
open INPUT, "$ARGV[1]";
my $totalNUmber = 0;
my $goodnumber = 0;
while( my $line=<INPUT> ){
$line =~ s/^\s+//;
$line =~ s/\s+$//;
my @words = split /\s+/, $line;
my $chr = $words[0];
my $start = $words[1];
$start = $start + 1;
my $end = $words[2];
my $teLength = $end - $start + 1;
$start = $start - 35;
$end = $end + 35;
my $good = 0;
opendir my $dir, "./" or die "Cannot open directory: $!";
my @files = readdir $dir;
closedir $dir;
for my $bamFile ( @files ){
if( $bamFile=~/^$ARGV[0]$/){
my $maximumGapLength = 0;
my $maximumGapPreNonGapLength = 0;
my $maximumGapPostNonGapLength = -1;
my $thisGapLength = 0;
my $thisNonGapLength = 0;
my $lastGap = 0;
#my $result = `samtools depth -r $chr:$start-$end $ARGV[0]`;
my $result = `samtools mpileup -r $chr:$start-$end $bamFile`;
# print "samtools mpileup -r $chr:$start-$end $bamFile\n";
my @lines = split /\n+/, $result;
my $lastPosition = $start - 1;
my $numberOfLines = scalar(@lines);
my $nonZoroCoverage = 0;
for my $eachline (@lines){
my @elements = split /\s+/, $eachline;
# for( my $i= $lastPosition+1; $i<$elements[1]; $i = $i + 1){
# if( $lastGap ){
# $thisGapLength = $thisGapLength + 1;
# }else{
# if( $maximumGapPostNonGapLength == -1 ){
# $maximumGapPostNonGapLength = $thisNonGapLength;
# }
# $thisGapLength = 1;
# }
# $lastGap = 1;
# $numberOfLines = $numberOfLines + 1;
# }
$lastPosition = $elements[1];
#if ( $elements[2] != 0 ){
if ( $elements[4] ne "*" ){
$nonZoroCoverage = $nonZoroCoverage + 1;
if( $lastGap ){
if( $thisGapLength > $maximumGapLength ){
$maximumGapLength = $thisGapLength;
$maximumGapPreNonGapLength = $thisNonGapLength;
$maximumGapPostNonGapLength = -1;
}
$thisNonGapLength = 1;
}else{
$thisNonGapLength = $thisNonGapLength + 1;
}
$lastGap = 0;
}else{
if( $lastGap ){
$thisGapLength = $thisGapLength + 1;
}else{
if( $maximumGapPostNonGapLength == -1 ){
$maximumGapPostNonGapLength = $thisNonGapLength;
}
$thisGapLength = 1;
}
$lastGap = 1;
}
}
if( $maximumGapPostNonGapLength == -1 ){
$maximumGapPostNonGapLength = $thisNonGapLength;
}
if( $thisGapLength > $maximumGapLength ){
$maximumGapLength = $thisGapLength;
$maximumGapPostNonGapLength = 0;
}
if( ($teLength + 70) > $numberOfLines ){
}elsif( $maximumGapPostNonGapLength == 0 || $maximumGapPreNonGapLength == 0 ){
}elsif ( $maximumGapLength < $teLength && ($teLength - $maximumGapLength) < 35 ){
$good = $good + 1;
}elsif ( $maximumGapLength < $teLength ){
}elsif ( $maximumGapLength > $teLength && ($maximumGapLength - $teLength) < 35 ){
$good = $good + 1;
}elsif ( $maximumGapLength > $teLength ){
}elsif ( $maximumGapPostNonGapLength > 0 && $maximumGapPreNonGapLength > 0 ){
$good = $good + 1;
}else{
}
}
}
if( $good > 0 ){
$goodnumber = $goodnumber + 1;
}
$totalNUmber = $totalNUmber + 1;
}
close INPUT;
print "totalNUmber:$totalNUmber\n";
print "goodnumber:$goodnumber\n";