โครงสร้างของไฟล์ .mat ใน Python
ในแบบฝึกหัดนี้ เราจะมาดูกันว่า dictionary ของ MATLAB ที่โหลดไว้ในแบบฝึกหัดก่อนหน้านั้นมีอะไรอยู่บ้าง
ไฟล์ 'albeck_gene_expression.mat' ถูกโหลดไว้ในตัวแปร mat เรียบร้อยแล้ว และได้ import ไลบรารีต่อไปนี้ไว้แล้วเช่นกัน:
import scipy.io
import matplotlib.pyplot as plt
import numpy as np
ไฟล์นี้มีข้อมูลการแสดงออกของยีน (gene expression) จาก Albeck Lab ที่ UCDavis เช่นเดิม
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Python เบื้องต้น: การนำเข้าข้อมูล
คำแนะนำการฝึกหัด
- ใช้เมธอด
.keys()กับ dictionarymatเพื่อพิมพ์ key ทั้งหมด key ส่วนใหญ่ (โดยเฉพาะที่ไม่ได้ขึ้นต้นและลงท้ายด้วย '__') คือตัวแปรจาก MATLAB environment ที่เกี่ยวข้อง - พิมพ์ชนิดข้อมูลของค่าที่ตรงกับ key
'CYratioCyt'ในmatโดยใช้mat['CYratioCyt']เพื่อเข้าถึงค่าดังกล่าว - พิมพ์ shape ของค่าที่ตรงกับ key
'CYratioCyt'โดยใช้ฟังก์ชันshape()ของnumpy - รันสคริปต์ทั้งหมดเพื่อดูข้อมูล gene expression แบบ oscillatory!
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Print the keys of the MATLAB dictionary
print(____)
# Print the type of the value corresponding to the key 'CYratioCyt'
# Print the shape of the value corresponding to the key 'CYratioCyt'
# Subset the array and plot it
data = mat['CYratioCyt'][25, 5:]
fig = plt.figure()
plt.plot(data)
plt.xlabel('time (min.)')
plt.ylabel('normalized fluorescence (measure of expression)')
plt.show()