idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
62,700
def get_by_name ( self , name ) : san_managers = self . _client . get_all ( ) result = [ x for x in san_managers if x [ 'name' ] == name ] return result [ 0 ] if result else None
Gets a SAN Manager by name .
62,701
def get_by_provider_display_name ( self , provider_display_name ) : san_managers = self . _client . get_all ( ) result = [ x for x in san_managers if x [ 'providerDisplayName' ] == provider_display_name ] return result [ 0 ] if result else None
Gets a SAN Manager by provider display name .
62,702
def update_configuration ( self , configuration ) : return self . _client . update ( configuration , uri = self . URI + "/configuration" )
Updates the metrics configuration with the new values . Overwrites the existing configuration .
62,703
def delete_all ( self , filter = None , timeout = - 1 ) : return self . _client . delete_all ( filter = filter , timeout = timeout )
Delete an SNMPv3 User based on User name specified in filter . The user will be deleted only if it has no associated destinations .
62,704
def update_ports ( self , ports , id_or_uri ) : ports = merge_default_values ( ports , { 'type' : 'port' } ) uri = self . _client . build_uri ( id_or_uri ) + "/update-ports" return self . _client . update ( uri = uri , resource = ports )
Updates the switch ports . Only the ports under the management of OneView and those that are unlinked are supported for update .
62,705
def from_json_file ( cls , file_name ) : with open ( file_name ) as json_data : config = json . load ( json_data ) return cls ( config )
Construct OneViewClient using a json file .
62,706
def from_environment_variables ( cls ) : ip = os . environ . get ( 'ONEVIEWSDK_IP' , '' ) image_streamer_ip = os . environ . get ( 'ONEVIEWSDK_IMAGE_STREAMER_IP' , '' ) api_version = int ( os . environ . get ( 'ONEVIEWSDK_API_VERSION' , OneViewClient . DEFAULT_API_VERSION ) ) ssl_certificate = os . environ . get ( 'ONEVIEWSDK_SSL_CERTIFICATE' , '' ) username = os . environ . get ( 'ONEVIEWSDK_USERNAME' , '' ) auth_login_domain = os . environ . get ( 'ONEVIEWSDK_AUTH_LOGIN_DOMAIN' , '' ) password = os . environ . get ( 'ONEVIEWSDK_PASSWORD' , '' ) proxy = os . environ . get ( 'ONEVIEWSDK_PROXY' , '' ) sessionID = os . environ . get ( 'ONEVIEWSDK_SESSIONID' , '' ) timeout = os . environ . get ( 'ONEVIEWSDK_CONNECTION_TIMEOUT' ) config = dict ( ip = ip , image_streamer_ip = image_streamer_ip , api_version = api_version , ssl_certificate = ssl_certificate , credentials = dict ( userName = username , authLoginDomain = auth_login_domain , password = password , sessionID = sessionID ) , proxy = proxy , timeout = timeout ) return cls ( config )
Construct OneViewClient using environment variables .
62,707
def create_image_streamer_client ( self ) : image_streamer = ImageStreamerClient ( self . __image_streamer_ip , self . __connection . get_session_id ( ) , self . __connection . _apiVersion , self . __connection . _sslBundle ) return image_streamer
Create the Image Streamer API Client .
62,708
def certificate_authority ( self ) : if not self . __certificate_authority : self . __certificate_authority = CertificateAuthority ( self . __connection ) return self . __certificate_authority
Gets the Certificate Authority API client .
62,709
def connections ( self ) : if not self . __connections : self . __connections = Connections ( self . __connection ) return self . __connections
Gets the Connections API client .
62,710
def fcoe_networks ( self ) : if not self . __fcoe_networks : self . __fcoe_networks = FcoeNetworks ( self . __connection ) return self . __fcoe_networks
Gets the FcoeNetworks API client .
62,711
def fabrics ( self ) : if not self . __fabrics : self . __fabrics = Fabrics ( self . __connection ) return self . __fabrics
Gets the Fabrics API client .
62,712
def restores ( self ) : if not self . __restores : self . __restores = Restores ( self . __connection ) return self . __restores
Gets the Restores API client .
62,713
def scopes ( self ) : if not self . __scopes : self . __scopes = Scopes ( self . __connection ) return self . __scopes
Gets the Scopes API client .
62,714
def datacenters ( self ) : if not self . __datacenters : self . __datacenters = Datacenters ( self . __connection ) return self . __datacenters
Gets the Datacenters API client .
62,715
def network_sets ( self ) : if not self . __network_sets : self . __network_sets = NetworkSets ( self . __connection ) return self . __network_sets
Gets the NetworkSets API client .
62,716
def server_hardware ( self ) : if not self . __server_hardware : self . __server_hardware = ServerHardware ( self . __connection ) return self . __server_hardware
Gets the ServerHardware API client .
62,717
def server_hardware_types ( self ) : if not self . __server_hardware_types : self . __server_hardware_types = ServerHardwareTypes ( self . __connection ) return self . __server_hardware_types
Gets the ServerHardwareTypes API client .
62,718
def id_pools_vsn_ranges ( self ) : if not self . __id_pools_vsn_ranges : self . __id_pools_vsn_ranges = IdPoolsRanges ( 'vsn' , self . __connection ) return self . __id_pools_vsn_ranges
Gets the IdPoolsRanges API Client for VSN Ranges .
62,719
def id_pools_vmac_ranges ( self ) : if not self . __id_pools_vmac_ranges : self . __id_pools_vmac_ranges = IdPoolsRanges ( 'vmac' , self . __connection ) return self . __id_pools_vmac_ranges
Gets the IdPoolsRanges API Client for VMAC Ranges .
62,720
def id_pools_vwwn_ranges ( self ) : if not self . __id_pools_vwwn_ranges : self . __id_pools_vwwn_ranges = IdPoolsRanges ( 'vwwn' , self . __connection ) return self . __id_pools_vwwn_ranges
Gets the IdPoolsRanges API Client for VWWN Ranges .
62,721
def id_pools_ipv4_ranges ( self ) : if not self . __id_pools_ipv4_ranges : self . __id_pools_ipv4_ranges = IdPoolsIpv4Ranges ( self . __connection ) return self . __id_pools_ipv4_ranges
Gets the IdPoolsIpv4Ranges API client .
62,722
def id_pools_ipv4_subnets ( self ) : if not self . __id_pools_ipv4_subnets : self . __id_pools_ipv4_subnets = IdPoolsIpv4Subnets ( self . __connection ) return self . __id_pools_ipv4_subnets
Gets the IdPoolsIpv4Subnets API client .
62,723
def id_pools ( self ) : if not self . __id_pools : self . __id_pools = IdPools ( self . __connection ) return self . __id_pools
Gets the IdPools API client .
62,724
def switches ( self ) : if not self . __switches : self . __switches = Switches ( self . __connection ) return self . __switches
Gets the Switches API client .
62,725
def roles ( self ) : if not self . __roles : self . __roles = Roles ( self . __connection ) return self . __roles
Gets the Roles API client .
62,726
def switch_types ( self ) : if not self . __switch_types : self . __switch_types = SwitchTypes ( self . __connection ) return self . __switch_types
Gets the SwitchTypes API client .
62,727
def logical_switches ( self ) : if not self . __logical_switches : self . __logical_switches = LogicalSwitches ( self . __connection ) return self . __logical_switches
Gets the LogicalSwitches API client .
62,728
def tasks ( self ) : if not self . __tasks : self . __tasks = Tasks ( self . __connection ) return self . __tasks
Gets the Tasks API client .
62,729
def enclosure_groups ( self ) : if not self . __enclosure_groups : self . __enclosure_groups = EnclosureGroups ( self . __connection ) return self . __enclosure_groups
Gets the EnclosureGroups API client .
62,730
def logical_enclosures ( self ) : if not self . __logical_enclosures : self . __logical_enclosures = LogicalEnclosures ( self . __connection ) return self . __logical_enclosures
Gets the LogicalEnclosures API client .
62,731
def metric_streaming ( self ) : if not self . __metric_streaming : self . __metric_streaming = MetricStreaming ( self . __connection ) return self . __metric_streaming
Gets the MetricStreaming API client .
62,732
def interconnects ( self ) : if not self . __interconnects : self . __interconnects = Interconnects ( self . __connection ) return self . __interconnects
Gets the Interconnects API client .
62,733
def interconnect_link_topologies ( self ) : if not self . __interconnect_link_topologies : self . __interconnect_link_topologies = InterconnectLinkTopologies ( self . __connection ) return self . __interconnect_link_topologies
Gets the InterconnectLinkTopologies API client .
62,734
def sas_interconnect_types ( self ) : if not self . __sas_interconnect_types : self . __sas_interconnect_types = SasInterconnectTypes ( self . __connection ) return self . __sas_interconnect_types
Gets the SasInterconnectTypes API client .
62,735
def internal_link_sets ( self ) : if not self . __internal_link_sets : self . __internal_link_sets = InternalLinkSets ( self . __connection ) return self . __internal_link_sets
Gets the InternalLinkSets API client .
62,736
def logical_interconnect_groups ( self ) : if not self . __logical_interconnect_groups : self . __logical_interconnect_groups = LogicalInterconnectGroups ( self . __connection ) return self . __logical_interconnect_groups
Gets the LogicalInterconnectGroups API client .
62,737
def sas_logical_interconnects ( self ) : if not self . __sas_logical_interconnects : self . __sas_logical_interconnects = SasLogicalInterconnects ( self . __connection ) return self . __sas_logical_interconnects
Gets the SasLogicalInterconnects API client .
62,738
def logical_downlinks ( self ) : if not self . __logical_downlinks : self . __logical_downlinks = LogicalDownlinks ( self . __connection ) return self . __logical_downlinks
Gets the LogicalDownlinks API client .
62,739
def power_devices ( self ) : if not self . __power_devices : self . __power_devices = PowerDevices ( self . __connection ) return self . __power_devices
Gets the PowerDevices API client .
62,740
def unmanaged_devices ( self ) : if not self . __unmanaged_devices : self . __unmanaged_devices = UnmanagedDevices ( self . __connection ) return self . __unmanaged_devices
Gets the Unmanaged Devices API client .
62,741
def racks ( self ) : if not self . __racks : self . __racks = Racks ( self . __connection ) return self . __racks
Gets the Racks API client .
62,742
def san_managers ( self ) : if not self . __san_managers : self . __san_managers = SanManagers ( self . __connection ) return self . __san_managers
Gets the SanManagers API client .
62,743
def endpoints ( self ) : if not self . __endpoints : self . __endpoints = Endpoints ( self . __connection ) return self . __endpoints
Gets the Endpoints API client .
62,744
def storage_systems ( self ) : if not self . __storage_systems : self . __storage_systems = StorageSystems ( self . __connection ) return self . __storage_systems
Gets the StorageSystems API client .
62,745
def storage_pools ( self ) : if not self . __storage_pools : self . __storage_pools = StoragePools ( self . __connection ) return self . __storage_pools
Gets the StoragePools API client .
62,746
def storage_volume_templates ( self ) : if not self . __storage_volume_templates : self . __storage_volume_templates = StorageVolumeTemplates ( self . __connection ) return self . __storage_volume_templates
Gets the StorageVolumeTemplates API client .
62,747
def storage_volume_attachments ( self ) : if not self . __storage_volume_attachments : self . __storage_volume_attachments = StorageVolumeAttachments ( self . __connection ) return self . __storage_volume_attachments
Gets the StorageVolumeAttachments API client .
62,748
def firmware_drivers ( self ) : if not self . __firmware_drivers : self . __firmware_drivers = FirmwareDrivers ( self . __connection ) return self . __firmware_drivers
Gets the FirmwareDrivers API client .
62,749
def firmware_bundles ( self ) : if not self . __firmware_bundles : self . __firmware_bundles = FirmwareBundles ( self . __connection ) return self . __firmware_bundles
Gets the FirmwareBundles API client .
62,750
def volumes ( self ) : if not self . __volumes : self . __volumes = Volumes ( self . __connection ) return self . __volumes
Gets the Volumes API client .
62,751
def sas_logical_jbod_attachments ( self ) : if not self . __sas_logical_jbod_attachments : self . __sas_logical_jbod_attachments = SasLogicalJbodAttachments ( self . __connection ) return self . __sas_logical_jbod_attachments
Gets the SAS Logical JBOD Attachments client .
62,752
def managed_sans ( self ) : if not self . __managed_sans : self . __managed_sans = ManagedSANs ( self . __connection ) return self . __managed_sans
Gets the Managed SANs API client .
62,753
def migratable_vc_domains ( self ) : if not self . __migratable_vc_domains : self . __migratable_vc_domains = MigratableVcDomains ( self . __connection ) return self . __migratable_vc_domains
Gets the VC Migration Manager API client .
62,754
def sas_interconnects ( self ) : if not self . __sas_interconnects : self . __sas_interconnects = SasInterconnects ( self . __connection ) return self . __sas_interconnects
Gets the SAS Interconnects API client .
62,755
def sas_logical_interconnect_groups ( self ) : if not self . __sas_logical_interconnect_groups : self . __sas_logical_interconnect_groups = SasLogicalInterconnectGroups ( self . __connection ) return self . __sas_logical_interconnect_groups
Gets the SasLogicalInterconnectGroups API client .
62,756
def drive_enclosures ( self ) : if not self . __drive_enclures : self . __drive_enclures = DriveEnclosures ( self . __connection ) return self . __drive_enclures
Gets the Drive Enclosures API client .
62,757
def sas_logical_jbods ( self ) : if not self . __sas_logical_jbods : self . __sas_logical_jbods = SasLogicalJbods ( self . __connection ) return self . __sas_logical_jbods
Gets the SAS Logical JBODs API client .
62,758
def labels ( self ) : if not self . __labels : self . __labels = Labels ( self . __connection ) return self . __labels
Gets the Labels API client .
62,759
def index_resources ( self ) : if not self . __index_resources : self . __index_resources = IndexResources ( self . __connection ) return self . __index_resources
Gets the Index Resources API client .
62,760
def alerts ( self ) : if not self . __alerts : self . __alerts = Alerts ( self . __connection ) return self . __alerts
Gets the Alerts API client .
62,761
def events ( self ) : if not self . __events : self . __events = Events ( self . __connection ) return self . __events
Gets the Events API client .
62,762
def os_deployment_servers ( self ) : if not self . __os_deployment_servers : self . __os_deployment_servers = OsDeploymentServers ( self . __connection ) return self . __os_deployment_servers
Gets the Os Deployment Servers API client .
62,763
def certificate_rabbitmq ( self ) : if not self . __certificate_rabbitmq : self . __certificate_rabbitmq = CertificateRabbitMQ ( self . __connection ) return self . __certificate_rabbitmq
Gets the Certificate RabbitMQ API client .
62,764
def users ( self ) : if not self . __users : self . __users = Users ( self . __connection ) return self . __users
Gets the Users API client .
62,765
def appliance_device_read_community ( self ) : if not self . __appliance_device_read_community : self . __appliance_device_read_community = ApplianceDeviceReadCommunity ( self . __connection ) return self . __appliance_device_read_community
Gets the ApplianceDeviceReadCommunity API client .
62,766
def appliance_device_snmp_v1_trap_destinations ( self ) : if not self . __appliance_device_snmp_v1_trap_destinations : self . __appliance_device_snmp_v1_trap_destinations = ApplianceDeviceSNMPv1TrapDestinations ( self . __connection ) return self . __appliance_device_snmp_v1_trap_destinations
Gets the ApplianceDeviceSNMPv1TrapDestinations API client .
62,767
def appliance_device_snmp_v3_trap_destinations ( self ) : if not self . __appliance_device_snmp_v3_trap_destinations : self . __appliance_device_snmp_v3_trap_destinations = ApplianceDeviceSNMPv3TrapDestinations ( self . __connection ) return self . __appliance_device_snmp_v3_trap_destinations
Gets the ApplianceDeviceSNMPv3TrapDestinations API client .
62,768
def appliance_device_snmp_v3_users ( self ) : if not self . __appliance_device_snmp_v3_users : self . __appliance_device_snmp_v3_users = ApplianceDeviceSNMPv3Users ( self . __connection ) return self . __appliance_device_snmp_v3_users
Gets the ApplianceDeviceSNMPv3Users API client .
62,769
def appliance_node_information ( self ) : if not self . __appliance_node_information : self . __appliance_node_information = ApplianceNodeInformation ( self . __connection ) return self . __appliance_node_information
Gets the ApplianceNodeInformation API client .
62,770
def appliance_time_and_locale_configuration ( self ) : if not self . __appliance_time_and_locale_configuration : self . __appliance_time_and_locale_configuration = ApplianceTimeAndLocaleConfiguration ( self . __connection ) return self . __appliance_time_and_locale_configuration
Gets the ApplianceTimeAndLocaleConfiguration API client .
62,771
def versions ( self ) : if not self . __versions : self . __versions = Versions ( self . __connection ) return self . __versions
Gets the Version API client .
62,772
def backups ( self ) : if not self . __backups : self . __backups = Backups ( self . __connection ) return self . __backups
Gets the Backup API client .
62,773
def login_details ( self ) : if not self . __login_details : self . __login_details = LoginDetails ( self . __connection ) return self . __login_details
Gets the login details
62,774
def get_available_networks ( self , ** kwargs ) : query_string = '&' . join ( '{}={}' . format ( key , value ) for key , value in kwargs . items ( ) if value ) uri = self . URI + "{}?{}" . format ( "/available-networks" , query_string ) return self . _helper . do_get ( uri )
Retrieves the list of Ethernet networks Fibre Channel networks and network sets that are available to a server profile template along with their respective ports . The scopeUris serverHardwareTypeUri and enclosureGroupUri parameters should be specified to get the available networks for a new server profile template . The serverHardwareTypeUri enclosureGroupUri and profileTemplateUri should be specified to get available networks for an existing server profile template . The scopeUris parameter is ignored when the profileTemplateUri is specified .
62,775
def get_all_without_ethernet ( self , start = 0 , count = - 1 , filter = '' , sort = '' ) : without_ethernet_client = ResourceClient ( self . _connection , "/rest/logical-downlinks/withoutEthernet" ) return without_ethernet_client . get_all ( start , count , filter = filter , sort = sort )
Gets a paginated collection of logical downlinks without ethernet . The collection is based on optional sorting and filtering and is constrained by start and count parameters .
62,776
def get_without_ethernet ( self , id_or_uri ) : uri = self . _client . build_uri ( id_or_uri ) + "/withoutEthernet" return self . _client . get ( uri )
Gets the logical downlink with the specified ID without ethernet .
62,777
def update_firmware ( self , firmware_information , force = False ) : firmware_uri = "{}/firmware" . format ( self . data [ "uri" ] ) result = self . _helper . update ( firmware_information , firmware_uri , force = force ) self . refresh ( ) return result
Installs firmware to the member interconnects of a SAS Logical Interconnect .
62,778
def get_firmware ( self ) : firmware_uri = "{}/firmware" . format ( self . data [ "uri" ] ) return self . _helper . do_get ( firmware_uri )
Gets baseline firmware information for a SAS Logical Interconnect .
62,779
def update_compliance_all ( self , information , timeout = - 1 ) : uri = self . URI + "/compliance" result = self . _helper . update ( information , uri , timeout = timeout ) return result
Returns SAS Logical Interconnects to a consistent state . The current SAS Logical Interconnect state is compared to the associated SAS Logical Interconnect group .
62,780
def replace_drive_enclosure ( self , information ) : uri = "{}/replaceDriveEnclosure" . format ( self . data [ "uri" ] ) result = self . _helper . create ( information , uri ) self . refresh ( ) return result
When a drive enclosure has been physically replaced initiate the replacement operation that enables the new drive enclosure to take over as a replacement for the prior drive enclosure . The request requires specification of both the serial numbers of the original drive enclosure and its replacement to be provided .
62,781
def update_configuration ( self ) : uri = "{}/configuration" . format ( self . data [ "uri" ] ) result = self . _helper . update ( { } , uri ) self . refresh ( ) return result
Asynchronously applies or re - applies the SAS Logical Interconnect configuration to all managed interconnects of a SAS Logical Interconnect .
62,782
def mutationhash ( strings , nedit ) : maxlen = max ( [ len ( string ) for string in strings ] ) indexes = generate_idx ( maxlen , nedit ) muthash = defaultdict ( set ) for string in strings : muthash [ string ] . update ( [ string ] ) for x in substitution_set ( string , indexes ) : muthash [ x ] . update ( [ string ] ) return muthash
produce a hash with each key a nedit distance substitution for a set of strings . values of the hash is the set of strings the substitution could have come from
62,783
def substitution_set ( string , indexes ) : strlen = len ( string ) return { mutate_string ( string , x ) for x in indexes if valid_substitution ( strlen , x ) }
for a string return a set of all possible substitutions
62,784
def valid_substitution ( strlen , index ) : values = index [ 0 ] return all ( [ strlen > i for i in values ] )
skip performing substitutions that are outside the bounds of the string
62,785
def acgt_match ( string ) : search = re . compile ( r'[^ACGT]' ) . search return not bool ( search ( string ) )
returns True if sting consist of only A C G T
62,786
def stream_fastq ( file_handler ) : next_element = '' for i , line in enumerate ( file_handler ) : next_element += line if i % 4 == 3 : yield next_element next_element = ''
Generator which gives all four lines if a fastq read as one string
62,787
def read_fastq ( filename ) : if not filename : return itertools . cycle ( ( None , ) ) if filename == "-" : filename_fh = sys . stdin elif filename . endswith ( 'gz' ) : if is_python3 : filename_fh = gzip . open ( filename , mode = 'rt' ) else : filename_fh = BufferedReader ( gzip . open ( filename , mode = 'rt' ) ) else : filename_fh = open ( filename ) return stream_fastq ( filename_fh )
return a stream of FASTQ entries handling gzipped and empty files
62,788
def write_fastq ( filename ) : if filename : if filename . endswith ( 'gz' ) : filename_fh = gzip . open ( filename , mode = 'wb' ) else : filename_fh = open ( filename , mode = 'w' ) else : filename_fh = None return filename_fh
return a handle for FASTQ writing handling gzipped files
62,789
def detect_alignment_annotations ( queryalignment , tags = False ) : annotations = set ( ) for k , v in BARCODEINFO . items ( ) : if tags : if queryalignment . has_tag ( v . bamtag ) : annotations . add ( k ) else : if v . readprefix in queryalignment . qname : annotations . add ( k ) return annotations
detects the annotations present in a SAM file inspecting either the tags or the query names and returns a set of annotations present
62,790
def detect_fastq_annotations ( fastq_file ) : annotations = set ( ) queryread = tz . first ( read_fastq ( fastq_file ) ) for k , v in BARCODEINFO . items ( ) : if v . readprefix in queryread : annotations . add ( k ) return annotations
detects annotations preesent in a FASTQ file by examining the first read
62,791
def construct_transformed_regex ( annotations ) : re_string = '.*' if "cellular" in annotations : re_string += ":CELL_(?P<CB>.*)" if "molecular" in annotations : re_string += ":UMI_(?P<MB>\w*)" if "sample" in annotations : re_string += ":SAMPLE_(?P<SB>\w*)" if re_string == ".*" : logger . error ( "No annotation present on this file, aborting." ) sys . exit ( 1 ) return re_string
construct a regex that matches possible fields in a transformed file annotations is a set of which keys in BARCODEINFO are present in the file
62,792
def _infer_transform_options ( transform ) : TransformOptions = collections . namedtuple ( "TransformOptions" , [ 'CB' , 'dual_index' , 'triple_index' , 'MB' , 'SB' ] ) CB = False SB = False MB = False dual_index = False triple_index = False for rx in transform . values ( ) : if not rx : continue if "CB1" in rx : if "CB3" in rx : triple_index = True else : dual_index = True if "SB" in rx : SB = True if "CB" in rx : CB = True if "MB" in rx : MB = True return TransformOptions ( CB = CB , dual_index = dual_index , triple_index = triple_index , MB = MB , SB = SB )
figure out what transform options should be by examining the provided regexes for keywords
62,793
def _extract_readnum ( read_dict ) : pat = re . compile ( r"(?P<readnum>/\d+)$" ) parts = pat . split ( read_dict [ "name" ] ) if len ( parts ) == 3 : name , readnum , endofline = parts read_dict [ "name" ] = name read_dict [ "readnum" ] = readnum else : read_dict [ "readnum" ] = "" return read_dict
Extract read numbers from old - style fastqs .
62,794
def sparse ( csv , sparse ) : import pandas as pd df = pd . read_csv ( csv , index_col = 0 , header = 0 ) pd . Series ( df . index ) . to_csv ( sparse + ".rownames" , index = False ) pd . Series ( df . columns . values ) . to_csv ( sparse + ".colnames" , index = False ) with open ( sparse , "w+b" ) as out_handle : scipy . io . mmwrite ( out_handle , scipy . sparse . csr_matrix ( df ) )
Convert a CSV file to a sparse matrix with rows and column names saved as companion files .
62,795
def cb_histogram ( fastq , umi_histogram ) : annotations = detect_fastq_annotations ( fastq ) re_string = construct_transformed_regex ( annotations ) parser_re = re . compile ( re_string ) cb_counter = collections . Counter ( ) umi_counter = collections . Counter ( ) for read in read_fastq ( fastq ) : match = parser_re . search ( read ) . groupdict ( ) cb = match [ 'CB' ] cb_counter [ cb ] += 1 if umi_histogram : umi = match [ 'MB' ] umi_counter [ ( cb , umi ) ] += 1 for bc , count in cb_counter . most_common ( ) : sys . stdout . write ( '{}\t{}\n' . format ( bc , count ) ) if umi_histogram : with open ( umi_histogram , "w" ) as umi_handle : for cbumi , count in umi_counter . most_common ( ) : umi_handle . write ( '{}\t{}\t{}\n' . format ( cbumi [ 0 ] , cbumi [ 1 ] , count ) )
Counts the number of reads for each cellular barcode
62,796
def umi_histogram ( fastq ) : annotations = detect_fastq_annotations ( fastq ) re_string = construct_transformed_regex ( annotations ) parser_re = re . compile ( re_string ) counter = collections . Counter ( ) for read in read_fastq ( fastq ) : match = parser_re . search ( read ) . groupdict ( ) counter [ match [ 'MB' ] ] += 1 for bc , count in counter . most_common ( ) : sys . stdout . write ( '{}\t{}\n' . format ( bc , count ) )
Counts the number of reads for each UMI
62,797
def get_cb_depth_set ( cb_histogram , cb_cutoff ) : cb_keep_set = set ( ) if not cb_histogram : return cb_keep_set with read_cbhistogram ( cb_histogram ) as fh : cb_map = dict ( p . strip ( ) . split ( ) for p in fh ) cb_keep_set = set ( [ k for k , v in cb_map . items ( ) if int ( v ) > cb_cutoff ] ) logger . info ( 'Keeping %d out of %d cellular barcodes.' % ( len ( cb_keep_set ) , len ( cb_map ) ) ) return cb_keep_set
Returns a set of barcodes with a minimum number of reads
62,798
def guess_depth_cutoff ( cb_histogram ) : with read_cbhistogram ( cb_histogram ) as fh : cb_vals = [ int ( p . strip ( ) . split ( ) [ 1 ] ) for p in fh ] histo = np . histogram ( np . log10 ( cb_vals ) , bins = 50 ) vals = histo [ 0 ] edges = histo [ 1 ] mids = np . array ( [ ( edges [ i ] + edges [ i + 1 ] ) / 2 for i in range ( edges . size - 1 ) ] ) wdensity = vals * ( 10 ** mids ) / sum ( vals * ( 10 ** mids ) ) baseline = np . median ( wdensity ) wdensity = list ( wdensity ) peak = wdensity . index ( max ( wdensity [ len ( wdensity ) / 2 : ] ) ) cutoff = None for index , dens in reversed ( list ( enumerate ( wdensity [ 1 : peak ] ) ) ) : if dens < 2 * baseline : cutoff = index break if not cutoff : return None else : cutoff = 10 ** mids [ cutoff ] logger . info ( 'Setting barcode cutoff to %d' % cutoff ) return cutoff
Guesses at an appropriate barcode cutoff
62,799
def cb_filter ( fastq , bc1 , bc2 , bc3 , cores , nedit ) : with open_gzipsafe ( bc1 ) as bc1_fh : bc1 = set ( cb . strip ( ) for cb in bc1_fh ) if bc2 : with open_gzipsafe ( bc2 ) as bc2_fh : bc2 = set ( cb . strip ( ) for cb in bc2_fh ) if bc3 : with open_gzipsafe ( bc3 ) as bc3_fh : bc3 = set ( cb . strip ( ) for cb in bc3_fh ) annotations = detect_fastq_annotations ( fastq ) re_string = construct_transformed_regex ( annotations ) if nedit == 0 : filter_cb = partial ( exact_barcode_filter , bc1 = bc1 , bc2 = bc2 , bc3 = bc3 , re_string = re_string ) else : bc1hash = MutationHash ( bc1 , nedit ) bc2hash = None bc3hash = None if bc2 : bc2hash = MutationHash ( bc2 , nedit ) if bc3 : bc3hash = MutationHash ( bc3 , nedit ) filter_cb = partial ( correcting_barcode_filter , bc1hash = bc1hash , bc2hash = bc2hash , bc3hash = bc3hash , re_string = re_string ) p = multiprocessing . Pool ( cores ) chunks = tz . partition_all ( 10000 , read_fastq ( fastq ) ) bigchunks = tz . partition_all ( cores , chunks ) for bigchunk in bigchunks : for chunk in p . map ( filter_cb , list ( bigchunk ) ) : for read in chunk : sys . stdout . write ( read )
Filters reads with non - matching barcodes Expects formatted fastq files .