Ejemplo n.º 1
0
 def reverse( self, clone=True ):
     if clone:
         rval = self.clone()
     else:
         rval = self
     rval.sequence = transform.reverse( self.sequence )
     rval.quality = rval.quality[::-1]
     return rval
Ejemplo n.º 2
0
 def reverse(self, clone=True):
     if clone:
         rval = self.clone()
     else:
         rval = self
     rval.sequence = transform.reverse(self.sequence)
     rval.quality = rval.quality[::-1]
     return rval
Ejemplo n.º 3
0
 def reverse( self, clone = True ):
     #need to override how color space is reversed
     if clone:
         rval = self.clone()
     else:
         rval = self
     if rval.has_adapter_base():
         adapter = rval.sequence[0]
         #sequence = rval.sequence[1:]
         rval.sequence = self.color_space_converter.to_color_space( transform.reverse( self.color_space_converter.to_base_space( rval.sequence ) ), adapter_base = adapter )
     else:
         rval.sequence = transform.reverse( rval.sequence )
     
     if rval.is_ascii_encoded():
         rval.quality = rval.quality[::-1]
     else:
         rval.quality = reversed( rval.get_decimal_quality_scores() )
         rval.quality = "%s " % " ".join( map( str, rval.quality ) )
     return rval
Ejemplo n.º 4
0
    def forward(self, batch, h, c):
        """Compute tree-lstm prediction given a batch.

        Parameters
        ----------
        batch : dgl.data.SSTBatch
            The data batch.
        h : Tensor
            Initial hidden state.
        c : Tensor
            Initial cell state.

        Returns
        -------
        out
        """

        g = batch.graph
        h_bottom_up = self.propagate(g, self.cell_bottom_up, batch.X, h, c)

        g_rev = dgl.batch([reverse(gu) for gu in dgl.unbatch(batch.graph)])
        h_top_down = self.propagate(g_rev, self.cell_top_down,
                                    th.cat([batch.X, h_bottom_up], dim=1), h,
                                    c)

        # indexes of root nodes
        root_ids = batch.isroot.nonzero().flatten()
        # h of root nodes
        root_h_bottom_up = th.index_select(h_bottom_up, 0, root_ids)

        # limit of ids of trees in graphs batch
        lims_ids = root_ids.tolist() + [g.number_of_nodes()]

        trees_h = [
            h_top_down[s:e, :] for s, e in zip(lims_ids[:-1], lims_ids[1:])
        ]
        trees_isleaf = [
            batch.isleaf[s:e] for s, e in zip(lims_ids[:-1], lims_ids[1:])
        ]
        leaves_h_top_down = th.cat([
            th.mean(th.index_select(tree, 0,
                                    leaves.nonzero().flatten()),
                    dim=0).view(1, -1)
            for (tree, leaves) in zip(trees_h, trees_isleaf)
        ],
                                   dim=0)

        # average of h of non root node by tree
        #inner_h_top_down = th.cat([th.mean(h_top_down[s+1:e-1,:],dim=0).view(1,-1) for s, e in zip(lims_ids[:-1],lims_ids[1:])])
        out = th.cat([root_h_bottom_up, leaves_h_top_down], dim=1)
        #out = root_h_bottom_up
        return out
Ejemplo n.º 5
0
 def reverse( self, clone = True ):
     #need to override how decimal quality scores are reversed
     if clone:
         rval = self.clone()
     else:
         rval = self
     rval.sequence = transform.reverse( self.sequence )
     if rval.is_ascii_encoded():
         rval.quality = rval.quality[::-1]
     else:
         rval.quality = reversed( rval.get_decimal_quality_scores() )
         rval.quality = "%s " % " ".join( map( str, rval.quality ) )
     return rval
Ejemplo n.º 6
0
 def reverse(self, clone=True):
     """return a new object with a reverses self.sequence strand
     
     call using my_object.reverse(clone=False) if you wish to reverse and
     return the current object.
     
     """
     if clone:
         rval = self.clone()
     else:
         rval = self
     rval.sequence = transform.reverse(self.sequence)
     rval.quality = rval.quality[::-1]
     return rval
Ejemplo n.º 7
0
 def reverse(self, clone = True):
     """return a new object with a reverses self.sequence strand
     
     call using my_object.reverse(clone=False) if you wish to reverse and
     return the current object.
     
     """
     if clone:
         rval = self.clone()
     else:
         rval = self
     rval.sequence = transform.reverse(self.sequence)
     rval.quality = rval.quality[::-1]
     return rval