Ejemplo n.º 1
0
def get_cases(variant_source, case_lines=None, case_type='ped', 
            variant_type='snv', variant_mode='vcf'):
        """Create a cases and populate it with individuals

            Args:
                variant_source (str): Path to vcf files
                case_lines (Iterable): Ped like lines
                case_type (str): Format of case lines

            Returns:
                case_objs (list(puzzle.models.Case))
        """
        individuals = get_individuals(
            variant_source=variant_source,
            case_lines=case_lines,
            case_type=case_type,
            variant_mode=variant_mode
        )
        case_objs = []
        case_ids = set()
        
        compressed = False
        tabix_index = False
        #If no individuals we still need to have a case id
        if variant_source.endswith('.gz'):
            logger.debug("Found compressed variant source")
            compressed = True
            tabix_file = '.'.join([variant_source, 'tbi'])
            if os.path.exists(tabix_file):
                logger.debug("Found index file")
                tabix_index = True
        
        for individual in individuals:
            case_ids.add(individual.case_id)
        
        for case_id in case_ids:
            logger.info("Found case {0}".format(case_id))
            case = Case(
                case_id=case_id,
                name=case_id,
                variant_source=variant_source,
                variant_type=variant_type,
                variant_mode=variant_mode,
                compressed=compressed,
                tabix_index=tabix_index
                )
            
            # Add the individuals to the correct case
            for individual in individuals:
                if individual.case_id == case_id:
                    logger.info("Adding ind {0} to case {1}".format(
                        individual.name, individual.case_id
                    ))
                    case.add_individual(individual)

            case_objs.append(case)

        return case_objs
Ejemplo n.º 2
0
    def _get_cases(self, individuals):
        """Return the cases found in the database

            Args:
                individuals(list): List of Individuals

            Returns:
                case_objs(list): List of Cases
        """
        case_objs = []
        case_ids = set()
        logger.info("Looking for cases in {0}".format(
            self.db
        ))
        for individual in individuals:
            case_ids.add(individual.case_id)

        for case_id in case_ids:
            logger.info("Found case {0}".format(case_id))
            case = Case(
                case_id=case_id,
                name=case_id,
                variant_source=self.db,
                variant_type=self.variant_type,
                variant_mode='gemini',
                )
            # Add the individuals to the correct case
            for individual in individuals:
                if individual.case_id == case_id:
                    logger.info("Adding ind {0} to case {1}".format(
                        individual.name, individual.case_id
                    ))
                    case.add_individual(individual)

            case_objs.append(case)

        return case_objs
Ejemplo n.º 3
0
def get_case(variant_source, case_lines=None, case_type='ped', variant_type='snv',
            variant_mode='vcf'):
        """Create a cases and populate it with individuals

            Args:
                variant_source (str): Path to vcf files
                case_lines (Iterable): Ped like lines
                case_type (str): Format of case lines

            Returns:
                case_objs (list): List with Case objects
        """
        individuals = get_individuals(
            vcf=variant_source,
            case_lines=case_lines,
            case_type=case_type,
        )
        
        #If no individuals we still need to have a case id
        case_id = os.path.basename(variant_source)
        
        for individual in individuals:
            case_id = individual.case_id

        case = Case(case_id=case_id, variant_source=variant_source,
                    name=case_id, variant_type=variant_type, 
                    variant_mode=variant_mode,
                    )

        logger.debug("Found case with case_id: {0} and name: {1}".format(
            case.case_id, case.name))

        for individual in individuals:
            case.add_individual(individual)

        return case