Problem

Figure 2. The probability of any outcome (leaf) in a probability tree diagram is given by the product of probabilities from the start of the tree to the outcome. For example, the probability that X is blue and Y is blue is equal to (2/5)(1/4), or 1/10.

Probability is the mathematical study of randomly occurring phenomena. We will model such a phenomenon with a random variable, which is simply a variable that can take a number of different distinct outcomes depending on the result of an underlying random process.

For example, say that we have a bag containing 3 red balls and 2 blue balls. If we let X represent the random variable corresponding to the color of a drawn ball, then the probability of each of the two outcomes is given by Pr(X=red)=35 and Pr(X=blue)=25.

Random variables can be combined to yield new random variables. Returning to the ball example, let Y model the color of a second ball drawn from the bag (without replacing the first ball). The probability of Y being red depends on whether the first ball was red or blue. To represent all outcomes of X and Y, we therefore use a probability tree diagram. This branching diagram represents all possible individual probabilities for X and Y, with outcomes at the endpoints ("leaves") of the tree. The probability of any outcome is given by the product of probabilities along the path from the beginning of the tree; see Figure 2 for an illustrative example.

An event is simply a collection of outcomes. Because outcomes are distinct, the probability of an event can be written as the sum of the probabilities of its constituent outcomes. For our colored ball example, let A be the event "Y is blue." Pr(A) is equal to the sum of the probabilities of two different outcomes:Pr(X=blue and Y=blue)+Pr(X=red and Y=blue), or 310+110=25 (see Figure 2 above).

Given: Three positive integers km, and n, representing a population containing k+m+n organisms: k individuals are homozygous dominant for a factor, m are heterozygous, and n are homozygous recessive.

Return: The probability that two randomly selected mating organisms will produce an individual possessing a dominant allele (and thus displaying the dominant phenotype). Assume that any two organisms can mate.



num1=29
num2=24
num3=19
case = num1+num2+num3
mendel = []
probability = 0

def combination(n,k):
numerator = 1
denominator = 1
k = min(n-k,k)
for i in range(1,k+1):
denominator*=i
numerator*=n+1-i
return numerator/denominator

total = combination(case,2)

for i in range(1,case+1):
if i <= num1:
mendel.append("AA")
elif i <= num1+num2:
mendel.append("Aa")
else:
mendel.append("aa")


for i in range(0,len(mendel)):
for j in range(i+1,len(mendel)):
if mendel[i]=="AA":
probability+=1
elif mendel[i]=="Aa" and mendel[j]=="Aa":
probability+=0.75
elif mendel[i]=="Aa" and mendel[j]=="aa":
probability+=0.5

print(round(probability/total,5))


Introduction to Mendelian Inheritanceclick to collapse

Figure 1. A Punnett square representing the possible outcomes of crossing a heterozygous organism (Yy) with a homozygous recessive organism (yy); here, the dominant allele Y corresponds to yellow pea pods, and the recessive allele y corresponds to green pea pods.

Modern laws of inheritance were first described by Gregor Mendel (an Augustinian Friar) in 1865. The contemporary hereditary model, called blending inheritance, stated that an organism must exhibit a blend of its parent's traits. This rule is obviously violated both empirically (consider the huge number of people who are taller than both their parents) and statistically (over time, blended traits would simply blend into the average, severely limiting variation).

Mendel, working with thousands of pea plants, believed that rather than viewing traits as continuous processes, they should instead be divided into discrete building blocks called factors. Furthermore, he proposed that every factor possesses distinct forms, called alleles.

In what has come to be known as his first law (also known as the law of segregation), Mendel stated that every organism possesses a pair of alleles for a given factor. If an individual's two alleles for a given factor are the same, then it is homozygous for the factor; if the alleles differ, then the individual is heterozygous. The first law concludes that for any factor, an organism randomly passes one of its two alleles to each offspring, so that an individual receives one allele from each parent.

Mendel also believed that any factor corresponds to only two possible alleles, the dominant and recessive alleles. An organism only needs to possess one copy of the dominant allele to display the trait represented by the dominant allele. In other words, the only way that an organism can display a trait encoded by a recessive allele is if the individual is homozygous recessive for that factor.

We may encode the dominant allele of a factor by a capital letter (e.g., A) and the recessive allele by a lower case letter (e.g., a). Because a heterozygous organism can possess a recessive allele without displaying the recessive form of the trait, we henceforth define an organism's genotypeto be its precise genetic makeup and its phenotype as the physical manifestation of its underlying traits.

The different possibilities describing an individual's inheritance of two alleles from its parents can be represented by a Punnett square; see Figure 1 for an example.


'Python > rosaland' 카테고리의 다른 글

Combing Through the Haystack  (0) 2018.11.30
Translating RNA into Protein  (0) 2018.11.30
Counting Point Mutations  (0) 2018.11.21
Computing GC Content  (0) 2018.11.21
Rabbits and Recurrence Relations  (0) 2018.11.16

openxlsx 패키지

이번 포스팅에서는 openxlsx 패키지를 이용하여 여러개의 데이터프레임을 하나의 엑셀파일에 저장해 보도록하겠습니다.

library(openxlsx)

Workbook을 만들고-sheet를 만들고-쓰고-저장하는 다음 4개의 함수를 기억하시면 됩니다. createWorkbook()-addWorksheet()-writeDataTable()-saveWorkbook()

우리가 사랑하는 iris와 mtcars로 예시 데이터를 만들어 보겠습니다.

a <- iris
b <- mtcars
  1. 예제 Workbook을 만들고
example <- createWorkbook("example")
example
## A Workbook object.
##
## Worksheets:
##  No worksheets attached
  1. Worksheet를 추가해줍니다.
addWorksheet(example, "a")
addWorksheet(example, "b")
example
## A Workbook object.
##
## Worksheets:
##  Sheet 1: "a"
##
##
##  Sheet 2: "b"
##
##
##
##  Worksheet write order: 1, 2
  1. 다음과 같이 만들어 놓은 Worksheet에 각 데이터를 넣을 수 있습니다.
writeDataTable(example,"a",a)
writeDataTable(example,"b",b)
  1. 저장해 줍니다. write.csv()와 비슷하게 사용하면 됩니다.
saveWorkbook(example, file="example.xlsx")

결과물은 다음과 같습니다.


출처 : https://youngjunna.github.io/2018/04/03/openxlsx/

'R' 카테고리의 다른 글

데이터프레임 column 위치(순서) 변경  (0) 2018.11.21
1차 자료형  (0) 2018.11.21
Bioconductor ShortRead  (0) 2018.11.15
scope <<-  (0) 2018.11.09
엑셀 변환을 위한 R script  (0) 2018.10.29

1. fdisk -l

   

   드라이브 목록을 확인한다.


# fdisk -l


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     1026047      512000   83  Linux

/dev/sda2         1026048  1469032447   734003200   83  Linux

/dev/sda3      1469032448  1510975487    20971520   83  Linux

/dev/sda4      1510975488  1953523711   221274112    5  Extended

/dev/sda5      1510977536  1531949055    10485760   83  Linux

/dev/sda6      1531951104  1552922623    10485760   83  Linux

/dev/sda7      1552924672  1560788991     3932160   82  Linux swap / Solaris

/dev/sda8      1560791040  1952958463   196083712   83  Linux


Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes, 7814037168 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes



   할당되지 않은 4TB 크기의 /dev/sdb 드라이브가 보인다. 이걸 파티션 할당해줘야 한다.

   (리눅스는 보통 첫번째 드라이브가 /dev/sda1,2,3...두번째 드라이브가 /dev/sdb1,2,3... 이렇게 설정된다.)



   2. fdisk /dev/[디스크명]


   새로운 하드디스크를 추가한다.


# fdisk /dev/sdb


Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.


Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x6ad31b53.


WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).



The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.


Command (m for help): m

Command action

     toggle a bootable flag

     edit bsd disklabel

     toggle the dos compatibility flag

     delete a partition

     create a new empty GPT partition table

     create an IRIX (SGI) partition table

     list known partition types

     print this menu

     add a new partition

     create a new empty DOS partition table

     print the partition table

     quit without saving changes

     create a new empty Sun disklabel

     change a partition's system id

     change display/entry units

     verify the partition table

     write table to disk and exit

     extra functionality (experts only)


Command (m for help): n

Partition type:

     primary (0 primary, 0 extended, 4 free)

     extended

Select (default p):p  

Partition number (1-4, default 1): 1

First sector (2048-4294967295, default 2048): 2048

Last sector, +sectors or +size{K,M,G} (2048-4294967294, default 4294967294):  #Enter를 치면 default로 잡힌다.  

Using default value 4294967294

Partition 1 of type Linux and of size 2 TiB is set 

#하드디스크의 용량은 4TB이지만, 파티션에 할당할 수 있는 최대 크기는 2TB다.


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks.

 


   3. mkfs -t [파일시스템] /dev/[디스크명]

   파일시스템 만들기.


mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

134217728 inodes, 536870655 blocks

26843532 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

16384 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 

102400000, 214990848, 512000000


Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 



   4. mount -t [파일시스템] /dev/[디스크명] 

   마운트하기.


mount -t ext4 /dev/sdb1 /second


df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

/dev/sdb1       2.0T   81M  1.9T   1% /second   # 새로 마운트한 드라이브가 보일 것이다.



   이렇게 하면 4TB의 하드디스크 중에 2TB를 할당해서 사용할 수 있다.


   그러나 2TB씩 쪼개서 사용하기 싫고 4TB를 통으로 사용하고 싶다면, 다르게 설정해줘야 한다. 



   5. 되돌리기


   우선, 추가해줬던 파티션을 삭제하고 마운트도 다시 해제하자.


fdisk /dev/sdb


WARNING: The size of this disk is 4.0 TB (4000787030016 bytes).

DOS partition table format can not be used on drives for volumes

larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 

partition table format (GPT).



The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

Welcome to fdisk (util-linux 2.23.2).


Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.



Command (m for help): m

Command action

     toggle a bootable flag

     edit bsd disklabel

     toggle the dos compatibility flag

     delete a partition

     create a new empty GPT partition table

     create an IRIX (SGI) partition table

     list known partition types

     print this menu

     add a new partition

     create a new empty DOS partition table

     print the partition table

     quit without saving changes

     create a new empty Sun disklabel

     change a partition's system id

     change display/entry units

     verify the partition table

     write table to disk and exit

     extra functionality (experts only)


Command (m for help): d

Selected partition 1

Partition 1 is deleted


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: 장치나 자원이 동작 중.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.


# umount /second


   df- h로 확인해보면 디스크를 추가하지 전의 원래 상태로 돌아옴을 확인할 수 있다. 




   6. 2TB를 초과하는 디스크 할당하기.


   2TB를 초과하는 파티션을 할당하기 위해선 parted 명령어를 사용해야 한다.


parted /dev/sdb

GNU Parted 3.1

Using /dev/sdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) help                                                             

  align-check TYPE N                        check partition N for TYPE(min|opt) alignment

  help [COMMAND]                           print general help, or help on COMMAND

  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)

  mkpart PART-TYPE [FS-TYPE] START END     make a partition

  name NUMBER NAME                         name partition NUMBER as NAME

  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a

        particular partition

  quit                                     exit program

  rescue START END                         rescue a lost partition near START and END

  rm NUMBER                                delete partition NUMBER

  select DEVICE                            choose the device to edit

  disk_set FLAG STATE                      change the FLAG on selected device

  disk_toggle [FLAG]                       toggle the state of FLAG on selected device

  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER

  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER

  unit UNIT                                set the default unit to UNIT

  version                                  display the version number and copyright information of GNU Parted

(parted) mklabel gpt                                                      

Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?

Yes/No? yes                                                               

(parted) unit TB  # 단위를 설정한다. GB or TB                                                         

(parted) mkpart primary 0.00TB 4.00TB  # 용량 설정 start end

(parted) print                                                            

Model: ATA HGST HDN726040AL (scsi)

Disk /dev/sdb: 4.00TB

Sector size (logical/physical): 512B/4096B

Partition Table: gpt

Disk Flags: 


Number  Start   End     Size    File system  Name     Flags

 1      0.00TB  4.00TB  4.00TB  ext4         primary         # 정상적으로 추가됐다.


(parted) quit 

Information: You may need to update /etc/fstab.                                   


   파일시스템을 만든다.

mkfs -t ext4 /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

244195328 inodes, 976754176 blocks

48837708 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=3124756480

29809 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 

102400000, 214990848, 512000000, 550731776, 644972544


Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done 


   마운트한다.

mount -t ext4 /dev/sdb1 /second


df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        20G   93M   19G   1% /

.

.

.

.

/dev/sdb1       3.6T   89M  3.4T   1% /second   # 마운트 완료



   이 과정을 모두 마쳤다면, /second 폴더에 넣는 파일들은 모두 새로 추가한 디스크에 저장될 것이다.


   그러나 재부팅 시 마운트가 자동으로 해제되기 때문에, 부팅할 때 자동으로 마운트를 해주는 설정을 해줘야 한다.



   7. fstab 파일 등록


   재부팅 시 자동마운트가 되도록 설정한다.


blkid   # 먼저 자동마운트 등록할 디스크의 UUID를 알아내야 한다.

/dev/sda1: UUID="22a87868-322e-4661-af01-93b2062044ce" TYPE="xfs" 

.

.

.

/dev/sdb1: UUID="e001a7f9-1154-129e-a916-dad0b54116f2" TYPE="ext4" PARTLABEL="primary" PARTUUID="52412c84-700e-2313-9e2f-c12b1ca1676a"


# vi /etc/fstab



#

# /etc/fstab

# Created by anaconda on Sat Sep 26 08:52:44 2015

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=1c407d96-e43b-4b52-af5f-b191560e8267 /                       ext4    defaults        1 1

.

.

.

.

UUID=e001a7f9-1154-129e-a916-dad0b54116f2 /second              ext4    defaults        1 2  # 여기에 추가한다.




   이렇게 하면 재부팅을 하더라도 자동마운트 된다.


   굳이 재부팅을 할 필요없이 자동으로 마운트가 되는지 확인하고 싶다면, 마운트를 해제하고 mount -a 을 해보면 된다.


'Linux' 카테고리의 다른 글

리눅스 캐시 메모리 정리  (0) 2018.12.11
PATH 설정  (0) 2018.10.15
리눅스 명령어  (0) 2018.10.11
리눅스 find & grep  (0) 2018.10.10

+ Recent posts