File: CIGAR.pm

package info (click to toggle)
trinityrnaseq 2.15.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 468,004 kB
  • sloc: perl: 49,905; cpp: 17,993; java: 12,489; python: 3,282; sh: 1,989; ansic: 985; makefile: 717; xml: 62
file content (94 lines) | stat: -rw-r--r-- 2,032 bytes parent folder | download | duplicates (2)
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
package CIGAR;

use strict;
use warnings;

use Nuc_translator;

####
sub construct_cigar {
	my ($genome_coords_aref, $query_coords_aref, $read_length, # required
		$genome_seq_sref, $strand # optional
		) = @_;

	my $cigar = "";
		

	for (my $i = 0; $i <= $#$genome_coords_aref; $i++) {
		
		my ($curr_genome_lend, $curr_genome_rend) = @{$genome_coords_aref->[$i]};
		my ($curr_query_lend, $curr_query_rend) = @{$query_coords_aref->[$i]};

		if ($i == 0) {

			if ($curr_query_lend > 1) {
				$cigar .= ($curr_query_lend - 1) . "S";
			}
		}
		else {
			my ($prev_genome_lend, $prev_genome_rend) = @{$genome_coords_aref->[$i-1]};
			my ($prev_query_lend, $prev_query_rend) = @{$query_coords_aref->[$i-1]};
			
			if ( (my $delta_genome = $curr_genome_lend - $prev_genome_rend) > 1) {
				my $deletion_intron_char = ($genome_seq_sref && $strand) ? &_check_intron_consensus($prev_genome_rend, $curr_genome_lend, $genome_seq_sref, $strand) : 'D'; # intron or deletion?
				$cigar .= ($delta_genome-1) . $deletion_intron_char;
			}
			if ( (my $delta_query = $curr_query_lend - $prev_query_rend) > 1) {
				$cigar .= ($delta_query-1) . "I";
			}
		}
		

		my $len = $curr_genome_rend - $curr_genome_lend + 1;
		
		$cigar .= "$len" . "M";
		
		if ($i == $#$genome_coords_aref) {
			
			if ($curr_query_rend < $read_length) {
				$cigar .= ($read_length - $curr_query_rend) . "S";
			}
		}
		
	}

	return($cigar);
}


####
sub _check_intron_consensus {
	my ($left_segment_bound, $right_segment_bound, $genome_sref, $strand) = @_;

	my $left_dinuc = uc substr($$genome_sref, $left_segment_bound, 2);

	my $right_dinuc = uc substr($$genome_sref, $right_segment_bound-3, 2);

	if ($strand eq '-') {
		$left_dinuc = &reverse_complement($right_dinuc);
		$right_dinuc = &reverse_complement($left_dinuc);
	}

	if (  
		( ($left_dinuc eq "GT" || $left_dinuc eq "GC") && $right_dinuc eq "AG")
		||
		($left_dinuc eq "CT" && $right_dinuc eq "AC")
		) {

		return("N"); # got splice pair
	}
	else {
		return("D"); # deletion
	}
	

}








1; #EOM