forked from Dfam-consortium/RepeatModeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeedAlignmentCollection.pm
executable file
·303 lines (240 loc) · 7.59 KB
/
SeedAlignmentCollection.pm
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/perl -w
##---------------------------------------------------------------------------##
## File:
## @(#) SeedAlignmentCollection.pm
## Author:
## Robert M. Hubley [email protected]
## Description:
## An datastructure for holding a set of SeedAlignment
## objects. This object can read/write Stockholm files
## in the Dfam dialect.
##
#******************************************************************************
#* Copyright (C) Institute for Systems Biology 2017 Developed by
#* Robert Hubley.
#*
#* This work is licensed under the Open Source License v2.1. To view a copy
#* of this license, visit http://www.opensource.org/licenses/osl-2.1.php or
#* see the license.txt file contained in this distribution.
#*
#******************************************************************************
# Implementation Details:
#
# bless( { 'seed_objects' => [ $SeedObjectRef1,
# $SeedObjectRef2,
# ..
# ]
# }
# }, 'SeedAlignmentCollection' );
#
###############################################################################
# ChangeLog
#
# $Log: SeedAlignmentCollection.pm,v $
# Revision 1.2 2017/04/05 00:03:31 rhubley
# Cleanup before a distribution
#
#
###############################################################################
# To Do:
#
#
=head1 NAME
SeedAlignmentCollection
=head1 SYNOPSIS
use SeedAlignmentCollection
Usage:
my $stockholmFile = SeedAlignmentCollection->new();
my $IN;
open $IN,"<library.stk" or die;
$stockholmFile->read_stockholm( $IN );
=head1 DESCRIPTION
An datastructure for holding a set of SeedAlignment objects. This
object can read/write Stockholm files in the Dfam dialect.
=head1 INSTANCE METHODS
=cut
package SeedAlignmentCollection;
use strict;
use SeedAlignment;
use Data::Dumper;
use Carp;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
use lib "/usr/local/RepeatMasker";
require ArrayList;
require Exporter;
@ISA = qw(ArrayList Exporter);
@EXPORT = qw();
@EXPORT_OK = qw();
%EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
my $CLASS = "SeedAlignmentCollection";
my $DEBUG = 0;
##-------------------------------------------------------------------------##
## Constructor
##-------------------------------------------------------------------------##
sub new
{
my $class = shift;
my $this = $class->SUPER::new( @_ );
return $this;
}
##-------------------------------------------------------------------------##
## Get and Set Methods
##-------------------------------------------------------------------------##
##-------------------------------------------------------------------------##
## General Object Methods
##-------------------------------------------------------------------------##
##-------------------------------------------------------------------------##
=head2 read_stockholm()
Use: $obj->read_stockholm(\*INPUT);
or
$obj->read_stockholm(\@array_ref);
Reads the Dfam dialect of the Stockholm format.
Minimal Example
===============
# STOCKHOLM 1.0
#=GF ID Jumbo1
#=GF DE A very common DNA transposon with two deletion products Jumbo1A
#=GF DE and Jumbo1B.
#=GF SE Predicted; RepeatModeler
#=GF TP Interspersed_Repeat;Unknown
#=GF OC Colius striatus
#=GF SQ 2
#=GC RF xxxx.xxx.x.x...x.x.x
colStr1:KK551537:690782-691123 .GCT.GGGAT.G...CTGCG
colStr1:KK551537:1038-2834 AGCTTGGG.TTGTACC.G.G
//
Complex Example
===============
# STOCKHOLM 1.0
#=GF ID Jumbo1
#=GF DE A very common DNA transposon with two deletion products Jumbo1A
#=GF DE and Jumbo1B.
#=GF SE Predicted; RepeatModeler
#=GF TP Interspersed_Repeat;Transposable_Element;DNA;TIR;hAT;Tip100
#=GF OC Eutheria
#=GF OC Metatheria
#=GF RN [1]
#=GF RM 382832
#=GF RN [2]
#=GF RM 28834
#=GF DR DPTEdb; af31b_dna;
#=GF SQ 2
#=GC RF xxxx.xxx.x.x...x.x.x
hg38:chr12:690782-691123 .GCT.GGGAT.G...CTGCG
hg38:chr2:38282-38399 AGCTTGGG.TTGTACC.G.G
//
Recommended features
====================
#=GF
Compulsory fields:
------------------
ID Identification: One word name for family.
DE Definition: Short description of family.
AU Author: Authors of the entry.
SE Source of seed: The source suggesting the seed members
belong to one family.
TP Type/Classification: Classifcation of family -- Presently we use the
new unified RepeatMasker classification
heirarchy.
OC Clade: Organism (clade, etc.) Multiple OC records are
allowed.
SQ Sequence: Number of sequences in alignment.
Optional fields:
----------------
RN Reference Number: Reference Number.
RM Reference PubMed: Pubmed reference number.
RT Reference Title: Reference Title.
RA Reference Author: Reference Author
RL Reference Location: Journal location.
DR Database Reference: Reference to external database.
#=GC
Optional fields:
----------------
RF Reference annotation Often the consensus DNA is used as a reference
or simple "x" for match columns and "." for
insert columns.
=cut
##-------------------------------------------------------------------------##
sub read_stockholm
{
my $this = shift;
my $in = shift;
my $input;
if ( ref $in eq "GLOB" )
{
$input = [ <$in> ];
} else
{
$input = $in;
}
my @data;
my $inSection = 0;
foreach ( @$input )
{
if ( /^\#\s+STOCKHOLM/ )
{
if ( $inSection )
{
croak $CLASS
. "::read_stockholm: Two headings found without an intervening '//' line.";
}
$inSection = 1;
}
if ( /^\/\// && $inSection && @data )
{
# Process it
push @data, $_;
my $seedAlignObj = SeedAlignment->new();
$seedAlignObj->read_stockholm( \@data );
$this->add( $seedAlignObj );
@data = ();
$inSection = 0;
}
push @data, $_
if ( $inSection );
}
if ( @data )
{
croak $CLASS
. "::read_stockholm: Incomplete Stockholm section at the end of the file.";
}
}
##-------------------------------------------------------------------------##
=head2 write()
Use: $obj->write( $file );
$file : String
=cut
##-------------------------------------------------------------------------##
sub write
{
my $this = shift;
my $filename = shift;
open OUT, ">$filename"
or croak "SeedAlignmentCollection::write - "
. "Error...could not open file $filename "
. "for writing!\n";
for ( my $i = 0 ; $i < $this->size() ; $i++ )
{
print OUT $this->get( $i )->toString();
}
close OUT;
}
##-------------------------------------------------------------------------##
=head2 toString()
Use: my $str = $obj->toString();
Create a monolithic string with all the object data
formatted for output.
=cut
##-------------------------------------------------------------------------##
sub toString()
{
my $this = shift;
my $alignmentMode = shift;
my $str = "";
for ( my $i = 0 ; $i < $this->size() ; $i++ )
{
$str .= $this->get( $i )->toString();
}
return $str;
}
1;