Skip to content

Commit

Permalink
Added convenience methods for synteny data from 'i' lines.
Browse files Browse the repository at this point in the history
For #68.
  • Loading branch information
csw committed Jul 16, 2012
1 parent 7c20449 commit fd46ba0
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/bio/maf/maf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,43 @@ def gapped?
size != text.size
end

I_STATUS = {
'C' => :contiguous,
'I' => :intervening,
'N' => :first,
'n' => :first_bridged,
'M' => :missing_data,
'T' => :tandem
}

def decode_status_char(c)
I_STATUS[c] || raise("Unsupported status character #{c}!")
end

def left_status_char
i_data && i_data[0]
end

def left_status
i_data && decode_status_char(left_status_char())
end

def left_count
i_data && i_data[1].to_i
end

def right_status_char
i_data && i_data[2]
end

def right_status
i_data && decode_status_char(right_status_char())
end

def right_count
i_data && i_data[3].to_i
end

def species
parts = source.split('.', 2)
parts.size == 2 ? parts[0] : nil
Expand Down
23 changes: 23 additions & 0 deletions spec/bio/maf/maf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,30 @@ module MAF
range = s.text_range(9076...(9077 + 9))
}.to raise_error
end
end

describe "synteny data" do
it "extracts basic data from i lines" do
p = Parser.new(TestData + 'chr22_ieq2.maf',
:parse_extended => true)
b = p.parse_block
b.sequences[0].left_status_char.should be_nil
b.sequences[0].left_status.should be_nil
b.sequences[0].left_count.should be_nil
b.sequences[0].right_status_char.should be_nil
b.sequences[0].right_status.should be_nil
b.sequences[0].right_count.should be_nil
# works but let's not over-specify internal state
#b.sequences[1].i_data.should == %w(N 0 C 0)
b.sequences[1].left_status_char.should == 'N'
b.sequences[1].left_status.should == :first
b.sequences[1].right_status_char.should == 'C'
b.sequences[1].right_status.should == :contiguous
b.sequences[2].left_status.should == :contiguous
b.sequences[2].right_status_char.should == 'I'
b.sequences[2].right_status.should == :intervening
b.sequences[2].right_count.should == 146
end
end

describe "#to_bioalignment" do
Expand Down
11 changes: 11 additions & 0 deletions test/data/chr22_ieq2.maf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##maf version=1 scoring=autoMZ.v1
a score=13668.000000
s hg19.chr22 16054189 54 + 51304566 TCTGTGAAACCCACAGTAATGGGGCTGACATCCTCTGCCCTATGCAAGAGAGGT
s ponAbe2.chrUn 13354616 54 + 72422247 TCTTTCAAACCCACAGTAATGGGGCTGACATCCTCTACCATATGCAAGAGAGGT
q ponAbe2.chrUn 855489998999999899968899889893997969799999879999999989
i ponAbe2.chrUn N 0 C 0
s panTro2.chrUn 7684562 54 + 58616431 TCTGTGAAACCCACAGTAATGGGGCTGACATCCTCTGCCCTATGCAAGAGAGAT
q panTro2.chrUn 999999999999999999999999999999999999999999999999999999
i panTro2.chrUn C 0 I 146
e turTru1.scaffold_109008 25049 1601 + 50103 I

0 comments on commit fd46ba0

Please sign in to comment.