Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
groovy & grails - lecture 4
1. Groovy: Efficiency Oriented Programming
Lecture 4
Master Proteomics & Bioinformatics - University of Geneva
Alexandre Masselot - summer 2011
2. Contents
‣ Eclipse & linux tips
‣ xml parsing
‣ Introduction to Object Oriented Programming
3. A couple of eclipse tips
‣ team -> local history
4. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
5. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
6. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
7. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
- <ctrl>-L + number : jump to the given line number
8. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
- <ctrl>-L + number : jump to the given line number
‣ right button -> source -> toggle comment
9. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
- <ctrl>-L + number : jump to the given line number
‣ right button -> source -> toggle comment
‣ right button -> source -> format
10. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
- <ctrl>-L + number : jump to the given line number
‣ right button -> source -> toggle comment
‣ right button -> source -> format
- indent & format the select code
11. A couple of eclipse tips
‣ team -> local history
- browse by all version of you saved file (by date)
‣ general -> editors -> text editor -> show line number
- lines numbers appear in the editor left margin
- <ctrl>-L + number : jump to the given line number
‣ right button -> source -> toggle comment
‣ right button -> source -> format
- indent & format the select code
- use conjunction with <ctrl>-A to select the whole file
12. A couple of linux (shell) tips
‣ less filename : more power than ’more filename’
- use arrows to go back and forth the file
- g to jump to top; G to jump to the end; / text to search next occurrence
of a text in the file (n to jump to the following occurrence); h to have
help; q to quit
13. A couple of linux (shell) tips
‣ less filename : more power than ’more filename’
- use arrows to go back and forth the file
- g to jump to top; G to jump to the end; / text to search next occurrence
of a text in the file (n to jump to the following occurrence); h to have
help; q to quit
‣ wget -O my.fasta http:/http://www.uniprot.org/uniprot/
P41159.fasta
- to save a url target into a local file
14. A couple of linux (shell) tips
‣ less filename : more power than ’more filename’
- use arrows to go back and forth the file
- g to jump to top; G to jump to the end; / text to search next occurrence
of a text in the file (n to jump to the following occurrence); h to have
help; q to quit
‣ wget -O my.fasta http:/http://www.uniprot.org/uniprot/
P41159.fasta
- to save a url target into a local file
‣ don’t forget to get command documentation with man
16. XML: introduction (cont’d)
‣ Let's consider an element as a record of:
- atomic number (int)
- symbol (string)
- name (string)
- list of isotopes (int number, double mass and double abundance)
17. XML: introduction (cont’d)
‣ Let's consider an element as a record of:
- atomic number (int)
- symbol (string)
- name (string)
- list of isotopes (int number, double mass and double abundance)
‣ Goal : store and retrieve a list of element characteristics
18. XML: introduction (cont’d)
‣ Let's consider an element as a record of:
- atomic number (int)
- symbol (string)
- name (string)
- list of isotopes (int number, double mass and double abundance)
‣ Goal : store and retrieve a list of element characteristics
‣ Old fashion way, in a text file
12;Carbon;c;12.011;0,12,98.90:1,13.003355,1.10
...
19. XML: introduction (cont’d)
‣ Let's consider an element as a record of:
- atomic number (int)
- symbol (string)
- name (string)
- list of isotopes (int number, double mass and double abundance)
‣ Goal : store and retrieve a list of element characteristics
‣ Old fashion way, in a text file
12;Carbon;c;12.011;0,12,98.90:1,13.003355,1.10
...
‣ Pros: compact
20. XML: introduction (cont’d)
‣ Let's consider an element as a record of:
- atomic number (int)
- symbol (string)
- name (string)
- list of isotopes (int number, double mass and double abundance)
‣ Goal : store and retrieve a list of element characteristics
‣ Old fashion way, in a text file
12;Carbon;c;12.011;0,12,98.90:1,13.003355,1.10
...
‣ Pros: compact
‣ Cons: cryptic, hard to add new info or multiple type of
info into one file, problem adding free text etc.
21. XML: introduction - text storage
‣ Old fashion way, in a text file
12;Carbon;c;12.011;0,12,98.90:1,13.003355,1.10
...
23. XML: introduction - text storage (cont’d)
‣ Cons:
- cryptic (what field is what)
- error prone
- hard to add new info
- hard to add multiple type of info into one file
- problem adding free text etc.
24. XML: introduction - RDBM storage
‣ RDBM is another reflex to store structured data
CREATE TABLE elements (atomicNumber int UNIQUE, name name, symbol name UNIQUE, mass double precision);
CREATE TABLE isotopes (atomicNumberBase int REFERENCES elements (atomicNumber), plus int, abundance double
precision, mass double precision);
INSERT into elements VALUES (12, 'Carbon', 'C', 12.011);
INSERT INTO isotopes VALUES(12, 0, 12, 98.90);
INSERT INTO isotopes VALUES(12, 1, 13.003355, 1.10);
26. XML: introduction - RDBM storage (cont’d)
‣ cons:
- can be rather heavy to manage (third parties tools or
libraries)
- HSQLDB or Derby offer light alternative to postgres,
mysql or oracle for small databases
- needs expertise in DB (install/management/update)
- a bit over killer for “small” problems
28. XML: structure
‣ Header: encode for the charset (change if accent, japanese characters...)
<?xml version="1.0" encoding="ISO-8859-1"?>
29. XML: structure
‣ Header: encode for the charset (change if accent, japanese characters...)
<?xml version="1.0" encoding="ISO-8859-1"?>
‣ Element: a node in the structured tree of the document
<oneElement>...</oneElement>
<isImportant/> // open/close at once
30. XML: structure
‣ Header: encode for the charset (change if accent, japanese characters...)
<?xml version="1.0" encoding="ISO-8859-1"?>
‣ Element: a node in the structured tree of the document
<oneElement>...</oneElement>
<isImportant/> // open/close at once
‣ Content
<author>J.R.R. Tolkien</author>
<title><![CDATA[Laurel & Hardy]]></title>
31. XML: structure
‣ Header: encode for the charset (change if accent, japanese characters...)
<?xml version="1.0" encoding="ISO-8859-1"?>
‣ Element: a node in the structured tree of the document
<oneElement>...</oneElement>
<isImportant/> // open/close at once
‣ Content
<author>J.R.R. Tolkien</author>
<title><![CDATA[Laurel & Hardy]]></title>
‣ Attribute
<oneElement name="Carbon" symbol="C">
</oneElement>
32. XML: structure
‣ Header: encode for the charset (change if accent, japanese characters...)
<?xml version="1.0" encoding="ISO-8859-1"?>
‣ Element: a node in the structured tree of the document
<oneElement>...</oneElement>
<isImportant/> // open/close at once
‣ Content
<author>J.R.R. Tolkien</author>
<title><![CDATA[Laurel & Hardy]]></title>
‣ Attribute
<oneElement name="Carbon" symbol="C">
</oneElement>
‣ Comments
<!-- whatever comment (not parsed by default) -->
33. XML: child elements or attributes?
‣ What attribute cannot do?
- no nested structures
- no repeated attributes: <tag name="one" name="two"/> is not allowed
- limited characters, not CDATA for the value
34. XML: child elements or attributes?
‣ So, when to use attributes instead of elements?
- Attributes could be avoided and only child elements used. Usually, the
main part of the node information should be stored in sub chidren.
However attributes can have a natural use:
- for short information,
- for information that should be read at the element level (before diving
into its children nodes)
36. XML: cons
‣ File size
- large tag name for storing only one integer value
- list of data stored at once e.g. peak list in the mzXml-like file (base64)
37. XML: cons
‣ File size
- large tag name for storing only one integer value
- list of data stored at once e.g. peak list in the mzXml-like file (base64)
‣ Random access to data no native (data index can be stored)
38. XML: cons
‣ File size
- large tag name for storing only one integer value
- list of data stored at once e.g. peak list in the mzXml-like file (base64)
‣ Random access to data no native (data index can be stored)
‣ Hand edition can be tedious (but possible)
39. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
40. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
‣ XML structure definition
- Schema
- DTD
41. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
‣ XML structure definition
- Schema
- DTD
‣ XSLT for xml structure transformation
42. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
‣ XML structure definition
- Schema
- DTD
‣ XSLT for xml structure transformation
‣ namespaces
43. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
‣ XML structure definition
- Schema
- DTD
‣ XSLT for xml structure transformation
‣ namespaces
‣ storing binary data
44. XML: what we will not talk about (today...)
‣ XML file generation
- it is simple text file
- Groovy uses XmlTemplateEngine
‣ XML structure definition
- Schema
- DTD
‣ XSLT for xml structure transformation
‣ namespaces
‣ storing binary data
‣ We will focus on retrieving information from an xml file (or String)
45. XML: parsing challenges
‣ A common need: retrieve partial information (substructure or filtered with
criteria)
- syntax to access to info within the tree
- navigate through all children
46. XML: parsing challenges
‣ A common need: retrieve partial information (substructure or filtered with
criteria)
- syntax to access to info within the tree
- navigate through all children
‣ XML tree can be large (>4GB for uniprot.xml)
- no possible to load everything at once, then scan through memory
- loop across all substructure (e.g. a uniprot entry), then access to
descendant easily and release memory before opening next entry
47. XML: parsing challenges
‣ A common need: retrieve partial information (substructure or filtered with
criteria)
- syntax to access to info within the tree
- navigate through all children
‣ XML tree can be large (>4GB for uniprot.xml)
- no possible to load everything at once, then scan through memory
- loop across all substructure (e.g. a uniprot entry), then access to
descendant easily and release memory before opening next entry
‣ Groovy
- XmlParser: access and modify the tree, but all is in memory. Not
covered here
- XmlSlurper: lazy loading, access through iterators, readonly access
48. XML: XmlSlurper
‣ XmlSlurper parse a source into a structure ready for traversing
def records=new XmlSlurper().parseText(aStringWithXml)
def records=new XmlSlurper().parse(new File(aStringPath))
49. XML: XmlSlurper
‣ XmlSlurper parse a source into a structure ready for traversing
def records=new XmlSlurper().parseText(aStringWithXml)
def records=new XmlSlurper().parse(new File(aStringPath))
‣ Parsing is done iterating through NodeChildren
(groovy.util.slurpersupport.NodeChildren), specifying a path &
constraints in the xml tree
50. XML: XmlSlurper (cont’d)
‣ All the document is not loaded at once, but only the matching subtrees,
one after the other
51. XML: XmlSlurper (cont’d)
‣ All the document is not loaded at once, but only the matching subtrees,
one after the other
‣ Compared to other xml parser, it corresponds to a mix between DOM and
SAX methods
52. XML: XmlSlurper (cont’d)
‣ All the document is not loaded at once, but only the matching subtrees,
one after the other
‣ Compared to other xml parser, it corresponds to a mix between DOM and
SAX methods
‣ Perl equivalent would be the module XML::Twig
54. XmlSlurper accessing a single element
‣ Instantiating the slurper
def dataDef = new XmlSlurper().parseText( xmlText )
55. XmlSlurper accessing a single element
‣ Instantiating the slurper
def dataDef = new XmlSlurper().parseText( xmlText )
‣ Single element
<inSilicoDefinitions>
<description>
<source type="program">
<name>elementator</name>
<isValidated/>
</source>
</description>
def source=dataDef.description.source
56. XmlSlurper accessing a single element
‣ Instantiating the slurper
def dataDef = new XmlSlurper().parseText( xmlText )
‣ Single element
<inSilicoDefinitions>
<description>
<source type="program">
<name>elementator</name>
<isValidated/>
</source>
</description>
def source=dataDef.description.source
‣ Reading an attribute
source.@type.text() // -> ‘program’
57. XmlSlurper accessing a single element
‣ Instantiating the slurper
def dataDef = new XmlSlurper().parseText( xmlText )
‣ Single element
<inSilicoDefinitions>
<description>
<source type="program">
<name>elementator</name>
<isValidated/>
</source>
</description>
def source=dataDef.description.source
‣ Reading an attribute
source.@type.text() // -> ‘program’
‣ Reading a sub element contents
source.name.text() // -> ‘elementator’
58. XmlSlurper: selecting a list
‣ Getting all substructure giving a path will generate an array
dataDef.elements.oneElement // 3 elements
59. XmlSlurper: selecting a list
‣ Getting all substructure giving a path will generate an array
dataDef.elements.oneElement // 3 elements
‣ Can be visited with closure
insilicoDef.elements.oneElement.each{println it.@symbol}
insilicoDef.elements.oneElement.collect{it.mass.@average.toDouble()}
60. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
61. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
‣ Getting oneElement where symbol attribute has 2 characters
insilicoDef.elements.oneElement.findAll{
it.@symbol.text() ==~ /../
}
62. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
‣ Getting oneElement where symbol attribute has 2 characters
insilicoDef.elements.oneElement.findAll{
it.@symbol.text() ==~ /../
}
‣ Where mass children has monoisotopic attribute is >6
findAll{ (it.mass.@monoisotopic.text() as BigDecimal) > 6 }
63. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
‣ Getting oneElement where symbol attribute has 2 characters
insilicoDef.elements.oneElement.findAll{
it.@symbol.text() ==~ /../
}
‣ Where mass children has monoisotopic attribute is >6
findAll{ (it.mass.@monoisotopic.text() as BigDecimal) > 6 }
‣ Elements with exactly 2 isotopes.oneIsotope children
findAll{ it.isotopes.oneIsotope.size() == 2 }
64. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
‣ Getting oneElement where symbol attribute has 2 characters
insilicoDef.elements.oneElement.findAll{
it.@symbol.text() ==~ /../
}
‣ Where mass children has monoisotopic attribute is >6
findAll{ (it.mass.@monoisotopic.text() as BigDecimal) > 6 }
‣ Elements with exactly 2 isotopes.oneIsotope children
findAll{ it.isotopes.oneIsotope.size() == 2 }
‣ Getting the first element and piping closures
insilicoDef.elements.oneElement[0]
.isotopes.oneIsotope.'@mass'*.toDouble().sum()
65. XmlSlurper: subtree with constraints with findAll
‣ We can add constraints on the element to be actually walked through
‣ Getting oneElement where symbol attribute has 2 characters
insilicoDef.elements.oneElement.findAll{
it.@symbol.text() ==~ /../
}
‣ Where mass children has monoisotopic attribute is >6
findAll{ (it.mass.@monoisotopic.text() as BigDecimal) > 6 }
‣ Elements with exactly 2 isotopes.oneIsotope children
findAll{ it.isotopes.oneIsotope.size() == 2 }
‣ Getting the first element and piping closures
insilicoDef.elements.oneElement[0]
.isotopes.oneIsotope.'@mass'*.toDouble().sum()
‣ http://groovy.codehaus.org/Reading+XML+using+Groovy%27s
66. Object Oriented Programming : class
‣ Although Groovy can be seen as a scripting language, with a rather loose
syntax (think of dynamic typing with def), it is is also fully OO
67. Object Oriented Programming : class
‣ Although Groovy can be seen as a scripting language, with a rather loose
syntax (think of dynamic typing with def), it is is also fully OO
‣ Based on Java, enforcing string OO design, but still adding freedom of
scripting
68. Object Oriented Programming : class
‣ Although Groovy can be seen as a scripting language, with a rather loose
syntax (think of dynamic typing with def), it is is also fully OO
‣ Based on Java, enforcing string OO design, but still adding freedom of
scripting
‣ The basic component of OOP is a Class, a structure containing
- enforced properties, named fields
- actions, names methods
70. OOP one example: Date
‣ Like Mr Jourdain, you use OOP...
‣ Instance (on object)
- Date d = new Date()
71. OOP one example: Date
‣ Like Mr Jourdain, you use OOP...
‣ Instance (on object)
- Date d = new Date()
‣ Setter/getter
- println d.month
- d.year = 2012
72. OOP one example: Date
‣ Like Mr Jourdain, you use OOP...
‣ Instance (on object)
- Date d = new Date()
‣ Setter/getter
- println d.month
- d.year = 2012
‣ Operation
- Date d2 = d - 1
74. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
75. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
‣ Then a script uses this class
Person guy=new Person(name:'Joe',
birth:new Date('3/12/1980'))
println "$guy.name is ${guy.age()}" // -> Joe is 30
76. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
‣ Then a script uses this class
Person guy=new Person(name:'Joe',
birth:new Date('3/12/1980'))
println "$guy.name is ${guy.age()}" // -> Joe is 30
77. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
‣ Then a script uses this class
Person guy=new Person(name:'Joe',
birth:new Date('3/12/1980'))
println "$guy.name is ${guy.age()}" // -> Joe is 30
78. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
‣ Then a script uses this class
Person guy=new Person(name:'Joe',
birth:new Date('3/12/1980'))
println "$guy.name is ${guy.age()}" // -> Joe is 30
79. Class: an introduction
‣ An first example
class Person{
String name // field of type String
Date birth // field of type Date
int age(){ // a method returning an int
return (new Date()).year - birth.year
}
}
‣ Then a script uses this class
Person guy=new Person(name:'Joe',
birth:new Date('3/12/1980'))
println "$guy.name is ${guy.age()}" // -> Joe is 30
80. Making a new class
‣ By convention, class name starts with an upper case (when variable usually
start with lower case)
81. Making a new class
‣ By convention, class name starts with an upper case (when variable usually
start with lower case)
‣ Within a source directory, create a package (a subdirectory structure,
where ‘.’ is a directory path separator), for example
unige.mpb.eop.proteomics.sequence
82. Making a new class
‣ By convention, class name starts with an upper case (when variable usually
start with lower case)
‣ Within a source directory, create a package (a subdirectory structure,
where ‘.’ is a directory path separator), for example
unige.mpb.eop.proteomics.sequence
‣ In eclipse File -> new -> package (<ctrl>-N package)
83. Making a new class
‣ By convention, class name starts with an upper case (when variable usually
start with lower case)
‣ Within a source directory, create a package (a subdirectory structure,
where ‘.’ is a directory path separator), for example
unige.mpb.eop.proteomics.sequence
‣ In eclipse File -> new -> package (<ctrl>-N package)
‣ Within this package, create a class : File -> new -> groovy class and set
name Protein.
84. Making a new class
‣ By convention, class name starts with an upper case (when variable usually
start with lower case)
‣ Within a source directory, create a package (a subdirectory structure,
where ‘.’ is a directory path separator), for example
unige.mpb.eop.proteomics.sequence
‣ In eclipse File -> new -> package (<ctrl>-N package)
‣ Within this package, create a class : File -> new -> groovy class and set
name Protein.
‣ A Protein.groovy file is create with
package unige.mpb.eop.proteomics.sequence
class Protein{
...
}
85. Class: fields
‣ Fields are properties of a class, they can be dynamically or statically typed
(of any existing type (Integer, List, Map, etc...)
86. Class: fields
‣ Fields are properties of a class, they can be dynamically or statically typed
(of any existing type (Integer, List, Map, etc...)
‣ Field are by default associated to an instance of the class (an object
generated by new Person())
87. Class: fields
‣ Fields are properties of a class, they can be dynamically or statically typed
(of any existing type (Integer, List, Map, etc...)
‣ Field are by default associated to an instance of the class (an object
generated by new Person())
‣ They can be changed directly from outside the class (GBean)
guy.name = ‘Jimmy‘
guy.setName(‘Jimmy’)
88. Class: fields
‣ Fields are properties of a class, they can be dynamically or statically typed
(of any existing type (Integer, List, Map, etc...)
‣ Field are by default associated to an instance of the class (an object
generated by new Person())
‣ They can be changed directly from outside the class (GBean)
guy.name = ‘Jimmy‘
guy.setName(‘Jimmy’)
‣ Or read
println guy.name
println guy.getName()
89. Class: fields
‣ Fields are properties of a class, they can be dynamically or statically typed
(of any existing type (Integer, List, Map, etc...)
‣ Field are by default associated to an instance of the class (an object
generated by new Person())
‣ They can be changed directly from outside the class (GBean)
guy.name = ‘Jimmy‘
guy.setName(‘Jimmy’)
‣ Or read
println guy.name
println guy.getName()
‣ Inside a method, the instance properties are directly used by their name
int age(){return (new Date()).year - birth.year}
90. Class: static fields
‣ Fields can also be static i.e. a global value, shared by all instances of the
class (by convention upper case).
91. Class: static fields
‣ Fields can also be static i.e. a global value, shared by all instances of the
class (by convention upper case).
‣ If we come back to our previous Person example, we want
static int AGE_LIMIT = 18
boolean canDrive(){return age >= AGE_LIMIT}
92. Class: static fields
‣ Fields can also be static i.e. a global value, shared by all instances of the
class (by convention upper case).
‣ If we come back to our previous Person example, we want
static int AGE_LIMIT = 18
boolean canDrive(){return age >= AGE_LIMIT}
‣ We can change this value at once for all Person instances
Person.AGE_LIMIT = 16
93. Constructor
‣ Thanks to the scripting spirit, there is no need to declare constructor (the
function to instantiate an object)
94. Constructor
‣ Thanks to the scripting spirit, there is no need to declare constructor (the
function to instantiate an object)
‣ Field can be filled with a map structure
Person girl=new Person(name:‘Marylyn’)
95. Constructor
‣ Thanks to the scripting spirit, there is no need to declare constructor (the
function to instantiate an object)
‣ Field can be filled with a map structure
Person girl=new Person(name:‘Marylyn’)
‣ It is not compulsory to set all the field
96. Constructor
‣ Thanks to the scripting spirit, there is no need to declare constructor (the
function to instantiate an object)
‣ Field can be filled with a map structure
Person girl=new Person(name:‘Marylyn’)
‣ It is not compulsory to set all the field
‣ To set default value to a field, you can define it in the property declaration
String name=‘John Doe’
98. Methods
‣ Methods are functions, with are called within the context of an object
instance
99. Methods
‣ Methods are functions, with are called within the context of an object
instance
‣ All properties of the instance are accessed directly
100. Methods
‣ Methods are functions, with are called within the context of an object
instance
‣ All properties of the instance are accessed directly
‣ It is possible to modify the instance, directly addressing the instance fields
101. Methods
‣ Methods are functions, with are called within the context of an object
instance
‣ All properties of the instance are accessed directly
‣ It is possible to modify the instance, directly addressing the instance fields
‣ It is possible to pass argument to the function
102. Methods
‣ Methods are functions, with are called within the context of an object
instance
‣ All properties of the instance are accessed directly
‣ It is possible to modify the instance, directly addressing the instance fields
‣ It is possible to pass argument to the function
‣ It is possible to return a value (of whatever type)
103. Unit testing
‣ Each method of a class must be tested, to ensure it fulfills the intended
goals
104. Unit testing
‣ Each method of a class must be tested, to ensure it fulfills the intended
goals
‣ One class file = one test file
- in another directory (src/test)
- same package name
- MyClass.groovy => MyClassTest.groovy
105. Unit testing
‣ Each method of a class must be tested, to ensure it fulfills the intended
goals
‣ One class file = one test file
- in another directory (src/test)
- same package name
- MyClass.groovy => MyClassTest.groovy
‣ Eclipse/groovy offers a integrated environment for that purpose
106. Unit testing (cont’d)
‣ In another source folder (typically src/tests/groovy), test will be
generated:
- select a class
- File -> new -> Groovy Test Case
- select the other src/test/groovy source folder
- select junit 3 (better for later use of grails for the moment)
- next -> select methods to be tested
107. Unit testing (cont’d)
‣ In another source folder (typically src/tests/groovy), test will be
generated:
- select a class
- File -> new -> Groovy Test Case
- select the other src/test/groovy source folder
- select junit 3 (better for later use of grails for the moment)
- next -> select methods to be tested
‣ In junit 3, any method with name starting with test* will be used as test
108. Unit testing (cont’d)
‣ In another source folder (typically src/tests/groovy), test will be
generated:
- select a class
- File -> new -> Groovy Test Case
- select the other src/test/groovy source folder
- select junit 3 (better for later use of grails for the moment)
- next -> select methods to be tested
‣ In junit 3, any method with name starting with test* will be used as test
‣ right button -> run as -> junit test (<ctrl>-<alt>-X-T)
109. Unit testing (cont’d)
‣ In another source folder (typically src/tests/groovy), test will be
generated:
- select a class
- File -> new -> Groovy Test Case
- select the other src/test/groovy source folder
- select junit 3 (better for later use of grails for the moment)
- next -> select methods to be tested
‣ In junit 3, any method with name starting with test* will be used as test
‣ right button -> run as -> junit test (<ctrl>-<alt>-X-T)
‣ Customize show view (<ctrl>-<alt>-Q-U + down arrow and tab)
Notas del editor
\n
horizontal learning\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
read the function shortcuts and try to memorize your most commons\n
wget, use -O\n
wget, use -O\n
wget, use -O\n
carbon case\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
I don&#x2019;t see any advantage of storing info in text file, except maybe for large output of data in a very controlled environment, or for piping local info (think of exporting data to R)\nGB is cheap, speed in reading is often not the major issue\n
\n
\n
\n
widely used solution in bioinformatics - a very common way to export data\nOpen office and even MS Word / excel native file format is now XML\n\n
root of the document is a single el containing it all\ntake care of nesting comments\n
root of the document is a single el containing it all\ntake care of nesting comments\n
root of the document is a single el containing it all\ntake care of nesting comments\n
root of the document is a single el containing it all\ntake care of nesting comments\n
root of the document is a single el containing it all\ntake care of nesting comments\n
almost a philosophical question (computer scientist philosophy???)\nsome love all attributes or all elements\na middle line is often a good practical tradeoff\n
almost a philosophical question (computer scientist philosophy???)\nsome love all attributes or all elements\na middle line is often a good practical tradeoff\n
disk is cheap\nfast disk (even SSD)\nfile in memory\n
disk is cheap\nfast disk (even SSD)\nfile in memory\n
disk is cheap\nfast disk (even SSD)\nfile in memory\n
\n
\n
\n
\n
\n
\n
only the amino acid from a global chemical definition file\ndon&#x2019;t load the isotopic distribution\nonly element with mass <100Da ...\na factor 10 in term of memory\n
only the amino acid from a global chemical definition file\ndon&#x2019;t load the isotopic distribution\nonly element with mass <100Da ...\na factor 10 in term of memory\n
only the amino acid from a global chemical definition file\ndon&#x2019;t load the isotopic distribution\nonly element with mass <100Da ...\na factor 10 in term of memory\n
GPathResult\nDOM => memory ~ 10x the file (swissProt.xml = 4GB)\n
GPathResult\nDOM => memory ~ 10x the file (swissProt.xml = 4GB)\n
GPathResult\nDOM => memory ~ 10x the file (swissProt.xml = 4GB)\n
GPathResult\nDOM => memory ~ 10x the file (swissProt.xml = 4GB)\n
GPathResult\nDOM => memory ~ 10x the file (swissProt.xml = 4GB)\n
see lecture 4 project on dokeos lecture demo script\n
root element is not to be specified in the path\nconversion to String with .text()\nwe could go recursively to children\n
root element is not to be specified in the path\nconversion to String with .text()\nwe could go recursively to children\n
root element is not to be specified in the path\nconversion to String with .text()\nwe could go recursively to children\n
root element is not to be specified in the path\nconversion to String with .text()\nwe could go recursively to children\n
it.@symbol => toString() conversion by default\n
it.@symbol => toString() conversion by default\n
will be very similar with database SELECT like philosophy\n*. to apply \n
will be very similar with database SELECT like philosophy\n*. to apply \n
will be very similar with database SELECT like philosophy\n*. to apply \n
will be very similar with database SELECT like philosophy\n*. to apply \n
will be very similar with database SELECT like philosophy\n*. to apply \n
will be very similar with database SELECT like philosophy\n*. to apply \n
&#x201C;enforced&#x201D; contrary to map\nwe see a very few basics today, we&#x2019;ll go in more details in the following lectures\n * more OOP functionalities\n * OOP patterns\ngo to exercise to see in more details\n
&#x201C;enforced&#x201D; contrary to map\nwe see a very few basics today, we&#x2019;ll go in more details in the following lectures\n * more OOP functionalities\n * OOP patterns\ngo to exercise to see in more details\n
&#x201C;enforced&#x201D; contrary to map\nwe see a very few basics today, we&#x2019;ll go in more details in the following lectures\n * more OOP functionalities\n * OOP patterns\ngo to exercise to see in more details\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
a file Protein.groovy is created\npackage & class file are only directories & files => no magic, use any text editor\n
a file Protein.groovy is created\npackage & class file are only directories & files => no magic, use any text editor\n
a file Protein.groovy is created\npackage & class file are only directories & files => no magic, use any text editor\n
a file Protein.groovy is created\npackage & class file are only directories & files => no magic, use any text editor\n
a file Protein.groovy is created\npackage & class file are only directories & files => no magic, use any text editor\n
setter /getter with java standard\nno properties with reserved word\nif needed access to field directly through gui.@name\n
setter /getter with java standard\nno properties with reserved word\nif needed access to field directly through gui.@name\n
setter /getter with java standard\nno properties with reserved word\nif needed access to field directly through gui.@name\n
setter /getter with java standard\nno properties with reserved word\nif needed access to field directly through gui.@name\n
setter /getter with java standard\nno properties with reserved word\nif needed access to field directly through gui.@name\n