This file is indexed.

/usr/lib/python2.7/dist-packages/cogent/app/guppy.py is in python-cogent 1.9-9.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
"""Application controller for guppy 1.1"""
       
__author__ = "Jesse Stombaugh"
__copyright__ = "Copyright 2007-2016, The Cogent Project"
__credits__ = ["Jesse Stombaugh"]
__license__ = "GPL"
__version__ = "1.9"
__maintainer__ = "Jesse Stombaugh"
__email__ = "jesse.stombaugh@colorado.edu"
__status__ = "Production"

from cogent.app.parameters import ValuedParameter, FlagParameter
from cogent.app.util import CommandLineApplication, FilePath, system, \
       CommandLineAppResult, ResultPath, remove, ApplicationError
from cogent.core.alignment import Alignment
from os.path import splitext,split,join
from os import listdir
from cogent.parse.tree import DndParser
from cogent.core.tree import PhyloNode

class Guppy(CommandLineApplication):
    """guppy Application Controller
    """

    _command = 'guppy'
    _input_handler = '_input_as_multiline_string'
    _parameters = {
    #visualizations
        # makes trees with edges fattened in proportion to the number of reads
        'fat': FlagParameter('', Name='fat'),
        
        # maps an an arbitrary vector of the correct length to the tree
        'heat': FlagParameter('', Name='heat'),
        
        # writes a taxonomically annotated reference tree and an induced 
        # taxonomic tree
        'ref_tree': FlagParameter('', Name='ref_tree'),
        
        # makes one tree for each query sequence, showing uncertainty
        'sing': FlagParameter('', Name='sing'),
        
        # makes a tree with each of the reads represented as a pendant edge
        'tog': FlagParameter('', Name='tog'),
      
      #statistical comparison
        # draws the barycenter of a placement collection on the reference tree
        'bary': FlagParameter('', Name='bary'),
        
        # makes a phyloXML tree showing the bootstrap values
        'bootviz': FlagParameter('', Name='bootviz'),
        
        # calculates the EDPL uncertainty values for a collection of pqueries
        'edpl': FlagParameter('', Name='edpl'),
        
        # calculates the Kantorovich-Rubinstein distance and corresponding 
        # p-values
        'kr': FlagParameter('', Name='kr'),
        
        # makes a heat tree
        'kr_heat': FlagParameter('', Name='kr_heat'),
        
        # performs edge principal components
        'pca': FlagParameter('', Name='pca'),
        
        # writes out differences of masses for the splits of the tree
        'splitify': FlagParameter('', Name='splitify'),
        
        # performs squash clustering
        'squash': FlagParameter('', Name='squash'),
      
      #classification
        # outputs classification information in a tabular or SQLite format
        'classify': FlagParameter('', Name='classify'),
      
      #utilities
        # check a reference package
        'check_refpkg': FlagParameter('', Name='check_refpkg'),
        
        # splits apart placements with multiplicity, undoing a round procedure
        'demulti': FlagParameter('', Name='demulti'),
        
        # prints out a pairwise distance matrix between the edges
        'distmat': FlagParameter('', Name='distmat'),
        
        # filters one or more placefiles by placement name
        'filter': FlagParameter('', Name='filter'),
        
        # writes the number of leaves of the reference tree and the number of 
        # pqueries
        'info': FlagParameter('', Name='info'),
        
        # merges placefiles together
        'merge': FlagParameter('', Name='merge'),
        
        # restores duplicates to deduped placefiles
        'redup': FlagParameter('', Name='redup'),
        
        # clusters the placements by rounding branch lengths
        'round': FlagParameter('', Name='round'),
        
        # makes SQL enabling taxonomic querying of placement results
        'taxtable': FlagParameter('', Name='taxtable'),
        
        # converts old-style .place files to .json placement files
        'to_json': FlagParameter('', Name='to_json'),
        
        # Run the provided batch file of guppy commands
        'batch': FlagParameter('--', Name='batch'),
        
        # Print version and exit
        'version': FlagParameter('--', Name='version'),
        
        # Print a list of the available commands.
        'cmds': FlagParameter('--', Name='cmds'),
        
        # Display this list of options
        '--help': FlagParameter('--', Name='help'),
        
        # Display this list of options
        '-help': FlagParameter('-', Name='help'),
    }
 
    def getTmpFilename(self, tmp_dir='/tmp/',prefix='tmp',suffix='.json',\
           include_class_id=False,result_constructor=FilePath):
        """ Define Tmp filename to contain .json suffix, since guppy requires
            the suffix to be .json """
        
        return super(Guppy,self).getTmpFilename(tmp_dir=tmp_dir,
                                    prefix=prefix,
                                    suffix=suffix,
                                    include_class_id=include_class_id,
                                    result_constructor=result_constructor)
                                    
    def _handle_app_result_build_failure(self,out,err,exit_status,result_paths):
        """ Catch the error when files are not produced """
        raise ApplicationError, \
         'Guppy failed to produce an output file due to the following error: \n\n%s ' \
         % err.read()
    
    def _get_result_paths(self,data):
        basepath,basename=split(splitext(self._input_filename)[0])
        outfile_list=listdir(split(self._input_filename)[0])

        result = {}
        for i in outfile_list:
            if i.startswith(basename) and not i.endswith('.json') and \
                                                    not i.endswith('.txt'):
                result['result'] = ResultPath(Path=join(basepath,i))
                
        return result
    
def build_tree_from_json_using_params(fname,output_dir='/tmp/',params={}):
    """Returns a tree from a json.
    
    fname: filepath to input json 
    
    output_dir: location of output files
    
    params: dict of parameters to pass in to the RAxML app controller.

    The result will be a Tree.
    """

    # convert aln to fasta in case it is not already a fasta file
    
    ih = '_input_as_multiline_string'    

    guppy_app = Guppy(params=params,
                      InputHandler=ih,
                      WorkingDir=output_dir,
                      TmpDir=output_dir,
                      SuppressStderr=True,
                      SuppressStdout=True,
                      HALT_EXEC=False)
                      
    guppy_result = guppy_app(open(fname).read())
    
    try:
        new_tree=guppy_result['result'].read()
    except:
        # catch the error of not producing any results and print the command
        # run so user can check error
        guppy_cmd=Guppy(params=params,
                      InputHandler=ih,
                      WorkingDir=output_dir,
                      TmpDir=output_dir,
                      SuppressStderr=True,
                      SuppressStdout=True,
                      HALT_EXEC=True)
        out_msg=guppy_cmd(open(fname).read())
        
    tree = DndParser(new_tree, constructor=PhyloNode)
    
    guppy_result.cleanUp()

    return tree