python.phytomine - k821209/pipelines GitHub Wiki

module

from intermine.webservice import Service
service = Service("http://phytozome.jgi.doe.gov/phytomine/service")

desc ret

def get_desc(name): # genename 
    template = service.get_template('Gene_info')
    rows = template.rows(
            A = {"op": "=", "value": name}
            )
    for row in rows:
        return row["briefDescription"]

pep ret

def get_pep(name): # name should be transcript name
    template = service.get_template('Transcript_peptide_sequence')
    rows = template.rows(
        A = {"op": "=", "value": name}
        )
    for row in rows:
        return row["sequence.residues"]

cds ret

def get_cds(name): # name should be transcript name
    template = service.get_template('Transcript_CDS_sequence')
    rows = template.rows(
        A = {"op": "=", "value": name}
        )
    for row in rows:
        return row["CDSs.sequence.residues"]

gene info

def get_info(genelist): # genelist should be consisted with genenames
    dic = {"organism.shortName" : [],
           "primaryIdentifier" : [],
           "transcripts.primaryIdentifier" : [],
           "transcripts.protein.primaryIdentifier" : [],
           "briefDescription" : [],
           "symbol" : [],
           "description" : [],
           "CDSSequence" :[],
           "PEPSequence" : []}

    template = service.get_template('Gene_info')

    for gene in genelist:

            rows = template.rows(
                A = {"op": "=", "value": gene}
            )

            for row in rows:
                dic["organism.shortName"].append(row["organism.shortName"])
                dic["primaryIdentifier"].append(row["primaryIdentifier"])
                dic["transcripts.primaryIdentifier"].append(row["transcripts.primaryIdentifier"])
                dic["transcripts.protein.primaryIdentifier"].append(row["transcripts.protein.primaryIdentifier"])
                dic["briefDescription"].append(row["briefDescription"])
                dic["symbol"].append(row["symbol"])
                dic["description"].append(row["description"])
                dic["CDSSequence"].append(get_cds(row["transcripts.primaryIdentifier"]))
                dic["PEPSequence"].append(get_pep(row["transcripts.primaryIdentifier"]))
    return dic
def get_info(genelist): # genelist should be consisted with genenames
    dic = {"organism.shortName" : [],
           "primaryIdentifier" : [],
           "transcripts.primaryIdentifier" : [],
           "transcripts.protein.primaryIdentifier" : [],
           "briefDescription" : [],
           "symbol" : [],
           "description" : [],
           "CDSSequence" :[],
           "PEPSequence" : [],
           "Organism": []
          }

    # Get a new query on the class (table) you will be querying:
    query = service.new_query("Gene")

    # The view specifies the output columns
    query.add_view(
        "primaryIdentifier", "transcripts.primaryIdentifier",
        "transcripts.protein.primaryIdentifier", "briefDescription", "symbol",
        "description", "organism.shortName"
    )


    for gene in genelist:

            query.add_constraint("primaryIdentifier", "=", gene, code = "A")

            for row in query.rows():
                dic["organism.shortName"].append(row["organism.shortName"])
                dic["primaryIdentifier"].append(row["primaryIdentifier"])
                dic["transcripts.primaryIdentifier"].append(row["transcripts.primaryIdentifier"])
                dic["transcripts.protein.primaryIdentifier"].append(row["transcripts.protein.primaryIdentifier"])
                dic["briefDescription"].append(row["briefDescription"])
                dic["symbol"].append(row["symbol"])
                dic["description"].append(row["description"])
                dic["CDSSequence"].append(get_cds(row["transcripts.primaryIdentifier"]))
                dic["PEPSequence"].append(get_pep(row["transcripts.primaryIdentifier"]))
                dic["Organism"].append(row["organism.shortName"])
    return dic