File: interactions2SIF.pl

package info (click to toggle)
libchado-perl 1.31-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 44,716 kB
  • sloc: sql: 282,721; xml: 192,553; perl: 25,524; sh: 102; python: 73; makefile: 57
file content (114 lines) | stat: -rwxr-xr-x 2,590 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
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
#!/usr/bin/env perl
use strict;
use warnings;

use DBI;
use Bio::GMOD::Config;
use Bio::GMOD::DB::Config;
use Data::Dumper;
use Getopt::Long;

=head1 NAME

interactions2SIF.pl - Export Chado interaction information in SIF format

=head1 SYNOPSIS

  % interactions2SIF..pl [options] > out.sif

=head1 DESCRIPTION

Reads the feature_relationship table to find interactions.  Outputs those
interactions in Simple Interaction File format (used by Cytoscape).

=head1 COMMAND-LINE OPTIONS

If no arguments are provided, dump_gff3.pl will dump all features
for the default organism in the database.  The command line options
are these:

=over 4

=item * feature_id 

Refines the search to nodes related to this feature_id

=item * cv

Refines the search to edges that have terms that come fromhis 

=back

=head1 AUTHOR

Ben Faga E<lt>faga@cshl.edu<gt>

Copyright (c) 2005

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

my ( $FEATURE_ID, $CV );

GetOptions(
    'feature_id:s' => \$FEATURE_ID,
    'cv:s'         => \$CV,
);

my $gmod_conf =
  $ENV{'GMOD_ROOT'}
  ? Bio::GMOD::Config->new( $ENV{'GMOD_ROOT'} )
  : Bio::GMOD::Config->new();
my $db_conf = Bio::GMOD::DB::Config->new( $gmod_conf, 'default' );

my $dbh = $db_conf->dbh;

my $select_sql = qq[
    select  f1.name as subject_name,
            f1.uniquename as subject_uniquename,
            cvt.name as cvterm,
            f2.name as object_name,
            f2.uniquename as object_uniquename
];
my $from_sql = qq[
    from    feature f1,
            feature f2,
            feature_relationship fr,
            cvterm cvt 
];
my $where_sql = qq[
    where   f1.feature_id = fr.subject_id 
            and f2.feature_id = fr.object_id 
            and cvt.cvterm_id = fr.type_id
];

if ($FEATURE_ID) {
    $where_sql .=
      " and (f1.feature_id = $FEATURE_ID or f2.feature_id = $FEATURE_ID) ";
}
if ($CV) {
    $from_sql   .= ", cv ";
    $where_sql .= " and cvt.cv_id = cv.cv_id and cv.name = '$CV' ";
}

my $sql_str = $select_sql . $from_sql . $where_sql;

my $sth = $dbh->prepare($sql_str);

$sth->execute();

while ( my $hashref = $sth->fetchrow_hashref ) {
    my $s_name       = $$hashref{subject_name};
    my $s_uniquename = $$hashref{subject_uniquename};
    my $o_name       = $$hashref{object_name};
    my $o_uniquename = $$hashref{object_uniquename};
    my $cvterm       = $$hashref{cvterm};

    $s_name = $s_uniquename unless $s_name;
    $o_name = $o_uniquename unless $o_name;

    print join( "\t", ( $s_name, $cvterm, $o_name, ) ), "\n";
}