logo
Tags down

shadow

Asp.Net VB or C# how to combine lines & columns based on unique primary field


By : user3851008
Date : October 18 2020, 11:12 AM
Does that help I've used a custom user defined function in SQL server that uses the COALESCE function in SQL Server. Here is an example.
code :


Share : facebook icon twitter icon

Define a unique primary key based on 2 columns


By : avinash negi
Date : March 29 2020, 07:55 AM
it should still fix some issue add_index :words, ["id", "language_id"], :unique => true
It should work. Maybe you have already some non-unique data in your db and index can't be created? But (as @Doon noticed it will be redundant since id is always unique). So you need create primary key on two columns.
code :
create_table :words, {:id => false} do |t|
  t.integer :id
  t.integer :language_id
  t.string :value
  t.timestamps
end
execute "ALTER TABLE words ADD PRIMARY KEY (id,language_id);"
class Word < ActiveRecord::Base
    self.primary_keys = :id,:language_id
end

MySQL/InnoDB: more optimal to have two non-unique index columns or combine them in unique primary key?


By : Dun Dun
Date : March 29 2020, 07:55 AM
I wish this help you Whether you use it or not, InnoDB always has a primary key, kind of. InnoDB uses a clustered index for storing the data, which basically means that primary key and the data are in the same place. If you don't define a suitable index, it creates an internal index. This also means that the primary key is "free"; it doesn't require any extra space since the data is stored in the index. If you always find rows to update by using both columns, you should definitely make a composite primary index. Even if you don't use two columns every time to filter data, you will probably benefit from a composite primary index.
As for the data types, I'd make both as small as possible. I'm not sure about the specifics of how the index is handled in memory, but you're probably not going to be able to measure any significant difference due to memory access differences and the smaller index size wouldn't hurt.

Selecting unique lines based on two columns


By : user3815422
Date : March 29 2020, 07:55 AM
may help you . You can perfectly use an index that uses more than one field for the array elements:
code :
awk -F"\t" '!seen[$2, $3]++' file

Get unique lines based ONLY on 2 Columns


By : Zdenek
Date : March 29 2020, 07:55 AM
it should still fix some issue Consider using the excellent pandas library to load and mangle such data:
code :
data_string = """
chr1    35276   35481   NR_026820_exon_1_0_chr1_35277_r 0       -       0.526829        0.473171        54      37      60      54      0       0       205
chr1    35720   36081   NR_026818_exon_2_0_chr1_35721_r 0       -       0.398892        0.601108        73      116     101     71      0       0       361
chr1    35720   36081   NR_026820_exon_2_0_chr1_35721_r 0       -       0.398892        0.601108        73      116     101     71      0       0       361
chr1    69090   70008   NM_001005484_exon_0_0_chr1_69091_f      0       +       0.571895        0.428105        212     218     175     313     0       0       918
chr1    134772  139696  NR_039983_exon_0_0_chr1_134773_r        0       -       0.366775        0.633225        997     1194    1924    809     0       0       4924
chr1    139789  139847  NR_039983_exon_1_0_chr1_139790_r        0       -       0.551724        0.448276        13      12      14      19      0       0       58
chr1    140074  140566  NR_039983_exon_2_0_chr1_140075_r        0       -       0.475610        0.524390        126     144     114     108     0       0       492
chr1    323891  324060  NR_028322_exon_0_0_chr1_323892_f        0       +       0.426035        0.573964        37      41      56      35      0       0       169
chr1    323891  324060  NR_028325_exon_0_0_chr1_323892_f        0       +       0.426035        0.573964        37      41      56      35      0       0       169
chr1    323891  324060  NR_028327_exon_0_0_chr1_323892_f        0       +       0.426035        0.573964        37      41      56      35      0       0       169
chr1    324287  324345  NR_028322_exon_1_0_chr1_324288_f        0       +       0.551724        0.448276        19      15      11      13      0       0       58
chr1    324287  324345  NR_028325_exon_1_0_chr1_324288_f        0       +       0.551724        0.448276        19      15      11      13      0       0       58
chr1    324287  324345  NR_028327_exon_1_0_chr1_324288_f        0       +       0.551724        0.448276        19      15      11      13      0       0       58
chr1    324438  326938  NR_028327_exon_2_0_chr1_324439_f        0       +       0.375200        0.624800        400     1013    549     538     0       0       2500
chr1    324438  328581  NR_028322_exon_2_0_chr1_324439_f        0       +       0.378228        0.621772        678     1580    996     889     0       0       4143
chr1    324438  328581  NR_028325_exon_2_0_chr1_324439_f        0       +       0.378228        0.621772        678     1580    996     889     0       0       4143
"""

# this looks suspicously csv-like

import pandas
import StringIO

buf = StringIO.StringIO(data_string)

# this will create a DataFrame object with header: 0, 1, 2, ...
# if you have the file path, you can use that instead of the StringIO buffer
df = pandas.read_csv(buf, delim_whitespace=True, header=None)

>>> print df

      0       1       2                                   3   4  5         6   \
0   chr1   35276   35481     NR_026820_exon_1_0_chr1_35277_r   0  -  0.526829   
1   chr1   35720   36081     NR_026818_exon_2_0_chr1_35721_r   0  -  0.398892   
2   chr1   35720   36081     NR_026820_exon_2_0_chr1_35721_r   0  -  0.398892   
3   chr1   69090   70008  NM_001005484_exon_0_0_chr1_69091_f   0  +  0.571895   
4   chr1  134772  139696    NR_039983_exon_0_0_chr1_134773_r   0  -  0.366775   
5   chr1  139789  139847    NR_039983_exon_1_0_chr1_139790_r   0  -  0.551724   
6   chr1  140074  140566    NR_039983_exon_2_0_chr1_140075_r   0  -  0.475610   
7   chr1  323891  324060    NR_028322_exon_0_0_chr1_323892_f   0  +  0.426035   
8   chr1  323891  324060    NR_028325_exon_0_0_chr1_323892_f   0  +  0.426035   
9   chr1  323891  324060    NR_028327_exon_0_0_chr1_323892_f   0  +  0.426035   
10  chr1  324287  324345    NR_028322_exon_1_0_chr1_324288_f   0  +  0.551724   
11  chr1  324287  324345    NR_028325_exon_1_0_chr1_324288_f   0  +  0.551724   
12  chr1  324287  324345    NR_028327_exon_1_0_chr1_324288_f   0  +  0.551724   
13  chr1  324438  326938    NR_028327_exon_2_0_chr1_324439_f   0  +  0.375200   
14  chr1  324438  328581    NR_028322_exon_2_0_chr1_324439_f   0  +  0.378228   
15  chr1  324438  328581    NR_028325_exon_2_0_chr1_324439_f   0  +  0.378228  

# ... more data skipped...
# drop duplicates for non-unique sets of values in columns 1, 2 (start, end)
no_dups = df.drop_duplicates([1, 2])

>>> print no_dups
          0       1       2                                   3   4  5         6   \
0   chr1   35276   35481     NR_026820_exon_1_0_chr1_35277_r   0  -  0.526829   
1   chr1   35720   36081     NR_026818_exon_2_0_chr1_35721_r   0  -  0.398892   
3   chr1   69090   70008  NM_001005484_exon_0_0_chr1_69091_f   0  +  0.571895   
4   chr1  134772  139696    NR_039983_exon_0_0_chr1_134773_r   0  -  0.366775   
5   chr1  139789  139847    NR_039983_exon_1_0_chr1_139790_r   0  -  0.551724   
6   chr1  140074  140566    NR_039983_exon_2_0_chr1_140075_r   0  -  0.475610   
7   chr1  323891  324060    NR_028322_exon_0_0_chr1_323892_f   0  +  0.426035   
10  chr1  324287  324345    NR_028322_exon_1_0_chr1_324288_f   0  +  0.551724   
13  chr1  324438  326938    NR_028327_exon_2_0_chr1_324439_f   0  +  0.375200   
14  chr1  324438  328581    NR_028322_exon_2_0_chr1_324439_f   0  +  0.378228 

Combine rows based on multiple columns and keep all unique values


By : Farah Etmeh
Date : March 29 2020, 07:55 AM
wish of those help You can write your own summarization function like
concat_unique <- function(x){paste(unique(x), collapse=',')}
Related Posts Related Posts :
  • How can I get back a previously created Excel ListObject?
  • What API can be used to read OAB Files?
  • In linq to entity, how to retrieve objects matching a list of conditions without looping?
  • RESTful web service in C# code
  • C#, Process.Start hide?
  • Multi resolution
  • Alternatives for Crystal Report
  • Lucene.NET, StandardAnalyzer, stopwords and thread-safety
  • How to implement CCAvenue payment gateway option
  • Silverlight and WCF: NotFound error!
  • C# How can I get a list of country codes?
  • Intellisense - Javascript in a string
  • How to change the opacity value of a 3D object
  • Assembly.ReflectionOnlyLoadFrom not working
  • C# Audio - How to time stretch (different tempo, same pitch)
  • Getting certain lines of text c#
  • Can we display Hyperlink from Javascript alert on ASP.NET Page?
  • Can you see programmatically how much amperage a USB device is requesting in windows?
  • What is a way to do a Generic Repository with Entity Framework 4.0 where I have function imports?
  • C# How to determine if a date is within 180 days of now
  • Programmatically hiding properties in a PropertyGrid
  • How do I get a list of fields returned by an OdbcDataReader?
  • ASP.Net Creating Server Side Posting to external website with redirect
  • Adding a tool bar to a web page
  • Convert Audio file into MP3 format using C#
  • Check if a windows service is running?
  • Assembly re-direction in .NET
  • Parse and filter javascript array
  • How to handle a generic dictionary whose types are unknown and don't matter?
  • Distribute images with C# Setup project
  • Is there a way to publish rdl reports programmatically with C#?
  • How to call base.base.method()?
  • How to install Emgu CV wrapper?
  • Interview question - c#
  • .NET Remoting client config creates local object, not remote
  • Is there a possibility to differ virtual printer from physical one?
  • Print barcode which has high scan rate
  • Query string value having "&"
  • Which is best for perfomance?
  • Can we make overloaded controller method in ASP .NET MVC
  • Nested loop in StringTemplate
  • How to get SSID and RSSI for Win7 using C#
  • Send messages to applications on the network (.Net)
  • Detect and prevent/delay windows mobile power off
  • How X509 Certificate renewal does not impact the code?
  • Silverlight: How to make my custom control act like a button
  • C# basic Dictionary Ordering Just need to clear an error
  • Common c# idioms including coalesce ?? operator
  • Why Does Thread.CurrentThread.CurrentCulture Change between Page Rendering and HttpModule.PostRequestHandlerExecute?
  • COM Exception 0x8004005
  • How do I show a message box from inside a class in a class library?
  • LINQ Distinct Query
  • Issue with number guessing game c#
  • Usage of a using statement
  • Building a forms system using DDD
  • How can I programmatically tell in C# if an unmanaged lib is x86 or x64?
  • How do I get an Excel range using row and column numbers in VSTO / C#?
  • .NET 4.0 Memory Mapped Files Performance
  • db4o Indexing problem - Not Working? Poor performance?
  • Realtime Console Output Redirection using Process
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org