Ejemplo n.º 1
0
class LimsService(object):
    name = "lims_service"

    def __init__(self):
        super(LimsService, self).__init__()
        self.lims = Lims(BASEURI, USERNAME, PASSWORD)
        self.lims.check_version()

    @rpc
    def sample(self, lims_id):
        """Get a sample from LIMS."""
        sample_obj = LimsSample(self.lims, id=lims_id)
        sample_dict = transform_entry(sample_obj)
        return sample_dict

    @rpc
    def validate_sample(self, lims_id):
        """Validate information in the LIMS on sample level."""
        logger.debug("fetch sample from LIMS")
        sample_obj = LimsSample(self.lims, id=lims_id)

        try:
            case_id = sample_obj.udf["familyID"]
            cust_id = sample_obj.udf["customer"]
        except KeyError as error:
            raise MissingLimsDataException(error.message)
        except HTTPError as error:
            raise LimsSampleNotFoundError(error.message)

    @rpc
    def ls_case(self, cust_id, case_id):
        """Fetch all samples for a case from the LIMS."""
        sample_objs = self.lims.get_samples(udf={"customer": cust_id, "familyID": case_id})
        sample_dicts = [transform_entry(sample) for sample in sample_objs]
        analysis_types = set(sample["analysis_type"] for sample in sample_dicts)
        case_data = {"analysis_types": list(analysis_types), "samples": sample_dicts}
        return case_data

    @rpc
    def ls_project(self, project_id):
        """List all samples in a project."""
        samples = self.lims.get_samples(projectname=project_id)
        lims_ids = [sample.id for sample in samples]
        return lims_ids

    @rpc
    def pedigree(self, cust_id, case_id):
        """Generate pedigree content for a case."""
        ped_content = serialize_pedigree(self.lims, cust_id, case_id)
        return ped_content

    @rpc
    def target_reads(self, lims_id):
        """Determine the amount of reads to be sequenced."""
        sample_obj = LimsSample(self.lims, id=lims_id)
        app_tag = analysis_info(sample_obj)
        # millions of reads
        target_reads = app_tag["reads"] * 1000000
        return target_reads
Ejemplo n.º 2
0
    def __init__(self, current_step, logger=None, cache=False):
        """
        Initializes the context.

        :param current_step: The step from which the extension is running
        :param logger: A logger instance
        :param cache: Set to True to use the cache folder (.cache) for downloaded files
        """
        lims = Lims(BASEURI, USERNAME, PASSWORD)
        lims.check_version()

        self.advanced = Advanced(lims)
        self.current_step = Process(lims, id=current_step)
        self.logger = logger or logging.getLogger(__name__)
        self._local_shared_files = []
        self.cache = cache
Ejemplo n.º 3
0
    def __init__(self, current_step, logger=None, cache=False):
        """
        Initializes the context.

        :param current_step: The step from which the extension is running
        :param logger: A logger instance
        :param cache: Set to True to use the cache folder (.cache) for downloaded files
        """
        lims = Lims(BASEURI, USERNAME, PASSWORD)
        lims.check_version()

        self.advanced = Advanced(lims)
        self.current_step = Process(lims, id=current_step)
        self.logger = logger or logging.getLogger(__name__)
        self._local_shared_files = []
        self.cache = cache
Ejemplo n.º 4
0
        x for x in io if x[1]['output-generation-type'] == 'PerInput'
    ]

    # Fetch the first input-output artifact pair
    (input, output) = io_filtered[0]

    # Instantiate the output artifact
    output_artifact = Artifact(output['limsid'])

    # Attach the file
    attach_file(args.file, output_artifact)


if __name__ == "__main__":
    parser = ArgumentParser()
    # Arguments that are useful in all EPP scripts
    parser.add_argument("--log", default=sys.stdout, help="Log file")

    # Arguments specific for this scripts task
    parser.add_argument("--pid", help="Process id")
    parser.add_argument("--file", help="File to upload")

    args = parser.parse_args()

    # Log everything to log argument
    with EppLogger(args.log):
        lims = Lims(BASEURI, USERNAME, PASSWORD)
        lims.check_version()

        main(lims, args.pid, args.file)
Ejemplo n.º 5
0
    elif lines: # Avoid printing empty files
        lp_args = ["lp"]
        if args.hostname:
            #remove that when all the calls to this script have been updated
            if args.hostname == 'homer.scilifelab.se:631':
                args.hostname='homer2.scilifelab.se:631'
            lp_args += ["-h",args.hostname]
        if args.destination:
            lp_args += ["-d",args.destination]
        lp_args.append("-") # lp accepts stdin if '-' is given as filename
        logging.info('Ready to call lp for printing.')
        sp = subprocess.Popen(lp_args, 
                              stdin=subprocess.PIPE, 
                              stdout=subprocess.PIPE, 
                              stderr=subprocess.PIPE)
        sp.stdin.write(str('\n'.join(lines)))
        logging.info('lp command is called for printing.')
        stdout,stderr = sp.communicate() # Will wait for sp to finish
        logging.info('lp stdout: {0}'.format(stdout))
        logging.info('lp stderr: {0}'.format(stderr))
        logging.info('lp command finished')
        sp.stdin.close()

if __name__ == '__main__':
    arguments = getArgs()
    lims = Lims(BASEURI,USERNAME,PASSWORD)
    lims.check_version()
    prepend = not arguments.no_prepend
    with EppLogger(arguments.log,lims=lims,prepend=prepend) as epp_logger:
        main(arguments,lims,epp_logger)
Ejemplo n.º 6
0
def namesetter(PID):

    lims = Lims(BASEURI, USERNAME, PASSWORD)
    lims.check_version()
    #Find LIMS entry with same PID
    allProjects = lims.get_projects()
    for proj in allProjects:
        if proj.id == PID:
            limsproject = proj.name
            break
    #Error handling
    if not 'limsproject' in locals():
        print("{} not available in LIMS.".format(PID))
        return None

    #Enter project summary process
    stepname=['Project Summary 1.3']
    process=lims.get_processes(type=stepname, projectname=limsproject)
    #Error handling
    if process == []:
        print("{} for {} is not available in LIMS.".format(stepname, limsproject))
        return None

    loop = True
    while loop:
        if "Bioinfo responsible" in process[0].udf:
            response = process[0].udf["Bioinfo responsible"]
        else:
            response = "Unassigned"
        print("Existing Bioinfo responsible for project {} aka {} is: {}".format(limsproject, PID, response.encode('utf-8')))

        #Checks for valid name
        in_responsibles = False
        config_responsibles =Udfconfig(lims, id="1128")
        while not in_responsibles:
            if sys.version_info[0] == 3:
                newname = input("Enter name of new Bioinfo responsible: ")
            elif sys.version_info[0] == 2:
                newname = raw_input("Enter name of new Bioinfo responsible: ")
            for names in config_responsibles.presets:
                if newname in names:
                    in_responsibles = True
                    newname = names
            if not in_responsibles:
                print("Subset {} not found in accepted Bioinfo responsible list.".format(newname))
            else:
                print("Suggested name is {}".format(newname))

        if sys.version_info[0] == 3:
            confirmation = input("Project {} aka {} will have {} as new Bioinfo responsible, is this correct (Y/N)? ".format(limsproject, PID, newname))
        elif sys.version_info[0] == 2:
            confirmation = raw_input("Project {} aka {} will have {} as new Bioinfo responsible, is this correct (Y/N)? ".format(limsproject, PID, newname))
        if confirmation == 'Y' or confirmation == 'y':
            try:
                newname.encode('ascii')
                process[0].udf["Bioinfo responsible"] = str(newname)
                process[0].put()
                print("Project {} aka {} assigned to {}".format(limsproject, PID, newname))
                return None
            except (UnicodeDecodeError, UnicodeEncodeError):
                #Weird solution due to put function
                process[0].udf["Bioinfo responsible"] = response
                print("ERROR: You tried to use a special character, didn't you? Don't do that. New standards and stuff...")
        elif confirmation == 'N' or confirmation == 'n':
            loop = False
        else:
            print("Invalid answer.")
def namesetter(PID):

    lims = Lims(BASEURI, USERNAME, PASSWORD)
    lims.check_version()
    #Find LIMS entry with same PID
    allProjects = lims.get_projects()
    for proj in allProjects:
        if proj.id == PID:
            limsproject = proj.name
            break
    #Error handling
    if not 'limsproject' in locals():
        print "{} not available in LIMS.".format(PID)
        return None
    
    #Enter project summary process
    stepname=['Project Summary 1.3']
    process=lims.get_processes(type=stepname, projectname=limsproject)
    #Error handling
    if process == []:
        print "{} for {} is not available in LIMS.".format(stepname, limsproject)
        return None

    loop = True
    while loop:
        if "Bioinfo responsible" in process[0].udf:
            response = process[0].udf["Bioinfo responsible"]
        else:
            response = "Unassigned"
        print "Existing Bioinfo responsible for project {} aka {} is: {}".format(limsproject, PID, response.encode('utf-8'))
        
        #Checks for valid name
        in_responsibles = False
        config_responsibles =Udfconfig(lims, id="1128")
        while not in_responsibles:
            newname = raw_input("Enter name of new Bioinfo responsible: ")
            for names in config_responsibles.presets:
                if newname in names:
                    in_responsibles = True
                    newname = names
            if not in_responsibles:
                print "Subset {} not found in accepted Bioinfo responsible list.".format(newname)
            else:
                print "Suggested name is {}".format(newname)
        
        confirmation = raw_input("Project {} aka {} will have {} as new Bioinfo responsible, is this correct (Y/N)? ".format(limsproject, PID, newname))
        if confirmation == 'Y' or confirmation == 'y':
            try:
                newname.decode('ascii')
                process[0].udf["Bioinfo responsible"] = unicode(newname)
                process[0].put()
                print "Project {} aka {} assigned to {}".format(limsproject, PID, newname)
                return None
            except UnicodeDecodeError:
                #Weird solution due to put function
                process[0].udf["Bioinfo responsible"] = response
                print "ERROR: You tried to use a special character, didn't you? Don't do that. New standards and stuff..."
        elif confirmation == 'N' or confirmation == 'n':
            loop = False
        else:
            print "Invalid answer."