<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Adding optional relationships changes the dcnt value
SYNOPSIS
Step1:  2) Depth-01 term, GO
Step2:  Notice that dcnt=0 for GO
Step3:  3) Depth-01 term, GO
Step4:  4) Depth-01 term, GO
Step5:  5) Descendants under GO
Step6:  6) Plot descendants of virion
<ASSISTANT_TASK:>
Python Code:
from goatools.base import get_godag
godag = get_godag("go-basic.obo", optional_attrs={'relationship'})
go_leafs = set(o.item_id for o in godag.values() if not o.children)
Explanation: Adding optional relationships changes the dcnt value
SYNOPSIS: For GO:0019012, virion, the descendants count dcnt, is:
  * 0 when using is_a relationships (the default) and 
  * 48 when adding the optional relationship, part_of.
Table of Contents:  
  1. Download Ontologies, if necessary
  2. Depth-01 term, virion, has dcnt=0 through is_a relationships (default)
  3. Depth-01 term, virion, dcnt value is higher using all relationships
  4. Depth-01 term, virion, dcnt value is higher using part_of relationships
  5. Descendants under virion
  6. Plot some descendants of virion
1) Download Ontologies, if necessary
End of explanation
virion = 'GO:0019012'
from goatools.gosubdag.gosubdag import GoSubDag
gosubdag_r0 = GoSubDag(go_leafs, godag)
Explanation: 2) Depth-01 term, GO:0019012 (virion) has dcnt=0 through is_a relationships (default)
GO:0019012, virion, has no GO terms below it through the is_a relationship, so the default value of dcnt will be zero, even though it is very high in the DAG at depth=01.
End of explanation
nt_virion = gosubdag_r0.go2nt[virion]
print(nt_virion)
print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))
Explanation: Notice that dcnt=0 for GO:0019012, virion, even though it is very high in the DAG hierarchy (depth=1). This is because there are no GO IDs under GO:0019012 (virion) using the is_a relationship.
End of explanation
gosubdag_r1 = GoSubDag(go_leafs, godag, relationships=True)
nt_virion = gosubdag_r1.go2nt[virion]
print(nt_virion)
print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))
Explanation: 3) Depth-01 term, GO:0019012 (virion) dcnt value is higher using all relationships
Load all relationships into GoSubDag using relationships=True
End of explanation
gosubdag_partof = GoSubDag(go_leafs, godag, relationships={'part_of'})
nt_virion = gosubdag_partof.go2nt[virion]
print(nt_virion)
print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))
Explanation: 4) Depth-01 term, GO:0019012 (virion) dcnt value is higher using part_of relationships
Load all relationships into GoSubDag using relationships={'part_of'}
End of explanation
virion_descendants = gosubdag_partof.rcntobj.go2descendants[virion]
print('{N} descendants of virion were found'.format(N=len(virion_descendants)))
Explanation: 5) Descendants under GO:0019012 (virion)
End of explanation
from goatools.gosubdag.plot.gosubdag_plot import GoSubDagPlot
# Limit plot of descendants to get a smaller plot
virion_capsid_fiber = {'GO:0098033', 'GO:0098032'}
nts = gosubdag_partof.prt_goids(virion_capsid_fiber, 
                         '{NS} {GO} dcnt({dcnt}) D-{depth:02} {GO_name}')
# Limit plot size by choosing just two virion descendants
# Get a subset containing only a couple virion descendants and their ancestors
pltdag = GoSubDag(virion_capsid_fiber, godag, relationships={'part_of'})
pltobj = GoSubDagPlot(pltdag)
pltobj.plt_dag('virion_capsid_fiber.png')
Explanation: 6) Plot descendants of virion
End of explanation
<END_TASK>