File: bedEffOnePerLine.pl

package info (click to toggle)
snpeff 5.2.f%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 701,384 kB
  • sloc: java: 62,547; perl: 2,279; sh: 1,185; python: 744; xml: 507; makefile: 50
file content (42 lines) | stat: -rwxr-xr-x 1,099 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
#!/usr/bin/perl

#-------------------------------------------------------------------------------
#
# Read a BED file (via STDIN), split EFF fields from fourth column into many lines
# leaving one line per effect.
#
# Note: In lines having multiple effects, all other information will be 
#       repeated. Only the 'EFF' field will change.
#
#															Pablo Cingolani 2013
#-------------------------------------------------------------------------------

$EFF_COLUMN = 3;

while( $l = <STDIN> ) {
	# Show header lines
	if( $l =~ /^#/ ) { print $l; }	
	else {
		chomp $l;

		@t = @infos = @effs = (); # Clear arrays

		# Non-header lines: Parse fields
		@t = split /\t/, $l;

		# Parse INFO column 
		@effs = split /;/, $t[ $EFF_COLUMN ];

		# Print BED line
		if( $#effs <= 0 )	{ print "$l\n"; }	# No EFF found, just show line
		else {
			$pre = "";
			for( $i=0 ; $i < $EFF_COLUMN ; $i++ ) { $pre .= ( $i > 0 ? "\t" : "" ) . "$t[$i]"; }

			$post = "";
			for( $i=$EFF_COLUMN+1 ; $i <= $#t ; $i++ ) { $post .= "\t$t[$i]"; }

			foreach $eff ( @effs ) { print "$pre\t$eff$post\n"; }
		}
	}
}