Operations on VariantCallSupport objects


In [1]:
import sys, os
from bl.vl.kb import KnowledgeBase

OME_HOST = os.getenv('OME_HOST', 'localhost')
OME_USER = os.getenv('OME_USER', 'test')
OME_PASSWD = os.getenv('OME_PASSWD', 'test')
CHECK_OME_VERSION = os.getenv('CHECK_OME_VERSION', "True") == "True"

BaseProxy = KnowledgeBase(driver='omero')

class Proxy(BaseProxy):
  def get_objects_dict(self, klass):
    return dict((o.label, o) for o in super(Proxy, self).get_objects(klass))

kb = Proxy(OME_HOST, OME_USER, OME_PASSWD, check_ome_version=CHECK_OME_VERSION)

def cleanup():
  print "# disconnecting the kb"
  kb.disconnect()

sys.exitfunc = cleanup

print
print "### KB ENV PRELOADED ###"
print "# connected to %s" % OME_HOST
print "# knowledge base: kb"
print "# extra method: kb.get_objects_dict"
print "########################"


### KB ENV PRELOADED ###
# connected to biobank04.crs4.it
# knowledge base: kb
# extra method: kb.get_objects_dict
########################

Reload a presaved vcs


In [2]:
vcss = kb.get_objects_dict(kb.VariantCallSupport)

In [3]:
vcss


Out[3]:
{'human_exom-V1-test+GRCh37.1': <bl.vl.kb.drivers.omero.variant_call_support.VariantCallSupport at 0x4845090>}

In [4]:
vcs = kb.genomics.get_vcs_by_label('human_exom-V1-test+GRCh37.1')

In [5]:
ref_gen = vcs.referenceGenome

In [6]:
ref_gen.label


Out[6]:
'GRCh37.1'

In [7]:
ref_gen.nChroms


Out[7]:
26

In [8]:
nodes = vcs.get_nodes()
for i in range(1, ref_gen.nChroms):
    print 'Chrom {} -> {} snps'.format(i, sum(nodes['chrom'] == i))


Chrom 1 -> 25100 snps
Chrom 2 -> 17502 snps
Chrom 3 -> 14762 snps
Chrom 4 -> 10377 snps
Chrom 5 -> 11518 snps
Chrom 6 -> 15466 snps
Chrom 7 -> 11323 snps
Chrom 8 -> 9069 snps
Chrom 9 -> 10365 snps
Chrom 10 -> 9641 snps
Chrom 11 -> 15840 snps
Chrom 12 -> 12472 snps
Chrom 13 -> 4441 snps
Chrom 14 -> 7831 snps
Chrom 15 -> 8355 snps
Chrom 16 -> 10551 snps
Chrom 17 -> 13235 snps
Chrom 18 -> 3797 snps
Chrom 19 -> 15212 snps
Chrom 20 -> 6517 snps
Chrom 21 -> 2866 snps
Chrom 22 -> 5225 snps
Chrom 23 -> 5205 snps
Chrom 24 -> 141 snps
Chrom 25 -> 226 snps

In [9]:
vcs.get_nodes()[0:10]


Out[9]:
array([(1, 762320), (1, 861349), (1, 865545), (1, 865584), (1, 865625),
       (1, 865628), (1, 865662), (1, 865665), (1, 865694), (1, 865700)], 
      dtype=[('chrom', '<i8'), ('pos', '<i8')])

Basic operations


In [10]:
vcs2 = vcs.selection(((1, 762320), (1, 865625)))

In [11]:
vcs3 = vcs.selection(((1, 865545), (1, 865665)))

In [12]:
vcs4 = vcs2.intersection(vcs3)

In [13]:
vcs4.get_nodes()


Out[13]:
array([(1, 865545), (1, 865584)], 
      dtype=[('chrom', '<i8'), ('pos', '<i8')])

In [14]:
vcs5 = vcs2.union(vcs3)

In [15]:
vcs5.get_nodes()


Out[15]:
array([(1, 762320), (1, 861349), (1, 865545), (1, 865584), (1, 865625),
       (1, 865628), (1, 865662)], 
      dtype=[('chrom', '<i8'), ('pos', '<i8')])

In [16]:
vcs6 = vcs2.complement(vcs3)

In [17]:
vcs6.get_nodes()


Out[17]:
array([(1, 762320), (1, 861349)], 
      dtype=[('chrom', '<i8'), ('pos', '<i8')])

Note that, unless we do a vcs.save(), the vcs below are all only in the RAM of the client.


In [18]:
len(vcs6)


Out[18]:
2

In [19]:
vcs6.label


Out[19]:
'0e88cf825c854cfcaaddf4d57dad80e2'

In [20]:
kb.get_objects_dict(kb.VariantCallSupport)


Out[20]:
{'human_exom-V1-test+GRCh37.1': <bl.vl.kb.drivers.omero.variant_call_support.VariantCallSupport at 0x4845090>}

In [21]:
vcs6.save()

In [22]:
kb.get_objects_dict(kb.VariantCallSupport)


Out[22]:
{'0e88cf825c854cfcaaddf4d57dad80e2': <bl.vl.kb.drivers.omero.variant_call_support.VariantCallSupport at 0x4870e50>,
 'human_exom-V1-test+GRCh37.1': <bl.vl.kb.drivers.omero.variant_call_support.VariantCallSupport at 0x4845090>}

In [23]:
kb.delete(vcs6)

In [24]:
kb.get_objects_dict(kb.VariantCallSupport)


Out[24]:
{'human_exom-V1-test+GRCh37.1': <bl.vl.kb.drivers.omero.variant_call_support.VariantCallSupport at 0x4845090>}

In [25]:
vcs6.get_nodes()


Out[25]:
array([(1, 762320), (1, 861349)], 
      dtype=[('chrom', '<i8'), ('pos', '<i8')])

In [ ]: