In [2]:
    
import numpy as np
import skbio.stats.composition as cmpstn
    
In [9]:
    
# create communities with absolute abundances
## community 1
comm1 = np.array([500.0, 300.0, 200.0, 10.0, 10.0, 5.0, 5.0, 5.0, 5.0])
## commuity 2 (1st taxon has higher counts, but the others are the same)
comm2 = np.copy(comm1)
comm2[0] = comm2[0] + 1000.0
## commuity 3 (1st taxon has higher counts, but the others are the same)
comm3 = np.copy(comm1)
comm3 = comm3[comm3 > 5]
print comm1
print comm2
print comm3
    
    
In [10]:
    
# tranform absolute to relative abundace
comm1_rel = comm1 / np.sum(comm1)
comm2_rel = comm2 / np.sum(comm2)
comm3_rel = comm3 / np.sum(comm3)
print comm1
print comm2
print comm3
    
    
In [11]:
    
# pull out subset of taxa
#subs = np.arange(1,9)
comm1_sub = comm1[np.arange(1,comm1.shape[0])] 
comm2_sub = comm2[np.arange(1,comm2.shape[0])] 
comm3_sub = comm3[np.arange(1,comm3.shape[0])] 
print comm1_sub 
print comm2_sub 
print comm3_sub
    
    
In [12]:
    
# performing closure
comm1_sub_cls = comm1_sub / np.sum(comm1_sub)
comm2_sub_cls = comm2_sub / np.sum(comm2_sub)
comm3_sub_cls = comm3_sub / np.sum(comm3_sub)
print comm1_sub_cls
print comm2_sub_cls
print comm3_sub_cls
    
    
In [13]:
    
# overlapping taxa
print comm1_sub_cls[np.arange(4)]
print comm2_sub_cls[np.arange(4)]
print comm3_sub_cls[np.arange(4)]
    
    
In [14]:
    
# ratios of abundances
print '\nAbundance ratios of subset taxa (absolute abundances)'
print comm1[1] /  comm1[4]
print comm2[1] /  comm2[4]
print comm3[1] /  comm3[4]
print '\nAbundance ratios of subset taxa (relative abundances)'
print comm1_sub[0] /  comm1_sub[3]
print comm2_sub[0] /  comm2_sub[3]
print comm3_sub[0] /  comm3_sub[3]
print '\nAbundance ratios of subset taxa after transforming by the sum of the subset'
print comm1_sub_cls[0] /  comm1_sub_cls[3]
print comm2_sub_cls[0] /  comm2_sub_cls[3]
print comm3_sub_cls[0] /  comm3_sub_cls[3]
    
    
In [19]:
    
print comm1_sub_cls[0] /  comm2_sub_cls[0]
print comm1_sub_cls[0] /  comm3_sub_cls[0]
print comm2_sub_cls[0] /  comm3_sub_cls[0]