File: anal_gloc.pl

package info (click to toggle)
lagan 2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,360 kB
  • sloc: ansic: 8,542; perl: 7,732; cpp: 3,260; makefile: 85
file content (142 lines) | stat: -rwxr-xr-x 3,110 bytes parent folder | download | duplicates (3)
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
138
139
140
141
142
#!/usr/bin/perl

$savname1 = "";
$savname2 = "";
$skip = 0;
$endblock = 0;
$score = 0;
$strand = "";
$initstrnd;
$s1s = 999999999;
$s2s = 999999999;
$first = 1;
$plus_sc = 0;
$minus_sc = 0;


while ($line = <STDIN>) {

    if ($line =~ /^>/) {
	if (!$first) { 
	    if ($strand eq "+") {
		print STDOUT "  Region [$s1s $reg1s][$s2s $reg2s] $score $strand\n";
	    }
	    else {
		print STDOUT "  Region [$s1s $reg1s][$reg2s $s2s] $score $strand\n";
	    }

	    if ($strand ne $initstrnd) {
		print STDOUT "INV\n"
	    }
	    if ($strand eq "+") { $plus_sc += $score; }
	    else  { $minus_sc += $score; }	  
	    if ($plus_sc > $minus_sc) {
		print STDOUT "Main score (+) $plus_sc; Inverted $minus_sc\n";
	    }
	    else {
		print STDOUT "Main score (-) $minus_sc; Inverted $plus_sc\n";
	    }
	    $plus_sc = 0;
	    $minus_sc = 0;
	    $score = 0;
	    $s1s = 999999999;
	    $s2s = 999999999;
	    $strand = "";
	}
	$first = 1;
	$name1 = $line;
	chomp $name1;
	$line = <STDIN>;
	if ($line !~ /^>/) {
	    print STDERR "Expecting a name, but got $line";
	    exit (1);
	}
	$name2 = $line;
	chomp $name2;
	$inblock = 1;
	$skip = 0;
	if (($name1 eq $savname1) && ($name2 eq $savname2)) {
	    $skip = 1;
	}
	else { 	print STDOUT "$name1 $name2\n"; }

	$savname1 = $name1;
	$savname2 = $name2;
    }
    elsif (!$skip) {
	$endblock = 0;
	$line =~ /\((\d+) (\d+)\)=\((\d+) (\d+)\) ([0-9\.]*) (.) (.*)/;
	if ($1 == 0 || $3 == 0) {
	    next;
	}
#	print STDOUT "strand $strand $s2s $4\n";
	if (($strand eq "+") && ($6 eq "+") && ($s2s + 20 < $4) ) {
	    $endblock += 2;
	}
	if (($strand eq "-") && ($6 eq "-") && ($s2s > $4 + 20) ) {
	    $endblock += 2;
	}
	if ($strand eq "") { $strand = $6; }
	if ($6 ne $strand) {
	    $endblock += 1;
	}

	if (!$endblock) {
	    $s2s = $3;  
	    $s1s = $1;
	    $s1e = $2;
	    $s2e = $4;
	    $score += $5;
	    if ($first) {
		print STDOUT "    "; 
		print STDOUT "    "; 
		$initstrnd = $strand;
		$reg1s = $2;
		$reg2s = $4;
		$first = 0;
	    }
	}
	else {
	    if ($strand eq "+") {
		print STDOUT "  Region [$s1s $reg1s][$s2s $reg2s] $score $strand\n";
	    }
	    else {
		print STDOUT "  Region [$s1s $reg1s][$reg2s $s2s] $score $strand\n";
	    }

	    if ($strand eq "+") { $plus_sc += $score; }
	    else  { $minus_sc += $score; }	  

	    if ($endblock %2) { print STDOUT "INV "; }
	    else {print STDOUT "    "; }
	    if ($endblock > 1) { print STDOUT "TRL "; }
	    else {print STDOUT "    "; }
	    $s2s = $3;  
	    $s1s = $1;
	    $s1e = $2;
	    $s2e = $4; 
	    $reg1s = $s1e; 
	    $reg2s = $s2e; 
	    $score = $5;
	    $strand = $6;
	    #	    print STDOUT "strand $strand\n";
	}
    }
}
if (!$first){
    if ($strand eq "+") {
	print STDOUT "  Region [$s1s $reg1s][$s2s $reg2s] $score $strand\n";
    }
    else {
	print STDOUT "  Region [$s1s $reg1s][$reg2s $s2s] $score $strand\n";
    }
    if ($strand eq "+") { $plus_sc += $score; }
    else  { $minus_sc += $score; }
}

if ($plus_sc > $minus_sc) {
    print STDOUT "Main score (+) $plus_sc; Inverted $minus_sc\n";
}
else {
    print STDOUT "Main score (-) $minus_sc; Inverted $plus_sc\n";
}