























Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!
























Politecnico di Milano, DEIB Rosario M. Piro, Pietro Pinoli
Final exam (90 min), 14 th^ June 2022
Name: Immatriculation number:
Qapla’!
[1] if (!requireNamespace("BiocManager", quietly = TRUE)) [2] install.packages("BiocManager") [3] BiocManager::install("edgeR")
(a) ( points) Describe the meaning of :: in the last command.
(b) ( points) What will the following simple expressions return when they are executed?
(a) ( points) Given the following factor: myfac <- factor(1:4, 3)
(b) ( points) Given a list named “mylist” which contains three numeric matrices, e.g., $mat [,1] [,2] [1,] 1 3 [2,] 2 4
$mat [,1] [,2] [,3] [1,] 7 9 11 [2,] 8 10 12
$mat [,1] [,2] [1,] 0.1 0. [2,] 0.2 0.
a) What is GIL? How does it prevent a Python Script to be parallelized?
b)What is task switchng? Is it correlated with concurrent programming? Is it equivalent to true hardware parallelism?
(a) ( points) How do numpy’s multidimensional arrays reduce memory usage?
(b) ( points) What is a Pandas series? How is it related to a numpy array?
In the following multiple choice questions (2 points each), you have to choose the single best answer.
(a) Input and Output of getSeq? Input: Bsgenome, GRanges / Output: DNAStringSet
(b) Using the testthat framework for unit testing, how can you check whether two numeric vectors vecA and vecB contain exactly the same numbers? ◦ expect_match(vecA, vecB) ◦ expect_match(vecA, vecB, each_element=TRUE) ◦ expect_equal(vecA, vecB) ◦ expect_equal(vecA, vecB, each_element=TRUE)
(c) Consider the following type of object.Which of this object can contain multiple elements? XStringSet, GRanges, GRangesList, CompressedVCF
all of them XStringSet, GRanges, GRangesList GRanges, GRangesList, CompressedVCF XstringSet, GRangesList
Politecnico di Milano, DEIB Rosario M. Piro, Pietro Pinoli
Final exam (90 min), 14th^ June 2022
Name: Immatriculation number:
Qapla’!
A1 A2 A3 A4 A5 A6 A7 (Bonus)
[1] if (!requireNamespace("BiocManager", quietly = TRUE)) [2] install.packages("BiocManager") [3] BiocManager::install("edgeR")
(a) (6 points) Describe what each of these three lines mean and what exactly happens if they are exe- cuted!
(b) (3 points) What will the following simple expressions return when they are executed?
Consider the differences between the S4 and Reference class systems. For each of the class systems imagine a class “student” with the data items “name” (string), “university” (string) and “id” (number). Let s4 be an object of the S4 class and sR an object of the Reference class. (a) (6 points) Define the classes as necessary and create the two objects s4 (S4 class) and sR (Reference class) with the values “Gigi”, “PoliMI” and ID 112.
(b) (4 points) Make examples for the following tasks: Task S4 class Reference class
Set the name to “Eva”
Verify that the object is of class “student”
Make a full copy of the object
If possible, verify that the object is of the re- spective class system (S4/Reference)
Consider the following files and folders (in alphabetical order):
decompT2S decompT2S.R decompT2S.Rd decompT2S.Rmd DESCRIPTION man NAMESPACE R test-decomp.R testthat testthat.R tests vignettes
Distribute them in the following figure such that it reflects the correct structure of an R package named “decompT2S” (folders have a gray background):
(a) (4 points) Why are numpy’s multidimensional arrays preferred over Python’s built-in structures for scientific programming, in particular when a high performance is needed?
(b) (4 points) What is a Pandas series? How is it related to a numpy array?
Use the Python module “socket” to write a very simple server that waits for incoming connections without doing anything in particular, except closing each connection immediately (no need for concur- rency and spawning new processes). You will need the functions (in alphabetical order):
accept(), bind(), close(), listen(), socket()
Additional hints:
Politecnico di Milano, DEIB Rosario M. Piro, Pietro Pinoli
Final exam (90 min), 1 st^ July 2022
Name: Immatriculation number:
Qapla’!
1. (9 points) Some R basics
(a) What is the difference between load and attach a package and in which case NameSpace is used?
(b) What is masking, what happens and how to call the masked function?
A1 A2 A3 A4 A5 A6 A7 (Bonus) 9 10 10 8 6 8 9 (6) (^) Σ
60
2. (10 points) Matrices in R
4. (8 points) Network programming
Given the following functions from the Python module socket (in alphabetical order) accept(), bind(), close(), connect(), listen(), recv(), send(), socket()
Using this functions, describe the typical initialization and data flow both on the client and the server side by
filling the following figure with the appropriate function names.
5. (6 points) Concurrent programming
What is the GIL (Global Interpreter Lock)? How does it prevent speed-up gain when trying to parallelize a Python script? What is the most common solution?