File: dump_segment.pl

package info (click to toggle)
libchado-perl 1.23-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,976 kB
  • ctags: 10,378
  • sloc: xml: 192,540; sql: 165,945; perl: 28,339; sh: 101; python: 73; makefile: 46
file content (88 lines) | stat: -rwxr-xr-x 2,357 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl

use FindBin qw($RealBin);
use lib (($ENV{SOI_ROOT}) ||
                     (($INC[0]=~/^\./)?"$RealBin/$INC[0]":"$RealBin/.."));

use strict;

use SOI::Adapter;
use Getopt::Long;
use Carp;
use FileHandle;

my ($ad);
my $h = {};
GetOptions($h,
           "dbname|d=s",
           "program=s@",
           "sourcename=s@",
           "extend=s",
           "format=s",
           "debug",
          );
my $dbname = $h->{dbname};
my $type = 'scaffold';

eval {
    $ad = SOI::Adapter->new($dbname);
};
if ($@) {
    print STDERR "There was an error\n";
    print STDERR $@;
    exit 1;
}

foreach my $seg (@ARGV) {
    my ($features, $range, $t);
    ($range, $features) = &get_type_features($ad, $type, $seg);
    if (@{$features || []}) {
        my $arm = $ad->get_f({range=>$range}, {feature_types=>'chromosome_arm',noauxillaries=>1});
        my ($fmin, $fmax) = ($range->{fmin},$range->{fmax});
        my $new_f = $arm->stitch_child_segments($fmin,$fmax);
        $arm->hash->{residues} = "";
        my $rset_constr = {range=>$range};
        $rset_constr->{program} = $h->{program} if ($h->{program});
        $rset_constr->{sourcename} = $h->{sourcename} if ($h->{sourcename});
        my $rsets = $ad->get_results($rset_constr);
        map{$_->transform($new_f)}(@{$features},@{$rsets || []});
        my $ans = $ad->get_analysis();
        my %an_h;
        map{$an_h{$_->analysis_id}=$_}@{$ans || []};
        foreach my $rset (@{$rsets || []}) {
            my $an = $an_h{$rset->analysis_id};
            $an->add_node($rset) if ($an);
        }
        $arm->nodes([@{$arm->nodes || []},@{$features}, @{$ans || []}]);
        my $format = $h->{format} || "soi";
        my $m = "to_$format"."_xml";
        my $f;
        $f = "$seg.$format.xml" unless (scalar(@ARGV) == 1);
        $arm->$m($f);
    }
    else {
        printf STDERR "did not get any feature for %s=%s\n", $type, $seg
    }
}
$ad->close_handle;
exit;

sub get_type_features {
    my $ad = shift;
    my $by_type = shift;
    my $type = $by_type;
    my $val = shift;

    my $opts = {};
    if ($by_type eq 'gene') {
        $opts->{extend} = $h->{extend} || 50000;
    }
    my $method = "get_features_by_$type";

    if ($ad->can($method)) {
        return ($ad->$method($val, $opts));
    }
    else {
        confess("can not do $method");
    }
}