Defining your own types

Defining your own types

Julia user-defined types are as fast as built-in types. They are easy to define:

abstract type AbstractFeature end
struct Exon{T} <: AbstractFeature where {T <: Integer}
	start::T
	stop::T
end
Exon(5, 10)
Main.ex-05_DefiningTypes.Exon{Int64}(5, 10)
mutable struct MessengerRNA
	sequence::Vector{Char}
	exons::Vector{Exon}
	present::Vector{Bool}
end
mRNA = MessengerRNA(collect("ACTGTTGCATTGCAATTTAAGCAATGGCAAATAACATA"),
					[Exon(5,10), Exon(20,28), Exon(30,34)],
					[true, false, true])
Main.ex-05_DefiningTypes.MessengerRNA(['A', 'C', 'T', 'G', 'T', 'T', 'G', 'C', 'A', 'T'  …  'A', 'A', 'A', 'T', 'A', 'A', 'C', 'A', 'T', 'A'], Main.ex-05_DefiningTypes.Exon[Exon{Int64}(5, 10), Exon{Int64}(20, 28), Exon{Int64}(30, 34)], Bool[true, false, true])

You can access type fields using a dot:

mRNA.exons
3-element Array{Main.ex-05_DefiningTypes.Exon,1}:
 Main.ex-05_DefiningTypes.Exon{Int64}(5, 10) 
 Main.ex-05_DefiningTypes.Exon{Int64}(20, 28)
 Main.ex-05_DefiningTypes.Exon{Int64}(30, 34)

Exercise 1

Define a function that takes a MessengerRNA object and return a list with the sequences (as strings) of the exons present in the transcript, i.e. ["TTGCAT", "AATAA"]

# ... your function here ...

This page was generated using Literate.jl.