To transpose a PETScMatrix, use petsc4py, the petsc python interface.
You can also transpose the form by taking the adjoint of it and assembling it. The two approaches are shown below
from dolfin import *
from petsc4py import PETSc
import numpy as np
# Create mesh an unsymmetric form
mesh = UnitSquareMesh(100,100)
V = FunctionSpace(mesh, "CG", 1)
u, v= TrialFunction(V), TestFunction(V)
vec = as_vector((1,2))
a = inner(u,v)*dx + u*inner(vec, grad(v))*dx + inner(u,v)*ds
b = inner(1, v)*dx
A = assemble(a)
# Using dolfin
a_adj = adjoint(a)
A_adj_dolfin = assemble(a_adj)
Aadj_dolfin_np = A_adj_dolfin.array()
A_np = A.array()
assert(not np.allclose(A_np, Aadj_dolfin_np))
assert(np.allclose(A_np, Aadj_dolfin_np.T))
# Using PETSC
B = A.copy()
petsc_mat = as_backend_type(B).mat()
petsc_mat.transpose()
A_adj_petsc = PETScMatrix(petsc_mat)
Aadj_petsc_np = A_adj_petsc.array()
assert(np.allclose(Aadj_petsc_np, Aadj_dolfin_np))
assert(not np.allclose(Aadj_petsc_np, A_np))