Class: MultipleGFFs

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-pangenome/MultipleGFF3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder: "../mapping/", lines: [], suffix: ".SM1.cds.sorted.gff", is_gz: false) ⇒ MultipleGFFs

Returns a new instance of MultipleGFFs.



4
5
6
7
8
9
10
11
12
13
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 4

def initialize(folder: "../mapping/", lines:[], suffix:".SM1.cds.sorted.gff", is_gz:false )
    @folder = folder
    @lines = lines
    @suffix = suffix
    @lines_gffs = Hash.new
    @lines.each do |l|
        path ="#{folder}/#{l}#{suffix}"
        @lines_gffs[l] = GFF3.new(file: path, is_gz: is_gz)
    end
end

Instance Attribute Details

#lines_gffsObject (readonly)

Returns the value of attribute lines_gffs.



2
3
4
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 2

def lines_gffs
  @lines_gffs
end

Instance Method Details

#bedAround(distance: 1000, prefix: "../flanking/releasePGSBV1/", suffix: ".RefSeqv1.1.bed") ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 19

def bedAround(distance: 1000, prefix: "../flanking/releasePGSBV1/", suffix: ".RefSeqv1.1.bed" )
    each_gff do |k, v|
        path="#{prefix}#{k}_#{distance}bp_#{suffix}"
        puts path
        out=File.open(path, "w")
        v.bedAroundGene(distance:distance, out:out)
        out.close
    end
end

#each_gffObject



15
16
17
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 15

def each_gff
    @lines_gffs.each_pair{|k,v| yield k, v }
end

#summaryObject



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
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 29

def summary
    ret = []
    each_gff do |k,v|
        v.each_mrna do |record|
            tmp = {}
            tmp[:line] = k
            tmp[:id] = record.get_attribute "Name"
            tmp[:chr] = record.seqid
            tmp[:start] = record.start
            tmp[:end] = record.end
            tmp[:strand] = record.strand
            tmp[:genomic_length] = record.end - record.start
            tmp[:coverage] = record.get_attribute "coverage"
            tmp[:identity] = record.get_attribute "identity"
            tmp[:matches]  = record.get_attribute "matches"
            tmp[:mismatches]  = record.get_attribute "mismatches"
            tmp[:indels] = record.get_attribute "indels"
            tmp[:unknowns] = record.get_attribute "unknowns"
            mrna_stats = @lines_gffs[k].mrna_info(record.id)
            tmp[:cds_count]   = mrna_stats.cds_count
            tmp[:cds_max_gap] = mrna_stats.cds_max_gap
            ret << tmp
        end
    end
    ret
end

#to_svg(mrna: "Sm1_CDS.mrna1", positions: false, out: nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bio-pangenome/MultipleGFF3.rb', line 56

def to_svg(mrna: "Sm1_CDS.mrna1", positions: false, out: nil)
    p = Bio::Graphics::Page.new(width: 800,
     height: 1000, 
     number_of_intervals:10,
     background_color: "white"
     )
    each_gff do |k,v|
        generic_track = p.add_track(:glyph => :generic, 
            :name => k, 
            :label => true  )
        v.cds_to_print(mrna).each do |cds|

            f_id = positions ? cds.offset_start : nil
            feature = Bio::Graphics::MiniFeature.new(start: cds.start, 
        end: cds.end,
        fill_color: cds.color, 
        id: f_id)
            generic_track.add(feature) 
        end 
    end
end