import ga4gh_client.client as client
c = client.HttpClient("http://1kgenomes.ga4gh.org")

"""
Explanation: GA4GH 1000 Genome Sequence Annotation Example
This example illustrates how to access the sequence annotations for a given set of ....
Initialize Client
In this step we create a client object which will be used to communicate with the server. It is initialized using the URL
End of explanation
"""


for feature_sets in c.search_feature_sets(dataset_id="WyIxa2dlbm9tZXMiXQ"):
    print feature_sets

"""
Explanation: Search featuresets method
--- Description --- dataset_id obtained from 1kg_metadata_service notebook.
End of explanation
"""


feature_set = c.get_feature_set(feature_set_id=feature_sets.id)
print feature_set

"""
Explanation: Get featureset by id request
By knowing the id of the featureset_id we can also obtain the set in a get request. Also note that in the following reuest we simply set feature_set_id to feature_sets.id which was obtained in the previous search request.
End of explanation
"""


counter = 0
for features in c.search_features(feature_set_id=feature_set.id):
    if counter > 5:
        break
    counter += 1
    print"Id: {},".format(features.id)
    print" Name: {},".format(features.name)
    print" Gene Symbol: {},".format(features.gene_symbol)
    print" Parent Id: {},".format(features.parent_id)
    if features.child_ids:
        for i in features.child_ids:
            print" Child Ids: {}".format(i)
    print" Feature Set Id: {},".format(features.feature_set_id)
    print" Reference Name: {},".format(features.reference_name)
    print" Start: {},\tEnd: {},".format(features.start, features.end)
    print" Strand: {},".format(features.strand)
    print"  Feature Type Id: {},".format(features.feature_type.id)
    print"  Feature Type Term: {},".format(features.feature_type.term)
    print"  Feature Type Sorce Name: {},".format(features.feature_type.source_name)
    print"  Feature Type Source Version: {}\n".format(features.feature_type.source_version)

"""
Explanation: Search features method
-- Description ~~
End of explanation
"""


feature = c.get_feature(feature_id=features.id)
print"Id: {},".format(feature.id)
print" Name: {},".format(feature.name)
print" Gene Symbol: {},".format(feature.gene_symbol)
print" Parent Id: {},".format(feature.parent_id)
if feature.child_ids:
    for i in feature.child_ids:
        print" Child Ids: {}".format(i)
print" Feature Set Id: {},".format(feature.feature_set_id)
print" Reference Name: {},".format(feature.reference_name)
print" Start: {},\tEnd: {},".format(feature.start, feature.end)
print" Strand: {},".format(feature.strand)
print"  Feature Type Id: {},".format(feature.feature_type.id)
print"  Feature Type Term: {},".format(feature.feature_type.term)
print"  Feature Type Sorce Name: {},".format(feature.feature_type.source_name)
print"  Feature Type Source Version: {}\n".format(feature.feature_type.source_version)
for vals in feature.attributes.vals:
    print"{}: {}".format(vals, feature.attributes.vals[vals].values[0].string_value)

"""
Explanation: Note: Not all of the elements returned in the response are present in the example. All of the parameters will be shown in the get by id method.
End of explanation
"""


