-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_gene.pl
80 lines (58 loc) · 1.72 KB
/
update_gene.pl
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
#!/usr/bin/perl
use strict;
use Carp;
use Data::Dumper;
use Ace;
use Model::Gene;
use GFF3::GFF3Rec;
use XML::DOM;
use Chado::WriteChadoMac;
use Chado::PrettyPrintDom;
my $gfffile = $ARGV[0];
open my $gfffh, "<", $gfffile;
my$xmlfile = $ARGV[1];
open my $xmlfh, ">>", $xmlfile;
my $doc = new XML::DOM::Document;
my $root = $doc->createElement("chado");
#append elegans as the default organism
my $worm = new Model::Worm({genus => 'Caenorhabditis',
species => 'elegans',
});
my $organism = $worm->write_organism($doc);
$root->appendChild($organism);
my $class = 'Gene';
my $host = 'localhost';
my $port = 23100;
my $db = Ace->connect(-host => $host, -port => $port)
|| croak("Couldn't open database at host $host port $port");
while (<$gfffh>) {
chomp;
next if $_ =~ /^\s*$/ || $_ =~ /^#/;
my $rec = new GFF3::GFF3Rec({line => $_});
my $id = $rec->get_ID();
$id =~ s/^Gene://;
my $wb_gene = $db->fetch($class, $id);
#print $wb_gene->asTable;
my $gene = new Model::Gene({gene => $wb_gene});
my $feature = $gene->write_feature($doc, $organism, 'update');
$root->appendChild($feature);
}
$doc->appendChild($root);
pretty_print($root, $xmlfh);
close($gfffh);
close($xmlfh);
#my $wb_gene = $db->fetch($class, $id);
#print $wb_gene->asTable;
#my $xml = DUMP . $id . ".xml";
#my $fh;
#my $gene = new Model::Gene({gene => $wb_gene});
#if (lc($gene->get_status()) eq 'live') {
# if (defined($gene->get_worm())) {
# print $gene->get_name();
# if ($gene->get_worm()->get_species() eq 'elegans') {
# open($fh, "> $xml") || croak("Couldn't open file $xml");
# $gene->write_feature_to_file($fh, 'force');
# close($fh);
# }
# }
#}